Finished the main menu :)
This commit is contained in:
parent
501cdba995
commit
86118d7e2e
6 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.png-autosave.kra
Normal file
BIN
assets/button.png-autosave.kra
Normal file
Binary file not shown.
BIN
assets/button.png~
Normal file
BIN
assets/button.png~
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 908 B |
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 |
BIN
assets/button_highlighted.png~
Normal file
BIN
assets/button_highlighted.png~
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 908 B |
|
|
@ -29,11 +29,23 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
private int planetYOffset = 0;
|
private int planetYOffset = 0;
|
||||||
private String planetYOffsetDirection = "up"; // this makes the cool floating animation on the main menu
|
private String planetYOffsetDirection = "up"; // this makes the cool floating animation on the main menu
|
||||||
private int planetX = 580;
|
private int planetX = 580;
|
||||||
private int planetY = 120+ planetYOffset /6;
|
private int planetY = 140 + planetYOffset /6;
|
||||||
private int planetSize = 128*3;
|
private int planetSize = 128*3;
|
||||||
private Rectangle planetCollision = new Rectangle(planetX, planetY, planetSize, planetSize);
|
private Rectangle planetCollision = new Rectangle(planetX, planetY, planetSize, planetSize);
|
||||||
private boolean hoveringOverPlanet = false;
|
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() {
|
public Game() {
|
||||||
// sets the window size
|
// sets the window size
|
||||||
setPreferredSize(new Dimension(windowWidth,windowHeight));
|
setPreferredSize(new Dimension(windowWidth,windowHeight));
|
||||||
|
|
@ -54,6 +66,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
try {
|
try {
|
||||||
planetZX311 = ImageIO.read(new File("assets/planet-ZX311.png"));
|
planetZX311 = ImageIO.read(new File("assets/planet-ZX311.png"));
|
||||||
planetZX311h = ImageIO.read(new File("assets/planet-ZX311_highlighted.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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +91,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) { // update step
|
public void actionPerformed(ActionEvent e) { // update step
|
||||||
hoveringOverPlanet = planetCollision.contains(mouseX, mouseY);
|
hoveringOverPlanet = planetCollision.contains(mouseX, mouseY);
|
||||||
|
hoveringOverPlayButton = playButtonCollision.contains(mouseX, mouseY);
|
||||||
|
hoveringOverQuitButton = quitButtonCollision.contains(mouseX, mouseY);
|
||||||
if (planetYOffsetDirection == "up") {
|
if (planetYOffsetDirection == "up") {
|
||||||
planetYOffset++;
|
planetYOffset++;
|
||||||
if (planetYOffset > 90) {
|
if (planetYOffset > 90) {
|
||||||
|
|
@ -88,7 +104,7 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
planetYOffsetDirection = "up";
|
planetYOffsetDirection = "up";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
planetY = 120+ planetYOffset /6;
|
planetY = 140 + planetYOffset /6;
|
||||||
repaint(); // triggers render
|
repaint(); // triggers render
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,8 +118,8 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setColor(Color.GRAY);
|
g.setColor(Color.GRAY);
|
||||||
g.setFont(caveat.deriveFont(Font.BOLD, 96f));
|
g.setFont(caveat.deriveFont(Font.BOLD, 100f));
|
||||||
g.drawString("Very Cool Space Sim", 136, 96);
|
g.drawString("Very Cool Space Sim", 40, 100);
|
||||||
|
|
||||||
if (planetZX311 != null) {
|
if (planetZX311 != null) {
|
||||||
if (!hoveringOverPlanet) {
|
if (!hoveringOverPlanet) {
|
||||||
|
|
@ -112,6 +128,31 @@ public class Game extends JPanel implements ActionListener, KeyListener {
|
||||||
g.drawImage(planetZX311h, planetX, planetY, planetSize, planetSize, this);
|
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
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue