generated from mwc/project_game
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.
This commit is contained in:
30
asteroid_spawner.py
Normal file
30
asteroid_spawner.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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, 2–3 = 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user