Files
project_game/asteroid_spawner.py
angelotr 47a9e1abe3 I did not realize this had to be three submissions. My first progress was the add lives to the asteroid game.
For this feature, I added a health system so the player has three
lives instead of losing instantly. In nav_game.py, I added "health": 3
to the game state, and in spaceship.py I created a take_damage method
that subtracts one life when the ship is hit. If the player's health
reaches zero, the game ends. This change is important because it
makes the game less punishing, gives the player more chances to
recover from mistakes, and makes gameplay feel more balanced and fun.
2025-12-08 23:39:17 -05:00

30 lines
833 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# asteroid_spawner.py
# -------------------
# By MWC Contributors
# This module defines an AsteroidSpawner agent class.
from random import randint
from asteroid import Asteroid
class AsteroidSpawner:
display = False
def play_turn(self, game):
width, height = game.board_size
# Increase score each turn survived
game.state['score'] += 1
if self.should_spawn_asteroid(game.turn_number):
# Random x position at the top
x = randint(0, width - 1)
# Random speed: 1 = fast, 23 = slower
speed = randint(1, 3)
asteroid = Asteroid((x, 0), speed)
game.add_agent(asteroid)
def should_spawn_asteroid(self, turn_number):
# More asteroids as the game goes on
return randint(0, 1000) < turn_number