I'm currently working on a roguelike game and trying to figure out collision detection for walls. I currently have the player being drawn at a specific y, x coordinate in the terminal but I'm having trouble figuring out how I can use this to detect if the player runs into a wall, signified by a "#" character.
Movement is done like so:
def main(root):
max_h, max_w = root.getmaxyx()
current_row = 0
current_col = 0
while True:
key = root.getch()
if key == curses.KEY_UP and current_row > 1:
current_row -= 1
elif key == curses.KEY_DOWN and current_row < max_h - 5:
current_row += 1
elif key == curses.KEY_LEFT and current_col > 1:
current_col -= 1
elif key == curses.KEY_RIGHT and current_col < max_w - 3:
current_col += 1
elif key == ord("q"):
break
gameWindow(root, current_row, current_col)
'current_row' and 'current_col' are sent off to another function where they actually move the player character around. For the sake of completelness, here's that function:
def player(game_win, current_row, current_col):
p = "@"
if current_row > 0:
game_win.addstr(current_row, current_col, p)