bomb hitbox and custom alien waves

bomb hitbox more accurate. invaders no longer drop bombs when just above ground level. spawn_alien_wave() can now spawn a custom wave (not from the main wave sequence)
This commit is contained in:
Marek Baczynski
2026-11-28 00:03:00 +01:00
parent b825b7fd12
commit 6592dfcab8
+15 -12
View File
@@ -164,7 +164,7 @@ class Alien:
def update(self): def update(self):
# INVADER aliens have a 1/300 chance of dropping a bomb every frame! # INVADER aliens have a 1/300 chance of dropping a bomb every frame!
if self.variant == Alien.INVADER: if self.variant == Alien.INVADER:
if randrange(300) == 1: if self.y<48 and randrange(300) == 1:
Bullet.launch(self.x+4, self.y+6, 1) Bullet.launch(self.x+4, self.y+6, 1)
# SCORE aliens update their values to always represent the players score # SCORE aliens update their values to always represent the players score
@@ -190,20 +190,22 @@ class Alien:
# Setup the waves of aliens # Setup the waves of aliens
alien_wave = -1 alien_wave = -1
alien_waves = [Alien.UFO, Alien.SCORE, Alien.INVADER, Alien.UFO, Alien.INVADER, Alien.SCORE, Alien.INVADER, Alien.INVADER, Alien.SCORE, Alien.UFO, Alien.INVADER, Alien.INVADER, Alien.SCORE] alien_waves = [Alien.INVADER, Alien.UFO, Alien.INVADER, Alien.SCORE, Alien.INVADER, Alien.INVADER, Alien.SCORE, Alien.UFO, Alien.INVADER, Alien.INVADER, Alien.SCORE]
def spawn_alien_wave(y=0): def spawn_alien_wave(y=0, alien_type=None):
global alien_wave global alien_wave
global alien_waves global alien_waves
if alien_type is None:
alien_wave += 1 alien_wave += 1
next_wave = alien_waves[alien_wave % len(alien_waves)] alien_type = alien_waves[alien_wave % len(alien_waves)]
if next_wave in [Alien.UFO, Alien.INVADER]:
for i in range(0, 8):
Alien.spawn(i*13 + 1, y, next_wave)
if next_wave == Alien.SCORE: if alien_type in [Alien.UFO, Alien.INVADER]:
for i in range(0, 8):
Alien.spawn(i*13 + 1, y, alien_type)
if alien_type == Alien.SCORE:
for i in range(0, 6): for i in range(0, 6):
Alien.spawn(i*9 + 24, y, next_wave) Alien.spawn(i*9 + 24, y, Alien.SCORE)
Alien.spawn(1, y, Alien.INVADER) Alien.spawn(1, y, Alien.INVADER)
Alien.spawn(12, y, Alien.INVADER) Alien.spawn(12, y, Alien.INVADER)
Alien.spawn(81, y, Alien.INVADER) Alien.spawn(81, y, Alien.INVADER)
@@ -234,8 +236,9 @@ while read_buttons() == 0:
pass pass
# spawn the first 2 waves # spawn the first 2 waves
spawn_alien_wave(12) spawn_alien_wave(0, Alien.SCORE)
spawn_alien_wave(0) spawn_alien_wave(12, Alien.UFO)
# main loop # main loop
while game_is_not_over_yet: while game_is_not_over_yet:
@@ -360,7 +363,7 @@ while game_is_not_over_yet:
continue continue
# Hit detection bomb to player # Hit detection bomb to player
if bomb.y>60 and bomb.x > tank_x-3 and bomb.x < tank_x + 2: if bomb.y>58 and bomb.x > tank_x-4 and bomb.x < tank_x + 3:
game_is_not_over_yet = False game_is_not_over_yet = False
oled.fill_rect(bomb.x, bomb.y, 2, 3, 1) oled.fill_rect(bomb.x, bomb.y, 2, 3, 1)