diff --git a/assets/planet-ZX311_highlighted.png b/assets/planet-ZX311_highlighted.png new file mode 100644 index 0000000..dc4704a Binary files /dev/null and b/assets/planet-ZX311_highlighted.png differ diff --git a/src/main/java/dev/dvorakmortonxd/Game.java b/src/main/java/dev/dvorakmortonxd/Game.java index afb09b7..b7c65a2 100644 --- a/src/main/java/dev/dvorakmortonxd/Game.java +++ b/src/main/java/dev/dvorakmortonxd/Game.java @@ -11,23 +11,37 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.util.Random; + + public class Game extends JPanel implements ActionListener, KeyListener { - private final int MENU_STAR_COUNT = 75; + private final int windowWidth = 1000; + private final int windowHeight = 600; + private final int MENU_STAR_COUNT = 256; private final int[] starX = new int[MENU_STAR_COUNT]; private final int[] starY = new int[MENU_STAR_COUNT]; private final Timer timer = new Timer(16, this); // 60 FPS private Font caveat; + + private int mouseX, mouseY; + private BufferedImage planetZX311; - private int planetfloat = 0; - private String planetfloatDirection = "up"; // this makes the cool floating animation on the main menu + private BufferedImage planetZX311h; + 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 planetSize = 128*3; + private Rectangle planetCollision = new Rectangle(planetX, planetY, planetSize, planetSize); + private boolean hoveringOverPlanet = false; + public Game() { // sets the window size - setPreferredSize(new Dimension(800,600)); + setPreferredSize(new Dimension(windowWidth,windowHeight)); // sets the star count for the main menu Random rand = new Random(); for (int i = 0; i < MENU_STAR_COUNT; i++) { - starX[i] = rand.nextInt(800); - starY[i] = rand.nextInt(600); + starX[i] = rand.nextInt(windowWidth); + starY[i] = rand.nextInt(windowHeight); } // loads up the fonts try { @@ -39,29 +53,42 @@ public class Game extends JPanel implements ActionListener, KeyListener { // loads up the image assets try { planetZX311 = ImageIO.read(new File("assets/planet-ZX311.png")); + planetZX311h = ImageIO.read(new File("assets/planet-ZX311_highlighted.png")); } catch (IOException e) { e.printStackTrace(); } + addMouseMotionListener(new MouseAdapter() { + @Override + public void mouseMoved(MouseEvent e) { + mouseX = e.getX(); + mouseY = e.getY(); + } + }); + setBackground(Color.BLACK); setFocusable(true); addKeyListener(this); timer.start(); } + + @Override public void actionPerformed(ActionEvent e) { // update step - if (planetfloatDirection == "up") { - planetfloat++; - if (planetfloat > 45) { - planetfloatDirection = "down"; + hoveringOverPlanet = planetCollision.contains(mouseX, mouseY); + if (planetYOffsetDirection == "up") { + planetYOffset++; + if (planetYOffset > 90) { + planetYOffsetDirection = "down"; } } else { - planetfloat--; - if (planetfloat < 0) { - planetfloatDirection = "up"; + planetYOffset--; + if (planetYOffset <= 0) { + planetYOffsetDirection = "up"; } } + planetY = 120+ planetYOffset /6; repaint(); // triggers render } @@ -75,11 +102,15 @@ public class Game extends JPanel implements ActionListener, KeyListener { } g.setColor(Color.GRAY); - g.setFont(caveat.deriveFont(Font.BOLD, 72f)); - g.drawString("Very Cool Space Sim", 120, 80); + g.setFont(caveat.deriveFont(Font.BOLD, 96f)); + g.drawString("Very Cool Space Sim", 136, 96); if (planetZX311 != null) { - g.drawImage(planetZX311, 375, 150+planetfloat/3, 128*3, 128*3, this); + if (!hoveringOverPlanet) { + g.drawImage(planetZX311, planetX, planetY, planetSize, planetSize, this); + } else { + g.drawImage(planetZX311h, planetX, planetY, planetSize, planetSize, this); + } } }