forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameMenu.java
More file actions
911 lines (712 loc) · 32.7 KB
/
Copy pathgameMenu.java
File metadata and controls
911 lines (712 loc) · 32.7 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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
package gui;
import java.util.ArrayList;
import java.util.Arrays;
import java.awt.Image;
import java.awt.image.PixelGrabber;
import javax.imageio.ImageIO;
import core.*;
public class gameMenu {
public int gameSuspendCount;
public static int menuStatus = 0;
public static final int mainMenu = 0;
public static final int difficulitySelectionMenu = 1;
public static final int helpMenu = 2;
public static final int endGameMenu = 3;
public static final int optionMenu = 4;
public static final int highscoreMenu = 5;
public int[] screen;
public int[] screenBlurBuffer;
public String imageFolder = "";
public int[] titleImage, lightTankImage, rocketTankImage, stealthTankImage, heavyTankImage;
public button newGame, unpauseGame, showHelp, showOptions, showHighscores, quitGame, abortGame, easyGame, normalGame, hardGame, quitDifficulty, quitHelpMenu, quitOptionMenu, quitHighscoreMenu, nextPage, previousPage,
enableMouseCapture, disableMouseCapture, enableFogOfWar, disableFogOfWar, confirmErrorLoadingHighscore, normalToHardButton, normalToEasyButton, hardToNormalButton, easyToNormalButton,
backToMapDefeat, leaveGameDefeat, backToMapVictory, leaveGameVictory, uploadScore;
public char[] easyDescription, normalDescription, hardDescription, helpPage1, helpPage2, helpPage3, helpPage4, mouseMode;
public int currentHelpPage;
public int highscoreLevel;
public ArrayList<button> buttons = new ArrayList<button>();
public highscoreManager theHighscoreManager;
public char[] name;
public String nameString;
public static boolean uploadingScore, scoreUploaded;
public static int screen_width = mainThread.screen_width;
public static int screen_height = mainThread.screen_height;
public void init() {
if(titleImage == null) {
titleImage = new int[288*46];
lightTankImage = new int[44*44];
rocketTankImage = new int[44*44];
stealthTankImage = new int[44*44];
heavyTankImage = new int[44*44];
}
if(screenBlurBuffer == null)
screenBlurBuffer = new int[screen_height * screen_width];
theHighscoreManager = new highscoreManager();
Thread t = new Thread(theHighscoreManager);
t.start();
highscoreLevel = 1;
name = new char[32];
for(int i = 0; i< 32; i++)
name[i] = 255;
String folder = "../images/";
loadTexture(folder + "title.png", titleImage, 216, 35);
loadTexture(folder + "58.jpg", lightTankImage, 44, 44);
loadTexture(folder + "59.jpg", rocketTankImage, 44, 44);
loadTexture(folder + "72.jpg", stealthTankImage, 44, 44);
loadTexture(folder + "83.jpg", heavyTankImage, 44, 44);
newGame = new button("newGame", "New Game", 324, 110, 120, 28);
buttons.add(newGame);
unpauseGame = new button("unpauseGame", "Resume Game", 324, 110, 120, 28);
buttons.add(unpauseGame);
showHelp = new button("showHelp", "Help", 324, 160, 120, 28);
buttons.add(showHelp);
showOptions = new button("showOptions", "Options", 324, 210, 120, 28);
buttons.add(showOptions);
showHighscores = new button("showHighscores", "Highscores", 324, 260, 120, 28);
buttons.add(showHighscores);
quitGame = new button("quitGame", "Quit Game", 324, 345, 120, 28);
buttons.add(quitGame);
abortGame = new button("abortGame", "Abort Game", 324, 345, 120, 28);
buttons.add(abortGame);
easyGame = new button("easyGame", "Easy", 190, 120, 85, 28);
buttons.add(easyGame);
normalGame = new button("normalGame", "Normal", 190, 200, 85, 28);
buttons.add(normalGame);
hardGame = new button("hardGame", "Hard", 190, 280, 85, 28);
buttons.add(hardGame);
quitDifficulty = new button("quitDifficulty", "x", 570, 80, 18,16);
buttons.add(quitDifficulty);
easyDescription = "AI will attack blindly at player's base \nwithout thinking too much. ".toCharArray();
normalDescription = "AI will launch timed attacks, it will also \nchange its army composition based on \nthe scouted information.".toCharArray();
hardDescription = "AI will micro each of its units, expand \nmore aggressively and carry out high\nlevel maneuver such as harassing during \npeaceful peirod.".toCharArray();
helpPage1 = (" Controls \n\n"
+ "\"Esc\" -- Pause/Unpause the game.\n\n"
+ "\"Left Click\" -- Select a unit. Left click + mouse drag can be used to select up to \n100 units at a time. Double left click on a unit will automatically select surrounding \nunits of the same type.\n\n"
+ "\"Right Click\" -- Issue a move or attack command to the selected unit(s). You can \nalso use right click to set rally point or cancel build progress.\n\n"
+ "\"a\" -- Force attack a unit. If no unit is under the cursor, then the selected units will \nbe set to attack move to the cursor location.\n\n"
+ "\"s\" -- stop current action for the selected unit(s).\n\n"
+ "\"Ctrl + number\" -- Create a control group and assigned the number to the group.\n\n"
+ "\"Ctrl + Left Click\" -- Add/Remove a unit to/from the selected units.\n\n"
+ "\"Ctrl + Mouse Drag\" -- Add units in the dragging box to the selected units.\n\n\n"
+ " 1/4 ").toCharArray();
helpPage2 = (" Controls (Cont.) \n\n"
+ "\"Left and Right arrow keys\" -- Change camera view angle.\n\n"
+ "\"c\" -- Toggle between different construction yards under your control.\n\n"
+ "\"f\" -- Toggle between different factories under your control.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
+ " 2/4 ").toCharArray();
helpPage3 = (" Units \n\n"
+ "There are 4 type of military units, each has its own strength and weakness.\n\n"
+ " Light Tank -- Cheap but lightly armored. Has moderate movement speed \n and firepower. It can be considered as the jack of all trades. It can be \n upgraded to have increased range.\n\n"
+ " Rocket Tank -- A slow moving and lightly armored unit. It has long reload \n time but can out range static defenses. It does extra damage to buildings \n and can be upgraded to deal even more damage to buildings.\n\n"
+ " Stealth Tank -- Fast but lightly armoured. It has a passive cloak ablility that \n turns the tank invisible when not attacking. It does more damage to light \n armoured unit but significantly less damage to heavy armoured unit. It can \n be upgraded to damage multiple units with one shot.\n\n"
+ " Heavy Tank -- The Slowest and most expensive tank in the game. Equiped \n with twin cannons, it is a moving fortress. It can be upgraded with self \n repair capability so it can last even longer in battle field.\n\n\n\n"
+ " 3/4 ").toCharArray();
helpPage4 = (" About Me \n\n"
+ "Hi everyone, my name is Pan Hu, I have a great interest in making video games. \n"
+ "It has been a dream job for me since a very young age. Unfortunately I ended \n"
+ "up make a living doing the \"boring\" job like most other folks. But it will not stop\n"
+ "me from doing what I enjoy in my spare time!\n\n"
+ "In this project I am trying to create a small RTS game with somewhat challenging \n"
+ "AI using pure Java. However the AI will not cheat by any means, i.e. Its vision is\n"
+ "limited by fog of war, it doesn't have any advantage in resource gathering. Well,\n"
+ "the only advantage is porbably the inhuman action per second the AI carries out \n"
+ "in higher difficulty.\n\n"
+ "This game is completely open source. You can find the source code at my github \n"
+ "page: https://github.com/phu004/JavaRTS. If you are intersted in other projects of\n"
+ "mine, feel free to check out my YouTube channel, user name is \"Pan Hu\".\n\n"
+ "Have a nice Day!\n\n\n\n\n\n"
+ " 4/4").toCharArray();
mouseMode = (" Options \n\n\nMouse capture. When enabled the game will prevent \nthe mouse cursor from leaving the current window.\n\n\n"
+ "Fog of war. When enabled, enemy units that are not \nin vision will be hidden. Note that your score will NOT \nbe saved when this option is disabled.").toCharArray();
quitHelpMenu = new button("quitHelpMenu", "x", 670, 80, 18,16);
buttons.add(quitHelpMenu);
quitOptionMenu = new button("quitOptionMenu", "x", 620, 80, 18,16);
buttons.add(quitOptionMenu);
quitHighscoreMenu = new button("quitHighscoreMenu", "x", 570, 80, 18,16);
buttons.add(quitHighscoreMenu);
nextPage = new button("nextPage", "Next Page", 550, 450, 120, 28);
buttons.add(nextPage);
previousPage = new button("previousPage", "Previous Page", 98, 450, 120, 28);
buttons.add(previousPage);
enableMouseCapture = new button("enableMouseCapture", "Disabled", 545, 145, 80, 25);
buttons.add(enableMouseCapture);
disableMouseCapture = new button("disableMouseCapture", "Enabled", 545, 145, 80, 25);
buttons.add(disableMouseCapture);
enableFogOfWar = new button("enableFogOfWar", "Disabled", 545, 215, 80, 25);
buttons.add(enableFogOfWar);
disableFogOfWar = new button("disableFogOfWar", "Enabled", 545, 215, 80, 25);
buttons.add(disableFogOfWar);
confirmErrorLoadingHighscore = new button("confirmErrorLoadingHighscore", "Ok", 350, 280, 80, 25);
buttons.add(confirmErrorLoadingHighscore);
normalToHardButton = new button("normalToHardButton", ">", 543, 430, 40, 25);
buttons.add(normalToHardButton);
normalToEasyButton = new button("normalToEasyButton", "<", 185, 430, 40, 25);
buttons.add(normalToEasyButton);
hardToNormalButton = new button("hardToNormalButton", "<", 185, 430, 40, 25);
buttons.add(hardToNormalButton);
easyToNormalButton = new button("easyToNormalButton", ">", 543, 430, 40, 25);
buttons.add(easyToNormalButton);
backToMapDefeat = new button("backToMap", "Back to Map", 210, 235, 120, 25);
buttons.add(backToMapDefeat);
leaveGameDefeat = new button("abortGame", "Leave game", 440, 235, 120, 25);
buttons.add(leaveGameDefeat);
backToMapVictory = new button("backToMap", "Back to Map", 135, 315, 120, 25);
buttons.add(backToMapVictory);
leaveGameVictory = new button("abortGame", "Leave game", 515, 315, 120, 25);
buttons.add(leaveGameVictory);
uploadScore = new button("uploadScore", "Upload", 530, 250, 90, 25);
buttons.add(uploadScore);
}
public void updateAndDraw(int[] screen, boolean gameStarted, boolean gamePaused, boolean playerVictory, boolean AIVictory) {
this.screen = screen;
textRenderer tRenderer = postProcessingThread.theTextRenderer;
if(gamePaused){
gameSuspendCount++;
}else {
gameSuspendCount = 0;
}
if(gameSuspendCount == 1) {
for(int i = 0; i < screen_height*screen_width; i++)
screenBlurBuffer[i] = screen[i];
}
//make all buttons off screen and reduce their action cooldown
for (int i = 0; i < buttons.size(); i++) {
buttons.get(i).display = false;
if(buttons.get(i).actionCooldown > 0)
buttons.get(i).actionCooldown--;
}
if(playerVictory || AIVictory) {
if(gameSuspendCount > 0) {
drawBluredBackground();
}
if(AIVictory) {
drawMenuFrame(400, 100, 70);
tRenderer.drawMenuText(320,178,"You Are Defeated!".toCharArray(), screen, 255,255,255, 0);
backToMapDefeat.display = true;
leaveGameDefeat.display = true;
}else if(playerVictory) {
drawMenuFrame(550, 210, 40);
tRenderer.drawMenuText(320,138,"You are Victorious!".toCharArray(), screen, 255,255,255, 0);
String difficulty = "Normal";
if(mainThread.ec.difficulty == 0)
difficulty = "Easy";
if(mainThread.ec.difficulty == 2)
difficulty = "Hard";
tRenderer.drawMenuText(205,198,("Difficulty: "+ difficulty).toCharArray(), screen, 255,255,255, 0);
String time = mainThread.timeString;
tRenderer.drawMenuText(232,228,("Time: "+ time).toCharArray(), screen, 255,255,255, 0);
if(!postProcessingThread.fogOfWarDisabled) {
tRenderer.drawMenuText(185,258,("Your Name:").toCharArray(), screen, 255,255,255, 0);
uploadScore.display = true;
uploadScore.disabled = true;
//only accept 0-9, A-Z, a-Z, space and backspace characters
char c = postProcessingThread.currentInputChar;
if(!uploadingScore && !scoreUploaded) {
if((c >= 48 && c < 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 8 || c == 32) {
if(c == 8) {
for(int i = 31; i >= 0; i--) {
if(name[i] != 255) {
name[i] = 255;
break;
}
}
}else {
for(int i = 0; i < 32; i++) {
if(name[i] == 255) {
name[i] = c;
break;
}
}
}
}
}
//check if upload condition is met
for(int i = 0; i < 32; i++) {
if((name[i] >= 48 && name[i] < 57) || (name[i] >= 65 && name[i] <= 90) || (name[i] >= 97 && name[i] <= 122)) {
uploadScore.disabled = false;
}
}
//draw name string
nameString = "";
for(int i = 0; i < 32; i++) {
if(name[i] != 255) {
nameString+=name[i];
}else {
break;
}
}
int centerX_old = 768/2-1;
int centery_old = 512/2-1;
int dx = 282 - centerX_old;
int dy = 258 - centery_old;
int centerX_new = screen_width/2-1;
int centerY_new = screen_height/2 -1;
tRenderer.drawText_outline(centerX_new+dx, centerY_new+dy, nameString, screen, 0xdddddd, 0);
//draw place marker
if(postProcessingThread.frameIndex%30 > 15 && !uploadingScore && !scoreUploaded)
tRenderer.drawText_outline(centerX_new+dx+nameString.length()*7, centerY_new+dy, "_", screen, 0xdddddd, 0);
if(uploadingScore || scoreUploaded) {
uploadScore.disabled = true;
}
if(uploadingScore && !scoreUploaded) {
if(theHighscoreManager.status == theHighscoreManager.idle && theHighscoreManager.playerName.equals("")) {
theHighscoreManager.playerName = nameString;
theHighscoreManager.task = theHighscoreManager.uploadScore;
}else if(theHighscoreManager.status == theHighscoreManager.error) {
}else if(theHighscoreManager.status == theHighscoreManager.idle && theHighscoreManager.task== theHighscoreManager.none && !theHighscoreManager.playerName.equals("")) {
scoreUploaded = true;
theHighscoreManager.playerName = "";
}
}
if(scoreUploaded) {
uploadScore.text = "Uploaded!";
uploadScore.theText = uploadScore.text.toCharArray();
uploadScore.messageMode = true;
}
}
backToMapVictory.display = true;
leaveGameVictory.display = true;
}
updateButtons();
drawButtons();
return;
}
//only show game menu when the game is not started or game is paused
if(!(!gameStarted || gamePaused))
return;
if(menuStatus == mainMenu) {
currentHelpPage = 0;
if(gameSuspendCount > 0) {
drawBluredBackground();
}
drawTitle();
drawMenuFrame(220, 300);
if(!gameStarted) {
newGame.display = true;
quitGame.display = true;
}else {
unpauseGame.display = true;
abortGame.display = true;
}
showHelp.display = true;
showOptions.display = true;
showHighscores.display = true;
}else if(menuStatus == difficulitySelectionMenu) {
if(postProcessingThread.escapeKeyPressed) {
menuStatus = mainMenu;
}else {
drawTitle();
drawMenuFrame(420, 260);
easyGame.display = true;
tRenderer.drawMenuText(285,118,easyDescription, screen, 255,255,255, 0);
normalGame.display = true;
tRenderer.drawMenuText(285,188,normalDescription, screen, 255,255,255,0);
hardGame.display = true;
tRenderer.drawMenuText(285,265,hardDescription, screen, 255,255,255,0);
quitDifficulty.display = true;
}
}else if(menuStatus == helpMenu) {
if(postProcessingThread.escapeKeyPressed) {
menuStatus = mainMenu;
}else{
if(gameSuspendCount > 0) {
drawBluredBackground();
}
drawTitle();
drawMenuFrame(620, 380);
if(currentHelpPage == 0) {
tRenderer.drawMenuText(82,90,helpPage1, screen, 255,255,255,0);
nextPage.display = true;
}else if(currentHelpPage == 1) {
tRenderer.drawMenuText(82,90,helpPage2, screen, 255,255,255,0);
nextPage.display = true;
previousPage.display = true;
}else if(currentHelpPage == 2) {
tRenderer.drawMenuText(82,90,helpPage3, screen, 255,255,255,0);
nextPage.display = true;
previousPage.display = true;
drawImage(83,157, 44, 44,lightTankImage);
drawImage(83,220, 44, 44,rocketTankImage);
drawImage(83,290, 44, 44,stealthTankImage);
drawImage(83,364, 44, 44,heavyTankImage);
}else if(currentHelpPage == 3) {
tRenderer.drawMenuText(82,90,helpPage4, screen, 255,255,255,0);
previousPage.display = true;
}
quitHelpMenu.display = true;
}
}else if(menuStatus == optionMenu) {
if(postProcessingThread.escapeKeyPressed) {
menuStatus = mainMenu;
}else{
if(gameSuspendCount > 0) {
drawBluredBackground();
}
drawTitle();
drawMenuFrame(520, 380);
tRenderer.drawMenuText(135,95,mouseMode, screen, 255,255,255,0);
if(postProcessingThread.capturedMouse == true) {
disableMouseCapture.display = true;
enableMouseCapture.display = false;
}else {
disableMouseCapture.display = false;
enableMouseCapture.display = true;
}
if(postProcessingThread.fogOfWarDisabled) {
disableFogOfWar.display = false;
enableFogOfWar.display = true;
}else {
disableFogOfWar.display = true;
enableFogOfWar.display = false;
}
quitOptionMenu.display = true;
if(postProcessingThread.gameStarted) {
disableFogOfWar.disabled = true;
enableFogOfWar.disabled = true;
}else {
disableFogOfWar.disabled = false;
enableFogOfWar.disabled = false;
}
}
}else if(menuStatus == highscoreMenu) {
if(postProcessingThread.escapeKeyPressed) {
quitHighscoreMenu();
}else {
if(gameSuspendCount > 0) {
drawBluredBackground();
}
drawTitle();
drawMenuFrame(420, 360);
if(theHighscoreManager.status == theHighscoreManager.processing) {
drawLoadingScreen(screen);
}else if(theHighscoreManager.status == theHighscoreManager.idle) {
if(theHighscoreManager.task == theHighscoreManager.none && theHighscoreManager.result == null) {
theHighscoreManager.task = theHighscoreManager.loadHighscores;
drawLoadingScreen(screen);
}else if(theHighscoreManager.task == theHighscoreManager.none && theHighscoreManager.result != null) {
drawHighscore();
}else if(theHighscoreManager.isSleeping && theHighscoreManager.result == null) {
drawLoadingScreen(screen);
}
}else if(theHighscoreManager.status == theHighscoreManager.error) {
tRenderer.drawMenuText(240,250,"Cannot load high scores, try again later.".toCharArray(), screen, 255,255,255,0);
confirmErrorLoadingHighscore.display=true;
}
quitHighscoreMenu.display = true;
}
}
updateButtons();
drawButtons();
}
public void drawHighscore() {
textRenderer tRenderer = postProcessingThread.theTextRenderer;
String[][] result = theHighscoreManager.result;
int startRow = 0;
//draw high scores
if(highscoreLevel == 1) {
tRenderer.drawScoreBoardText(270,100,"Highscores For Normal Difficulty", screen, 0xffffff,0);
startRow = 10;
normalToHardButton.display = true;
normalToEasyButton.display = true;
}else if(highscoreLevel == 0) {
tRenderer.drawScoreBoardText(270,100,"Highscores For Easy Difficulty", screen, 0xffffff,0);
startRow = 0;
easyToNormalButton.display = true;
}else if(highscoreLevel == 2) {
tRenderer.drawScoreBoardText(270,100,"Highscores For Hard Difficulty", screen, 0xffffff,0);
startRow = 20;
hardToNormalButton.display = true;
}
tRenderer.drawScoreBoardText(220,130," Rank Player Name Time", screen, 0xf2989d,0);
tRenderer.drawScoreBoardText(220,135,"_____________________________________________", screen, 0xaaaaaa,0);
for(int i = startRow; i < startRow + 10; i++) {
int color = 0xbbbbbb;
if(i -startRow == 0)
color = 0xffe559;
if(i -startRow == 1)
color = 0xe8e9ea;
if(i -startRow == 2)
color = 0xc99684;
if(i -startRow == 9)
tRenderer.drawScoreBoardText(210,160 + (i -startRow)*25, " " + (i -startRow + 1), screen, color,0);
else
tRenderer.drawScoreBoardText(213,160 + (i -startRow)*25, " " + (i -startRow + 1), screen, color,0);
if(result[i][0] != null) {
int l = (30 - result[i][0].length())/2;
tRenderer.drawScoreBoardText(220,160 + (i -startRow)*25, " " + result[i][1], screen, color,0);
tRenderer.drawScoreBoardText(265 + l*7,160 + (i -startRow)*25, result[i][0], screen, color,0);
}
}
}
public void drawLoadingScreen(int[] screen) {
textRenderer tRenderer = postProcessingThread.theTextRenderer;
if(postProcessingThread.frameIndex%50 < 10) {
tRenderer.drawMenuText(360,250,"Loading....".toCharArray(), screen, 255,255,255,0);
}else if(postProcessingThread.frameIndex%50 >= 10 && postProcessingThread.frameIndex%50 < 20) {
tRenderer.drawMenuText(360,250,"Loading".toCharArray(), screen, 255,255,255,0);
}else if(postProcessingThread.frameIndex%50 >= 20 && postProcessingThread.frameIndex%50 < 30) {
tRenderer.drawMenuText(360,250,"Loading.".toCharArray(), screen, 255,255,255,0);
}else if(postProcessingThread.frameIndex%50 >= 30 && postProcessingThread.frameIndex%50 < 40) {
tRenderer.drawMenuText(360,250,"Loading..".toCharArray(), screen, 255,255,255,0);
}else {
tRenderer.drawMenuText(360,250,"Loading...".toCharArray(), screen, 255,255,255,0);
}
}
public void quitHighscoreMenu() {
menuStatus = mainMenu;
theHighscoreManager.task = theHighscoreManager.none;
if(theHighscoreManager.status == theHighscoreManager.idle) {
theHighscoreManager.result = null;
}
highscoreLevel = 1;
}
public void updateButtons() {
for(int i = 0; i < buttons.size(); i++) {
if(buttons.get(i).checkIfCursorIsOnTop(postProcessingThread.mouse_x, postProcessingThread.mouse_y)) {
if(postProcessingThread.leftMouseButtonReleased) {
if(buttons.get(i).actionCooldown == 0 && buttons.get(i).display == true) {
buttons.get(i).actionCooldown = 5;
if(buttons.get(i).name == "newGame") {
menuStatus = difficulitySelectionMenu;
}else if(buttons.get(i).name == "showHelp") {
menuStatus = helpMenu;
}else if(buttons.get(i).name == "showOptions") {
menuStatus = optionMenu;
}else if(buttons.get(i).name == "quitDifficulty" || buttons.get(i).name == "quitHelpMenu" || buttons.get(i).name == "quitOptionMenu") {
menuStatus = mainMenu;
}else if(buttons.get(i).name == "nextPage") {
currentHelpPage++;
}else if(buttons.get(i).name == "previousPage") {
currentHelpPage--;
}else if(buttons.get(i).name == "showHighscores") {
menuStatus = highscoreMenu;
if(theHighscoreManager.status == theHighscoreManager.error) {
theHighscoreManager.counter = 0;
theHighscoreManager.status = theHighscoreManager.idle;
}
}else if(buttons.get(i).name == "quitHighscoreMenu" || buttons.get(i).name == "confirmErrorLoadingHighscore") {
quitHighscoreMenu();
}else if(buttons.get(i).name == "normalToHardButton") {
highscoreLevel = 2;
}else if(buttons.get(i).name == "hardToNormalButton") {
highscoreLevel = 1;
}else if(buttons.get(i).name == "easyToNormalButton") {
highscoreLevel = 1;
}else if(buttons.get(i).name == "normalToEasyButton") {
highscoreLevel = 0;
}else if(buttons.get(i).name == "abortGame") {
menuStatus = mainMenu;
for(int j = 0; j< 32; j++)
name[j] = 255;
scoreUploaded = false;
uploadingScore = false;
uploadScore.text = "Upload";
uploadScore.theText = uploadScore.text.toCharArray();
uploadScore.messageMode = false;
}else if(buttons.get(i).name == "uploadScore") {
uploadingScore = true;
}
postProcessingThread.buttonAction = buttons.get(i).name;
}
}
}
}
}
public void drawButtons() {
for (int i = 0; i < buttons.size(); i++) {
buttons.get(i).draw(screen);
}
}
public void drawBluredBackground() {
if(gameSuspendCount < 5) {
for(int k = 0; k < 3; k++)
for(int i = 1; i < screen_height-1; i++ ) {
for(int j = 1; j < screen_width-1; j++) {
int index = j + i*screen_width;
int r = ((screenBlurBuffer[index]&0xff0000) >> 16) + ((screenBlurBuffer[index + 1]&0xff0000) >> 16) + ((screenBlurBuffer[index - 1]&0xff0000) >> 16) + ((screenBlurBuffer[index - screen_width]&0xff0000) >> 16) + ((screenBlurBuffer[index + screen_width]&0xff0000) >> 16);
int g = ((screenBlurBuffer[index]&0xff00) >> 8) + ((screenBlurBuffer[index + 1]&0xff00) >> 8) + ((screenBlurBuffer[index - 1]&0xff00) >> 8) + ((screenBlurBuffer[index - screen_width]&0xff00) >> 8) + ((screenBlurBuffer[index + screen_width]&0xff00) >> 8);
int b = (screenBlurBuffer[index]&0xff) + (screenBlurBuffer[index + 1]&0xff) + (screenBlurBuffer[index - 1]&0xff) + (screenBlurBuffer[index - screen_width]&0xff) + (screenBlurBuffer[index + screen_width]&0xff);
screenBlurBuffer[index] = (r/5) << 16 | (g/5) << 8 | (b/5);
}
}
}
for(int i = 0; i < screen_height*screen_width; i++)
screen[i] = screenBlurBuffer[i];
}
public void drawMenuFrame(int width, int height){
drawFrame(width, height, 0);
}
public void drawMenuFrame(int width, int height, int topDistance){
drawFrame(width, height, topDistance);
}
public void drawFrame(int width, int height, int topDistance) {
topDistance = (screen_height - 512)/2 + topDistance;
int R = 4;
int G = 94;
int B = 132;
int R1 = 8;
int G1 = 188;
int B1 = 255;
int R2 = 3;
int G2 = 70;
int B2 = 99;
int pos = (screen_width - width)/2 + (90+topDistance) * screen_width;
//background
for(int i = 0; i < height; i++) {
for(int j = 0; j < width; j++) {
int pixel = screen[pos + j + i* screen_width];
screen[pos + j + i* screen_width] = ((pixel&0xFEFEFE)>>1) + ((R2/2) << 16 | (G2/2) << 8 | (B2/2));
}
}
float d = 20f;
for(int i = 0; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < width; j++) {
int pixel = screen[pos - 17*screen_width + j + i* screen_width];
screen[pos - 17*screen_width + j + i* screen_width] = ((pixel&0xFEFEFE)>>1) + ((R2/2) << 16 | (G2/2) << 8 | (B2/2));
}
}
pos+=(height+17)*screen_width;
for(int i = 0; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j =0; j < width - delta; j++) {
int pixel = screen[pos - 17*screen_width + j + i* screen_width];
screen[pos - 17*screen_width + j + i* screen_width] = ((pixel&0xFEFEFE)>>1) + ((R2/2) << 16 | (G2/2) << 8 | (B2/2));
}
}
//left
pos = (screen_width - width)/2 + (90+topDistance) * screen_width;
for(int i = 0; i < height + 17; i++) {
int pixel = screen[pos + i*screen_width];
screen[pos + i*screen_width] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
}
pos = (screen_width - width)/2 + (90+topDistance) * screen_width+1;
for(int i = 0; i < height + 16; i++) {
screen[pos + i*screen_width] = ((R1) << 16 | (G1) << 8 | (B1));
}
pos = (screen_width - width)/2 + (90+topDistance) * screen_width + 2;
for(int i = 0; i < height + 15; i++) {
int pixel = screen[pos + i*screen_width];
screen[pos + i*screen_width] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
}
//bottom
pos = (screen_width - width)/2 + ((90+topDistance)+height+14) * screen_width;
for(int i = 3; i < width - 18; i++) {
int pixel = screen[pos + i];
screen[pos + i] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
}
pos = (screen_width - width)/2 + ((90+topDistance)+height+15) * screen_width;
for(int i = 2; i < width - 18; i++) {
screen[pos + i] = ((R1) << 16 | (G1) << 8 | (B1));
}
pos = (screen_width - width)/2 + ((90+topDistance)+height+16) * screen_width;
for(int i = 1; i < width - 18; i++) {
int pixel = screen[pos + i];
screen[pos + i] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
}
//bottom right
pos = (screen_width - width)/2 + width - 18 + ((90+topDistance)+height+16) * screen_width;
for(int i = 2; i < 20; i++) {
int delta = (int)((17f/d)*i);
int pixel = screen[pos + i -2 + (-delta)*screen_width];
screen[pos + i - 2 + (-delta)*screen_width] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
}
for(int i = 2; i < 18; i++) {
int delta = (int)((17f/d)*i);
int pixel = screen[pos + i -2 + (-delta - 2)*screen_width];
screen[pos + i - 2 + (-delta - 2)*screen_width] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
}
for(int i = 2; i < 19; i++) {
int delta = (int)((17f/d)*i);
screen[pos + i - 2 + (-delta-1)*screen_width] = ((R1) << 16 | (G1) << 8 | (B1));
}
screen[pos - 5*screen_width + 4] = ((R1) << 16 | (G1) << 8 | (B1));
screen[pos - 11*screen_width + 11] = ((R1) << 16 | (G1) << 8 | (B1));
//right
pos = (screen_width - width)/2 + width -3 + (75+topDistance) * screen_width;
for(int i = 0; i < height + 15; i++) {
int pixel = screen[pos + i*screen_width];
screen[pos + i*screen_width] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
}
pos = (screen_width - width)/2 + width -2+ (74+topDistance) * screen_width;
for(int i = 0; i < height + 16; i++) {
screen[pos + i*screen_width] = ((R1) << 16 | (G1) << 8 | (B1));
}
pos = (screen_width - width)/2 + width - 1 + (73+topDistance) * screen_width;
for(int i = 0; i < height + 17; i++) {
int pixel = screen[pos + i*screen_width];
screen[pos + i*screen_width] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
}
//top
pos = (screen_width - width)/2 + ((90+topDistance)-17) * screen_width;
for(int i = 20; i < width -1; i++) {
int pixel = screen[pos + i];
screen[pos + i] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
}
pos = (screen_width - width)/2 + ((90+topDistance)-16) * screen_width;
for(int i = 20; i < width - 2; i++) {
screen[pos + i] = ((R1) << 16 | (G1) << 8 | (B1));
}
pos = (screen_width - width)/2 + ((90+topDistance)-15) * screen_width;
for(int i = 20; i < width - 3; i++) {
int pixel = screen[pos + i];
screen[pos + i] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
}
//top left
pos = (screen_width - width)/2 + (90+topDistance) * screen_width;
for(int i = 0; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < 20-delta; j++) {
int pixel = screen[pos - 17*screen_width + j + i* screen_width];
screen[pos - 17*screen_width + j + i* screen_width] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
}
}
pos = (screen_width - width)/2 + 2 + (90+topDistance) * screen_width;
for(int i = 2; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < 20-delta; j++) {
int pixel = screen[pos - 17*screen_width + j + i* screen_width];
screen[pos - 17*screen_width + j + i* screen_width] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
}
}
pos = (screen_width - width)/2 + 1 + (90+topDistance) * screen_width;
for(int i = 0; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < 20-delta; j++) {
screen[pos - 17*screen_width + j + i* screen_width] = ((R1) << 16 | (G1) << 8 | (B1));
}
}
}
public void drawTitle() {
int pos = screen_width/2 - (384-276) + (35 + (screen_height-512)/2)*screen_width;
for(int i = 0; i < 35; i++) {
for(int j = 0; j < 216; j++) {
int c = titleImage[j + i*216];
if(!((c&0xff0000 >> 16) > 254 && (c&0x00ff00 >> 8) > 254 && ((c&0xff) > 254)))
screen[pos+ screen_width*i + j] = c;
}
}
}
public void drawImage(int xPos, int yPos, int w, int h, int[] myImage) {
int pos = screen_width/2 - (384-xPos) + (yPos + (screen_height-512)/2)*screen_width;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
screen[pos + j + i*screen_width] = myImage[j+ i*h];
}
}
}
public void loadTexture(String imgName, int[] buffer, int width, int height){
Image img = null;
try{
img = ImageIO.read(getClass().getResource(imageFolder + imgName));
}catch(Exception e){
e.printStackTrace();
}
PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, buffer, 0, width);
try {
pg.grabPixels();
}catch(Exception e){
e.printStackTrace();
}
}
}