refined and continued the rocket animation, prepared the parachute asset files
This commit is contained in:
parent
5ba7c08b12
commit
bd1faa2f5e
4 changed files with 52 additions and 33 deletions
BIN
assets/parachute.png
Normal file
BIN
assets/parachute.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 542 B |
BIN
assets/rocket_bottom.png
Normal file
BIN
assets/rocket_bottom.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 924 B |
BIN
assets/rocket_top.png
Normal file
BIN
assets/rocket_top.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 429 B |
|
|
@ -59,11 +59,16 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
private boolean hoveringOverQuitButton = false;
|
private boolean hoveringOverQuitButton = false;
|
||||||
|
|
||||||
private BufferedImage rocket;
|
private BufferedImage rocket;
|
||||||
|
private BufferedImage rocketTop;
|
||||||
|
private BufferedImage rocketBottom;
|
||||||
private BufferedImage rocketExhaust;
|
private BufferedImage rocketExhaust;
|
||||||
private int rocketYPre = windowHeight/2-125;
|
private int rocketYPre = windowHeight/2-125;
|
||||||
private int rocketY = windowHeight/2-125;
|
private int rocketY = windowHeight/2-125;
|
||||||
private int rocketExhaustY = rocketY;
|
private int rocketExhaustY = rocketY;
|
||||||
private float opacityAnimation = 0.05f;
|
private int rocketBottomX;
|
||||||
|
private int rocketBottomY;
|
||||||
|
private float opacityAnimation = 0.03f;
|
||||||
|
private int detachTimer = 0;
|
||||||
|
|
||||||
public Game() {
|
public Game() {
|
||||||
// sets the window size
|
// sets the window size
|
||||||
|
|
@ -90,6 +95,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
buttonH = ImageIO.read(new File("assets/button_highlighted.png"));
|
buttonH = ImageIO.read(new File("assets/button_highlighted.png"));
|
||||||
rocket = ImageIO.read(new File("assets/rocket.png"));
|
rocket = ImageIO.read(new File("assets/rocket.png"));
|
||||||
rocketExhaust = ImageIO.read(new File("assets/rocket_exhaust.png"));
|
rocketExhaust = ImageIO.read(new File("assets/rocket_exhaust.png"));
|
||||||
|
rocketTop = ImageIO.read(new File("assets/rocket_top.png"));
|
||||||
|
rocketBottom = ImageIO.read(new File("assets/rocket_bottom.png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +133,7 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (level == 1) { planetY = planetYPre + hoverYOffset / 6; }
|
if (level == 1) { planetY = planetYPre + hoverYOffset / 6; }
|
||||||
if (level == 2) { rocketY = rocketYPre + hoverYOffset / 3; rocketExhaustY = rocketYPre + 150 + hoverYOffset / 2;}
|
if (level == 2) { rocketY = rocketYPre + hoverYOffset / 3; rocketExhaustY = rocketYPre + 150 + hoverYOffset / 2; detachTimer++;}
|
||||||
repaint(); // triggers render
|
repaint(); // triggers render
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,12 +195,22 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
for (int i = 0; i < MENU_STAR_COUNT; i++) { // drawing the stars
|
for (int i = 0; i < MENU_STAR_COUNT; i++) { // drawing the stars
|
||||||
g.fillOval(starX[i]-starSize, starY[i]-starSize, starSize, starSize);
|
g.fillOval(starX[i]-starSize, starY[i]-starSize, starSize, starSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (detachTimer < 240) {
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacityAnimation));
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacityAnimation));
|
||||||
g2.drawImage(rocketExhaust, windowWidth/2-25, rocketExhaustY, 50, 100, this);
|
g2.drawImage(rocketExhaust, windowWidth / 2 - 25, rocketExhaustY, 50, 100, this);
|
||||||
g2.setComposite(AlphaComposite.SrcOver); // reset so nothing else is transparent
|
g2.setComposite(AlphaComposite.SrcOver); // reset so nothing else is transparent
|
||||||
g.drawImage(rocket, windowWidth/2-73, rocketY, 147, 234, this);
|
g.drawImage(rocket, windowWidth / 2 - 73, rocketY, 147, 234, this);
|
||||||
|
} else {
|
||||||
|
g.drawImage(rocketTop, windowWidth / 2 - 73, rocketY - hoverYOffset / 3, 147, 84, this);
|
||||||
|
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
rocketBottomX = windowWidth / 2 - 73;
|
||||||
|
rocketBottomY = rocketY - hoverYOffset / 3 + 64 + (detachTimer - 240) * 2;
|
||||||
|
g2.rotate(Math.toRadians((detachTimer-240)/3), rocketBottomX + 147 / 2, rocketBottomY + 171 / 2);
|
||||||
|
g2.drawImage(rocketBottom, rocketBottomX, rocketBottomY, 147, 171, this);
|
||||||
|
}
|
||||||
|
|
||||||
if (levelProgress) {
|
if (levelProgress) {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
|
@ -223,6 +240,7 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
addMouseListener(new MouseAdapter() {
|
addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
|
if (level == 1) {
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverQuitButton) {
|
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverQuitButton) {
|
||||||
quitButtonX = quitButtonX - 5;
|
quitButtonX = quitButtonX - 5;
|
||||||
quitButtonY = quitButtonY + 5;
|
quitButtonY = quitButtonY + 5;
|
||||||
|
|
@ -232,16 +250,17 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
playButtonY = playButtonY + 5;
|
playButtonY = playButtonY + 5;
|
||||||
}
|
}
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlanet) {
|
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlanet) {
|
||||||
planetX = planetX-5;
|
planetX = planetX - 2;
|
||||||
planetYPre = planetYPre+5;
|
planetYPre = planetYPre + 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addMouseListener(new MouseAdapter() {
|
addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
if (level == 1) {
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverQuitButton) {
|
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverQuitButton) {
|
||||||
quitButtonX = quitButtonX + 5;
|
quitButtonX = quitButtonX + 5;
|
||||||
quitButtonY = quitButtonY - 5;
|
quitButtonY = quitButtonY - 5;
|
||||||
|
|
@ -253,10 +272,10 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
levelProgress = true;
|
levelProgress = true;
|
||||||
}
|
}
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlanet) {
|
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlanet) {
|
||||||
planetX = planetX+5;
|
planetX = planetX + 2;
|
||||||
planetYPre = planetYPre-5;
|
planetYPre = planetYPre - 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue