More modularity, add properties in tiles
This commit is contained in:
parent
c9d136929b
commit
e84a5efee2
|
@ -38,6 +38,12 @@ class Tile(Enum):
|
||||||
WALL = '#'
|
WALL = '#'
|
||||||
FLOOR = '.'
|
FLOOR = '.'
|
||||||
|
|
||||||
|
def is_wall(self) -> bool:
|
||||||
|
return self == Tile.WALL
|
||||||
|
|
||||||
|
def can_walk(self) -> bool:
|
||||||
|
return not self.is_wall()
|
||||||
|
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
x: int
|
x: int
|
||||||
|
|
|
@ -19,18 +19,17 @@ def proof_of_concept() -> None:
|
||||||
while True:
|
while True:
|
||||||
key = stdscr.getkey()
|
key = stdscr.getkey()
|
||||||
stdscr.addstr(cur[0], cur[1], '.')
|
stdscr.addstr(cur[0], cur[1], '.')
|
||||||
|
next_pos = cur[:]
|
||||||
if key == 'z' or key == 'KEY_UP':
|
if key == 'z' or key == 'KEY_UP':
|
||||||
if cur[0] > 0 and m.tiles[cur[0] - 1][cur[1]].value != '#':
|
next_pos[0] = cur[0] - 1
|
||||||
cur[0] = cur[0] - 1
|
|
||||||
if key == 's' or key == 'KEY_DOWN':
|
if key == 's' or key == 'KEY_DOWN':
|
||||||
if cur[0] < m.height - 1 and \
|
next_pos[0] = cur[0] + 1
|
||||||
m.tiles[cur[0] + 1][cur[1]].value != '#':
|
|
||||||
cur[0] = cur[0] + 1
|
|
||||||
if key == 'q' or key == 'KEY_LEFT':
|
if key == 'q' or key == 'KEY_LEFT':
|
||||||
if cur[1] > 0 and m.tiles[cur[0]][cur[1] - 1].value != '#':
|
next_pos[1] = cur[1] - 1
|
||||||
cur[1] = cur[1] - 1
|
|
||||||
if key == 'd' or key == 'KEY_RIGHT':
|
if key == 'd' or key == 'KEY_RIGHT':
|
||||||
if cur[1] < m.width and \
|
next_pos[1] = cur[1] + 1
|
||||||
m.tiles[cur[0]][cur[1] + 1].value != '#':
|
if 0 <= next_pos[0] < m.height and 0 <= next_pos[0] < m.width:
|
||||||
cur[1] = cur[1] + 1
|
next_tile = m.tiles[next_pos[0]][next_pos[1]]
|
||||||
|
if next_tile.can_walk():
|
||||||
|
cur = next_pos
|
||||||
stdscr.addstr(cur[0], cur[1], '🐿️')
|
stdscr.addstr(cur[0], cur[1], '🐿️')
|
||||||
|
|
Loading…
Reference in New Issue