-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
2670 lines (2377 loc) · 105 KB
/
Main.java
File metadata and controls
2670 lines (2377 loc) · 105 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
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.w3c.dom.css.RGBColor;
import java.util.ArrayList;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Objects;
import javax.imageio.ImageIO;
import java.net.URL;
import java.util.Random;
import java.util.Scanner;
public class Main extends JPanel implements KeyListener, Runnable {
// GS 0 = Main Screen
// GS 1 = Credits
// GS 2 = Settings
// GS 3 = Character Selection
// GS 4 = Keybind Select
// GS 5 = Map Select
// GS 6 = Gameplay
// GS 7 = Winner and Loser Screen
// what each of the many arrays indexes represent
static int forward = 0;
static int back = 1;
static int idle = 2;
static int punch = 3;
static int kick = 4;
static int jump = 5;
static int jumpKick = 6;
static int jumpPunch = 7;
static int duck = 8;
static int duckPunch = 9;
static int duckKick = 10;
static int block = 11;
static int duckBlock = 12;
static int hit = 13;
static int duckHit = 14;
static int knocked = 15;
static int special = 16;
static int knockedOut = 17;
// this method takes an image and returns a specific part of the image that you want
public static BufferedImage grabImage(BufferedImage image, int spriteNum) {
return image.getSubimage(200 * spriteNum, 0, 200, 140);
}
//miscilaneous variables
public static int gameState = 0;
public static boolean blink = true;
public static int frameController = 0;
public static boolean hoverBlink = true;
// creating background and the title screen
public static Image bg;
public static BufferedImage[] ui = new BufferedImage[1];
// game music/sfx
public static boolean gameMusic = true;
public static boolean gameSFX = true;
public static int logoHeight = 0;
// character select related
public static BufferedImage p1retsuBig, p2retsuBig;
public static BufferedImage p1ryuBig, p2ryuBig;
public static BufferedImage retsuPortrait;
public static BufferedImage ryuPortrait;
public static BufferedImage comingSoon, comingSoonBig;
// total moves for characters
public static int totalMoves = 18;
// creating array for each character and their p1 and p2 varients
public static BufferedImage[] p1Retsu = new BufferedImage[totalMoves];
public static BufferedImage[] p2Retsu = new BufferedImage[totalMoves];
public static BufferedImage[] p1Ryu = new BufferedImage[totalMoves];
public static BufferedImage[] p2Ryu = new BufferedImage[totalMoves];
// loading Ryu's special projectile
public static BufferedImage p1RyuSpecial;
public static BufferedImage p2RyuSpecial;
public static boolean isp1RyuThrowSpecial = false;
public static boolean isp2RyuThrowSpecial = false;
public static int p1RyuProjectileX;
public static int p2RyuProjectileX;
// used for gamestate 3 to see if both players have selected characters.
public static boolean charactersSelected = false;
// map select related
public static Image map0Icon, map1Icon, map2Icon, map3Icon;
public static Image map0, map1, map2, map3;
public static Image chosenMap;
public static int chosenMapNum = -1;
public static int defaultPosY = 0;
public static String startTimer = "3";
// p1 and p2 related variables
public static BufferedImage[][] p1 = new BufferedImage[totalMoves][10]; // thsi variable holds the sprite png for each move, and inside that has each indivdial sprite
public static String p1Char = "";
public static BufferedImage p1CurrentMovement;
public static int p1PosX = 100;
public static int p1PosY = 250;
public static int p1Health = 100;
public static int p1Stamina = 100;
public static int p1Hover = 0;
public static int p1HoverCharMovement = -50;
public static boolean p1CharSwitch = false;
public static int p1Map = -1;
public static int p1Combo = 0;
public static boolean p1Action[] = new boolean[totalMoves]; // all of the boolean isp1 doing something variables
public static boolean p2Action[] = new boolean[totalMoves];
public static BufferedImage[][] p2 = new BufferedImage[totalMoves][10];
public static String p2Char = "";
public static BufferedImage p2CurrentMovement;
public static int[] p1Sprite = new int[totalMoves];
public static int[] p2Sprite = new int[totalMoves];
public static int[] p1MoveStamina = new int[totalMoves];
public static int[] p2MoveStamina = new int[totalMoves];
public static int p2PosX = 700;
public static int p2PosY = 250;
public static int p2Health = 100;
public static int p2Stamina = 100;
public static int p2Hover = 0;
public static int p2HoverCharMovement = 495;
public static boolean p2CharSwitch = false;
public static int p2Map = -1;
// map score
public static int p1Score = 0;
public static int p2Score = 0;
// has each player hit in a move's span
public static boolean hasp1Hit = false;
public static boolean hasp2Hit = false;
// fonts sizes
public static Font largeText, text, comboText;
// staminas
public static boolean takenP1Stamina = false;
public static boolean takenP2Stamina = false;
// keybind related
public static Scanner p1BindFile;
public static Scanner p2BindFile;
public static PrintWriter p1BindFileOutputing;
public static PrintWriter p2BindFileOutputing;
public static int p1ForwardBind, p2ForwardBind;
public static int p1BackBind, p2BackBind;
public static int p1JumpBind, p2JumpBind;
public static int p1KickBind, p2KickBind;
public static int p1PunchBind, p2PunchBind;
public static int p1DuckBind, p2DuckBind;
public static int p1BlockBind, p2BlockBind;
public static int p1SpecialBind, p2SpecialBind;
public static int p2Combo = 0;
// the damages for each attack for each player
public static int p1PunchDamage = 5;
public static int p1KickDamage = 7;
public static int p1JumpPunchDamage = 7;
public static int p1JumpKickDamage = 10;
public static int p1SpecialDamage = 15;
public static int p2PunchDamage = 5;
public static int p2KickDamage = 7;
public static int p2JumpPunchDamage = 7;
public static int p2JumpKickDamage = 10;
public static int p2SpecialDamage = 15;
// holds the length of each move for each character;
public static int[] p1MoveLength = new int[totalMoves];
public static int[] p2MoveLength = new int[totalMoves];
// controls the height of the jump for each;
public static int p1JumpY;
public static int p2JumpY;
public static int p1JumpX;
public static int p2JumpX;
// holds the keys currently pressed
public static ArrayList<Integer> keysPressed = new ArrayList();
// audio
public static URL music;
public static java.applet.AudioClip musicAudio;
public static URL fight;
public static java.applet.AudioClip fightAudio;
public static URL win;
public static java.applet.AudioClip winAudio;
public static boolean winMusicIsPlaying = false;
public static boolean p1KeySelect = false;
public static boolean p2KeySelect = false;
public Main() {
setPreferredSize(new Dimension(800, 367));
setFocusable(true);
addKeyListener(this);
Thread t = new Thread(this);
t.start();
}
public static void main(String[] args) throws FontFormatException, IOException {
// Image Importation
try {
// this line is for fonts
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// registering fonts
largeText = Font.createFont(Font.TRUETYPE_FONT, new File("UI/Act_Of_Rejection.ttf")).deriveFont(80f);
ge.registerFont(largeText);
comboText = Font.createFont(Font.TRUETYPE_FONT, new File("UI/Act_Of_Rejection.ttf")).deriveFont(30f);
ge.registerFont(comboText);
text = Font.createFont(Font.TRUETYPE_FONT, new File("UI/PressStart2P.ttf")).deriveFont(15f);
ge.registerFont(text);
//loading the main screen background
bg = new ImageIcon(new File("bg/0.gif").toURL()).getImage();
// loading all the character select images
comingSoon = ImageIO.read(new File("Characters/comingSoon.png"));
comingSoonBig = ImageIO.read(new File("Characters/comingSoonBig.png"));
retsuPortrait = ImageIO.read(new File("Characters/Retsu/portrait.png"));
ryuPortrait = ImageIO.read(new File("Characters/Ryu/portrait.png"));
p1retsuBig = ImageIO.read(new File("Characters/Retsu/p1/retsuBig.png"));
p2retsuBig = ImageIO.read(new File("Characters/Retsu/p2/retsuBig.png"));
p1ryuBig = ImageIO.read(new File("Characters/Ryu/p1/ryuBig.png"));
p2ryuBig = ImageIO.read(new File("Characters/Ryu/p2/ryuBig.png"));
// map select related
map0Icon = new ImageIcon(new File("bg/0s.gif").toURL()).getImage();
map1Icon = new ImageIcon(new File("bg/1s.gif").toURL()).getImage();
map2Icon = new ImageIcon(new File("bg/2s.gif").toURL()).getImage();
map3Icon = new ImageIcon(new File("bg/3s.gif").toURL()).getImage();
map0 = new ImageIcon(new File("bg/0.gif").toURL()).getImage();
map1 = new ImageIcon(new File("bg/1.gif").toURL()).getImage();
map2 = new ImageIcon(new File("bg/2.gif").toURL()).getImage();
map3 = new ImageIcon(new File("bg/3.gif").toURL()).getImage();
// load all character sprites
for (int i = 0; i < p1.length; i++) {
p1Retsu[i] = ImageIO.read(new File("Characters/Retsu/p1/" + i + ".png"));
p2Retsu[i] = ImageIO.read(new File("Characters/Retsu/p2/" + i + ".png"));
p1Ryu[i] = ImageIO.read(new File("Characters/Ryu/p1/" + i + ".png"));
p2Ryu[i] = ImageIO.read(new File("Characters/Ryu/p2/" + i + ".png"));
}
// ryu special sprites
p1RyuSpecial = ImageIO.read(new File("Characters/Ryu/p1/ryuSpecial.png"));
p2RyuSpecial = ImageIO.read(new File("Characters/Ryu/p2/ryuSpecial.png"));
//audio
music = new File("Audio/music.wav").toURI().toURL();
fight = new File("Audio/fight.wav").toURI().toURL();
win = new File("Audio/win.wav").toURI().toURL();
musicAudio = java.applet.Applet.newAudioClip(music);
fightAudio = java.applet.Applet.newAudioClip(fight);
winAudio = java.applet.Applet.newAudioClip(win);
toggleMusic();
} catch (IOException e) {
System.out.println("Something Wrong");
}
p1RyuSpecial = crop(p1RyuSpecial); // runs a function that crops the sprite
p2RyuSpecial = crop(p2RyuSpecial);
//loading the keybinds
p1BindFile = new Scanner(new File("keybinds/p1Keybinds.txt"));
p2BindFile = new Scanner(new File("keybinds/p2Keybinds.txt"));
p1ForwardBind = p1BindFile.nextInt();
p1JumpBind = p1BindFile.nextInt();
p1BackBind = p1BindFile.nextInt();
p1DuckBind = p1BindFile.nextInt();
p1PunchBind = p1BindFile.nextInt();
p1SpecialBind = p1BindFile.nextInt();
p1KickBind = p1BindFile.nextInt();
p1BlockBind = p1BindFile.nextInt();
p2ForwardBind = p2BindFile.nextInt();
p2JumpBind = p2BindFile.nextInt();
p2BackBind = p2BindFile.nextInt();
p2DuckBind = p2BindFile.nextInt();
p2PunchBind = p2BindFile.nextInt();
p2SpecialBind = p2BindFile.nextInt();
p2KickBind = p2BindFile.nextInt();
p2BlockBind = p2BindFile.nextInt();
JFrame frame = new JFrame("Game");
Main panel = new Main();
frame.add(panel);
frame.setVisible(true);
frame.pack();
}
public void paintComponent(Graphics g) {
frameController++;
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradientBackground = new GradientPaint(0, 0, Color.ORANGE, 0, 700, Color.RED);
Color textColor = new Color(255, 165, 0);
if (gameState == 0) {
// main screen loading
g2d.setColor(Color.BLACK);
// g2d.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(map0, 0, 0, this);
g2d.setPaint(new GradientPaint(0, 0, Color.ORANGE, 0, 200, Color.RED));
g2d.setFont(largeText);
centerString(g2d, "Fighting Fury", "H" + logoHeight);
g2d.setFont(text);
g2d.setPaint(Color.WHITE);
if (logoHeight == 100) {
centerString(g2d, "PRESS ENTER TO CONTINUE", "H250");
centerString(g2d, "PRESS ESC FOR SETTINGS", "H300");
g.drawString("MADE BY: FAHAD", 550, 365);
centerString(g2d, "PRESS M FOR INSTRUCTIONS", "H350");
}
// logo height adds a animation where the logo comes from the top
logoHeight = logoHeight == 100 ? logoHeight : logoHeight + 2;
} else if (gameState == 1) {
// a secret credits page if you press backspace on mani menu
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setFont(largeText);
g2d.setPaint(gradientBackground);
centerString(g2d, "SECRET CREDITS", "H85");
g2d.setFont(text);
g2d.setPaint(textColor);
centerString(g2d, "Mr. Chow And His 15 Cars which ", "H200");
centerString(g2d, "was a massive inspiration", "H230");
centerString(g2d, "Press BACKSPACE to go back to main screen", "H340");
}
else if (gameState == 2) {
// menu page where you can press shift to toggle music and caps lock to toggle sfx
g2d.setPaint(gradientBackground);
g2d.setFont(largeText);
g2d.fillRect(0, 0, 800, 367);
g2d.setPaint(Color.WHITE);
centerString(g2d, "SETTINGS", "H100");
g2d.setFont(text);
String gameSoundText = gameMusic ? "ON" : "OFF";
String gameSFXText = gameSFX ? "ON" : "OFF";
centerString(g2d, "GAME MUSIC: " + gameSoundText, "H250");
centerString(g2d, "GAME SFX: " + gameSFXText, "H300");
}
else if (gameState == 3) {
// character select screen
g2d.setPaint(gradientBackground);
g2d.fillRect(0, 0, 800, 367);
g2d.setFont(largeText);
g2d.setPaint(Color.WHITE);
centerString(g2d, "CHARACTER SELECT", "H100");
g2d.setStroke(new BasicStroke(3));
// loading the rectangles for characters
g2d.fillRect(getWidth() / 2 - 115, 200, 50, 50);
g2d.fillRect(getWidth() / 2 - 55, 200, 50, 50);
g2d.fillRect(getWidth() / 2 + 5, 200, 50, 50);
g2d.fillRect(getWidth() / 2 + 65, 200, 50, 50);
g2d.setPaint(Color.BLACK);
g2d.drawRect(getWidth() / 2 - 115, 200, 50, 50);
g2d.drawRect(getWidth() / 2 - 55, 200, 50, 50);
g2d.drawRect(getWidth() / 2 + 5, 200, 50, 50);
g2d.drawRect(getWidth() / 2 + 65, 200, 50, 50);
//loading the character images
g.drawImage(retsuPortrait, getWidth() / 2 - 110, 205, null);
g.drawImage(ryuPortrait, getWidth() / 2 - 50, 205, null);
g.drawImage(comingSoon, getWidth() / 2 + 10, 205, null);
g.drawImage(comingSoon, getWidth() / 2 + 70, 205, null);
// p1/p2 hover related things. Uses a p1Hover and p2Hover variable to see which character they are hovering
if (!p1Char.equals("")) { // the p1Hover icon stays permanantely if they have selected
g2d.setStroke(new BasicStroke(5));
int moveAmount = 0;
g2d.setPaint(new Color(171, 26, 219));
moveAmount = p1Hover == 0 ? -115 : p1Hover == 1 ? -55 : p1Hover == 2 ? 5 : 65; // loads rectangle depending on the p1Hover
g2d.drawRect(getWidth() / 2 + moveAmount, 200, 50, 50);
}
if (!p2Char.equals("")) {
g2d.setStroke(new BasicStroke(5));
int moveAmount = 0;
g2d.setPaint(new Color(219, 26, 113));
moveAmount = p2Hover == 0 ? -115 : p2Hover == 1 ? -55 : p2Hover == 2 ? 5 : 65;
g2d.drawRect(getWidth() / 2 + moveAmount, 200, 50, 50);
}
if (hoverBlink) { // if player has not selected, the icon blinks
g2d.setStroke(new BasicStroke(5));
int moveAmount = 0;
if (p1Char.equals("")) {
// p1 hover
g2d.setPaint(new Color(171, 26, 219));
moveAmount = p1Hover == 0 ? -115 : p1Hover == 1 ? -55 : p1Hover == 2 ? 5 : 65;
g2d.drawRect(getWidth() / 2 + moveAmount, 200, 50, 50);
}
if (p2Char.equals("")) {
// p2 hover
g2d.setPaint(new Color(219, 26, 113));
moveAmount = p2Hover == 0 ? -115 : p2Hover == 1 ? -55 : p2Hover == 2 ? 5 : 65;
g2d.drawRect(getWidth() / 2 + moveAmount, 200, 50, 50);
}
if (p1Hover == p2Hover) {
g2d.setPaint(new Color(81, 26, 219));
moveAmount = p1Hover == 0 ? -115 : p1Hover == 1 ? -55 : p1Hover == 2 ? 5 : 65;
g2d.drawRect(getWidth() / 2 + moveAmount, 200, 50, 50);
}
}
// checks if players just switched their characters for animation reset
if (p1CharSwitch) {
p1CharSwitch = false;
p1HoverCharMovement = -50;
}
if (p2CharSwitch) {
p2CharSwitch = false;
p2HoverCharMovement = 495;
}
g2d.setPaint(new Color(171, 26, 219));
// animation for hover
if (p1Hover == 0) {
g.drawImage(p1retsuBig, p1HoverCharMovement, -10, null);
g2d.drawString("RETSU", 50, -p1HoverCharMovement + 280);
if (p1HoverCharMovement != -20) {
p1HoverCharMovement += 1;
}
} else if (p1Hover == 1) {
g.drawImage(p1ryuBig, p1HoverCharMovement, 30, null);
g2d.drawString("RYU", 50, -p1HoverCharMovement + 280);
if (p1HoverCharMovement != -20) {
p1HoverCharMovement += 1;
}
} else {
g.drawImage(comingSoonBig, p1HoverCharMovement, -10, null);
g2d.drawString("SOON", 60, -p1HoverCharMovement + 280);
if (p1HoverCharMovement != -20) {
p1HoverCharMovement += 1;
}
}
g2d.setPaint(new Color(219, 26, 113));
if (p2Hover == 0) {
g.drawImage(p2retsuBig, p2HoverCharMovement, -10, null);
g2d.drawString("RETSU", 550, p2HoverCharMovement - 165);
if (p2HoverCharMovement != 465) {
p2HoverCharMovement -= 1;
}
} else if (p2Hover == 1) {
g.drawImage(p2ryuBig, p2HoverCharMovement, 30, null);
g2d.drawString("RYU", 630, p2HoverCharMovement - 165);
if (p2HoverCharMovement != 465) {
p2HoverCharMovement -= 1;
}
} else {
g.drawImage(comingSoonBig, p2HoverCharMovement, -10, null);
g2d.drawString("SOON", 540, p2HoverCharMovement - 165);
if (p2HoverCharMovement != 465) {
p2HoverCharMovement -= 1;
}
}
if (frameController % 5 == 0) {
// used for the blink animation
hoverBlink = hoverBlink ? false : true;
}
}
else if (gameState == 4) { // uses textfile streaming to get keybinds and upload them if they changed
g2d.setPaint(gradientBackground);
g2d.fillRect(0, 0, 800, 367);
g2d.setFont(largeText);
g2d.setPaint(Color.WHITE);
centerString(g2d, "KEYBIND SELECT", "H100");
g2d.setFont(text);
for (int i = 0; i < 4; i++) {
g.drawRect(30, 152 + i * 40, 175, 40);
g.drawRect(205, 152 + i * 40, 175, 40);
g.drawRect(420, 152 + i * 40, 175, 40);
g.drawRect(595, 152 + i * 40, 175, 40);
}
g.drawString("FORWARD: " + (char) p1ForwardBind, 40, 180);
g.drawString("BACK: " + (char) p1BackBind, 40, 220);
g.drawString("PUNCH: " + (char) p1PunchBind, 40, 260);
g.drawString("KICK: " + (char) p1KickBind, 40, 300);
g.drawString("JUMP: " + (char) p1JumpBind, 215, 180);
g.drawString("DUCK: " + (char) p1DuckBind, 215, 220);
g.drawString("SPECIAL: " + (char) p1SpecialBind, 215, 260);
g.drawString("BLOCK: " + (char) p1BlockBind, 215, 300);
// ← ↑ →
g.drawString(
"FORWARD: "
+ (char) (p2ForwardBind == 38 ? '↑'
: p2ForwardBind == 39 ? '→'
: p2ForwardBind == 40 ? '↓' : p2ForwardBind == 37 ? '←' : p2ForwardBind),
430, 180);
g.drawString(
"BACK: " + (char) (p2BackBind == 38 ? '↑'
: p2BackBind == 39 ? '→' : p2BackBind == 40 ? '↓' : p2BackBind == 37 ? '←' : p2BackBind),
430, 220);
g.drawString("PUNCH: " + (char) p2PunchBind, 430, 260);
g.drawString("KICK: " + (char) p2KickBind, 430, 300);
g.drawString(
"JUMP: " + (char) (p2JumpBind == 38 ? '↑'
: p2JumpBind == 39 ? '→' : p2JumpBind == 40 ? '↓' : p2JumpBind == 37 ? '←' : p2BackBind),
605, 180);
g.drawString(
"DUCK: " + (char) (p2DuckBind == 38 ? '↑'
: p2DuckBind == 39 ? '→' : p2DuckBind == 40 ? '↓' : p2DuckBind == 37 ? '←' : p2BackBind),
605, 220);
g.drawString("SPECIAL: " + (char) p2SpecialBind, 605, 260);
g.drawString("BLOCK: " + (char) p2BlockBind, 605, 300);
// hover and selected for keybinds
if (hoverBlink || p1KeySelect) {
g2d.setPaint(new Color(171, 26, 219));
g2d.setStroke(new BasicStroke(3));
if (p1Hover % 2 == 0) {
g.drawRect(30, 152 + (p1Hover / 2) * 40, 175, 40);
} else {
g.drawRect(205, 152 + ((p1Hover - 1) / 2) * 40, 175, 40);
}
}
if (hoverBlink || p2KeySelect) {
g2d.setPaint(new Color(219, 26, 113));
g2d.setStroke(new BasicStroke(3));
if (p2Hover % 2 == 0) {
g.drawRect(420, 152 + (p2Hover / 2) * 40, 175, 40);
} else {
g.drawRect(595, 152 + ((p2Hover - 1) / 2) * 40, 175, 40);
}
}
if (frameController % 5 == 0) {
hoverBlink = hoverBlink ? false : true;
}
}
else if (gameState == 5) {
// map select, similar process to the last two
g2d.setPaint(gradientBackground);
g2d.fillRect(0, 0, 800, 367);
g2d.setFont(largeText);
g2d.setPaint(Color.WHITE);
centerString(g2d, "MAP SELECT", "H100");
g.drawImage(map0Icon, getWidth() / 2 - 222, 130, null);
g.drawImage(map1Icon, getWidth() / 2 + 15, 130, null);
g.drawImage(map2Icon, getWidth() / 2 - 222, 250, null);
g.drawImage(map3Icon, getWidth() / 2 + 15, 250, null);
g2d.setPaint(Color.BLACK);
g2d.setStroke(new BasicStroke(5));
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
if (p1Map != -1 && p2Map != -1) {
g2d.setPaint(new Color(81, 26, 219));
if (chosenMapNum == 0) {
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
p1PosY = 240;
p2PosY = 240;
defaultPosY = 240;
} else if (chosenMapNum == 1) {
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
p1PosY = 265;
p2PosY = 265;
defaultPosY = 265;
} else if (chosenMapNum == 2) {
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
p1PosY = 250;
p2PosY = 250;
defaultPosY = 250;
} else {
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
p1PosY = 250;
p2PosY = 250;
defaultPosY = 250;
}
gameState = 6;
} else {
if (p1Map != -1) {
g2d.setPaint(new Color(171, 26, 219));
if (p1Hover == 0) {
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
} else if (p1Hover == 1) {
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
} else if (p1Hover == 2) {
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
} else {
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
}
}
if (p2Map != -1) {
g2d.setPaint(new Color(219, 26, 113));
if (p2Hover == 0) {
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
} else if (p2Hover == 1) {
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
} else if (p2Hover == 2) {
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
} else {
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
}
}
if (hoverBlink) {
if (p1Map == -1) { // if p2Map is -1 that means they have not selected
// p1 hover
g2d.setPaint(new Color(171, 26, 219));
if (p1Hover == 0) {
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
} else if (p1Hover == 1) {
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
} else if (p1Hover == 2) {
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
} else {
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
}
}
if (p2Map == -1) {
// p2 hover
g2d.setPaint(new Color(219, 26, 113));
if (p2Hover == 0) {
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
} else if (p2Hover == 1) {
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
} else if (p2Hover == 2) {
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
} else {
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
}
}
if (p1Hover == p2Hover) { // has a different color if both are same hover
g2d.setPaint(new Color(81, 26, 219));
if (p1Hover == 0) {
g2d.drawRect(getWidth() / 2 - 222, 130, 207, 95);
} else if (p1Hover == 1) {
g2d.drawRect(getWidth() / 2 + 15, 130, 207, 95);
} else if (p1Hover == 2) {
g2d.drawRect(getWidth() / 2 - 222, 250, 207, 95);
} else {
g2d.drawRect(getWidth() / 2 + 15, 250, 207, 95);
}
}
}
if (frameController % 15 == 0) {
hoverBlink = hoverBlink ? false : true;
}
}
} else if (gameState == 6) { // main screen
// loads the chosen map the characters and the UI
g.drawImage(chosenMap, 0, 0, this);
g2d.setColor(Color.WHITE);
g2d.fillRect(19, 16, 304, 29);
g2d.fillRect(getWidth() - 22 - 300, 16, 304, 29);
g2d.setColor(Color.RED);
g2d.fillRect(21, 18, 300, 25);
g2d.fillRect(getWidth() - 21 - 300, 18, 300, 25);
g2d.setColor(Color.YELLOW);
g2d.fillRect(21, 18, p1Health * 3, 25);
g2d.fillRect(getWidth() - 21 - p2Health * 3, 18, p2Health * 3, 25);
g2d.setPaint(gradientBackground);
g2d.fillRect(21, 52, p1Stamina * 3, 5);
g2d.fillRect(getWidth() - 21 - p2Stamina * 3, 52, p2Stamina * 3, 5);
g2d.setPaint(Color.WHITE);
g2d.setStroke(new BasicStroke(2));
g2d.setPaint(gradientBackground);
if (p1Score == 1) {
g.fillOval(300, 70, 10, 10);
}
if (p2Score == 1) {
g.fillOval(490, 70, 10, 10);
}
g2d.setPaint(Color.WHITE);
g.drawOval(300, 70, 10, 10);
g.drawOval(490, 70, 10, 10);
// shows the p1/p2 combo on the left/right
g.setFont(comboText);
if (p1Combo > 0) {
g.drawString("x" + p1Combo, 20, 250);
}
if (p2Combo > 0) {
g.drawString("x" + p2Combo, 760, 250);
}
// for start timer
if (Integer.parseInt(startTimer) > -1) {
g2d.setFont(largeText);
if (startTimer.equals("3") && gameSFX) {
fightAudio.play();
}
if (!startTimer.equals("0")) {
centerString(g2d, startTimer, "B");
}
if (startTimer.equals("0")) {
centerString(g2d, "FIGHT!", "B");
}
if (frameController % 100 == 0) {
startTimer = "" + (Integer.parseInt(startTimer) - 1);
}
return;
}
// all of the actions that p1 can do
if (p1Action[knockedOut])
knockedOut(g, "p1");
if (p1Action[hit] && !p1Action[knockedOut])
hit(g, "p1");
else if (p1Action[duck])
duck(g, "p1");
else if (p1Action[block])
block(g, "p1");
else if (p1Action[jump])
jump(g, "p1");
else if (p1Action[forward])
moveForward(g, "p1");
else if (p1Action[back])
moveBack(g, "p1");
else if (p1Action[punch])
punch(g, "p1");
else if (p1Action[kick])
kick(g, "p1");
else if (p1Action[special])
special(g, "p1");
else if (!p1Action[knockedOut])
idle(g, "p1");
if (isp1RyuThrowSpecial)
throwRyuSpecial(g, "p1");
// adds stamina if p1 is not attacking
if (!p1Action[punch] && !p1Action[kick] && !p1Action[block] && frameController % 15 == 0) {
p1Stamina = p1Stamina + 5 >= 100 ? 100 : p1Stamina + 5;
}
// all moves that p2 can do
if (p2Action[knockedOut])
knockedOut(g, "p2");
else if (p2Action[hit])
hit(g, "p2");
else if (p2Action[duck])
duck(g, "p2");
else if (p2Action[block])
block(g, "p2");
else if (p2Action[jump])
jump(g, "p2");
else if (p2Action[forward])
moveForward(g, "p2");
else if (p2Action[back])
moveBack(g, "p2");
else if (p2Action[punch])
punch(g, "p2");
else if (p2Action[kick])
kick(g, "p2");
else if (p2Action[special])
special(g, "p2");
else if (!p2Action[knockedOut])
idle(g, "p2");
if (isp2RyuThrowSpecial)
throwRyuSpecial(g, "p2");
// adds stamina if not attacking
if (!p2Action[punch] && !p2Action[kick] && !p2Action[block] && frameController % 15 == 0) {
p2Stamina = p2Stamina + 5 >= 100 ? 100 : p2Stamina + 5;
}
}
if (gameState == 7) {
// p1 win screen
g2d.setPaint(gradientBackground);
g.fillRect(0, 0, 800, 367);
if (p1Char.equals("Retsu")) {
g.drawImage(p1retsuBig, 200, 0, null);
}
if (p1Char.equals("Ryu")) {
g.drawImage(p1ryuBig, 200, 0, null);
}
g2d.setFont(largeText);
g2d.setPaint(new Color(171, 26, 219));
centerString(g2d, "PLAYER 1 WINS", "B");
g2d.setFont(text);
g2d.setPaint(Color.WHITE);
centerString(g2d, "Press BACKSPACE For Main Menu", "H300");
centerString(g2d, "Press ENTER To Restart With Same Settings", "H350");
}
if (gameState == 8) {
// p2 win screen
g2d.setPaint(gradientBackground);
g.fillRect(0, 0, 800, 367);
if (p2Char.equals("Retsu")) {
g.drawImage(p2retsuBig, 250, 0, null);
}
g2d.setFont(largeText);
g2d.setPaint(new Color(219, 26, 113));
centerString(g2d, "PLAYER 2 WINS", "B");
g2d.setFont(text);
g2d.setPaint(Color.WHITE);
centerString(g2d, "Press BACKSPACE For Main Menu", "H300");
centerString(g2d, "Press ENTER To Restart With Same Settings", "H350");
}
if (gameState == 9) {
g2d.setPaint(Color.BLACK);
g2d.fillRect(0, 0, 800, 367);
g2d.setPaint(Color.WHITE);
g2d.setFont(largeText);
centerString(g2d, "MENU", "H100");
g2d.setFont(text);
g.drawString("P1 Select: M", 100, 150);
g.drawString("P1 Navigate: WASD", 100, 200);
g.drawString("P1 Select: /", 450, 150);
g.drawString("P1 Navigate: arrow keys", 450, 200);
}
if (p2Health <= 0) {
// activates knockedout of health <= 0
p2Action[knockedOut] = true;
} else if (p1Health <= 0) {
p1Action[knockedOut] = true;
}
}
// move forward function that makes characters move forward
public void moveForward(Graphics g, String player) {
if (player.equals("p1")) {
g.drawImage(p1[forward][p1Sprite[forward]], p1PosX, p1PosY, null);
p1CurrentMovement = p1[forward][p1Sprite[forward]];
if (frameController % p1MoveLength[forward] == 0) {
if (!checkForCollisions("p1", "walk").equals("Collision")) { // checks for collisions to see if they collide with player 2
p1PosX += 5;
}
// increase sprite num
p1Sprite[forward] = (p1Sprite[forward] + 1) % p1[forward].length;
}
} else {
g.drawImage(p2[forward][p2Sprite[forward]], p2PosX, p2PosY, null);
p2CurrentMovement = p2[forward][p2Sprite[forward]];
if (frameController % p2MoveLength[forward] == 0) {
if (!checkForCollisions("p2", "walk").equals("Out of bounds")) {
p2PosX += 5;
} else {
p2PosX = getWidth() - (p2CurrentMovement.getWidth() == 199 ? 70 : p2CurrentMovement.getWidth());
}
p2Sprite[forward] = (p2Sprite[forward] + 1) % p2[forward].length;
}
}
}
// move backward. Check for collision and if they do not collide with opponent or wall it moves
public void moveBack(Graphics g, String player) {
if (player.equals("p1")) {
g.drawImage(p1[back][p1Sprite[back]], p1PosX, p1PosY, null);
p1CurrentMovement = p1[back][p1Sprite[back]];
if (frameController % p1MoveLength[back] == 0) {
if (!checkForCollisions("p1", "walk").equals("Out of bounds")) {
p1PosX -= 5;
} else {
p1PosX = 0;
}
p1Sprite[back] = (p1Sprite[back] + 1) % p1[back].length; // increase sprite num
}
} else {
g.drawImage(p2[back][p2Sprite[back]], p2PosX, p2PosY, null);
p2CurrentMovement = p2[back][p2Sprite[back]];
if (frameController % p2MoveLength[back] == 0) {
if (!checkForCollisions("p2", "walk").equals("Collision")) {
p2PosX -= 5;
} else {
p2PosX += 5;
}
p2Sprite[back] = (p2Sprite[back] + 1) % p2[back].length;
}
}
}
// punching
public void punch(Graphics g, String player) {
if (player.equals("p1")) {
g.drawImage(p1[punch][p1Sprite[punch]], p1PosX, p1PosY, null);
p1CurrentMovement = p1[punch][p1Sprite[punch]];
if (frameController % p1MoveLength[punch] == 0) {
if (checkForCollisions("p1", "attack").equals("Collision") && !hasp1Hit) { // checks for collision with opponent and that player has not already hit so they don't hit 50 times in one move
p2Health = p2Health - p1PunchDamage < 0 ? 0 : p2Health - p1PunchDamage;
p2Action[hit] = true;
hasp1Hit = true;
p1Combo++; // increaes p1 combo
p2Combo = 0; // reset p2 combo
}
p1Sprite[punch] = (p1Sprite[punch] + 1) % p1[punch].length; // sprite num increase
if (p1Sprite[punch] == 0) {
// if the sprite has come back down to 0, meaning that it is finished then it stops punching
p1Action[punch] = false;
hasp1Hit = false;
}
}
} else {
g.drawImage(p2[punch][p2Sprite[punch]], p2PosX, p2PosY, null);
p2CurrentMovement = p2[punch][p2Sprite[punch]];
if (frameController % p2MoveLength[punch] == 0) {
if (p2Sprite[punch] == 0)
p2PosX -= 35;
else if (p2Sprite[punch] == 1)
p2PosX += 35;
if (checkForCollisions("p2", "attack").equals("Collision") && !hasp2Hit) {
p1Health = p1Health - p2PunchDamage < 0 ? 0 : p1Health - p2PunchDamage;
p1Action[hit] = true;
hasp2Hit = true;
p2Combo++;
p1Combo = 0;
}
p2Sprite[punch] = (p2Sprite[punch] + 1) % p2[punch].length;
if (p2Sprite[punch] == 0) {
p2Action[punch] = false;
hasp2Hit = false;
}
}
}