Compare commits
2 commits
501cdba995
...
82104f7859
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82104f7859 | ||
|
|
86118d7e2e |
3 changed files with 45 additions and 4 deletions
BIN
assets/button.png
Normal file
BIN
assets/button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
assets/button_highlighted.png
Normal file
BIN
assets/button_highlighted.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
|
|
@ -29,11 +29,23 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
private int planetYOffset = 0;
|
||||
private String planetYOffsetDirection = "up"; // this makes the cool floating animation on the main menu
|
||||
private int planetX = 580;
|
||||
private int planetY = 120+ planetYOffset /6;
|
||||
private int planetY = 140 + planetYOffset /6;
|
||||
private int planetSize = 128*3;
|
||||
private Rectangle planetCollision = new Rectangle(planetX, planetY, planetSize, planetSize);
|
||||
private boolean hoveringOverPlanet = false;
|
||||
|
||||
private BufferedImage button;
|
||||
private BufferedImage buttonh;
|
||||
private int buttonX = 130;
|
||||
private int playButtonY = 210;
|
||||
private int quitButtonY = 350;
|
||||
private int buttonWidth = 108*3;
|
||||
private int buttonHeight = 108;
|
||||
private Rectangle playButtonCollision = new Rectangle(buttonX, playButtonY, buttonWidth, buttonHeight);
|
||||
private Rectangle quitButtonCollision = new Rectangle(buttonX, quitButtonY, buttonWidth, buttonHeight);
|
||||
private boolean hoveringOverPlayButton = false;
|
||||
private boolean hoveringOverQuitButton = false;
|
||||
|
||||
public Game() {
|
||||
// sets the window size
|
||||
setPreferredSize(new Dimension(windowWidth,windowHeight));
|
||||
|
|
@ -54,6 +66,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
try {
|
||||
planetZX311 = ImageIO.read(new File("assets/planet-ZX311.png"));
|
||||
planetZX311h = ImageIO.read(new File("assets/planet-ZX311_highlighted.png"));
|
||||
button = ImageIO.read(new File("assets/button.png"));
|
||||
buttonh = ImageIO.read(new File("assets/button_highlighted.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -77,6 +91,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) { // update step
|
||||
hoveringOverPlanet = planetCollision.contains(mouseX, mouseY);
|
||||
hoveringOverPlayButton = playButtonCollision.contains(mouseX, mouseY);
|
||||
hoveringOverQuitButton = quitButtonCollision.contains(mouseX, mouseY);
|
||||
if (planetYOffsetDirection == "up") {
|
||||
planetYOffset++;
|
||||
if (planetYOffset > 90) {
|
||||
|
|
@ -88,7 +104,7 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
planetYOffsetDirection = "up";
|
||||
}
|
||||
}
|
||||
planetY = 120+ planetYOffset /6;
|
||||
planetY = 140 + planetYOffset /6;
|
||||
repaint(); // triggers render
|
||||
}
|
||||
|
||||
|
|
@ -102,8 +118,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
}
|
||||
|
||||
g.setColor(Color.GRAY);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 96f));
|
||||
g.drawString("Very Cool Space Sim", 136, 96);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 100f));
|
||||
g.drawString("Very Cool Space Sim", 40, 100);
|
||||
|
||||
if (planetZX311 != null) {
|
||||
if (!hoveringOverPlanet) {
|
||||
|
|
@ -112,6 +128,31 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
g.drawImage(planetZX311h, planetX, planetY, planetSize, planetSize, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (button != null) {
|
||||
if (!hoveringOverPlayButton) {
|
||||
g.drawImage(button, buttonX, playButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 48f));
|
||||
g.drawString("Start the game", buttonX+25, playButtonY+67);
|
||||
} else {
|
||||
g.drawImage(buttonh, buttonX, playButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 48f));
|
||||
g.drawString("Start the game", buttonX+25, playButtonY+67);
|
||||
}
|
||||
if (!hoveringOverQuitButton) {
|
||||
g.drawImage(button, buttonX, quitButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 40f));
|
||||
g.drawString("Quit (pretty lame)", buttonX+24, quitButtonY+67);
|
||||
} else {
|
||||
g.drawImage(buttonh, buttonX, quitButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 40f));
|
||||
g.drawString("Quit (pretty lame)", buttonX+24, quitButtonY+67);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue