-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorion.java
More file actions
1334 lines (1101 loc) · 42.3 KB
/
orion.java
File metadata and controls
1334 lines (1101 loc) · 42.3 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 javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.util.*;
public class orion extends JPanel implements KeyListener, MouseListener, Runnable{
// Variables
public static int gameState = 0;
public static int setting = 1;
public static int mouseX;
public static int mouseY;
public static int mapX = 0;
public static int mapY = 0;
public static int change = 1;
// chara variables
public static int charaX = 475;
public static int charaY = 220;
public static int charaSpeed = 5;
public static int globalPos;
public static int fps = 20;
public static boolean up = false;
public static boolean left = false;
public static boolean down = false;
public static boolean right = false;
public static boolean test = false;
// [map][setting][1 = start, 2 = exit]
public static corner[][][] allPos = new corner[4][5][3];
// Creating a path to import the pictures
public static File path = new File("assets/charaAnimation");
public static File[] charaFile = path.listFiles();
public static BufferedImage[] charaImages = new BufferedImage[10];
public static int curChara = 2; // know which frame of chara to show
//IMAGES
public static BufferedImage titleScreen;
// map images
public static File path2 = new File("assets/maps/ruins");
public static File[] ruinsFile = path2.listFiles();
public static BufferedImage[] ruinsImages = new BufferedImage[5];
public static ArrayList<dimension>[] ruinsBounds = new ArrayList[5];
public static ArrayList<dimension>[] ruinsExits = new ArrayList[5];
public static BufferedImage[] snowdenImages = new BufferedImage[5];
public static ArrayList<dimension>[] snowdenBounds = new ArrayList[5];
public static ArrayList<dimension>[] snowdenExits = new ArrayList[5];
public static BufferedImage[] flowey = new BufferedImage[2];
public static ArrayList<dimension>[] floweyBounds = new ArrayList[2];
public static ArrayList<dimension>[] floweyExits = new ArrayList[2];
// gameState is the map, setting is the current place
public static ArrayList<dimension>[][] allBounds = new ArrayList[4][5];
public static ArrayList<dimension>[][] allExits = new ArrayList[4][5];
public static BufferedImage[][] allMaps = new BufferedImage[4][5];
// set of coords in specific maps where the map camera needs to move
public static dimension[][] moveMap = new dimension[3][5];
BufferedImage fadeStart;
BufferedImage fadeEnd;
// audio
// Stops the music when going through exits / entrances of snowden
public static boolean stop = false;
// position
// battle
public static boolean battling = false;
public static boolean winner = false;
public static BufferedImage player;
public static BufferedImage brokenHeart;
// menu images
public static BufferedImage[] menuImages = new BufferedImage[4];
public static File path1 = new File("assets/battleImages/menus");
public static File[] menuFiles = path1.listFiles();
// menu options
public static BufferedImage[] selectionImages = new BufferedImage[4];
public static File path3 = new File("assets/battleImages/options");
public static File[] selectionFiles = path3.listFiles();
public static corner[] optionPos = new corner[4];
// slash animation
public static BufferedImage[] slashImage = new BufferedImage[4];
public static corner[] slashCoords = new corner[4];
// player boundaries in battle
public static ArrayList<dimension> gameBounds = new ArrayList<dimension>();
// font
public static Font font;
public static Font damageFont;
// slider
public static BufferedImage slider;
public static BufferedImage bar;
// boss image
public static BufferedImage BD;
public static BufferedImage deadBoss;
// When user runs out of hp
public static BufferedImage gameOver;
public static BufferedImage gameOver2;
public static int z = 0;
public static boolean over = false;
// Attacks
public static BufferedImage bone;
public static BufferedImage bone2;
public static corner[] bonePositions = new corner[11];
public static corner[] bonePositions2 = new corner[12];
public static int tester = 0;
public static int xe;
// other
animation animation = new animation(this);
charaAnimation charaAnimation = new charaAnimation(this);
audio audio = new audio(this);
battle battle = new battle(this);
public orion() {
// 10 pixels less height and width than the background because
// for some reason there is extra space when defining the frame
// to be the same size as the background image
// 615
setPreferredSize(new Dimension(990, 615));
setBackground(new Color(0, 0, 0));
// import images
try {
titleScreen = ImageIO.read(new File("assets/undertalestartmenu.png"));
// maps
snowdenImages[1] = ImageIO.read(new File("assets/maps/snowden/snowden1.png"));
snowdenImages[2] = ImageIO.read(new File("assets/maps/snowden/snowden2.png"));
snowdenImages[3] = ImageIO.read(new File("assets/maps/snowden/snowden3.png"));
snowdenImages[4] = ImageIO.read(new File("assets/maps/snowden/snowden4.png"));
ruinsImages[1] = ImageIO.read(new File("assets/maps/ruins/ruins1.png"));
ruinsImages[2] = ImageIO.read(new File("assets/maps/ruins/ruins2.png"));
ruinsImages[3] = ImageIO.read(new File("assets/maps/ruins/ruins3.png"));
ruinsImages[4] = ImageIO.read(new File("assets/maps/ruins/ruins4.png"));
flowey[1] = ImageIO.read(new File("assets/story/Flowey2.png"));
// character
charaImages[0] = ImageIO.read(new File("assets/charaAnimation/AcharaB1.png"));
charaImages[1] = ImageIO.read(new File("assets/charaAnimation/AcharaL1.png"));
charaImages[2] = ImageIO.read(new File("assets/charaAnimation/BcharaF1.png"));
charaImages[3] = ImageIO.read(new File("assets/charaAnimation/BcharaR1.png"));
charaImages[4] = ImageIO.read(new File("assets/charaAnimation/charaB2.png"));
charaImages[5] = ImageIO.read(new File("assets/charaAnimation/charaB3.png"));
charaImages[6] = ImageIO.read(new File("assets/charaAnimation/charaF2.png"));
charaImages[7] = ImageIO.read(new File("assets/charaAnimation/charaF3.png"));
charaImages[8] = ImageIO.read(new File("assets/charaAnimation/charaL2.png"));
charaImages[9] = ImageIO.read(new File("assets/charaAnimation/charaR2.png"));
// menu / buttons
menuImages[1] = ImageIO.read(new File("assets/battleImages/menus/menu1.png"));
menuImages[2] = ImageIO.read(new File("assets/battleImages/menus/menu2.png"));
menuImages[3] = ImageIO.read(new File("assets/battleImages/menus/menu3.png"));
selectionImages[1] = ImageIO.read(new File("assets/battleImages/options/option1.png"));
selectionImages[2] = ImageIO.read(new File("assets/battleImages/options/option2.png"));
selectionImages[3] = ImageIO.read(new File("assets/battleImages/options/option3.png"));
player = ImageIO.read(new File("assets/battleImages/characters/player.png"));
bar = ImageIO.read(new File("assets/battleImages/menus/bar.jpg"));
bone = ImageIO.read(new File("assets/battleImages/attacks/bone.png"));
bone2 = ImageIO.read(new File("assets/battleImages/attacks/bone2.png"));
BD = ImageIO.read(new File("assets/battleImages/characters/boss.png"));
brokenHeart = ImageIO.read(new File("assets/battleImages/characters/deadPlayer.png"));
gameOver = ImageIO.read(new File("assets/battleImages/menus/gameOver.png"));
gameOver2 = ImageIO.read(new File("assets/battleImages/menus/gameOver2.png"));
deadBoss = ImageIO.read(new File("assets/battleImages/menus/deadBoss.png"));
// slash animation
slashImage[0] = ImageIO.read(new File("assets/battleImages/slash/slash1.1.png"));
slashImage[1] = ImageIO.read(new File("assets/battleImages/slash/slash2.1.png"));
slashImage[2] = ImageIO.read(new File("assets/battleImages/slash/slash3.1.png"));
slashImage[3] = ImageIO.read(new File("assets/battleImages/slash/slash4.1.png"));
}
catch (Exception e) {
System.out.println("Image does not exist");
}
// create thread
Thread thread = new Thread(this);
thread.start();
// add listeners
addKeyListener(this);
this.setFocusable(true);
addMouseListener(this);
// create boundaries & exits
for (int i = 1; i < 5; i++) {
ruinsBounds[i] = new ArrayList<dimension>();
ruinsExits[i] = new ArrayList<dimension>();
snowdenBounds[i] = new ArrayList<dimension>();
snowdenExits[i] = new ArrayList<dimension>();
}
floweyBounds[1] = new ArrayList<dimension>();
floweyExits[1] = new ArrayList<dimension>();
for (int i = 1; i < 3; i++) { // map
for (int x = 0; x < 3; x++) { // setting
allBounds[i][x] = new ArrayList<dimension>();
allExits[i][x] = new ArrayList<dimension>();
}
}
// Positions of Chara
// ruins1
allPos[1][1][1] = new corner(480, 220); // Initial position after menu
allPos[1][1][2] = new corner(15, 340); // In front of exit
// ruins2
allPos[1][2][1] = new corner(900, 255); // In front of entrance
allPos[1][2][2] = new corner(130, 185); // In front of exit
// ruins3
allPos[1][3][1] = new corner(85, 240); // In front of entrance
allPos[1][3][2] = new corner(870, 415); // In front of exit
// ruins4
allPos[1][4][1] = new corner(475, 450); // In front of entrance
allPos[1][4][2] = new corner(470, 80); // In front of exit
// snowden1
allPos[2][1][1] = new corner(140, 400); // In front of entrance
allPos[2][1][2] = new corner(905, 400); // In front of exit
// snowden2
allPos[2][2][1] = new corner(10, 360); // In front of entrance
allPos[2][2][2] = new corner(930, 345); // In front of exit
// snowden3
allPos[2][3][1] = new corner(920, 380); // In front of entrance
allPos[2][3][2] = new corner(60, 155); // In front of exit
// snowden4
allPos[2][4][1] = new corner(0, 265); // In front of entrance
allPos[2][4][2] = new corner(865, 140); // In front of exit
// end room
allPos[3][1][1] = new corner(450, 120);
allPos[3][1][2] = new corner(0,0);
// ruins1
ruinsBounds[1].add(new dimension(new corner (135, -10), new corner (800, 375)));
ruinsBounds[1].add(new dimension(new corner(-35, 260), new corner(135, 375)));
ruinsExits[1].add(new dimension(new corner(1000, 625), new corner(1000, 625))); // there is no entrance so set to max val
ruinsExits[1].add(new dimension(new corner(-35, 260), new corner(-35, 375))); // exit
// ruins2
ruinsBounds[2].add(new dimension(new corner (45, 175), new corner (940, 300)));
ruinsBounds[2].add(new dimension(new corner (100, 150), new corner (170, 175)));
ruinsExits[2].add(new dimension(new corner(940,175), new corner(940, 300))); // entrance
ruinsExits[2].add(new dimension(new corner(100,150), new corner(170, 150))); // exit
// ruins3
ruinsBounds[3].add(new dimension(new corner(55, 180), new corner(135,285)));
ruinsBounds[3].add(new dimension(new corner(135, 125), new corner(765,460)));
ruinsBounds[3].add(new dimension(new corner(765, 355), new corner(900,460)));
ruinsExits[3].add(new dimension(new corner(55,180), new corner(55,285))); // entrance
ruinsExits[3].add(new dimension(new corner(900,355), new corner(900,460))); // exit
// ruins4
ruinsBounds[4].add(new dimension(new corner(450, 275), new corner(495,480)));
ruinsBounds[4].add(new dimension(new corner(250, 270), new corner(695,280)));
ruinsBounds[4].add(new dimension(new corner(395, 60), new corner(550,270)));
ruinsBounds[4].add(new dimension(new corner(465,40), new corner(475,60)));
ruinsExits[4].add(new dimension(new corner(445,480), new corner(500,480))); // entrance
ruinsExits[4].add(new dimension(new corner(465,40), new corner(475, 40))); // exit
// snowden1
snowdenBounds[1].add(new dimension(new corner(210, 265), new corner(365, 320)));
snowdenBounds[1].add(new dimension(new corner(210, 320), new corner(945, 470)));
snowdenBounds[1].add(new dimension(new corner(90, 370), new corner(210, 470)));
snowdenExits[1].add(new dimension(new corner(90, 370), new corner (90, 415))); // entrance
snowdenExits[1].add(new dimension(new corner(945, 320), new corner(945, 470))); // exit
// snowden2
snowdenBounds[2].add(new dimension(new corner(-25, 250), new corner(950, 445)));
snowdenBounds[2].add(new dimension(new corner(70, 0), new corner(605, 250)));
snowdenBounds[2].add(new dimension(new corner(605, 180), new corner(820, 250)));
snowdenExits[2].add(new dimension(new corner(-25, 250), new corner(-25, 445))); // entrance
snowdenExits[2].add(new dimension(new corner(950, 250), new corner(950, 445))); // exit
// snowden3
snowdenBounds[3].add(new dimension(new corner(805, 310), new corner(945, 400)));
snowdenBounds[3].add(new dimension(new corner(525, 160), new corner(805, 400)));
snowdenBounds[3].add(new dimension(new corner(125, 250), new corner(525, 400)));
snowdenBounds[3].add(new dimension(new corner(0, 160), new corner(390, 250)));
snowdenBounds[3].add(new dimension(new corner(45, 130), new corner(75, 160)));
snowdenExits[3].add(new dimension(new corner(945, 310), new corner(945, 400))); // entrance
snowdenExits[3].add(new dimension(new corner(45, 130), new corner(75, 130))); // exit
// snowden4
snowdenBounds[4].add(new dimension(new corner(-40, 185), new corner(355,290)));
snowdenBounds[4].add(new dimension(new corner(65, 10), new corner(355,290)));
snowdenBounds[4].add(new dimension(new corner(355, 130), new corner(450,140)));
snowdenBounds[4].add(new dimension(new corner(455, 130), new corner(880,140)));
snowdenBounds[4].add(new dimension(new corner(880, 130), new corner(910,155)));
snowdenBounds[4].add(new dimension(new corner(880, 155), new corner(895,175)));
snowdenBounds[4].add(new dimension(new corner(880, 175), new corner(910,280)));
snowdenExits[4].add(new dimension(new corner(-40, 190), new corner(-40, 305))); // entrance
snowdenExits[4].add(new dimension(new corner(910, 130), new corner(910, 155))); // exit
// Flowey
floweyBounds[1].add(new dimension(new corner(10, 15), new corner(300, 495)));
floweyBounds[1].add(new dimension(new corner(300, 110), new corner(615, 495)));
floweyBounds[1].add(new dimension(new corner(615, 15), new corner(910, 495)));
floweyBounds[1].add(new dimension(new corner(440, 75), new corner(470, 110)));
floweyExits[1].add(new dimension(new corner(1, 1), new corner(1,1)));
floweyExits[1].add(new dimension(new corner(440, 75), new corner(470,75)));
// putting them all in a list
allBounds[1] = ruinsBounds;
allBounds[2] = snowdenBounds;
allBounds[3] = floweyBounds;
allMaps[1] = ruinsImages;
allMaps[2] = snowdenImages;
allMaps[3] = flowey;
allExits[1] = ruinsExits;
allExits[2] = snowdenExits;
allExits[3] = floweyExits;
// Coords to move map
moveMap[1][3] = new dimension(new corner(0, 290), new corner(0, 900));
moveMap[1][4] = new dimension(new corner(0, 435), new corner(0, 900));
moveMap[2][1] = new dimension(new corner(370, 0), new corner(1200, 0));
moveMap[2][4] = new dimension(new corner(445, 0), new corner(1115, 0));
// Slash animation coords
slashCoords[0] = new corner(350, 0);
slashCoords[1] = new corner(350, 40);
slashCoords[2] = new corner(340, 70);
slashCoords[3] = new corner(350, 70);
// Font
try {
font = Font.createFont(Font.TRUETYPE_FONT, new File("assets/fonts/DTM-Sans.ttf")).deriveFont(30f);
damageFont = Font.createFont(Font.TRUETYPE_FONT, new File("assets/fonts/DTM-Sans.ttf")).deriveFont(50f);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
//register the font
ge.registerFont(font); }
catch (IOException | FontFormatException e) {
e.printStackTrace(); }
//use the font
this.setFont(font);
// Menu options
optionPos[1] = new corner(235, 539);
optionPos[2] = new corner(442, 539);
optionPos[3] = new corner(650, 539);
// Boundaries when in battle
gameBounds.add(new dimension(new corner(310, 295), new corner(655,445)));
}
public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
JFrame frame = new JFrame("UNDERTALE");
orion panel = new orion();
frame.add(panel);
frame.pack();
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, animation.alpha));
if(!battling) {
// fade
try {
audio.playMusic(gameState);
} catch (LineUnavailableException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnsupportedAudioFileException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (animation.fading) {
if (!animation.faded) {
g2d.drawImage(fadeStart, mapX, mapY, null);
// fade out the character as well
if (gameState - 1 != 0 && 1 <= gameState && gameState <= 3) {
g2d.drawImage(charaImages[curChara], charaX, charaY, null);
}
}
else {
// change chara position
charaX = allPos[gameState][setting][change].x;
charaY = allPos[gameState][setting][change].y;
System.out.println("CHARAX = " + charaX + " CHARAY = " + charaY);
// Used to determine if map needs to move
// at a certain point
// if chara spawns at the bottom
if (charaY > 312 && gameState == 1) {
globalPos = 1250 - (625 - charaY);
}
else if (gameState == 1 && setting == 3) {
globalPos = charaY;
}
else if(gameState == 2 && charaX > 625 && setting != 4) {
globalPos = (1250 - (640 - charaX));
}
else if (gameState == 2 && charaX < 625) {
globalPos = charaX;
}
g2d.drawImage(fadeEnd, mapX, mapY, null);
// fade in the character as well
if (1 <= gameState && gameState <= 3) {
g2d.drawImage(charaImages[curChara], charaX, charaY, null);
}
}
}
// the start menu
else if (gameState == 0) {
g2d.drawImage(titleScreen, 0, 0, null);
// startSong.start();
}
// exploration
else if (1 <= gameState && gameState <= 3) {
g2d.drawImage(allMaps[gameState][setting], mapX, mapY, null);
try {
Thread.sleep(60);
g2d.drawImage(charaImages[curChara], charaX, charaY, null);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else if (battling) {
g.setColor(new Color(255, 255, 255));
g.setFont(font);
// menu background
if(battle.menuState <= 3) {
g.drawImage(menuImages[battle.menuState], 0, 0, null);
g.drawImage(BD, 430, 85, null);
}
// stats
g.drawString(battle.health + "", 345, 518);
g.drawString("50", 425, 518);
g.drawString(battle.heals + "", 645, 518);
g.drawString("5", 710, 518);
g.drawString("BOSS HEALTH: ", 385, 75);
g.drawString(battle.bossHealth + "", 575, 75);
// if u lose or win
if (battle.menuState > 3 || battle.slashDraw) {
if (battle.menuState == 4) {
// We use if statements to ensure that the order of
// execution is correct as the thread.sleep causes
// issues with the order. Menus / Text need to be redrawn
// as the text for HP freezes at "1", then the sleep runs.
if(z == 0) {
if(battle.x == 0) {
g.drawImage(menuImages[3], 0, 0, null);
g.drawImage(BD, 430, 85, null);
g.drawString(battle.health + "", 345, 518);
g.drawString("50", 425, 518);
g.drawString(battle.heals + "", 645, 518);
g.drawString("5", 710, 518);
g.drawString("BOSS HEALTH: ", 385, 75);
g.drawString(battle.bossHealth + "", 575, 75);
battle.x++;
System.out.println("runed");
}
else if(battle.x == 1) {
super.paintComponent(g);
g.drawImage(brokenHeart, battle.playerX, battle.playerY, null);
battle.x++;
System.out.println("runed2");
}
else if (battle.x == 2) {
super.paintComponent(g);
g.drawImage(brokenHeart, battle.playerX, battle.playerY, null);
battle.x++;
battle.dead = true;
System.out.println("runed3");
}
}
if(battle.dead) {
over = true;
try {audio.playMusic(gameState);}
catch (LineUnavailableException | UnsupportedAudioFileException | IOException e1) {e1.printStackTrace();}
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
battle.dead = false;
}
else if(battle.x == 3) {
z++;
if(z < 30) {g.drawImage(gameOver2, 0, 0, null);}
if (z >= 30) {g.drawImage(gameOver, 0, 0, null); over = false;}
}
}
// When dealing damage to the boss, it will create
// a slash animation. To do so, you have to redraw
// all the images and the slash images
else if (battle.slashDraw) {
if(battle.num <= 3) {
super.paintComponent(g);
g.drawImage(menuImages[2], 0, 0, null);
g.drawImage(bar, battle.barX, 314, null);
g.drawImage(BD, 430, 85, null);
g.drawString(battle.health + "", 345, 518);
g.drawString("50", 425, 518);
g.drawString(battle.heals + "", 645, 518);
g.drawString("5", 710, 518);
g.drawString("BOSS HEALTH: ", 385, 75);
g.drawString(battle.bossHealth + "", 575, 75);
g.drawString("MINUS " + battle.damage + " HP", 620, 150);
if(battle.playHit) {
try {audio.hitSound(battle.damage);}
catch (LineUnavailableException | UnsupportedAudioFileException | IOException e1) {
e1.printStackTrace();}
battle.playHit = false;
}
g.drawImage(slashImage[battle.num], slashCoords[battle.num].x, slashCoords[battle.num].y, null);
System.out.println("SLASH DRAWN");
}
// Reset variable values to ensure
// that the animation can be reused
else {
g.drawImage(bar, battle.barX, 314, null);
battle.slashDraw = false;
battle.slash = false;
battle.num = 0;
System.out.println("bared: " + battle.barX);
}
// If the boss is defeated
if (battle.menuState == 5 && !battle.slashDraw) {
animation.fade(deadBoss, allMaps[2][4], "slow");
winner = true;
}
}
}
else {
// highlight selection
if (battle.menuState == 1) {
g.setFont(font);
if (battle.textState == 1) {
g.drawString("What will Chara do?", 75, 360);
}
else if (battle.textState == 2) {
if (battle.health == 50)
g.drawString("You are MAX HP!", 75, 360);
else if (battle.heals == 0)
g.drawString("You are out of heals!", 75, 360);
else
g.drawString("You healed 10 HP! You have " + battle.heals + " left", 75, 360);
}
else if (battle.textState == 3) {
g.drawString("You fled the scene" , 75, 360);
}
g.drawImage(selectionImages[battle.selectionState], optionPos[battle.selectionState].x, optionPos[battle.selectionState].y, null);
}
else if (battle.menuState == 2) {
// Reset bar values
if(battle.count == 0) {
battle.count = 1;
battle.barX = 60;
battle.damage = 0;
battle.stopBar = false;
}
if(battle.stopBar) {
try {
System.out.println("damaged");
Thread.sleep(1000);
}
catch (InterruptedException e1) {
e1.printStackTrace();
}
if (Math.random() >= 0.50)
battle.variation = 1;
else battle.variation = 2;
System.out.println("variation = " + battle.variation);
if (battle.attack == 1) {
firstAttack();
}
else if (battle.attack == 2) {
secondAttack();
}
battle.menuState = 3;
battle.stopBar = false;
}
else {
g.drawImage(bar, battle.barX, 314, null);
if(battle.barX >= 920 || battle.damage >= 1) {
battle.stopBar = true;
}
if(!battle.stopBar) {battle.barX += 20;}
}
}
else if (battle.menuState == 3) {
g.drawImage(player, battle.playerX, battle.playerY, null);
if (battle.attack == 1) {
for (int i = 1; i < 11; i++) {
corner cur = bonePositions[i];
if (297 < cur.x && cur.x < 670) {
g.drawImage(bone, cur.x, cur.y, null);
}
}
}
else if (battle.attack == 2) {
for (int i = 1; i < 11; i++) {
corner cur = bonePositions2[i];
if (battle.variation == 1) {
if (cur.x < 680) {
g.drawImage(bone2, cur.x, cur.y, null);
}
}
else {
if (cur.x > 297) {
g.drawImage(bone2, cur.x, cur.y, null);
}
}
}
}
}
}
}
}
@Override
public void keyPressed(KeyEvent e) {
xe = 0;
// Determines which direction the user has pressed
// and causes the character to move in that direction
// if it is within the boundaries
// When moving the map, the map is moving and the character is not
// This means that her X or Y value will not change. Thus, we use
// globalPos to track her theoretical position. If she is within certain
// values, the map will move. Otherwise, if she goes beyond those values,
// the map will stop moving and the character itself will.
charaAnimation.x = e.getKeyCode();
if(!over) {xe = e.getKeyCode();}
if(!battling) {
if (!animation.fading && 1 <= gameState && gameState <= 3) {
// change animation to run method as it depends on each click
// for animation to change directions
if(e.getKeyCode() == 38)
{
up = true;
}
if(e.getKeyCode() == 37)
{
left = true;
}
if(e.getKeyCode() == 40)
{
down = true;
}
if(e.getKeyCode() == 39)
{
right = true;
}
System.out.println();
System.out.println("globalPos: " + globalPos);
System.out.println("mapX: " + mapX + " mapY: " + mapY);
change = withinExit(charaX, charaY, allExits[gameState][setting]);
System.out.println("chara x = " + charaX + " " + "charaY = " + charaY);
if (change != 0) {
// save the current map
fadeStart = allMaps[gameState][setting];
System.out.println(gameState + " " + setting + " change " + change);
// go to next map
if (change == 1) {
System.out.println("next setting");
// if there are no more maps
if (gameState + 1 == 4) {
setting = 4;
gameState--;
change = 2;
}
// going to next map
else if (setting + 1 == 5) {
gameState++;
setting = 1;
}
else setting++;
}
else if (change == 2) {
// go to the previous MAP
if (setting - 1 == 0) {
gameState--;
setting = 4;
}
// go to the previous setting but still in same map
else setting--;
}
System.out.println("before: " + gameState + " " + setting);
fadeEnd = allMaps[gameState][setting];
System.out.println("new: " + gameState + " " + setting);
animation.fade(fadeStart, fadeEnd, "fast");
}
}
}
else if(battling && xe != 0){
if (battle.menuState == 1) {
// start state
if (battle.textState == 1) {
// left
if (xe == 37) {
if (battle.selectionState - 1 > 0) {
battle.selectionState --;
}
}
// right
else if (xe == 39) {
if (battle.selectionState + 1 < 4) {
battle.selectionState ++;
}
}
// if the key is z, then select
else if (xe == 90) {
if (battle.selectionState == 1) {
battle.textState = 1;
battle.menuState = 2;
battle.count = 0;
System.out.println("menu2");
}
else if (battle.selectionState == 2 && battle.health < 50 && battle.heals > 0) {
if (battle.health + 10 > 50) {
battle.health += 50 - battle.health;
}
else battle.health += 10;
battle.textState = 2;
battle.heals--;
}
else if (battle.selectionState == 3) {
battle.textState = 3;
}
}
/*
// if the key is x, then go back
else if (x == 88) {
}
*/
}
// if you picked to heal or flee, you must click z another time to progress
else {
if (xe == 90) {
if (battle.selectionState == 2) {
battle.textState = 1;
battle.menuState++;
}
else if (battle.selectionState == 3) {
battling = false;
}
System.out.println("brodie");
}
}
repaint();
}
// slider
// Pressing 'z' will stop the slider, determine
// the damage to apply onto the boss, and initalize
// the slash animation
else if (battle.menuState == 2 && !battle.slash) {
if(e.getKeyChar() == 'z' || e.getKeyChar() == 'Z') {
if(battle.barX <= 275 || battle.barX >= 705) {
battle.damage = 5;
}
else if(battle.barX <= 450 || battle.barX >= 530) {
battle.damage = 10;
}
else {
battle.damage = 100;
}
if(battle.damage > 0) {battle.slash = true;}
battle.bossHealth -= battle.damage;
if(battle.bossHealth <= 0) { battle.bossHealth = 0; battle.menuState = 5;}
battle.playHit = true;
System.out.println("DAMAGE: " + battle.damage);
}
}
else if (battle.menuState == 3) {
if (e.getKeyChar() == 'w' || e.getKeyCode() == 38) { // keycode 39 is the up arrow key
battle.up = true;
}
if (e.getKeyChar() == 's' || e.getKeyCode() == 40) {
battle.down = true;
}
if (e.getKeyChar() == 'a' || e.getKeyCode() == 37) {
battle.left = true;
}
if (e.getKeyChar() == 'd' || e.getKeyCode() == 39) {
battle.right = true;
}
}
else if (battle.menuState == 4) {
if(e.getKeyChar() == 'z' || e.getKeyChar() == 'Z') {
z = 0;
battle.resetStats();
try {audio.playMusic(gameState);}
catch (LineUnavailableException | UnsupportedAudioFileException | IOException e1) {e1.printStackTrace();}
System.out.println("quit");
}
}
}
}
public void run() {
while(true) {
if(!battling) {
try {
Thread.sleep(1000 / fps);
System.out.println("global " + globalPos + " x: " + charaX + "y: " + charaY);
if (up && withinBounds(charaX, charaY - charaSpeed, allBounds[gameState][setting])) {
charaAnimation.key = 1;
if(gameState == 1) {
if(setting > 2 && moveMap[gameState][setting].topLeft.y < globalPos && globalPos <= moveMap[gameState][setting].bottomRight.y) {
mapY += charaSpeed;
globalPos -= charaSpeed;
}
else {
charaY -= charaSpeed;
globalPos -= charaSpeed;
}
}
else {
charaY -= charaSpeed;
}
charaAnimation.run();
}
if (down && withinBounds(charaX, charaY + charaSpeed, allBounds[gameState][setting])) {
charaAnimation.key = 3;
if(gameState == 1) {
if(setting > 2 && moveMap[gameState][setting].topLeft.y <= globalPos && globalPos < moveMap[gameState][setting].bottomRight.y) {
mapY -= charaSpeed;
globalPos += charaSpeed;
}
else {
charaY += charaSpeed;
globalPos += charaSpeed;
}
}
else {
charaY += charaSpeed;
}
charaAnimation.run();
}
if (left && withinBounds(charaX - charaSpeed, charaY, allBounds[gameState][setting])) {
charaAnimation.key = 2;
// for moving the camera horizontally
if(gameState == 2 && (setting == 1 || setting == 4)) {
if(moveMap[gameState][setting].topLeft.x < globalPos && globalPos <= moveMap[gameState][setting].bottomRight.x) {
mapX += charaSpeed;
}
else {
charaX -= charaSpeed;
}
globalPos -= charaSpeed;
}
else {
charaX -= charaSpeed;
}
charaAnimation.run();
}
if (right && withinBounds(charaX + charaSpeed, charaY, allBounds[gameState][setting])) {
charaAnimation.key = 4;
if(gameState == 2 && (setting == 1 || setting == 4)) {
if(moveMap[gameState][setting].topLeft.x <= globalPos && globalPos < moveMap[gameState][setting].bottomRight.x) {
mapX -= charaSpeed;
}
else {
charaX += charaSpeed;
}
globalPos += charaSpeed;
}
else {
charaX += charaSpeed;
}
charaAnimation.run();
}
if(stop && audio.footP) {
stop = false;
audio.clip2.stop();
audio.footP = false;
}
if(up || down || left || right) {
try {