diff --git a/assets/button.png b/assets/button.png new file mode 100644 index 0000000..87cb911 Binary files /dev/null and b/assets/button.png differ diff --git a/assets/button_highlighted.png b/assets/button_highlighted.png new file mode 100644 index 0000000..d83f05d Binary files /dev/null and b/assets/button_highlighted.png differ diff --git a/src/main/java/dev/dvorakmortonxd/Game.java b/src/main/java/dev/dvorakmortonxd/Game.java index b7c65a2..9f3a65b 100644 --- a/src/main/java/dev/dvorakmortonxd/Game.java +++ b/src/main/java/dev/dvorakmortonxd/Game.java @@ -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