I really needed to perfect the main menu bro..
This commit is contained in:
parent
b4b03de400
commit
d49011edec
1 changed files with 39 additions and 19 deletions
|
|
@ -14,12 +14,18 @@ import java.util.Random;
|
|||
|
||||
|
||||
public class Game extends JPanel implements ActionListener, KeyListener {
|
||||
private final int windowWidth = 1000;
|
||||
private final int windowHeight = 600;
|
||||
private final int MENU_STAR_COUNT = 64;
|
||||
// defines the window dimensions
|
||||
private final int windowWidth = 900;
|
||||
private final int windowHeight = 550;
|
||||
// defines the star count for the main menu and also creates the arrays for the star positions
|
||||
private final int MENU_STAR_COUNT = 96;
|
||||
private final int[] starX = new int[MENU_STAR_COUNT];
|
||||
private final int[] starY = new int[MENU_STAR_COUNT];
|
||||
|
||||
private int starSize = 1;
|
||||
|
||||
private final Timer timer = new Timer(16, this); // 60 FPS
|
||||
|
||||
private Font caveat;
|
||||
|
||||
private int level = 1;
|
||||
|
|
@ -30,7 +36,7 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
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 planetX = 450;
|
||||
private int planetYPre = 140;
|
||||
private int planetY = planetYPre + planetYOffset /6;
|
||||
private int planetSize = 128*3;
|
||||
|
|
@ -39,13 +45,14 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
|
||||
private BufferedImage button;
|
||||
private BufferedImage buttonH;
|
||||
private int buttonX = 130;
|
||||
private int playButtonX = 70;
|
||||
private int quitButtonX = 70;
|
||||
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 Rectangle playButtonCollision = new Rectangle(playButtonX, playButtonY, buttonWidth, buttonHeight);
|
||||
private Rectangle quitButtonCollision = new Rectangle(quitButtonX, quitButtonY, buttonWidth, buttonHeight);
|
||||
private boolean hoveringOverPlayButton = false;
|
||||
private boolean hoveringOverQuitButton = false;
|
||||
|
||||
|
|
@ -112,12 +119,13 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
g.setColor(Color.WHITE);
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < MENU_STAR_COUNT; i++) { // drawing the stars
|
||||
g.fillOval(starX[i], starY[i], rand.nextInt(1,3), rand.nextInt(1,2));
|
||||
starSize = rand.nextInt(1,3);
|
||||
g.fillOval(starX[i]-starSize, starY[i]-starSize, starSize, starSize);
|
||||
}
|
||||
|
||||
g.setColor(Color.GRAY);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 100f));
|
||||
g.drawString("Very Cool Space Sim", 40, 100);
|
||||
g.drawString("Very Cool Space Sim", 72, 100);
|
||||
|
||||
if (planetZX311 != null) {
|
||||
if (!hoveringOverPlanet) {
|
||||
|
|
@ -129,26 +137,26 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
|
||||
if (button != null) {
|
||||
if (!hoveringOverPlayButton) {
|
||||
g.drawImage(button, buttonX, playButtonY, buttonWidth, buttonHeight, this);
|
||||
g.drawImage(button, playButtonX, playButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 48f));
|
||||
g.drawString("Start the game", buttonX+25, playButtonY+67);
|
||||
g.drawString("Start the game", playButtonX +25, playButtonY+67);
|
||||
} else {
|
||||
g.drawImage(buttonH, buttonX, playButtonY, buttonWidth, buttonHeight, this);
|
||||
g.drawImage(buttonH, playButtonX, playButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 48f));
|
||||
g.drawString("Start the game", buttonX+25, playButtonY+67);
|
||||
g.drawString("Start the game", playButtonX +25, playButtonY+67);
|
||||
}
|
||||
if (!hoveringOverQuitButton) {
|
||||
g.drawImage(button, buttonX, quitButtonY, buttonWidth, buttonHeight, this);
|
||||
g.drawImage(button, quitButtonX, quitButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 40f));
|
||||
g.drawString("Quit (pretty lame)", buttonX+24, quitButtonY+67);
|
||||
g.drawString("Quit (pretty lame)", quitButtonX +24, quitButtonY+67);
|
||||
} else {
|
||||
g.drawImage(buttonH, buttonX, quitButtonY, buttonWidth, buttonHeight, this);
|
||||
g.drawImage(buttonH, quitButtonX, quitButtonY, buttonWidth, buttonHeight, this);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setFont(caveat.deriveFont(Font.BOLD, 40f));
|
||||
g.drawString("Quit (pretty lame)", buttonX+24, quitButtonY+67);
|
||||
g.drawString("Quit (pretty lame)", quitButtonX +24, quitButtonY+67);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -174,10 +182,12 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverQuitButton) {
|
||||
System.exit(0);
|
||||
quitButtonX = quitButtonX - 5;
|
||||
quitButtonY = quitButtonY + 5;
|
||||
}
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlayButton) {
|
||||
level = 2;
|
||||
playButtonX = playButtonX - 5;
|
||||
playButtonY = playButtonY + 5;
|
||||
}
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlanet) {
|
||||
planetX = planetX-5;
|
||||
|
|
@ -190,6 +200,16 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
|||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverQuitButton) {
|
||||
quitButtonX = quitButtonX + 5;
|
||||
quitButtonY = quitButtonY - 5;
|
||||
System.exit(0);
|
||||
}
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlayButton) {
|
||||
playButtonX = playButtonX + 5;
|
||||
playButtonY = playButtonY - 5;
|
||||
level = 2;
|
||||
}
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && hoveringOverPlanet) {
|
||||
planetX = planetX+5;
|
||||
planetYPre = planetYPre-5;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue