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