-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDrawManager.java
More file actions
2855 lines (2570 loc) · 103 KB
/
DrawManager.java
File metadata and controls
2855 lines (2570 loc) · 103 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
package engine;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.font.GlyphVector;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage; // monster animation on a loading box
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.time.LocalTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import entity.Coin;
import entity.Entity;
import screen.GameScreen;
import screen.GameScreen_2P;
import screen.Screen;
/**
* Manages screen drawing.
*
* @author <a href="mailto:RobertoIA1987@gmail.com">Roberto Izquierdo Amo</a>
*
*/
public final class DrawManager {
/** Singleton instance of the class. */
private static DrawManager instance;
/** Current frame. */
private static Frame frame;
/** FileManager instance. */
private static FileManager fileManager;
/** Application logger. */
private static Logger logger;
/** Graphics context. */
private static Graphics graphics;
/** Buffer Graphics. */
private static Graphics backBufferGraphics;
/** Buffer image. */
private static BufferedImage backBuffer;
/** Normal sized font. */
private static Font fontSmall;
/** Normal sized font properties. */
private static FontMetrics fontSmallMetrics;
/** Normal sized font. */
private static Font fontRegular;
/** Normal sized font properties. */
private static FontMetrics fontRegularMetrics;
/** Big sized font. */
private static Font fontBig;
private static Font fontBig_2p;
/** Big sized font properties. */
private static FontMetrics fontBigMetrics;
private static Font fontVeryBig;
public Cooldown endTimer = new Cooldown(3000);
public long ghostTImer;
public int ghostPostionX;
public int ghostPostionY;
public int ghost1PostionX;
public int ghost1PostionY;
public int ghost2PostionX;
public int ghost2PostionY;
public Color ghostColor = new Color(1, 1, 1);
/** Cooldown timer for background animation. */
private Cooldown bgTimer = new Cooldown(100); // Draw bg interval
private int brightness = 0; // Used as RGB values for changing colors
private int lighter = 1; // For color to increase then decrease
private Cooldown bgTimer_init = new Cooldown(3000); // For white fade in at game start
private Cooldown bgTimer_lines = new Cooldown(100); // For bg line animation
private int lineConstant = 0; // For bg line animation
private Coin coin;
/** Sprite types mapped to their images. */
private static Map<SpriteType, boolean[][]> spriteMap;
private boolean initialSound = true;
public boolean initialSound2 = true;
private boolean isAfterLoading = false;
private CountUpTimer timer;
public int timercount = 0;
public String rewardTypeString;
public GameScreen gamescreen;
//BufferedImage img1, img2, img3, img4;
public int vector_x= 200, vector_y= 200, directionX = new Random().nextBoolean() ? 1 : -1,
directionY = new Random().nextBoolean() ? 1 : -1;
public Cooldown pump = new Cooldown(1000);
boolean isFirst = true;
int bigger = 36, direction = 1;
public String getRandomCoin;
/** Sprite types. */
public static enum SpriteType {
/** Player ship. */
ShipA,
ShipB,
ShipC,
ShipD,
ShipE,
ShipF,
ShipG,
/** Destroyed player ship. */
ShipADestroyed,
ShipBDestroyed,
ShipCDestroyed,
ShipDDestroyed,
ShipEDestroyed,
ShipFDestroyed,
ShipGDestroyed,
/** Player bullet. */
Bullet,
/** Player bulletY. */
BulletY,
/** Enemy bullet. */
EnemyBullet,
/** Enemy bullet goes left diag. */
EnemyBulletLeft,
/** Enemy bullet goes right diag. */
EnemyBulletRight,
/** First enemy ship normal - first form. */
ESnA_1,
/** First enemy ship normal - second form. */
ESnA_2,
/** Second enemy ship normal - first form. */
ESnB_1,
/** Second enemy ship normal - second form. */
ESnB_2,
/** Third enemy ship normal - first form. */
ESnC_1,
/** Third enemy ship normal - second form. */
ESnC_2,
/** Enemy ship mod1 damaged - first form. */
ESm1_1D,
/** Enemy ship mod1 damaged - second form. */
ESm1_2D,
/** Enemy ship mod1 - first form. */
ESm1_1,
/** Enemy ship mod1 - second form. */
ESm1_2,
/** First enemy ship mod2 - first form. */
ESm2A_1,
/** First enemy ship mod2 - second form. */
ESm2A_2,
/** First enemy ship mod2 (hit 1) - third form. */
ESm2A_1D1,
/** First enemy ship mod2 (hit 1) - forth form. */
ESm2A_2D1,
/** First enemy ship mod2 (hit 2) - fifth form. */
ESm2A_1D2,
/** First enemy ship mod2 (hit 2)- sixth form. */
ESm2A_2D2,
/** Second enemy ship mod2 - first form. */
ESm2B_1,
/** Second enemy ship mod2 - second form. */
ESm2B_2,
/** Second enemy ship mod2 (hit 1) - third form. */
ESm2B_1D1,
/** Second enemy ship mod2 (hit 1) - forth form. */
ESm2B_2D1,
/** Second enemy ship mod2 (hit 2) - fifth form. */
ESm2B_1D2,
/** Second enemy ship mod2 (hit 2)- sixth form. */
ESm2B_2D2,
/** Bonus ship1. */
EnemyShipSpecial1,
/** Bonus ship2. */
EnemyShipSpecial2,
/** Bonus ship3. */
EnemyShipSpecial3,
/** Bonus ship4. */
EnemyShipSpecial4,
/** Boss ship - first form. */
BossA1,
/** Boss ship - second form. */
BossA2,
/** Destroyed enemy ship. */
Explosion,
/** random sprit**/
Trash1,
Trash2,
Trash3,
Trash4,
BulletLine,
/** Destroyed enemy ship2. */
Explosion2,
/** Destroyed enemy ship3. */
Explosion3,
/** Destroyed enemy ship4. */
Explosion4,
/** Buff_item dummy sprite*/
Buff_Item,
/** Debuff_item dummy sprite */
Debuff_Item,
/** Laser */
Laser,
/** Laserline */
LaserLine,
Coin,
BlueEnhanceStone,
PerpleEnhanceStone,
ShipAShileded,
ShipBShileded,
ShipCShileded,
EnhanceStone,
//ShipCShileded,
gravestone,
Ghost;
};
/**
* Private constructor.
*/
private DrawManager() {
fileManager = Core.getFileManager();
logger = Core.getLogger();
logger.info("Started loading resources.");
try {
Random random = new Random();
int Trash_enemyA = random.nextInt(3);
spriteMap = new LinkedHashMap<SpriteType, boolean[][]>();
spriteMap.put(SpriteType.ShipA, new boolean[13][8]);
spriteMap.put(SpriteType.ShipB, new boolean[13][8]);
spriteMap.put(SpriteType.ShipC, new boolean[13][8]);
spriteMap.put(SpriteType.ShipD, new boolean[13][8]);
spriteMap.put(SpriteType.ShipE, new boolean[13][8]);
spriteMap.put(SpriteType.ShipF, new boolean[13][8]);
spriteMap.put(SpriteType.ShipG, new boolean[13][8]);
spriteMap.put(SpriteType.ShipADestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.ShipBDestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.ShipCDestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.ShipDDestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.ShipEDestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.ShipFDestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.ShipGDestroyed, new boolean[13][8]);
spriteMap.put(SpriteType.Bullet, new boolean[3][5]);
spriteMap.put(SpriteType.BulletY, new boolean[5][7]);
spriteMap.put(SpriteType.EnemyBullet, new boolean[3][5]);
spriteMap.put(SpriteType.EnemyBulletLeft, new boolean[3][5]);
spriteMap.put(SpriteType.EnemyBulletRight, new boolean[3][5]);
if (Trash_enemyA == 0){
spriteMap.put(SpriteType.ESnA_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESnA_2, new boolean[12][8]);
spriteMap.put(SpriteType.Trash1, new boolean[12][8]);
spriteMap.put(SpriteType.Trash2, new boolean[12][8]);
spriteMap.put(SpriteType.Trash3, new boolean[12][8]);
spriteMap.put(SpriteType.Trash4, new boolean[12][8]);
}
else if (Trash_enemyA == 1){
spriteMap.put(SpriteType.Trash1, new boolean[12][8]);
spriteMap.put(SpriteType.Trash2, new boolean[12][8]);
spriteMap.put(SpriteType.ESnA_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESnA_2, new boolean[12][8]);
spriteMap.put(SpriteType.Trash3, new boolean[12][8]);
spriteMap.put(SpriteType.Trash4, new boolean[12][8]);
}
else{
spriteMap.put(SpriteType.Trash1, new boolean[12][8]);
spriteMap.put(SpriteType.Trash2, new boolean[12][8]);
spriteMap.put(SpriteType.Trash3, new boolean[12][8]);
spriteMap.put(SpriteType.Trash4, new boolean[12][8]);
spriteMap.put(SpriteType.ESnA_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESnA_2, new boolean[12][8]);
}
spriteMap.put(SpriteType.ESnB_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESnB_2, new boolean[12][8]);
spriteMap.put(SpriteType.ESnC_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESnC_2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm1_1D, new boolean[12][8]);
spriteMap.put(SpriteType.ESm1_2D, new boolean[12][8]);
spriteMap.put(SpriteType.ESm1_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm1_2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2A_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2A_2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2A_1D1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2A_2D1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2A_1D2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2A_2D2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2B_1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2B_2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2B_1D1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2B_2D1, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2B_1D2, new boolean[12][8]);
spriteMap.put(SpriteType.ESm2B_2D2, new boolean[12][8]);
spriteMap.put(SpriteType.EnemyShipSpecial1, new boolean[16][7]);
spriteMap.put(SpriteType.EnemyShipSpecial2, new boolean[16][7]);
spriteMap.put(SpriteType.EnemyShipSpecial3, new boolean[16][7]);
spriteMap.put(SpriteType.EnemyShipSpecial4, new boolean[16][7]);
spriteMap.put(SpriteType.Explosion, new boolean[13][7]);
spriteMap.put(SpriteType.BulletLine, new boolean[1][160]);
spriteMap.put(SpriteType.Explosion2, new boolean[13][7]);
spriteMap.put(SpriteType.Explosion3, new boolean[12][8]);
spriteMap.put(SpriteType.Buff_Item, new boolean[9][9]);
spriteMap.put(SpriteType.Debuff_Item, new boolean[9][9]);
spriteMap.put(SpriteType.BlueEnhanceStone, new boolean[8][8]);
spriteMap.put(SpriteType.PerpleEnhanceStone, new boolean[8][8]);
spriteMap.put(SpriteType.BossA1, new boolean[22][13]);
spriteMap.put(SpriteType.BossA2, new boolean[22][13]);
spriteMap.put(SpriteType.Laser, new boolean[2][240]);
spriteMap.put(SpriteType.LaserLine, new boolean[1][240]);
spriteMap.put(SpriteType.Coin, new boolean[7][7]);
spriteMap.put(SpriteType.ShipAShileded, new boolean[13][8]);
spriteMap.put(SpriteType.ShipBShileded, new boolean[13][8]);
spriteMap.put(SpriteType.ShipCShileded, new boolean[13][8]);
spriteMap.put(SpriteType.Explosion4, new boolean[10][10]);
spriteMap.put(SpriteType.gravestone, new boolean[13][9]);
spriteMap.put(SpriteType.Ghost, new boolean[9][11]);
fileManager.loadSprite(spriteMap);
logger.info("Finished loading the sprites.");
// Font loading
fontSmall = fileManager.loadFont(12f);
fontRegular = fileManager.loadFont(14f);
fontBig = fileManager.loadFont(24f);
fontBig_2p = fileManager.loadFont(20f);
fontVeryBig = fileManager.loadFont(40f);
logger.info("Finished loading the fonts.");
} catch (IOException e) {
logger.warning("Loading failed.");
} catch (FontFormatException e) {
logger.warning("Font formating failed.");
}
}
public void stopTimer(CountUpTimer timer) {
timer.stop();
}
/**
* Returns shared instance of DrawManager.
*
* @return Shared instance of DrawManager.
*/
protected static DrawManager getInstance() {
if (instance == null)
instance = new DrawManager();
return instance;
}
/**
* Sets the frame to draw the image on.
*
* @param currentFrame
* Frame to draw on.
*/
public void setFrame(final Frame currentFrame) {
frame = currentFrame;
}
/**
* First part of the drawing process. Initialices buffers, draws the
* background and prepares the images.
*
* @param screen
* Screen to draw in.
*/
public void initDrawing(final Screen screen) {
backBuffer = new BufferedImage(screen.getWidth(), screen.getHeight(),
BufferedImage.TYPE_INT_RGB);
graphics = frame.getGraphics();
backBufferGraphics = backBuffer.getGraphics();
backBufferGraphics.setColor(Color.BLACK);
backBufferGraphics
.fillRect(0, 0, screen.getWidth(), screen.getHeight());
fontSmallMetrics = backBufferGraphics.getFontMetrics(fontSmall);
fontRegularMetrics = backBufferGraphics.getFontMetrics(fontRegular);
fontBigMetrics = backBufferGraphics.getFontMetrics(fontBig);
// drawBorders(screen);
// drawGrid(screen);
}
/**
* Draws the completed drawing on screen.
*
* @param screen
* Screen to draw on.
*/
public void completeDrawing(final Screen screen) {
graphics.drawImage(backBuffer, frame.getInsets().left,
frame.getInsets().top, frame);
}
/**
* Draws an entity, using the apropiate image.
*
* @param entity
* Entity to be drawn.
* @param positionX
* Coordinates for the left side of the image.
* @param positionY
* Coordinates for the upper side of the image.
*/
public void drawEntity(final Entity entity, final int positionX,
final int positionY) {
boolean[][] image = spriteMap.get(entity.getSpriteType());
backBufferGraphics.setColor(entity.getColor());
for (int i = 0; i < image.length; i++)
for (int j = 0; j < image[i].length; j++)
if (image[i][j])
backBufferGraphics.drawRect(positionX + i * 2, positionY
+ j * 2, 1, 1);
}
/**
* Entity can be drawn more precise size.
*
* [Clean Code Team] This method was created by dodo_kdy.
*
*
* @param SpriteType
* @param positionX
* @param positionY
* @param width
* @param height
*/
public void drawEntity(final SpriteType SpriteType, final int positionX,
final int positionY, final double width, final double height,
final Color color) {
boolean[][] image = spriteMap.get(SpriteType);
Graphics2D g2 = (Graphics2D) backBufferGraphics;
g2.setColor(color);
for (int i = 0; i < image.length; i++)
for (int j = 0; j < image[i].length; j++)
if (image[i][j])
g2.fill(new Rectangle2D.Double(positionX + i * width, positionY + j * height, width, height));
}
/**
* For debugging purpouses, draws the canvas borders.
*
* @param screen
* Screen to draw in.
*/
@SuppressWarnings("unused")
private void drawBorders(final Screen screen) {
backBufferGraphics.setColor(Color.GREEN);
backBufferGraphics.drawLine(0, 0, screen.getWidth() - 1, 0);
backBufferGraphics.drawLine(0, 0, 0, screen.getHeight() - 1);
backBufferGraphics.drawLine(screen.getWidth() - 1, 0,
screen.getWidth() - 1, screen.getHeight() - 1);
backBufferGraphics.drawLine(0, screen.getHeight() - 1,
screen.getWidth() - 1, screen.getHeight() - 1);
}
/**
* For debugging purpouses, draws a grid over the canvas.
*
* @param screen
* Screen to draw in.
*/
@SuppressWarnings("unused")
private void drawGrid(final Screen screen) {
backBufferGraphics.setColor(Color.DARK_GRAY);
for (int i = 0; i < screen.getHeight() - 1; i += 2)
backBufferGraphics.drawLine(0, i, screen.getWidth() - 1, i);
for (int j = 0; j < screen.getWidth() - 1; j += 2)
backBufferGraphics.drawLine(j, 0, j, screen.getHeight() - 1);
}
/**
* The color changes slightly depending on the score.
* [Clean Code Team] This method was created by highlees.
*
* @param score
*/
private Color scoreColor(final int score) {
if (score < 800)
return Color.WHITE;
if (score >= 800 && score < 1600)
return new Color(206, 255, 210);
if (score >= 1600 && score < 2400)
return new Color(151, 255, 158);
if (score >= 2400 && score < 3200)
return new Color(88, 255, 99);
if (score >= 3200 && score < 4000)
return new Color(50, 255, 64);
if (score >= 4000 && score < 4800)
return new Color(0, 255, 17);
else
return blinkingColor("HIGH_SCORES");
}
private Color scoreColor_1p(final int score) {
if (score < 800)
return new Color(238, 241, 255);
if (score >= 800 && score < 1600)
return new Color(210, 218, 255);
if (score >= 1600 && score < 2400)
return new Color(170, 196, 255);
if (score >= 2400 && score < 3200)
return new Color(142, 143, 250);
if (score >= 3200 && score < 4000)
return new Color(119, 82, 254);
if (score >= 4000 && score < 4800)
return new Color(25, 4, 130);
else
return blinkingColor("HIGH_SCORES");
}
private Color scoreColor_2p(final int score) {
if (score < 800)
return new Color(255, 234, 221);
if (score >= 800 && score < 1600)
return new Color(252, 174, 174);
if (score >= 1600 && score < 2400)
return new Color(255, 137, 137);
if (score >= 2400 && score < 3200)
return new Color(192, 100, 97);
if (score >= 3200 && score < 4000)
return new Color(154, 70, 70);
if (score >= 4000 && score < 4800)
return new Color(200, 60, 60);
else
return blinkingColor("HIGH_SCORES");
}
private Color levelColor(final int level) {
if (level == 1)
return Color.WHITE;
if (level == 2)
return new Color(206, 255, 210);
if (level == 3)
return new Color(151, 255, 158);
if (level == 4)
return new Color(88, 255, 99);
if (level == 5)
return new Color(50, 255, 64);
if (level == 6)
return new Color(0, 255, 17);
if (level == 7)
return new Color(0,250,13);
else
return new Color(0,250,10);
}
/**
* The emoji changes slightly depending on the score.
* [Clean Code Team] This method was created by highlees.
*
* @param screen
* @param score
*
*/
public void scoreEmoji(final Screen screen, final int score) {
backBufferGraphics.setFont(fontRegular);
if (score >= 800 && score < 1600) {
backBufferGraphics.setColor(scoreColor(800));
backBufferGraphics.drawString(" Z...z.. ( _ . _ )", screen.getWidth() - 250, 25);
}
if (score >= 1600 && score < 2400) {
backBufferGraphics.setColor(scoreColor(1600));
backBufferGraphics.drawString(" ??...?.. ( o . o )", screen.getWidth() - 240, 25);
}
if (score >= 2400 && score < 3200) {
backBufferGraphics.setColor(scoreColor(2400));
backBufferGraphics.drawString(" !!...!.. ) O . O )", screen.getWidth() - 240, 25);
}
if (score >= 3200 && score < 4000) {
backBufferGraphics.setColor(scoreColor(3200));
backBufferGraphics.drawString(" (_/ 0 ^ 0 )_/", screen.getWidth() - 250, 25);
}
if (score >= 4000 && score < 4800) {
backBufferGraphics.setColor(scoreColor(4000));
backBufferGraphics.drawString(" \\_( 0 ^ 0 )_/", screen.getWidth() - 240, 25);
}
if (score >= 4800) {
backBufferGraphics.setColor(blinkingColor("HIGH_SCORES"));
backBufferGraphics.drawString(" \\_( 0 ^ 0 )_/", screen.getWidth() - 240, 25);
}
}
public void drawLevel(final Screen screen, final int level){
backBufferGraphics.setFont(fontBig);
backBufferGraphics.setColor(levelColor(level));
backBufferGraphics.drawString(Integer.toString(level), 150, 28);
}
public void drawSoundButton1(GameScreen gamescreen){
backBufferGraphics.setColor(Color.WHITE);
backBufferGraphics.fillOval(375,425,55,45);
}
public void drawSoundButton2(GameScreen_2P gamescreen_2P){
backBufferGraphics.setColor(Color.WHITE);
backBufferGraphics.fillOval(375,425,55,45);
}
public void drawSoundStatus1(GameScreen gamescreen, boolean keyboard) {
String statusText = keyboard ? "ON" : "OFF";
backBufferGraphics.setColor(Color.BLACK);
backBufferGraphics.drawString(statusText, 379, 455);
}
public void drawSoundStatus2(GameScreen_2P gamescreen_2P, boolean keyboard) {
String statusText = keyboard ? "ON" : "OFF";
backBufferGraphics.setColor(Color.BLACK);
backBufferGraphics.drawString(statusText, 379, 455);
}
/**
* Draws current score on screen.
*
* @param screen
* Screen to draw on.
* @param score
* Current score.
*/
public void drawScore(final Screen screen, final int score) {
backBufferGraphics.setFont(fontBig);
backBufferGraphics.setColor(scoreColor(score));
String scoreString = String.format("%04d", score);
backBufferGraphics.drawString(scoreString, screen.getWidth() - 80, 28);
}
public void drawScore_2p(final Screen screen, final int score,final String player, final int x) {
backBufferGraphics.setFont(fontBig_2p);
if (player.equals("p1")) {
backBufferGraphics.setColor(scoreColor_1p(score));
} else if (player.equals("p2")) {
backBufferGraphics.setColor(scoreColor_2p(score));
} else{
backBufferGraphics.setColor(scoreColor(score));
}
String scoreString = String.format("%04d", score);
backBufferGraphics.drawString(scoreString, x, 26);
}
public void drawTimer(final Screen screen, final long elapsedTime) {
backBufferGraphics.setFont(fontSmall);
backBufferGraphics.setColor(Color.WHITE);
String timeString = formatTime(elapsedTime);
backBufferGraphics.drawString(timeString, 30, 450);
}
private String formatTime(long elapsedTime) {
long totalSeconds = elapsedTime / 1000;
long minutes = totalSeconds / 60;
long seconds = totalSeconds % 60;
return String.format("%02d:%02d", minutes, seconds);
}
/**
* Draws current score on screen.
*
* @param screen
* Screen to draw on.
* @param coin
* Current score.
*/
public void drawCoin(final Screen screen, final Coin coin, final int drawCoinOption) {
if (drawCoinOption == 0) {
this.drawEntity(SpriteType.Coin, 15, 55, 1.5, 1.5, Color.YELLOW);
backBufferGraphics.setFont(fontRegular);
backBufferGraphics.setColor(Color.WHITE);
String coinString = String.format("%03d", coin.getCoin());
backBufferGraphics.drawString(coinString, 30, 65);
}
else if (drawCoinOption == 1) {
this.drawEntity(SpriteType.Coin, 20, 13, 2, 2, Color.YELLOW);
backBufferGraphics.setFont(fontBig);
backBufferGraphics.setColor(Color.WHITE);
String coinString = String.format("%03d", coin.getCoin());
backBufferGraphics.drawString(coinString, 40, 28);
}
else if (drawCoinOption == 2) {
this.drawEntity(SpriteType.Coin, screen.getWidth()* 8/9 - 8, 43, 2, 2, Color.YELLOW);
backBufferGraphics.setFont(fontRegular);
backBufferGraphics.setColor(Color.WHITE);
String coinString = String.format("%03d", coin.getCoin());
backBufferGraphics.drawString(coinString, screen.getWidth() * 8/ 9 + 10, 55);
}
}
public void BulletsCount(final Screen screen, final int BulletsCount) {
backBufferGraphics.setFont(fontRegular);
backBufferGraphics.setColor(Color.WHITE);
String text = "Remaining Bullets: " + String.format("%02d", BulletsCount);
backBufferGraphics.drawString(text, screen.getWidth() - 180, 60);
}
public void BulletsCount_1p(final Screen screen, final int BulletsCount) {
backBufferGraphics.setFont(fontRegular);
backBufferGraphics.setColor(Color.WHITE);
String text = "Remaining Bullets_1p: " + String.format("%02d", BulletsCount);
backBufferGraphics.drawString(text, screen.getWidth() - 200, 60);
}
public void BulletsCount_2p(final Screen screen, final int BulletsCount_2p) {
backBufferGraphics.setFont(fontRegular);
backBufferGraphics.setColor(Color.WHITE);
String text = "Remaining Bullets_2p: " + String.format("%02d", BulletsCount_2p);
backBufferGraphics.drawString(text, screen.getWidth() - 200, 80);
}
/**
* Draws number of remaining lives on screen.
*
* @param screen
* Screen to draw on.
* @param lives
* Current lives.
*/
public void drawLivesbar(final Screen screen, final double lives) {
// Calculate the fill ratio based on the number of lives (assuming a maximum of 3 lives).
double fillRatio = lives / 3.0;
// Determine the width of the filled portion of the rectangle.
int filledWidth = (int) (120 * fillRatio);
// Create a gradient paint that transitions from green to yellow.
GradientPaint gradient = new GradientPaint(8, 8, Color.GREEN, 8 + filledWidth, 8, Color.YELLOW);
// Cast Graphics to Graphics2D for gradient painting.
Graphics2D g2d = (Graphics2D) backBufferGraphics;
// Draw the outline of the rectangle.
g2d.setColor(Color.WHITE);
g2d.drawRect(8, 8, 120, 20);
// Set the paint to the gradient and fill the left portion of the rectangle.
g2d.setPaint(gradient);
g2d.fillRect(8, 8, filledWidth, 20);
// Set the new font size and type
Font newFont = g2d.getFont().deriveFont(Font.BOLD, 19); // Adjust the font size as needed
// Set the new font in the Graphics2D context
g2d.setFont(newFont);
// Set color for the "lives" text.
g2d.setColor(Color.WHITE);
// Calculate the position to center the "lives" text.
int textX = (120 - g2d.getFontMetrics().stringWidth("Lives")) / 2 + 8; // Center horizontally
int textY = 7 + 20 / 2 + g2d.getFontMetrics().getAscent() / 2; // Center vertically
// Draw the "lives" text in the center of the rectangle.
g2d.drawString("Lives", textX, textY);
}
public void drawLivesbar_2p(final Screen screen, final double lives, final int x, final String live) {
// Calculate the fill ratio based on the number of lives (assuming a maximum of 3 lives).
double fillRatio = lives / 3.0;
// Determine the width of the filled portion of the rectangle.
int filledWidth = (int) (90 * fillRatio);
// Create a gradient paint that transitions from green to yellow.
GradientPaint gradient = new GradientPaint(x, 8, Color.GREEN, x + filledWidth, 8, Color.YELLOW);
// Cast Graphics to Graphics2D for gradient painting.
Graphics2D g2d = (Graphics2D) backBufferGraphics;
// Draw the outline of the rectangle.
g2d.setColor(Color.WHITE);
g2d.drawRect(x, 8, 90, 20);
// Set the paint to the gradient and fill the left portion of the rectangle.
g2d.setPaint(gradient);
g2d.fillRect(x, 8, filledWidth, 20);
// Set the new font size and type
Font newFont = g2d.getFont().deriveFont(Font.BOLD, 15); // Adjust the font size as needed
// Set the new font in the Graphics2D context
g2d.setFont(newFont);
// Set color for the "lives" text.
g2d.setColor(Color.WHITE);
// Calculate the position to center the "lives" text.
int textX = x + (90 - g2d.getFontMetrics().stringWidth(live)) / 2; // Center horizontally
int textY = 7 + 20 / 2 + g2d.getFontMetrics().getAscent() / 2; // Center vertically
// Draw the "lives" text in the center of the rectangle.
g2d.drawString(live, textX, textY);
}
public void drawitemcircle(final Screen screen, final int itemcount1, final int itemcount2) {
Graphics2D g2d = (Graphics2D) backBufferGraphics;
// this.drawEntity(SpriteType.Bullet,350,450,5,5); <<-- 이런식으로 아이콘 추가
float strokeWidth = 3.0f; // 원의 선굵기
BasicStroke stroke = new BasicStroke(strokeWidth); // 원의 선굵기
g2d.setStroke(stroke); // 원의 선굵기
g2d.setColor(Color.white); // 원의 선색깔
g2d.fillOval(375, 310, 55, 45); // 원 위치
g2d.fillOval(375, 365, 55, 45); // 원 위치
g2d.setColor(Color.black); // 원의 선색깔
g2d.drawString(Integer.toString(itemcount1), 395, 340); // 글자 추가
g2d.drawString(Integer.toString(itemcount2), 395, 395); // 글자 추가
}
public void drawBossLivesbar(final Screen screen, int boss_lives) {
double fillRatio = boss_lives / 50.0;
int x = 15;
int y = 85;
// Determine the width of the filled portion of the rectangle.
int filledWidth = (int) (398 * fillRatio);
// Cast Graphics to Graphics2D for gradient painting.
Graphics2D g2d = (Graphics2D) backBufferGraphics;
// Create a RoundRectangle2D for the filled portion with rounded edges.
RoundRectangle2D filledRect = new RoundRectangle2D.Double(x, y, filledWidth, 10, 10, 10);
// Create a RoundRectangle2D for the outline with rounded edges.
RoundRectangle2D outlineRect = new RoundRectangle2D.Double(x, y, 398, 10, 10, 10);
// Create a gradient paint that transitions from green to yellow.
GradientPaint gradient = new GradientPaint(x, y, Color.YELLOW, x + filledWidth, y, Color.RED);
// Draw the outline of the rounded rectangle.
g2d.setColor(Color.BLACK);
g2d.draw(outlineRect);
// Set the paint to the gradient and fill the left portion of the rounded rectangle.
g2d.setPaint(gradient);
g2d.fill(filledRect);
}
/**
* Draws a thick line from side to side of the screen.
*
* @param screen
* Screen to draw on.
* @param positionY
* Y coordinate of the line.
*/
public void drawHorizontalLine(final Screen screen, final int positionY) {
backBufferGraphics.setColor(Color.GREEN);
backBufferGraphics.drawLine(0, positionY, screen.getWidth(), positionY);
backBufferGraphics.drawLine(0, positionY + 1, screen.getWidth(),
positionY + 1);
}
/**
* Draws a circle line.
*
* @param screen
* Screen to draw on.
* @param positionX
* X coordinate of the line.
* @param positionY
* Y coordinate of the line.
* @param width
* Y coordinate of the line.
* @param height
* Y coordinate of the line.
* @param graphicOption
* if option 0, use backBufferGraphics Object. Otherwise use graphics Object.
*/
public void drawCircleLine(final Screen screen, final int positionX, final int positionY, final int width, final int height, final int graphicOption) {
backBufferGraphics.setColor(Color.GREEN);
((Graphics2D) backBufferGraphics).setStroke(new BasicStroke(2));
if (graphicOption == 0){
backBufferGraphics.drawOval(positionX, positionY, width, height);
}
else {
graphics.drawOval(positionX, positionY, width, height);
}
}
/**
* Draws a circle filled.
*
* @param screen
* Screen to draw on.
* @param positionX
* X coordinate of the line.
* @param positionY
* Y coordinate of the line.
* @param width
* Y coordinate of the line.
* @param height
* Y coordinate of the line.
*/
public void drawCircleFill(final Screen screen, final int positionX, final int positionY, final int width, final int height) {
backBufferGraphics.setColor(Color.BLACK);
backBufferGraphics.fillOval(positionX, positionY, width, height);
}
/**
* Creates blinking colors like an arcade screen.
* [Clean Code Team] This method was created by highlees.
*
*
*/
private Color blinkingColor(String color) {
if (color == "HIGH_SCORES") {
int R = (int) (Math.pow(Math.random() * (15 - 0), 2));
int G = (int) (Math.random() * (255 - 0));
int B = (int) 3.3 * LocalTime.now().getSecond();
Color title = new Color(R, G, B);
return title;
}
if (color == "GREEN") {
Color green = new Color(0, (int) (Math.random() * (255 - 155) + 155), 0);
return green;
}
if (color == "WHITE") {
int RGB = (int) (Math.random() * (255 - 155) + 155);
Color white = new Color(RGB, RGB, RGB);
return white;
}
if (color == "GRAY") {
int RGB = (int) (Math.random() * (160 - 100) + 100);
Color gray = new Color(RGB, RGB, RGB);
return gray;
}
return Color.WHITE;
}
/**
* Create slowly changing colors.
* Can be applied to multiple screens in the game.
* [Clean Code Team] This method was created by highlees.
*
*
*/
private Color slowlyChangingColors(String color) {
String sec = Integer.toString(LocalTime.now().getSecond());
char c = sec.charAt(sec.length() - 1);
if (color == "GREEN") {
if (c == '0') return new Color(0, 75, 0);
if (c == '1') return new Color(0, 100, 0);
if (c == '2') return new Color(0, 125, 0);
if (c == '3') return new Color(0, 150, 0);
if (c == '4') return new Color(0, 175, 0);
if (c == '5') return new Color(0, 205, 0);
if (c == '6') return new Color(0, 225, 0);
if (c == '7') return new Color(0, 254, 0);
if (c == '8') return new Color(0, 55, 0);
if (c == '9') return new Color(0, 65, 0);
}
if (color == "GRAY") {
if (c == '0') return new Color(75, 75, 75);
if (c == '1') return new Color(85, 85, 85);
if (c == '2') return new Color(105, 105, 105);
if (c == '3') return new Color(130, 130, 130);
if (c == '4') return new Color(155, 155, 155);
if (c == '5') return new Color(180, 180, 180);
if (c == '6') return new Color(205, 205, 205);
if (c == '7') return new Color(225, 225, 225);
if (c == '8') return new Color(55, 55, 55);
if (c == '9') return new Color(65, 65, 65);
}
if (color == "RAINBOW") {
if (c == '0') return new Color(254, 254, 0);
if (c == '1') return new Color(135, 254, 0);
if (c == '2') return new Color(0, 254, 0);
if (c == '3') return new Color(0, 254, 254);
if (c == '4') return new Color(0, 135, 254);
if (c == '5') return new Color(0, 0, 254);
if (c == '6') return new Color(135, 0, 205);
if (c == '7') return new Color(254, 0, 224);