-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
754 lines (649 loc) · 25.6 KB
/
GamePanel.java
File metadata and controls
754 lines (649 loc) · 25.6 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
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.geom.Rectangle2D;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.io.IOException;
import javax.swing.SwingUtilities;
import javax.swing.JComponent;
import javax.swing.JFrame;
import java.awt.AlphaComposite;
import java.awt.FontMetrics;
/**
A component that displays all the game entities
*/
public class GamePanel extends JPanel implements Runnable {
private Car car;
private Enemy[] enemies;
private EnemyBullet[] oppBullets;
private List<Bullet> bullets;
private List<EnemyBullet> enemyBullets;
private List<PowerUp> drops;
private List<StripAnimation> animations;
private boolean isRunning;
private boolean isPaused;
private TileMap tileMap;
private TileMapManager tileMapManager;
private BufferedImage image;
private Thread gameThread;
public ScoringPanel scoringPanel;
public LifePanel lifePanel;
private ImageFX imageFX1, imageFX2;
private ImageFX[] spawns;
private SoundManager soundManager;
private CutsceneManager cutsceneManager;
Random random= new Random();
int rand, type, move;
private int NUM_ENEMIES= 10;
private int kills= 0, powerupKills= 0;
private StripAnimation animation, animation2;
private int speed= 2;
private int time, timeChange= 1;
private PowerUp drop;
private int currentLevel = 3;
private static final int MAX_LEVEL = 3;
private treeveg Vageeta;
private int collectedTags= 0;
private boolean fadeActive = false;
private float fadeAlpha = 0.0f;
private String gameOverMessage = "";
private boolean gameOver = false;
private boolean victory = false;
private static final float FADE_SPEED = 0.05f;
public GamePanel() {
// setPreferredSize(new Dimension(VIEW_WIDTH, VIEW_HEIGHT));
soundManager= SoundManager.getInstance();
scoringPanel= new ScoringPanel();
lifePanel= new LifePanel();
lifePanel.setDoubleBuffered(true);
image = new BufferedImage(getWidth() > 0 ? getWidth() : 400,
getHeight() > 0 ? getHeight() : 400,
BufferedImage.TYPE_INT_ARGB);
car = null;
enemies= null;
spawns= null;
oppBullets= null;
gameThread = null;
isRunning = false;
drop= null;
bullets = new ArrayList<>();
enemyBullets = new ArrayList<>();
drops= new ArrayList<>();
animations= new ArrayList<>();
cutsceneManager = new CutsceneManager(this);
tileMap = null;
tileMapManager = new TileMapManager(
(JFrame)SwingUtilities.getWindowAncestor(this),
"tilemap/basic_tileset_and_assets_standard/terrain_tiles_v2.png"
);
}
// public void createGameEntities() {
// car = new Car (this, 200, 350);
// animation= new StripAnimation("images/kaboom.gif", 6, false);
// animation2= new StripAnimation("images/select.png", 4, true);
// // rotate= new RotateFX(this, "images/health.png");
// bullets.clear();
// enemyBullets.clear();
// }
public void checkOpponents(){
if(enemies== null){
createOpponentsForLevel(currentLevel);
}
}
public void run() {
try {
isRunning = true;
while (isRunning) {
if(!isPaused) {
gameUpdate();
}
gameRender();
if (!cutsceneManager.isPlaying() && car != null) {
car.tick();
}
Thread.sleep(33);
}
}
catch(InterruptedException e) {}
}
public void gameUpdate() {
if (fadeActive) {
enemyDeleteBullet(enemyBullets);
fadeAlpha += FADE_SPEED;
if (fadeAlpha >= 1.0f) {
fadeAlpha = 1.0f;
if ((gameOver && !victory) || victory) {
isRunning = false;
return;
}
}
}
if (cutsceneManager.isPlaying()) {
cutsceneManager.update();
return;
}
if(!isPaused){
if(car != null && tileMap != null) {
tileMap.centerOn(car.getX(), car.getY());
}
// WACK AHH bullet implememntation but we work
for (int i = bullets.size() - 1; i >= 0; i--) {
Bullet b = bullets.get(i);
b.shoot();
if (b.isOffScreen()) {
bullets.remove(i);
continue;
}
Rectangle2D.Double bulletRect = b.getBoundingRectangle();
boolean hitSomething = false;
if (enemies != null) {
for (int j = 0; j < NUM_ENEMIES; j++) {
if (enemies[j] != null && bulletRect.intersects(enemies[j].getBoundingRectangle())) {
soundManager.playClip("hit", false);
bullets.remove(i);
addPoints(1);
// rand = random.nextInt(3);
// if (rand == 0 || rand == 1) {
// drop = new DogTag(this, car, enemies[j].getX(), enemies[j].getY());
// } else {
// drop = new HealthPickup(this, car, enemies[j].getX(), enemies[j].getY());
// }
// StripAnimation dropAnim = new StripAnimation("images/select.png", 4, true);
// dropAnim.start(drop.getX() - 20, drop.getY() - 10);
// drops.add(drop);
// animations.add(dropAnim);
if (enemies[j].takeDamage()) {
killEnemy(enemies[j].getX(), enemies[j].getY(),
enemies[j].getBoundingRectangle().height,
enemies[j].getBoundingRectangle().width,
enemies[j].getType(), j, 0);
}
hitSomething = true;
break;
}
}
}
}
for (int i = enemyBullets.size() - 1; i >= 0; i--) {
EnemyBullet eb = enemyBullets.get(i);
eb.shoot();
if (eb.isOffScreen()) {
enemyBullets.remove(i);
continue;
}
if (car != null && eb.getBoundingRectangle().intersects(car.getBoundingRectangle())) {
soundManager.playClip("playerHit", false);
enemyBullets.remove(i);
loseLife(1);
if (getLifeTotal() <= 0) {
soundManager.playClip("death", false);
destroyed(car.getX(), car.getY(), car.getHeight(), car.getWidth());
startDeathSequence();
}
}
}
for (int i = drops.size() - 1; i >= 0; i--) {
PowerUp drop = drops.get(i);
// StripAnimation anim= animations.get(j);
if (car != null && drop.getBoundingRectangle().intersects(car.getBoundingRectangle())) {
drop.move();
drops.remove(i);
animations.remove(i);
}
}
for (int i=0; i<NUM_ENEMIES; i++) {
checkOpponents();
if(spawns[i]!= null){
spawns[i].update();
}
if (enemies[i] != null){
enemies[i].move();
if (random.nextInt(100) < 0.5) {
enemyShoot(i, enemies[i].getX(), enemies[i].getY(),
(int)enemies[i].getBoundingRectangle().width);
}
}
}
while (bullets.size() > 50) {
bullets.remove(0);
}
while (enemyBullets.size() > 50) {
enemyBullets.remove(0);
}
if(imageFX1!= null)
imageFX1.update();
if(imageFX2!= null)
imageFX2.update();
if(animation!= null)
animation.update();
if(animation2!= null)
animation2.update();
}
//we use here for fuel tanfk shenangicans
boolean allEnemiesDefeated = true;
for (Enemy enemy : enemies) {
if (enemy != null) {
allEnemiesDefeated = false;
break;
}
}
if (allEnemiesDefeated && currentLevel == 3 && !fadeActive) {
startVictorySequence();
}
if (collectedTags >= 5) {
collectedTags = 0;
advanceToNextLevel();
}
}
public void updateBat(int direction) {
if (car != null && !isPaused) {
car.move(direction);
}
}
public void batStop(int num){
if(num== 0){
car.setVelX(0);
}
if(num== 1){
car.setVelY(0);
}
}
public void removeDrop(){
// health= null;
animation2.stop();
}
public void destroyed(int x, int y, int height, int width){ //SNAHYBUIDFBAYUSFGYAUSGVBTUYASVTFYAUVSGTFAYTSVFTYGAVYDVAUT
int screenCenterX = getWidth() / 2 - width / 2;
int screenCenterY = getHeight() / 2 - height / 2;
animation.start(screenCenterX, screenCenterY);
// imageFX2 = new DisintegrateFX(this, screenCenterX, screenCenterY, height, width, "images/car.png");
// car.goAway(200, 350);
}
public void killEnemy(int x, int y, double height, double width, int type, int enemy, int method){
if(type==0){
enemies[enemy]= null;
animation.start(x, y);
imageFX1= new DisintegrateFX(this, x, y, height, width, "images/tank.png");
// repaint();
kills+= 1;
}else if(type==1){
enemies[enemy]= null;
animation.start(x, y);
imageFX1= new DisintegrateFX(this, x, y, height, width, "images/banditUp.png");
// repaint();
kills+= 1;
}else if(type==2){
enemies[enemy]= null;
animation.start(x, y);
imageFX1= new DisintegrateFX(this, x, y, height, width, "images/blimpUp.png");
// repaint();
kills+= 1;
}
rand = random.nextInt(3);
if (rand == 0 || rand == 1) {
drop = new DogTag(this, car,x, y);
} else {
drop = new HealthPickup(this, car, x, y);
}
StripAnimation dropAnim = new StripAnimation("images/select.png", 4, true);
dropAnim.start(drop.getX() - 20, drop.getY() - 10);
drops.add(drop);
animations.add(dropAnim);
}
public void endDisintegrate(){
imageFX1= null;
imageFX2= null;
}
public void endDisappear(int enemy){
spawns[enemy]= null;
}
public void shootBullet() {
if (car != null && !isPaused) {
soundManager.playClip("shoot", false);
int screenCenterX = getWidth() / 2;
int screenCenterY = getHeight() / 2;
int bulletX = (int)tileMap.getCameraX() + screenCenterX;
int bulletY = (int)tileMap.getCameraY() + screenCenterY;
Bullet newBullet = new Bullet(this, car.getHeight(), car.getWidth(),
bulletX - car.getWidth()/2,
bulletY - car.getHeight()/2,
car.getDirection());
bullets.add(newBullet);
}
}
public void enemyShoot(int enemy, int x, int y, int width) {
if (car != null && enemies[enemy] != null) {
EnemyBullet newEnemyBullet = new EnemyBullet(this, width, x, y, car, enemy);
enemyBullets.add(newEnemyBullet);
}
}
public boolean bulletExist(){
return !bullets.isEmpty();
}
public boolean enemyBulletExist(int enemy) {
for (EnemyBullet eb : enemyBullets) {
if (eb.getEnemyIndex() == enemy) {
return true;
}
}
return false;
}
public boolean running(){
return isRunning;
}
public void deleteBullet(){
if (!bullets.isEmpty()) {
bullets.remove(bullets.size() - 1);
}
}
public void enemyDeleteBullet(List<EnemyBullet> enemyBullets2){
for (int i = enemyBullets2.size() - 1; i >= 0; i--) {
EnemyBullet eb = enemyBullets2.get(i);
if (eb.isOffScreen()) {
enemyBullets2.remove(i);
}
}
}
public void addPoints(int points){
scoringPanel.addPoints(points);
}
public void loseLife(int oof){
lifePanel.loseLife(oof);
}
public void addLife(int yay){
lifePanel.addLife(yay);
}
public int getLifeTotal(){
return lifePanel.getLifeTotal();
}
public int getScoreTotal(){
return scoringPanel.getScore();
}
public void addDogTag(){
collectedTags+= 1;
}
public void gameRender() { //I FIXED MFING GAME RENDER YEAAAAAAAAAAAA https://jvm-gaming.org/t/best-way-to-render-with-java2d/45029
//https://stackoverflow.com/questions/14922999/2d-graphics-rendering-in-java
if (image == null) return;
Graphics2D imageContext = null;
Graphics2D g2 = null;
try {
imageContext = (Graphics2D) image.getGraphics();
imageContext.setColor(Color.BLACK);
imageContext.fillRect(0, 0, image.getWidth(), image.getHeight());
if (cutsceneManager.isPlaying()) {
cutsceneManager.draw(imageContext);
} else {
if (tileMap != null) {
tileMap.draw(imageContext);
}
double cameraX = tileMap != null ? tileMap.getCameraX() : 0;
double cameraY = tileMap != null ? tileMap.getCameraY() : 0;
Vageeta.draw(imageContext, cameraX, cameraY);
if (car != null) car.draw(imageContext, cameraX, cameraY);
for (Enemy e : enemies) if (e != null) e.draw(imageContext, cameraX, cameraY);
for (Bullet b : bullets) b.draw(imageContext, cameraX, cameraY);
for (EnemyBullet eb : enemyBullets) eb.draw(imageContext, cameraX, cameraY);
for (PowerUp p : drops) p.draw(imageContext, cameraX, cameraY);
for (StripAnimation a : animations) a.draw(imageContext, cameraX, cameraY);
if(imageFX1 != null) imageFX1.draw(imageContext); //I SAW THIS SICK AAH WAY TO WRITE THIS INSTEAD OF HOW LONG IT USUALLY IS
if(imageFX2 != null) imageFX2.draw(imageContext);
if(animation != null) animation.draw(imageContext, cameraX, cameraY);
if(animation2 != null) animation2.draw(imageContext, cameraX, cameraY);
// if(health != null) health.draw(imageContext, cameraX, cameraY);
renderlevel(imageContext);
renderhealth(imageContext);
renderDogTagCollected(imageContext);
renderScore(imageContext);
}
if (fadeActive) {
RenderFade(imageContext);
}
g2 = (Graphics2D) getGraphics();
if (g2 != null) {
g2.drawImage(image, 0, 0, getWidth(), getHeight(), null);
}
} finally {
if (imageContext != null) imageContext.dispose();
if (g2 != null) g2.dispose();
}
}
public void startGame() {
if (isRunning) return;
//soundManager.setVolume("background", 0.7f);
//soundManager.playClip("background", true);
isPaused = false;
currentLevel = 1; // Reset to level 1
collectedTags= 0;
fadeActive = false;
// Create car
car = new Car(this, 700, 540);
// create animations
animation= new StripAnimation("images/kaboom.gif", 6, false);
animation2= new StripAnimation("images/select.png", 4, true);
JFrame window = (JFrame)SwingUtilities.getWindowAncestor(this);
if (window != null) {
tileMapManager.setWindow(window);
}
// Load level 1
loadLevel(currentLevel);
gameThread = new Thread(this);
gameThread.start();
}
public void pauseGame() {
if (isRunning) {
if (isPaused)
isPaused = false;
else
isPaused = true;
}
}
public void endGame() {
soundManager.stopClip("backgroundfull");
soundManager.stopClip("country2");
soundManager.stopClip("country3");
soundManager.stopClip("background");
soundManager.stopClip("takeoff");
soundManager.stopClip("engine");
isRunning = false;
speed = 5;
}
public boolean isOnCar(int x, int y) {
return car.isOnCar(x, y);
}
public void playCutscene(String name) {
cutsceneManager.startCutscene(name);
}
public boolean isOffScreen(int x, int y) {
return x < 0 || x > getWidth() || y < 0 || y > getHeight();
}
public TileMap getTileMap() {
return tileMap;
}
public void advanceToNextLevel() {
if (currentLevel < MAX_LEVEL) {
currentLevel++;
loadLevel(currentLevel);
} else {
endGame();
}
}
private void loadLevel(int level) {
String tilesetPath;
switch (level) { //unfortunately i did not continue the funny if else statmenets here bc switch is sm easier here
case 1:
clearArray();
tilesetPath = "tilemap/level1.png";
soundManager.playClip("backgroundfull", false);
soundManager.setVolume("backgroundfull", 0.7f);
break;
case 2:
clearArray();
tilesetPath = "tilemap/level2.png"; //idk something
soundManager.stopClip("backgroundfull");
soundManager.playClip("country2", false);
soundManager.setVolume("country2", 0.7f);
break;
case 3:
clearArray();
tilesetPath = "tilemap/level3.png";
soundManager.stopClip("background2");
soundManager.playClip("country3", false);
soundManager.setVolume("country3", 0.7f);
break;
default:
tilesetPath = "tilemap/level1.png";
}
tileMapManager = new TileMapManager(
(JFrame)SwingUtilities.getWindowAncestor(this),
tilesetPath
);
try {
String mapFile = "maps/level" + level + ".map";
tileMap = tileMapManager.loadMap(mapFile);
tileMap.setPlayer(car);
createOpponentsForLevel(level);
Vageeta = new treeveg(tileMap);
if (level == 1 && cutsceneManager != null) {
cutsceneManager.setTileMap(tileMap);
cutsceneManager.startCutscene("takeoff");
}
if (level == 2 && cutsceneManager != null) {
cutsceneManager.setTileMap(tileMap);
cutsceneManager.startCutscene("takeoff");
}
if (level == 3 && cutsceneManager != null) {
cutsceneManager.setTileMap(tileMap);
cutsceneManager.startCutscene("takeoff");
}
} catch (IOException e) {
System.err.println("Error loading map: " + e.getMessage());
}
}
private void createOpponentsForLevel(int level) {
enemies = new Enemy[NUM_ENEMIES];
oppBullets = new EnemyBullet[NUM_ENEMIES];
spawns = new ImageFX[NUM_ENEMIES];
switch (level) { //no funny here bc it was easier for switch (maybe will replace with if else later toiday)
//@saeed you can use here to fix the enemy spawning and add what you need to
case 1:
for (int i = 0; i < NUM_ENEMIES; i++) {
spawnEnemyInWorldBounds(i, speed);
}
break;
case 2:
speed += 2;
for (int i = 0; i < NUM_ENEMIES; i++) {
spawnEnemyInWorldBounds(i, speed);
}
break;
case 3:
speed= 2;
NUM_ENEMIES= 1;
for (int i = 0; i < NUM_ENEMIES; i++) {
spawnEnemyInWorldBounds(i, speed);
}
break;
}
}
private void spawnEnemyInWorldBounds(int index, int speed) {
// int mapWidthTiles = tileMap.getWidth();//my god i want to put down my computer I SFDNJAIFNIUAJBNSU
// int mapHeightTiles = tileMap.getHeight();//the code was basically what i was doing in making things work with the world bounds and just having it all here but omgdfnsjk
//POV I found the fix
//minusing 150 for a buffer so that the enemies dont float off (Also for Blimp not spawning off the map)
int useableX= 1660 - 150;
int useableY= 1340 - 150;
int minX = 260;
int minY = 260;
// int maxX = TileMap.tilesToPixels(mapWidthTiles) - 1;
// int maxY = TileMap.tilesToPixels(mapHeightTiles) - 1;
int randX = random.nextInt(minX, useableX);
int randY = random.nextInt(minY, useableY);
if (currentLevel == 1) {
if (random.nextInt(2) == 0)
enemies[index] = new Tank(this, randX, randY, car, index, speed);
else
enemies[index] = new Bandit(this, randX, randY, car, index, speed);
}
else if (currentLevel == 2) {
if (random.nextInt(10) < 7)
enemies[index] = new Bandit(this, randX, randY, car, index, speed);
else
enemies[index] = new Tank(this, randX, randY, car, index, speed);
}
else if (currentLevel== 3){
enemies[index] = new Blimp(this, randX, randY, car, index, speed);
}
}
private void renderhealth(Graphics2D imageContext){
int healthval = getLifeTotal();
Font healthFont = new Font("Arial", Font.BOLD, 16);
imageContext.setFont(healthFont);
imageContext.setColor(Color.RED);
imageContext.drawString("HEALTH: " + healthval, 10, 40);
}
private void renderlevel(Graphics2D imageContext){
Font levelFont = new Font("Arial", Font.BOLD, 16);
imageContext.setFont(levelFont);
imageContext.setColor(Color.BLACK);
imageContext.drawString("LEVEL: " + currentLevel, 10, 20);
}
private void renderDogTagCollected(Graphics2D imageContext){
Font levelFont = new Font("Arial", Font.BOLD, 16);
imageContext.setFont(levelFont);
imageContext.setColor(Color.WHITE);
imageContext.drawString("Dog Tags: " + collectedTags+ " / 5",280, 40);
}
private void renderScore(Graphics2D imageContext){
int score= getScoreTotal();
Font levelFont = new Font("Arial", Font.BOLD, 16);
imageContext.setFont(levelFont);
imageContext.setColor(Color.WHITE);
imageContext.drawString("Score: " + score, 290, 20);
}
private void startDeathSequence() {
fadeActive = true;
gameOver = true;
gameOverMessage = "YOU DIED";
fadeAlpha = 0.0f;
}
private void startVictorySequence() {
fadeActive = true;
victory = true;
gameOverMessage = "VICTORY!";
fadeAlpha = 0.0f;
}
private void RenderFade (Graphics2D imageContext) {
imageContext.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fadeAlpha));
imageContext.setColor(Color.BLACK);
imageContext.fillRect(0, 0, getWidth(), getHeight());
if (fadeAlpha > 0.5f) {
Font pixelFont = new Font("Courier New", Font.BOLD, 48);
imageContext.setFont(pixelFont);
imageContext.setColor(Color.RED);
FontMetrics fm = imageContext.getFontMetrics(); // all of this fancy code to centre the text bc we have two messages that could play through this and i dont want to move this to two functions
int textWidth = fm.stringWidth(gameOverMessage); //bc this works now
int textX = (getWidth() - textWidth) / 2; // i forgor the width and height of the draw window again so please replace the width and height later
int textY = getHeight() / 2;
imageContext.drawString(gameOverMessage, textX, textY);
}
imageContext.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
}
public void clearArray() {
if (bullets != null) bullets.clear();
if (enemyBullets != null) enemyBullets.clear();
if (drops != null) drops.clear();
if (animations != null) animations.clear();
enemies = null;
oppBullets = null;
spawns = null;
}
}