-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
748 lines (620 loc) · 24.6 KB
/
main.py
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
import math
import random
import sys
import pygame
from pygame import mixer
# Initialize pygame
pygame.init()
# Create the screen
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
# Load images
intro_image = pygame.image.load('images/intro_image.png')
background = pygame.image.load('images/bgimage3.png')
background_height = background.get_height()
scroll = 0
scroll_speed = 1
icon = pygame.image.load('images/logo.png')
playerImg = pygame.image.load('images/player2.png')
bulletImg = pygame.image.load('images/bullet.png')
# Images for levels 4 and 5
asteroidImg = pygame.image.load('images/asteroid.png')
# Scale asteroid image smaller for level 5
small_asteroidImg = pygame.transform.scale(asteroidImg, (32, 32)) # Half the original size
fuelImg = pygame.image.load('images/fuel.png')
bossImg = pygame.image.load('images/boss.png')
# Make boss bigger
large_bossImg = pygame.transform.scale(bossImg, (192, 192)) # 1.5x the original size
bossProjectileImg = pygame.image.load('images/boss_projectile.png')
# Sound
mixer.music.load("sound/background.wav")
mixer.music.play(-1)
enemy_hit_sound = mixer.Sound("sound/explosion.mp3") # Add sound for level 4 enemy hits
# Caption and Icon
pygame.display.set_caption("Galactic Defender")
pygame.display.set_icon(icon)
# Player
playerX = 370
playerY = 520
playerX_change = 0
playerY_change = 0
player_speed = 5
player_angle = 0
# Enemy
enemyImg = []
enemyX = []
enemyY = []
enemyX_change = []
enemyY_change = []
num_of_enemies = 7
# Asteroid
asteroidImg = []
asteroidX = []
asteroidY = []
asteroidY_change = []
num_of_asteroids = 8
min_asteroid_speed = 1
max_asteroid_speed = 5
# Bullet
bulletX = 0
bulletY = 480
bullet_speed = 15
bullet_state = "ready"
# Score and Level
score_value = 0
level_value = 1
font = pygame.font.Font('freesansbold.ttf', 32)
over_font = pygame.font.Font('freesansbold.ttf', 64)
win_font = pygame.font.Font('freesansbold.ttf', 48)
# Level 2 timer
level2_start_time = 0
level2_duration = 20000
# Near miss
near_miss_distance = 30
near_miss_recorded = [False] * num_of_asteroids
# Level 4 variables
asteroids = []
fuel_pods = []
fuel_level = 100
fuel_consumption_rate = 0.05
level4_start_time = 0
level4_duration = 60000
level4_enemies = []
# Level 5 variables
boss_health = 100
boss_x = 400
boss_y = 100
boss_move_speed = 3 # Horizontal movement speed for boss
boss_projectiles = []
boss_attack_timer = 0
boss_attack_interval = 2000
boss_hitbox_size = 96 # Increased hitbox for larger boss
enemies = []
def intro_page():
start_time = pygame.time.get_ticks()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((0, 0, 0))
screen.blit(intro_image, (0, 0))
pygame.display.flip()
if pygame.time.get_ticks() - start_time >= 5000:
return
pygame.time.Clock().tick(60)
def initialize_game_objects():
global enemyImg, enemyX, enemyY, enemyX_change, enemyY_change
global asteroidImg, asteroidX, asteroidY, asteroidY_change
for i in range(num_of_enemies):
enemyImg.append(pygame.image.load('images/enemy.png'))
enemyX.append(random.randint(0, screen_width - 64))
enemyY.append(random.randint(50, 150))
enemyX_change.append(6)
enemyY_change.append(10)
for i in range(num_of_asteroids):
asteroidImg.append(pygame.image.load('images/asteroid.png'))
asteroidX.append(random.randint(0, screen_width - 64))
asteroidY.append(random.randint(-500, -50))
asteroidY_change.append(random.uniform(min_asteroid_speed, max_asteroid_speed))
def reset_asteroids():
global near_miss_recorded
for i in range(num_of_asteroids):
asteroidX[i] = random.randint(0, screen_width - 64)
asteroidY[i] = random.randint(-500, -50)
asteroidY_change[i] = random.uniform(min_asteroid_speed, max_asteroid_speed)
near_miss_recorded[i] = False
def reset_level4():
global asteroids, fuel_pods, fuel_level, level4_start_time, level4_enemies
asteroids = [
{
'x': random.randint(0, screen_width - 64),
'y': random.randint(-500, -50),
'speed': random.uniform(1, 3)
} for _ in range(6)
]
fuel_pods = [
{
'x': random.randint(0, screen_width - 32),
'y': random.randint(-500, -50),
'speed': random.uniform(1, 2)
} for _ in range(3)
]
level4_enemies = [
{
'x': random.randint(0, screen_width - 64),
'y': random.randint(50, 150),
'speed': 3,
'direction': 1
} for _ in range(4)
]
fuel_level = 100
level4_start_time = pygame.time.get_ticks()
# Functions remain the same until game_won_text()
def game_won_text():
# Create gradient background effect
for i in range(screen_height):
color = (
int(40 + (i / screen_height) * 50), # Dark blue to lighter blue
int(50 + (i / screen_height) * 100),
int(150 + (i / screen_height) * 105)
)
pygame.draw.line(screen, color, (0, i), (screen_width, i))
# Draw stars
for _ in range(50):
x = random.randint(0, screen_width)
y = random.randint(0, screen_height)
size = random.randint(1, 3)
pygame.draw.circle(screen, (255, 255, 255), (x, y), size)
# Main victory text
won_text = over_font.render("VICTORY!", True, (255, 255, 255))
won_rect = won_text.get_rect(center=(screen_width // 2, screen_height // 2 - 50))
screen.blit(won_text, won_rect)
# Subtitle text
defender_text = win_font.render("You are a Galactic Defender", True, (255, 215, 0))
defender_rect = defender_text.get_rect(center=(screen_width // 2, screen_height // 2 + 50))
screen.blit(defender_text, defender_rect)
# Score display
score_text = font.render(f"Final Score: {score_value}", True, (255, 255, 255))
score_rect = score_text.get_rect(center=(screen_width // 2, screen_height // 2 + 120))
screen.blit(score_text, score_rect)
def reset_level5():
global boss_health, boss_x, boss_y, boss_projectiles, boss_attack_timer, asteroids, fuel_pods, enemies
boss_health = 100
boss_x = 400
boss_y = 100
boss_projectiles = []
boss_attack_timer = 0
# Reduced number of enemies for level 5
enemies = [
{
'x': random.randint(0, screen_width - 64),
'y': random.randint(50, 150),
'speed': random.uniform(2, 4),
'direction': 1
} for _ in range(3) # Reduced from 5 to 3 enemies
]
# Fewer and smaller asteroids for level 5
asteroids = [
{
'x': random.randint(0, screen_width - 32), # Adjusted for smaller size
'y': random.randint(-500, -50),
'speed': random.uniform(1, 2)
} for _ in range(3) # Reduced from 5 to 3 asteroids
]
# Add fuel pods for level 5
fuel_pods = [
{
'x': random.randint(0, screen_width - 32),
'y': random.randint(-500, -50),
'speed': random.uniform(1, 1.5)
} for _ in range(2)
]
def show_score():
score = font.render("Score : " + str(score_value), True, (255, 255, 255))
screen.blit(score, (10, 10))
def show_level():
level = font.render("Level : " + str(level_value), True, (255, 255, 255))
screen.blit(level, (10, 50))
def show_fuel():
fuel_text = font.render(f"Fuel: {int(fuel_level)}%", True, (255, 255, 255))
screen.blit(fuel_text, (10, 90))
def show_boss_health():
bar_width = 150 # Increased bar width for larger boss
bar_height = 15 # Increased bar height
bar_x = boss_x + (192 - bar_width) // 2 # Centered above larger boss
bar_y = boss_y - 25
pygame.draw.rect(screen, (255, 0, 0), (bar_x, bar_y, bar_width, bar_height))
health_width = int((boss_health / 100) * bar_width)
pygame.draw.rect(screen, (0, 255, 0), (bar_x, bar_y, health_width, bar_height))
health_text = font.render(f"{boss_health}%", True, (255, 255, 255))
text_rect = health_text.get_rect()
text_rect.centerx = bar_x + bar_width // 2
text_rect.bottom = bar_y - 5
screen.blit(health_text, text_rect)
def game_over_text():
over_text = over_font.render("GAME OVER", True, (255, 255, 255))
screen.blit(over_text, (200, 250))
def game_won_text():
# Create gradient background effect
for i in range(screen_height):
color = (
int(40 + (i / screen_height) * 50),
int(50 + (i / screen_height) * 100),
int(150 + (i / screen_height) * 105)
)
pygame.draw.line(screen, color, (0, i), (screen_width, i))
# Draw animated stars
for _ in range(50):
x = random.randint(0, screen_width)
y = random.randint(0, screen_height)
size = random.randint(1, 3)
pygame.draw.circle(screen, (255, 255, 255), (x, y), size)
# Victory text
won_text = over_font.render("VICTORY!", True, (255, 255, 255))
won_rect = won_text.get_rect(center=(screen_width // 2, screen_height // 2 - 50))
screen.blit(won_text, won_rect)
# Subtitle
defender_text = win_font.render("You are now a Galactic Defender", True, (255, 215, 0))
defender_rect = defender_text.get_rect(center=(screen_width // 2, screen_height // 2 + 50))
screen.blit(defender_text, defender_rect)
# Final score
score_text = font.render(f"Final Score: {score_value}", True, (255, 255, 255))
score_rect = score_text.get_rect(center=(screen_width // 2, screen_height // 2 + 120))
screen.blit(score_text, score_rect)
def draw_background():
global scroll
screen.blit(background, (0, scroll))
screen.blit(background, (0, scroll - background_height))
scroll += scroll_speed
if scroll >= background_height:
scroll = 0
def player(x, y, angle):
rotated_player = pygame.transform.rotate(playerImg, angle)
new_rect = rotated_player.get_rect(center=playerImg.get_rect(topleft=(x, y)).center)
screen.blit(rotated_player, new_rect.topleft)
def enemy(x, y, i):
screen.blit(enemyImg[i], (x, y))
def asteroid(x, y, i):
screen.blit(asteroidImg[i], (x, y))
def fire_bullet(x, y):
global bullet_state
bullet_state = "fire"
screen.blit(bulletImg, (x + 16, y + 10))
def draw_asteroid(x, y):
screen.blit(asteroidImg[0], (x, y))
def draw_fuel_pod(x, y):
screen.blit(fuelImg, (x, y))
def draw_boss(x, y):
screen.blit(large_bossImg, (x, y))
def draw_boss_projectile(x, y):
screen.blit(bossProjectileImg, (x, y))
def draw_enemy(x, y):
screen.blit(enemyImg[0], (x, y))
def is_collision(x1, y1, x2, y2):
distance = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
return distance < 27
def is_asteroid_collision(x1, y1, x2, y2):
distance = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
return distance < 50
def is_near_miss(x1, y1, x2, y2):
distance = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
return near_miss_distance < distance < near_miss_distance + 20
def handle_events():
global playerX_change, bulletX, bulletY, bullet_state, player_angle
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
playerX_change = -player_speed
if event.key == pygame.K_RIGHT:
playerX_change = player_speed
if event.key == pygame.K_SPACE and bullet_state == "ready":
bulletSound = mixer.Sound("sound/laser.mp3")
bulletSound.play()
bulletX = playerX
bulletY = playerY
fire_bullet(bulletX, bulletY)
if event.type == pygame.KEYUP:
if event.key in (pygame.K_LEFT, pygame.K_RIGHT):
playerX_change = 0
return True
def update_player():
global playerX
playerX += playerX_change
if level_value < 4:
playerX = playerX % screen_width
else:
playerX = max(0, min(playerX, screen_width - 64))
def update_bullet():
global bulletX, bulletY, bullet_state
if bullet_state == "fire":
fire_bullet(bulletX, bulletY)
bulletY -= bullet_speed
if bulletY <= 0:
bulletY = playerY
bullet_state = "ready"
def level_1():
global score_value, level_value, level2_start_time, bullet_state, bulletY
for i in range(num_of_enemies):
enemyX[i] += enemyX_change[i]
if enemyX[i] <= 0 or enemyX[i] >= screen_width - 64:
enemyX_change[i] *= -1
enemyY[i] += enemyY_change[i]
if is_collision(enemyX[i], enemyY[i], playerX, playerY):
game_over_text()
return False
if is_collision(enemyX[i], enemyY[i], bulletX, bulletY):
explosionSound = mixer.Sound("sound/explosion.mp3")
explosionSound.play()
bulletY = playerY
bullet_state = "ready"
score_value += 1
enemyX[i] = random.randint(0, screen_width - 64)
enemyY[i] = random.randint(50, 150)
enemy(enemyX[i], enemyY[i], i)
if score_value >= 10:
level_value = 2
level2_start_time = pygame.time.get_ticks()
reset_asteroids()
return True
def level_2():
global level_value, score_value, max_asteroid_speed
current_time = pygame.time.get_ticks()
time_elapsed = current_time - level2_start_time
if time_elapsed < level2_duration:
for i in range(num_of_asteroids):
asteroidY[i] += asteroidY_change[i]
if asteroidY[i] > screen_height:
asteroidX[i] = random.randint(0, screen_width - 64)
asteroidY[i] = random.randint(-500, -50)
asteroidY_change[i] = random.uniform(min_asteroid_speed, max_asteroid_speed)
near_miss_recorded[i] = False
if is_asteroid_collision(asteroidX[i], asteroidY[i], playerX, playerY):
game_over_text()
return False
if not near_miss_recorded[i] and is_near_miss(asteroidX[i], asteroidY[i], playerX, playerY):
score_value += 1
near_miss_recorded[i] = True
asteroid(asteroidX[i], asteroidY[i], i)
if time_elapsed % 5000 == 0:
max_asteroid_speed += 0.5
for i in range(num_of_asteroids):
asteroidY_change[i] = random.uniform(min_asteroid_speed, max_asteroid_speed)
else:
level_value = 3
reset_asteroids()
return True
def level_3():
global score_value, level_value, bullet_state, bulletY, max_asteroid_speed
for i in range(num_of_enemies):
enemyX[i] += enemyX_change[i]
if enemyX[i] <= 0 or enemyX[i] >= screen_width - 64:
enemyX_change[i] *= -1
enemyY[i] += enemyY_change[i]
if is_collision(enemyX[i], enemyY[i], playerX, playerY):
game_over_text()
return False
if is_collision(enemyX[i], enemyY[i], bulletX, bulletY):
explosionSound = mixer.Sound("sound/explosion.mp3")
explosionSound.play()
bulletY = playerY
bullet_state = "ready"
score_value += 1
enemyX[i] = random.randint(0, screen_width - 64)
enemyY[i] = random.randint(50, 150)
enemy(enemyX[i], enemyY[i], i)
# Update asteroids
for i in range(num_of_asteroids):
asteroidY[i] += asteroidY_change[i]
if asteroidY[i] > screen_height:
asteroidX[i] = random.randint(0, screen_width - 64)
asteroidY[i] = random.randint(-500, -50)
asteroidY_change[i] = random.uniform(min_asteroid_speed, max_asteroid_speed)
near_miss_recorded[i] = False
if is_asteroid_collision(asteroidX[i], asteroidY[i], playerX, playerY):
game_over_text()
return False
if not near_miss_recorded[i] and is_near_miss(asteroidX[i], asteroidY[i], playerX, playerY):
score_value += 1
near_miss_recorded[i] = True
asteroid(asteroidX[i], asteroidY[i], i)
if score_value >= 30:
level_value = 4
reset_level4()
return True
def level_4():
global score_value, level_value, fuel_level, bullet_state, bulletX, bulletY
# Update and draw asteroids
for asteroid in asteroids[:]:
asteroid['y'] += asteroid['speed']
if asteroid['y'] > screen_height:
asteroid['y'] = random.randint(-500, -50)
asteroid['x'] = random.randint(0, screen_width - 64)
asteroid['speed'] = random.uniform(1.5, 3)
draw_asteroid(asteroid['x'], asteroid['y'])
if is_collision(playerX, playerY, asteroid['x'], asteroid['y']):
game_over_text()
return False
# Update and draw enemies
for enemy in level4_enemies[:]:
enemy['x'] += enemy['speed'] * enemy['direction']
if enemy['x'] <= 0 or enemy['x'] >= screen_width - 64:
enemy['direction'] *= -1
enemy['y'] += 20
draw_enemy(enemy['x'], enemy['y'])
if is_collision(playerX, playerY, enemy['x'], enemy['y']):
game_over_text()
return False
# Check bullet collision with enemies
if bullet_state == "fire":
if is_collision(enemy['x'], enemy['y'], bulletX, bulletY):
enemy_hit_sound.play() # Play sound effect when hitting enemy
level4_enemies.remove(enemy)
bullet_state = "ready"
bulletY = playerY
score_value += 2
# Respawn enemy at top
level4_enemies.append({
'x': random.randint(0, screen_width - 64),
'y': random.randint(-100, 0),
'speed': 3,
'direction': 1
})
# Update and draw fuel pods
for fuel_pod in fuel_pods[:]:
fuel_pod['y'] += fuel_pod['speed']
if fuel_pod['y'] > screen_height:
fuel_pod['y'] = random.randint(-500, -50)
fuel_pod['x'] = random.randint(0, screen_width - 32)
fuel_pod['speed'] = random.uniform(1, 1.5)
draw_fuel_pod(fuel_pod['x'], fuel_pod['y'])
if is_collision(playerX, playerY, fuel_pod['x'], fuel_pod['y']):
fuel_level = min(100, fuel_level + 30)
fuel_pod['y'] = random.randint(-500, -50)
fuel_pod['x'] = random.randint(0, screen_width - 32)
fuel_level -= fuel_consumption_rate
if fuel_level <= 0:
game_over_text()
return False
current_time = pygame.time.get_ticks()
if current_time - level4_start_time >= level4_duration or score_value >= 50:
level_value = 5
reset_level5()
show_fuel()
return True
def level_5():
global score_value, level_value, boss_health, boss_x, boss_y, boss_attack_timer
global boss_projectiles, bullet_state, bulletX, bulletY, fuel_level
# Enhanced boss movement (smoother horizontal movement)
boss_x += boss_move_speed * math.sin(pygame.time.get_ticks() / 1000)
boss_x = max(0, min(boss_x, screen_width - 192)) # Adjusted for larger boss size
# Random enemy spawning
if random.random() < 0.02 and len(enemies) < 3: # 2% chance each frame to spawn new enemy
enemies.append({
'x': random.randint(0, screen_width - 64),
'y': random.randint(-100, 0),
'speed': random.uniform(2, 4),
'direction': 1
})
# Boss attacks
current_time = pygame.time.get_ticks()
if current_time - boss_attack_timer >= boss_attack_interval:
boss_attack_timer = current_time
for offset in [-30, 0, 30]: # Wider spread for larger boss
boss_projectiles.append({
'x': boss_x + 96 + offset, # Adjusted for larger boss
'y': boss_y + 96,
'speed': 5,
'angle': math.radians(offset)
})
# Update and draw boss projectiles
for projectile in boss_projectiles[:]:
projectile['y'] += projectile['speed']
projectile['x'] += math.sin(projectile['angle']) * 2
draw_boss_projectile(projectile['x'], projectile['y'])
if is_collision(playerX, playerY, projectile['x'], projectile['y']):
game_over_text()
return False
# Update and draw enemies with random movement
for enemy in enemies[:]:
enemy['x'] += enemy['speed'] * enemy['direction']
if enemy['x'] <= 0 or enemy['x'] >= screen_width - 64:
enemy['direction'] *= -1
enemy['y'] += random.randint(10, 30) # Random vertical movement
draw_enemy(enemy['x'], enemy['y'])
if is_collision(playerX, playerY, enemy['x'], enemy['y']):
game_over_text()
return False
# Update and draw smaller asteroids
for asteroid in asteroids[:]:
asteroid['y'] += asteroid['speed']
if asteroid['y'] > screen_height:
asteroid['y'] = random.randint(-500, -50)
asteroid['x'] = random.randint(0, screen_width - 32) # Adjusted for smaller size
# Use small_asteroidImg instead of regular asteroidImg
screen.blit(small_asteroidImg, (asteroid['x'], asteroid['y']))
if is_collision(playerX, playerY, asteroid['x'], asteroid['y']):
game_over_text()
return False
# Update and draw fuel pods
for fuel_pod in fuel_pods[:]:
fuel_pod['y'] += fuel_pod['speed']
if fuel_pod['y'] > screen_height:
fuel_pod['y'] = random.randint(-500, -50)
fuel_pod['x'] = random.randint(0, screen_width - 32)
draw_fuel_pod(fuel_pod['x'], fuel_pod['y'])
if is_collision(playerX, playerY, fuel_pod['x'], fuel_pod['y']):
fuel_level = min(100, fuel_level + 30)
fuel_pod['y'] = random.randint(-500, -50)
fuel_pod['x'] = random.randint(0, screen_width - 32)
# Remove off-screen projectiles
boss_projectiles = [p for p in boss_projectiles if p['y'] < screen_height]
# Check for bullet collision with boss (enlarged hitbox)
if bullet_state == "fire":
boss_center_x = boss_x + 64
boss_center_y = boss_y + 64
distance = math.sqrt((boss_center_x - bulletX)**2 + (boss_center_y - bulletY)**2)
if distance < boss_hitbox_size: # Larger hitbox for easier targeting
boss_health -= 10
bullet_state = "ready"
bulletY = playerY
score_value += 5
# Check bullet collision with enemies
if bullet_state == "fire":
for enemy in enemies[:]:
if is_collision(enemy['x'], enemy['y'], bulletX, bulletY):
enemies.remove(enemy)
bullet_state = "ready"
bulletY = playerY
score_value += 2
# Decrease fuel level
fuel_level -= 0.05
if fuel_level <= 0:
game_over_text()
return False
if boss_health <= 0:
game_won_text()
return False
# Draw larger boss
screen.blit(large_bossImg, (boss_x, boss_y))
show_boss_health()
show_fuel()
if boss_health <= 0:
game_won_text()
return False
return True
def main_game_loop():
global playerX, bullet_state, bulletX, bulletY
running = True
clock = pygame.time.Clock()
while running:
draw_background()
running = handle_events()
if not running:
break
update_player()
update_bullet()
if level_value == 1:
running = level_1()
elif level_value == 2:
running = level_2()
elif level_value == 3:
running = level_3()
elif level_value == 4:
running = level_4()
elif level_value == 5:
running = level_5()
player(playerX, playerY, player_angle)
show_score()
show_level()
pygame.display.update()
clock.tick(60)
pygame.time.wait(2000)
if __name__ == "__main__":
intro_page()
initialize_game_objects()
main_game_loop()
pygame.quit()