User player entity instead of temporary Player class
This commit is contained in:
parent
81479f99e2
commit
8641e7d13d
|
@ -4,3 +4,15 @@ from ..interfaces import FightingEntity
|
|||
class Player(FightingEntity):
|
||||
maxhealth = 20
|
||||
strength = 5
|
||||
|
||||
def move_up(self) -> None:
|
||||
self.y -= 1
|
||||
|
||||
def move_down(self) -> None:
|
||||
self.y += 1
|
||||
|
||||
def move_left(self) -> None:
|
||||
self.x -= 1
|
||||
|
||||
def move_right(self) -> None:
|
||||
self.x += 1
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from typing import Any
|
||||
|
||||
from .entities.player import Player
|
||||
from .interfaces import Map
|
||||
from .mapdisplay import MapDisplay
|
||||
from .settings import Settings
|
||||
|
@ -22,8 +23,8 @@ class Game:
|
|||
m = Map.load("example_map.txt")
|
||||
player = Player()
|
||||
self.player = player
|
||||
player.y = 1
|
||||
player.x = 6
|
||||
m.entities.append(player)
|
||||
player.move(1, 6)
|
||||
d = MapDisplay(m, player)
|
||||
while True:
|
||||
screen.clear()
|
||||
|
@ -43,20 +44,3 @@ class Game:
|
|||
if key == 'd' or key == 'KEY_RIGHT':
|
||||
self.player.move_right()
|
||||
|
||||
|
||||
class Player:
|
||||
# FIXME Should be elsewhere, only useful to don't break the previous code
|
||||
y: int = 0
|
||||
x: int = 0
|
||||
|
||||
def move_up(self) -> None:
|
||||
self.y -= 1
|
||||
|
||||
def move_down(self) -> None:
|
||||
self.y += 1
|
||||
|
||||
def move_left(self) -> None:
|
||||
self.x -= 1
|
||||
|
||||
def move_right(self) -> None:
|
||||
self.x += 1
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
import curses
|
||||
from typing import Any
|
||||
|
||||
from dungeonbattle.entities.player import Player
|
||||
from dungeonbattle.interfaces import Map
|
||||
|
||||
|
||||
class MapDisplay:
|
||||
def __init__(self, m: Map, player: Any):
|
||||
# TODO Type the player field with the good type
|
||||
def __init__(self, m: Map, player: Player):
|
||||
self.map = m
|
||||
self.pad = curses.newpad(m.height, m.width + 1)
|
||||
self.player = player
|
||||
|
||||
def update_pad(self) -> None:
|
||||
self.pad.addstr(0, 0, self.map.draw_string())
|
||||
# TODO Not all entities should be a player
|
||||
for e in self.map.entities:
|
||||
self.pad.addch(e.y, e.x, e.img)
|
||||
self.pad.addstr(self.player.getPosY(), self.player.getPosX(), '🐿')
|
||||
self.pad.addstr(e.y, e.x, '🐿')
|
||||
|
||||
def display(self, y: int, x: int) -> None:
|
||||
deltay, deltax = (curses.LINES // 2) + 1, (curses.COLS // 2) + 1
|
||||
|
|
Loading…
Reference in New Issue