-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.java
More file actions
175 lines (129 loc) · 4.99 KB
/
Menu.java
File metadata and controls
175 lines (129 loc) · 4.99 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//Kaushik Siruvuri, Ishaan Sharma, Supreet Mishra
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Random;
public class Menu extends MouseAdapter {
private Game game;
private Handler handler;
private HUD hud;
private Random r = new Random();
public Menu(Game game, Handler handler, HUD hud) {
this.game = game;
this.hud = hud;
this.handler = handler;
}
public void mousePressed(MouseEvent e) {
int mx = e.getX();
int my = e.getY();
if (game.gameState == Game.STATE.MENU) {
//play button
if (mouseOver(mx, my, 210, 150, 200, 64)) {
game.gameState = Game.STATE.GAME;
hud.setLevel(1);
hud.setScore(0);
handler.clearEnemies();
handler.addObject(new Player(Game.WIDTH / 2 - 32, 400, ID.Player, handler));
for(int h = 0; h < 3; h++) {
for (int c = 0; c < 10; c++) {
handler.addObject(new BasicEnemy(50 + (50 * c), 50+(50*h), ID.BasicEnemy, handler));
}
}
}
//help button
if (mouseOver(mx, my, 210, 250, 200, 64)) {
game.gameState = Game.STATE.HELP;
}
//quit button
if (mouseOver(mx, my, 210, 350, 200, 64)) {
System.exit(1);
}
}
// Back button for help
if (game.gameState == Game.STATE.HELP) {
if (mouseOver(mx, my, 210, 350, 200, 64)) {
game.gameState = Game.STATE.MENU;
return;
}
}
// Back button for END
if (game.gameState == Game.STATE.END) {
if (mouseOver(mx, my, 210, 350, 200, 64)) {
game.gameState = Game.STATE.MENU;
return;
}
}
if (game.gameState == Game.STATE.WIN) {
if (mouseOver(mx, my, 210, 350, 200, 64)) {
game.gameState = Game.STATE.MENU;
return;
}
}
}
public void mouseReleased(MouseEvent e) {
}
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 tick() {
}
public void render(Graphics g) {
if (game.gameState == Game.STATE.MENU) {
Font fnt = new Font("arial", 1, 40);
Font fnt2 = new Font("arial", 1, 30);
g.setFont(fnt);
g.setColor(Color.white);
g.drawString("Social Distancing Invaders!", 60, 80);
g.setFont(fnt2);
g.drawRect(210, 150, 200, 64);
g.drawString("Play", 270, 190);
g.drawRect(210, 250, 200, 64);
g.drawString("Help", 270, 290);
g.drawRect(210, 350, 200, 64);
g.drawString("Quit", 270, 390);
} else if (game.gameState == Game.STATE.HELP) {
Font fnt = new Font("arial", 1, 50);
Font fnt2 = new Font("arial", 1, 30);
Font fnt3 = new Font("arial", 1, 20);
g.setFont(fnt);
g.setColor(Color.white);
g.drawString("Help", 240, 70);
g.setFont(fnt3);
g.drawString("Use the Left and Right Arrow keys to Move Your Ship!", 70, 150);
g.drawString("Use Space to Shoot Down Enemy Ships!", 130, 225);
g.drawString("The Game Ends When You Get Hit Three Times!", 100, 300);
g.setFont(fnt2);
g.drawRect(210, 350, 200, 64);
g.drawString("Back", 270, 390);
} else if (game.gameState == Game.STATE.END) {
Font fnt = new Font("arial", 1, 50);
Font fnt2 = new Font("arial", 1, 30);
Font fnt3 = new Font("arial", 1, 20);
g.setFont(fnt);
g.setColor(Color.white);
g.drawString("Game over", 200, 70);
g.setFont(fnt3);
g.drawString("You lost with a score of " + hud.getScore() + " at level " + hud.getLevel(), 140, 200);
g.setFont(fnt2);
g.drawRect(210, 350, 200, 64);
g.drawString("Try Again", 240, 395);
} else if (game.gameState == Game.STATE.WIN) {
Font fnt = new Font("arial", 1, 50);
Font fnt2 = new Font("arial", 1, 30);
Font fnt3 = new Font("arial", 1, 20);
g.setFont(fnt);
g.setColor(Color.white);
g.drawString("You WON!", 200, 70);
g.setFont(fnt3);
g.drawString("You won with a score of " + hud.getScore() + " at level " + hud.getLevel(), 140, 200);
g.drawString("You are officially virus free!", 200,300);
g.setFont(fnt2);
g.drawRect(210, 350, 200, 64);
g.drawString("Menu", 240, 395);
}
}
}