diff --git a/__pycache__/player.cpython-310.pyc b/__pycache__/player.cpython-310.pyc index 53a088e..eb05384 100644 Binary files a/__pycache__/player.cpython-310.pyc and b/__pycache__/player.cpython-310.pyc differ diff --git a/__pycache__/projectile.cpython-310.pyc b/__pycache__/projectile.cpython-310.pyc new file mode 100644 index 0000000..7db3417 Binary files /dev/null and b/__pycache__/projectile.cpython-310.pyc differ diff --git a/angband.py b/angband.py index 99ee75e..192588d 100644 --- a/angband.py +++ b/angband.py @@ -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() \ No newline at end of file diff --git a/player.py b/player.py index 6d35182..d235d96 100644 --- a/player.py +++ b/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] diff --git a/projectile.py b/projectile.py new file mode 100644 index 0000000..7ed6f3c --- /dev/null +++ b/projectile.py @@ -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 \ No newline at end of file