From fde19150cd21135dd99f516bfd1d81a4ec58f8fe Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Sat, 28 Nov 2026 00:47:12 +0100 Subject: [PATCH] limited effectiveness of shooting edge aliens otherwise it was possible to play indefinitely long once this strategy was discovered --- main.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 66a1806..fb3c74a 100644 --- a/main.py +++ b/main.py @@ -201,21 +201,22 @@ def spawn_alien_wave(y=0, alien_type=None): if alien_type in [Alien.UFO, Alien.INVADER]: for i in range(0, 8): - Alien.spawn(i*13 + 1, y, alien_type) + Alien.spawn(i*13, y, alien_type) if alien_type == Alien.SCORE: for i in range(0, 6): - Alien.spawn(i*9 + 24, y, Alien.SCORE) - Alien.spawn(1, y, Alien.INVADER) - Alien.spawn(12, y, Alien.INVADER) - Alien.spawn(81, y, Alien.INVADER) - Alien.spawn(92, y, Alien.INVADER) + Alien.spawn(i*9 + 23, y, Alien.SCORE) + Alien.spawn(0, y, Alien.INVADER) + Alien.spawn(11, y, Alien.INVADER) + Alien.spawn(80, y, Alien.INVADER) + Alien.spawn(91, y, Alien.INVADER) # game variables tank_x = 63 alien_step_delay = 8 alien_step_timer = 0 alien_step_direction = 1 +alien_armada_offset = 0 game_progress = 0 shoot_left_was_released = True shoot_right_was_released = True @@ -301,10 +302,16 @@ while game_is_not_over_yet: alien_step_timer = 0 switching_direction = False for alien in Alien.get_all_active(): - if alien.x + alien_step_direction> 118 or alien.x + alien_step_direction < 1: + # switch direction if an alien hits a side wall + if alien.x + alien_step_direction> 119 or alien.x + alien_step_direction < 0: switching_direction = True break + # BUT, shooting the aliens on the edge can only postpone the advancing to the next line by the width of 1 alien + if alien_armada_offset + alien_step_direction > 41 or alien_armada_offset + alien_step_direction < -13: + alien_armada_offset -= alien_step_direction * 13 + switching_direction = True + if switching_direction: # aliens turn around and go down by one line alien_step_direction *= -1 @@ -324,6 +331,7 @@ while game_is_not_over_yet: alien_step_delay -= 1 else: + alien_armada_offset += alien_step_direction for alien in Alien.get_all_active(): alien.x += alien_step_direction @@ -353,6 +361,7 @@ while game_is_not_over_yet: buzz_ms(10) continue + # draw the bullet (just 1 pixel) oled.pixel(bullet.x, bullet.y, 1) # process all bombs dropped by aliens @@ -366,8 +375,11 @@ while game_is_not_over_yet: if bomb.y>58 and bomb.x > tank_x-4 and bomb.x < tank_x + 3: game_is_not_over_yet = False + # draw the bomb (2x3 rectangle) oled.fill_rect(bomb.x, bomb.y, 2, 3, 1) + #debug text + #oled.text(str(alien_armada_offset), 2, 52, 1) oled.show() # outside of the loop, this is the GAME OVER SCREEN @@ -382,3 +394,4 @@ oled.rect(19, 11, 90, 38, 1) oled.text("GAME OVER", 25, 17, 1) oled.text(str(game_score) + "pts", 25, 32, 1) oled.show() +