-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
140 lines (138 loc) · 4.3 KB
/
Menu.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Menu extends MouseAdapter {
private Game game;
private Handler handler;
private HUD hud;
public Menu(Game game, Handler handler, HUD hud) {
this.game = game;
this.hud = hud;
this.handler = handler;
}
public void mousePressed(MouseEvent e) {
//mouse coordinates
int mx = e.getX();
int my = e.getY();
if (game.gameState == Game.STATE.Menu) {
//play button
if (mouseOver(mx,my,225,100,200,75)) {
game.gameState = Game.STATE.Game;
handler.addObject(new Player(Game.WIDTH/10+32,Game.HEIGHT/2+32,ID.Player,handler));
}
//exit button
if (mouseOver(mx,my,225,200,200,75)) {
System.exit(0);
}
if (mouseOver(mx,my,225,300,200,75)) {
game.gameState = Game.STATE.Help;
handler.addObject(new Player(Game.WIDTH/10+32,Game.HEIGHT/2+32,ID.Player,handler));
}
}
if (game.gameState == Game.STATE.GameOver ||game.gameState == Game.STATE.Victory) {
//play button
if (mouseOver(mx,my,210, 170, 200, 64)) {
hud.score(0);
Spawn.resetScoreKeep();
game.gameState = Game.STATE.Game;
handler.addObject(new Player(Game.WIDTH/10+32,Game.HEIGHT/2+32,ID.Player,handler));
}
//menu button
else if (mouseOver(mx,my,210, 270, 200, 64)) {
hud.score(0);
Spawn.resetScoreKeep();
game.gameState = Game.STATE.Menu;
}
//exit button
else if(mouseOver(mx,my,210,370,200, 64)) {
System.exit(0);
}
}
if (game.gameState == Game.STATE.Help) {
if (mouseOver(mx,my,210, 370, 200, 64)) {
hud.score(0);
Spawn.resetScoreKeep();
game.gameState = Game.STATE.Game;
handler.clearEnemies();
handler.addObject(new Player(Game.WIDTH/10+32,Game.HEIGHT/2+32,ID.Player,handler));
}
}
}
//used for menu system logic, determines update of gameState depending on box pressed
private boolean mouseOver(int mx, int my,int x, int y, int width, int height) {
if (mx>x && mx<x+width) {
if (my>y && my<y+height) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
public void render(Graphics g) {
//start menu screen
if (game.gameState == Game.STATE.Menu) {
Font fnt = new Font("arial",50,50);
g.setColor(Color.yellow);
g.setFont(fnt);
g.drawRect(225,100,200,75);
g.drawString("Play",270,155);
g.drawRect(225,200,200,75);
g.drawString("Quit",270,255);
g.drawRect(225,300,200,75);
g.drawString("Help",270,355);
}
//gameOver screen
else if (game.gameState == Game.STATE.GameOver) {
Font fnt = new Font("arial",50,50);
Font fnt2 = new Font("arial", 25,25);
g.setColor(Color.yellow);
g.setFont(fnt);
g.drawString("Game Over", 183, 70);
g.setFont(fnt2);
g.drawString("You lost with a score of: "+hud.getScore(), 160, 140);
g.drawRect(210, 370, 200, 64);
g.drawRect(210, 270, 200, 64);
g.drawRect(210, 170 ,200, 64);
g.drawString("Try Again", 255, 210);
g.drawString("Return to Menu", 225, 310);
g.drawString("Quit", 285, 410);
}
//victory screen
else if(game.gameState == Game.STATE.Victory) {
Font fnt = new Font("arial",50,50);
Font fnt2 = new Font("arial", 25,25);
g.setColor(Color.yellow);
g.setFont(fnt);
g.drawString("Victory!", 230, 70);
g.setFont(fnt2);
g.drawString("You've beaten the enemies!", 160, 140);
g.drawRect(210, 370, 200, 64);
g.drawRect(210, 270, 200, 64);
g.drawRect(210, 170 ,200, 64);
g.drawString("Play Again", 255, 210);
g.drawString("Return to Menu", 225, 310);
g.drawString("Quit", 285, 410);
}
else if(game.gameState == Game.gameState.Help) {
Font fnt = new Font("arial",35,35);
Font fnt2 = new Font("arial", 25,25);
g.setColor(Color.yellow);
g.setFont(fnt);
g.drawString("Survive and beat 3000 points to win!", 35, 70);
g.setFont(fnt2);
g.drawString("Use arrow keys to move & space-bar to shoot", 55, 120);
g.drawString("Every enemy shot, you receive 50 points", 75, 170);
g.drawString("Every 60 seconds, you receive 500 points bonus!", 50, 220);
g.drawRect(210, 370, 200, 64);
g.setFont(fnt);
g.drawString("Play", 280, 410);
}
}
public void mouseReleased(MouseEvent e) {}
}