-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenu.java
319 lines (314 loc) · 11.1 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import java.awt.Color;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.Image;
class MainMenu {
//BufferedImage menubuffer = myImage;//new BufferedImage (WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
//Graphics myBuffer = menubuffer.createGraphics();
int selected=0;
double xScale;
double yScale;
GWar world;
int menustatus=0;//0-main 1-help 2-alt
final static int STATUS_MAIN=0;
final static int STATUS_HELP=1;
final static int STATUS_ALT=2;
int numPlayers=1;
int oldnumPlayers=2;
int[] pNumPlayers = {1,2,3};
int[] pHP = {1,2,3,4,5,10};
int HPIndex=4;
int PlayerSizeSel=25;
int PelletSizeSel=5;
int LevelSel=1;
int numAI=1;
int numNick=0;
final int ListSize=7;
final int AltListSize=5;
final int spacebetweenlines = 25;
final int xoffset = 30;
final int yoffset = 120;
final int tabspace = 85;
final int HEIGHT=400;
final int WIDTH=600;
boolean ismusic=true;
//final String[] menuTitles new String[]{"Start", "# Human Players:", "# AI Players:", "Lives:", "Level:", "Toggle Fullscreen Mode (experimental)", "Help", "Exit"};
//final String[][] menuChoices = {{},{"0","1","2","3"},{"0","1","2","3"},{"1","2","3","4","5"},{"Battlefield","FD","new"},{},{}};
Image helpscreen;
//Image background;
MainMenu(GWar parent, double xs, double ys){
world=parent;
xScale=xs;
yScale=ys;
helpscreen = new ImageIcon(getClass().getClassLoader().getResource("data/helpscreen.PNG")).getImage();
//background = new ImageIcon(getClass().getClassLoader().getResource("background.PNG")).getImage();
//drawB();
}
void show(){
world.newBackgroundGame(numPlayers+numAI,numNick);
world.running=2;
}
void updateScreenInfo(double xs, double ys){
xScale=xs;
yScale=ys;
}
/*void draw(Graphics g){
if (helpshowing==true){
g.drawImage(helpscreen,0,0,null);
}
else{
g.drawImage(menubuffer,0,0,null);
}
}*/
void drawB(java.awt.Graphics myBuffer){
myBuffer.setFont(new Font("SansSerif",Font.BOLD,(int)(15*yScale)));
if (menustatus==STATUS_HELP){
myBuffer.drawImage(helpscreen,0,0,(int)(WIDTH*xScale),(int)(HEIGHT*yScale),null);
}
else if (menustatus==STATUS_ALT){
int counter = 0;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Back",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
myBuffer.setColor(new Color(0.0f,0.0f,0.8f,0.3f));
myBuffer.fillRect((int)(xScale*(tabspace*4.75+xoffset)),90,150,200);
setSelectedColor(myBuffer,0,0);
counter++;
int k;
for (k=0;k<numPlayers;k++){
myBuffer.setColor(GWar.PCOLOR[k]);
myBuffer.drawString("Human Player",(int)(xScale*(tabspace*5+xoffset)),(int)(yScale*((counter+k)*spacebetweenlines+yoffset)));
}
for (;k<numPlayers+numAI;k++){
myBuffer.setColor(GWar.PCOLOR[k]);
myBuffer.drawString("AI Player",(int)(xScale*(tabspace*5+xoffset)),(int)(yScale*((counter+k)*spacebetweenlines+yoffset)));
}
for (;k<numPlayers+numAI+numNick;k++){
myBuffer.setColor(GWar.PCOLOR[k]);
myBuffer.drawString("NickAI Player",(int)(xScale*(tabspace*5+xoffset)),(int)(yScale*((counter+k)*spacebetweenlines+yoffset)));
}
k=-1;
if(numPlayers+numAI+numNick<=1)
myBuffer.setColor(Color.GREEN);
else if(numPlayers+numAI+numNick>=6)
myBuffer.setColor(Color.RED);
else
myBuffer.setColor(Color.YELLOW);
myBuffer.drawString("PlayerList: ("+(numPlayers+numAI+numNick)+")",(int)(xScale*(tabspace*5+xoffset)),(int)(yScale*((counter+k)*spacebetweenlines+yoffset)));
counter = 1;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Add Human Player",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
//setSelectedColor(numPlayers,0);
//setSelectedColor(0,0);
//myBuffer.drawString(numPlayers+"",(int)(xScale*(tabspace*2+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 2;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Add AI Player",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
//setSelectedColor(numAI,0);
//setSelectedColor(0,0);
//myBuffer.drawString(numAI+"",(int)(xScale*(tabspace*2+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 3;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Add NickAI Player",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
//setSelectedColor(numAI,0);
//setSelectedColor(0,0);
//myBuffer.drawString(numNick+"",(int)(xScale*(tabspace*2+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 4;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Lives:",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,pHP[HPIndex],1);
setSelectedColor(myBuffer,0,0);
myBuffer.drawString(pHP[HPIndex]+"",(int)(xScale*(tabspace+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
}
else{
int counter = 0;
myBuffer.setFont(new Font("SansSerif",Font.BOLD,(int)(75*yScale)));
myBuffer.setColor(new Color(0,255,255));
myBuffer.drawString("GWar!",(int)(xoffset*xScale),(int)((spacebetweenlines+60)*yScale));
myBuffer.setFont(new Font("SansSerif",Font.BOLD,(int)(15*yScale)));
/*myBuffer.setColor(Color.BLACK);
myBuffer.fillRect(0,0,WIDTH,HEIGHT);*/
//myBuffer.drawImage(background,0,0,null);
setSelectedColor(myBuffer,counter,selected);
counter = 0;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Start",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 1;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Level:",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,LevelSel,1);
myBuffer.drawString("Totally Original",(int)(xScale*(tabspace+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,LevelSel,2);
myBuffer.drawString("Even Ground",(int)(xScale*(tabspace*3+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,LevelSel,3);
myBuffer.drawString("Overlook",(int)(xScale*(tabspace*5+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,LevelSel,4);
myBuffer.drawString("Islands",(int)(xScale*(tabspace*6+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 2;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Game Setup ... (Human: "+numPlayers+", AI: "+(numAI+numNick)+", Lives:"+pHP[HPIndex]+")",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 3;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Toggle Fullscreen Mode",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 4;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Music:",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,ismusic,true);
myBuffer.drawString("On",(int)(xScale*(tabspace+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,ismusic,false);
myBuffer.drawString("Off",(int)(xScale*(tabspace*2+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 5;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Help",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
counter = 6;
setSelectedColor(myBuffer,counter,selected);
myBuffer.drawString("Exit",(int)(xScale*(0+xoffset)),(int)(yScale*(counter*spacebetweenlines+yoffset)));
setSelectedColor(myBuffer,counter,-1);
myBuffer.setColor(new Color(0,255,255));
myBuffer.drawString("Music by RoeTaKa -- OverClocked ReMix (www.ocremix.org)",(int)(xScale*(0+xoffset)),(int)(yScale*(HEIGHT-45)));
myBuffer.drawString("By Daniel Johnson (johnmon2) for TJGames.org",(int)(xScale*(0+xoffset)),(int)(yScale*(HEIGHT-25)));
myBuffer.drawString("Licensed under GNU GPL 2",(int)(xScale*(0+xoffset)),(int)(yScale*(HEIGHT-5)));
}
//drawPlayer(myBuffer,1,15,selected*spacebetweenlines+yoffset-7,90,0,25,true);
}
void setSelectedColor(java.awt.Graphics myBuffer, int var1,int con1){
if (var1==con1){
myBuffer.setColor(Color.yellow);
}
else{
myBuffer.setColor(Color.white);
}
}
void setSelectedColor(java.awt.Graphics myBuffer, boolean var1,boolean con1){
if (var1==con1){
myBuffer.setColor(Color.yellow);
}
else{
myBuffer.setColor(Color.white);
}
}
void moveUp(){
selected--;
if (selected < 0){
if(menustatus==STATUS_ALT)
selected=AltListSize-1;
else
selected=ListSize-1;
}
//drawB();
}
void moveDown(){
selected++;
if(menustatus==STATUS_ALT){
if (selected >= AltListSize)
selected=0;
}
else if (selected >= ListSize){
selected=0;
}
//drawB();
}
void newGameCurrentSettings(){
world.loadLevel(LevelSel-1);
world.newGame(pHP[HPIndex],numPlayers,numAI,numNick);
}
void enter(){
if (menustatus==STATUS_HELP){
menustatus=STATUS_MAIN;
}
else if (menustatus==STATUS_ALT){
if(selected==0){
if(numPlayers+numAI+numNick>=2&&numPlayers+numAI+numNick<=6){
menustatus=STATUS_MAIN;
selected=2;
if(oldnumPlayers!=numPlayers+numAI+numNick)
world.newBackgroundGame(numPlayers+numAI,numNick);
//drawB();
}
}
else if (selected==1){
if (numPlayers+numAI+numNick<6){
numPlayers++;
}
else{
numPlayers=0;
}
//drawB();
}
else if (selected==2){
if (numPlayers+numAI+numNick<6){
numAI++;
}
else{
numAI=0;
}
//drawB();
}
else if (selected==3){
if (numPlayers+numAI+numNick<6){
numNick++;
}
else{
numNick=0;
}
//drawB();
}
else if (selected==4){
HPIndex++;
if (HPIndex >=6) {
HPIndex = 0;
}
}
}
else{
if (selected==0){
// NGWin.setLocationRelativeTo(null);
// NGWin.setVisible(true);
// while (NGWin.getDone()!=true){
// }
newGameCurrentSettings();
}
else if (selected==1){
if (LevelSel==1){
LevelSel=2;
}
else if(LevelSel==2){
LevelSel=3;
}
else if (LevelSel==3){
LevelSel=4;
}
else if(LevelSel==4){
LevelSel=1;
}
world.loadLevel(LevelSel-1);
//drawB();
}
else if (selected==2){
menustatus=STATUS_ALT;
selected=0;
//drawB();
}
else if (selected==3){
world.toggleFullscreen();
}
else if (selected==4){
world.toggleMusic();
ismusic=!ismusic;
//drawB();
}
else if (selected==5){
oldnumPlayers=numPlayers+numAI+numNick;
menustatus=STATUS_HELP;
//drawB();
}
else if (selected==6){
/*gametimer.stop();
window.setVisible(false);
//window.close();
window.dispose();
window=null;*/
System.exit(0);
}
}
}
}