generated from mwc/project_game
For the meteor speed mechanic, I updated asteroid.py to give each asteroid a speed value and move only on certain turns depending on that speed. I also changed the spawner so each new asteroid gets a random speed between 1 and 3. This means some asteroids fall quickly while others fall more slowly. This addition is important because it creates more variety in the game, makes movement patterns less predictable, and increases the challenge in a natural way as the player navigates different kinds of threats.
32 lines
996 B
Python
32 lines
996 B
Python
from asteroid import Asteroid
|
|
|
|
class Bullet:
|
|
"""A bullet fired by the spaceship that moves upward and destroys asteroids."""
|
|
character = '|'
|
|
|
|
def __init__(self, position):
|
|
self.position = position
|
|
|
|
def play_turn(self, game):
|
|
# Move bullet up one row each turn
|
|
x, y = self.position
|
|
y -= 1
|
|
|
|
# If the bullet goes off the top, remove it
|
|
if y < 0:
|
|
game.remove_agent(self)
|
|
return
|
|
|
|
self.position = (x, y)
|
|
|
|
# Check if we hit an asteroid
|
|
# We loop over a copy of the agents list because we may remove agents
|
|
for agent in list(game.agents):
|
|
if isinstance(agent, Asteroid) and agent.position == self.position:
|
|
# Destroy the asteroid and the bullet
|
|
game.remove_agent(agent)
|
|
game.remove_agent(self)
|
|
# Reward points for hitting an asteroid
|
|
game.state["score"] += 10
|
|
return
|
|
#here |