generated from mwc/lab_retro
updated player to be able to shoot projectiles
used some of the movement system "vector" idea for the movement system to drive how the projectile moves. Direction is based on the last direction the player moved. Eventually damage and speed will depend on the race and class, but for now, it moves!
This commit is contained in:
parent
03c110bea2
commit
2e7e13996f
Binary file not shown.
Binary file not shown.
|
@ -26,11 +26,10 @@ input("Press Enter to continue. Good luck!")
|
|||
|
||||
board_size = (25,25)
|
||||
x,y = board_size
|
||||
|
||||
walls = [Wall(position) for position in board_edges(board_size)]
|
||||
level = [Wall(position) for position in level_one(board_size)]
|
||||
game = Game(walls + level, {}, board_size = board_size)
|
||||
game.add_agent(Player((x//2,y//2),race,class_))
|
||||
|
||||
|
||||
|
||||
game.play()
|
18
player.py
18
player.py
|
@ -6,28 +6,37 @@
|
|||
# generally be adapted for other player character uses.
|
||||
|
||||
from retro.agent import ArrowKeyAgent
|
||||
from retro.game import Game
|
||||
from projectile import Projectile
|
||||
|
||||
class Player:
|
||||
character = "O"
|
||||
name = "player"
|
||||
level = 1
|
||||
direction = (1,0)
|
||||
class_ = ""
|
||||
|
||||
def __init__(self, position, race, class_):
|
||||
self.position = position
|
||||
if class_.capitalize() == "Warrior":
|
||||
self.color = "red"
|
||||
self.class_ == class_
|
||||
elif class_.capitalize() == "Rogue":
|
||||
self.color = "green"
|
||||
self.class_ == class_
|
||||
else:
|
||||
self.color = "blue"
|
||||
self.class_ == class_
|
||||
|
||||
def handle_keystroke(self, keystroke, game):
|
||||
x, y = self.position
|
||||
if keystroke.name in ("KEY_LEFT", "KEY_RIGHT"):
|
||||
if keystroke.name == "KEY_LEFT":
|
||||
new_position = (x - 1, y)
|
||||
self.direction = (-1,0)
|
||||
else:
|
||||
new_position = (x + 1, y)
|
||||
self.direction = (1,0)
|
||||
if game.on_board(new_position):
|
||||
if game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
|
@ -35,12 +44,21 @@ class Player:
|
|||
if keystroke.name in ("KEY_DOWN", "KEY_UP"):
|
||||
if keystroke.name == "KEY_DOWN":
|
||||
new_position = (x, y + 1)
|
||||
self.direction = (0,1)
|
||||
else:
|
||||
new_position = (x, y - 1)
|
||||
self.direction = (0,-1)
|
||||
if game.on_board(new_position):
|
||||
if game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
|
||||
if self.class_ != "Warrior" and keystroke == " ":
|
||||
projectile = Projectile((self.position[0] + self.direction[0],self.position[1] + self.direction[1]), self.direction, 1)
|
||||
game.add_agent(projectile)
|
||||
print("pew pew pew")
|
||||
|
||||
|
||||
|
||||
def get_agent_in_position(self, position, game):
|
||||
|
||||
agents = game.get_agents_by_position()[position]
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from retro.game import Game
|
||||
|
||||
class Projectile:
|
||||
character = "*"
|
||||
|
||||
def __init__(self, position, direction, speed):
|
||||
self.position = position
|
||||
self.direction = direction
|
||||
self.speed = speed
|
||||
|
||||
def move(self, game):
|
||||
dx, dy = self.direction
|
||||
new_position = (self.position[0] + dx * self.speed, self.position[1] + dy * self.speed)
|
||||
if game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
else:
|
||||
game.remove_agent(self)
|
||||
|
||||
def play_turn(self,game):
|
||||
self.move(game)
|
||||
|
||||
|
||||
|
||||
def handle_collision(self, game):
|
||||
# need to fix this at some point
|
||||
pass
|
Loading…
Reference in New Issue