Checkpoint 2: Attaching the "asteroid" to the player if the player touches the "asteroid" This part was challenging as there were new commands I learned while trying to incorporate the retro lab componemets. I included the "asteroid sprawner" to get more than on "asteroid" on the screen. The next part is to end the game.

This commit is contained in:
erbrown
2025-12-14 22:07:22 -05:00
parent 0141fafc98
commit 1a02f78bb1
7 changed files with 73 additions and 5 deletions

19
apple_sprawner.py Normal file
View File

@@ -0,0 +1,19 @@
from random import randint
from apple import Apple
class AppleSpawner:
display = False
def play_turn(self, game):
width, height = game.board_size
game.state['score'] += 1
if self.should_spawn_apple(game.turn_number):
x = randint(0,width - 1)
y = randint(0, height - 1)
if game.is_empty((x,y)):
apple = Apple((x,y))
game.add_agent(apple)
def should_spawn_apple(self, turn_number):
return randint(0, 1000) < turn_number