Files
project_game/proposal.md/shooter.py
tsmith37 35ed9eb328 add a alien target and a shooter to hit it
I am actually really proud that i was able to figure out how to make the alien move
in every direction randomly.
2025-12-08 20:30:45 -05:00

49 lines
1.1 KiB
Python

class Shooter:
name = "shooter"
character = 'I'
display = False
def __init__(self):
self.position = (0, 0)
def handle_keystroke(self, keystroke, game):
if keystroke == ' ' and not self.display:
ship = game.get_agent_by_name('ship')
if ship is None:
return
x, y = ship.position
new_position = (x, y - 1)
if game.on_board(new_position):
self.position = new_position
self.display = True
def play_turn(self, game):
if not self.display:
return
x, y = self.position
new_position = (x, y - 1)
if not game.on_board(new_position):
self.display = False
return
agents_by_position = game.get_agents_by_position()
agents_here = agents_by_position.get(new_position, [])
for agent in agents_here:
if getattr(agent, "character", None) == 'A':
game.end()
return
self.position = new_position