-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMenu.java
executable file
·71 lines (60 loc) · 2.27 KB
/
MainMenu.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class MainMenu implements Interactive
{
// Background image
private BufferedImage splashImage;
// Width and height for both buttons
private final int bW = (int) (237 / SCALE), bH = (int) (70 / SCALE);
// New Game Button
private BufferedImage newGameButton;
private final int ngX = (int) (478 / SCALE), ngY = (int) (300 / SCALE);
// How To Play Button
private BufferedImage howToButton;
private final int hpX = (int) (478 / SCALE), hpY = (int) (400 / SCALE);
public MainMenu()
{
try
{
splashImage = GamePanel.getImageFromFile("/img/splash.png");
newGameButton = GamePanel.getImageFromFile("/img/newgame-button.png");
howToButton = GamePanel.getImageFromFile("/img/how-to-play-button.png");
} catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public int render(Graphics2D g2d)
{
AffineTransform universalScale = new AffineTransform();
universalScale.scale(SCALE, SCALE);
g2d.drawImage(splashImage, universalScale, null);
AffineTransform newGameTrans = new AffineTransform();
newGameTrans.setToTranslation(ngX * SCALE, ngY * SCALE);
newGameTrans.scale(SCALE, SCALE);
g2d.drawImage(newGameButton, newGameTrans, null);
AffineTransform howToTrans = new AffineTransform();
howToTrans.setToTranslation(hpX * SCALE, hpY * SCALE);
howToTrans.scale(SCALE, SCALE);
g2d.drawImage(howToButton, howToTrans, null);
Point p = Mouse.getClickBuffer();
// Process click of "New Game"
if (p.getX() >= ngX * SCALE && p.getX() <= ngX * SCALE + bW * SCALE
&& p.getY() >= ngY * SCALE && p.getY() <= ngY * SCALE + bH * SCALE)
{
return PLAY_MENU;
}
// Process click of "How To Play"
else if (p.getX() >= hpX * SCALE && p.getX() <= hpX * SCALE + bW * SCALE
&& p.getY() >= hpY * SCALE && p.getY() <= hpY * SCALE + bH * SCALE)
{
return HOW_TO_PLAY;
}
return NO_CHANGE;
}
}