-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenu.java
More file actions
81 lines (67 loc) · 2.15 KB
/
Menu.java
File metadata and controls
81 lines (67 loc) · 2.15 KB
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
72
73
74
75
76
77
78
79
80
81
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class Menu extends MouseAdapter{
private boolean playTutorial = true;
private int score = 0;
private Button bPlay = new Button(250,280,300,60),
bQuit = new Button(250,360,300,60),
bContinue = new Button(40,410,300,60),
bLeave = new Button(460,410,300,60);
private Handler handler;
private Game game;
int mx = 0, my = 0;
public Menu(Game game, Handler handler) {
this.game = game;
this.handler = handler;
}
public void mousePressed(MouseEvent e) {
mx = e.getX();
my = e.getY();
// System.out.println(mx+" "+my);
}
public void mouseReleased(MouseEvent e) {
if (Game.gameState == State.Menu) {
if (bPlay.mouseOver(mx, my)) {
game.startLevel();
if (playTutorial) {
playTutorial = false;
Game.gameState = State.Tutorial;
}
else {
game.loadLobby();
Game.gameState = State.Lobby;
}
}
if (bQuit.mouseOver(mx, my)) {
game.close();
}
}
if (Game.gameState == State.GameOver) {
if (bContinue.mouseOver(mx, my)) {
game.startLevel();
game.loadLobby();
Game.gameState = State.Lobby;
}
if (bLeave.mouseOver(mx, my)) {
Game.gameState = State.Menu;
}
}
}
public void tick() {
}
public void render(Graphics g) {
if (Game.gameState == State.GameOver) {
g.setColor(Color.white);
g.setFont(new Font("8BIT WONDER", Font.PLAIN, 40));
g.drawString("SCORE",150,335);
g.drawString(String.format("%05d", score), 450, 335);
}
}
public void setScore(int score) {
this.score = score;
}
}