0

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)
Sugardust
  • 35
  • 4
  • Curses windows have a `.inch(row, column)` method that returns the contents of the screen at the specified position - as an integer, with the character code in the low 8 bits. – jasonharper Jun 27 '20 at 03:54
  • Does this answer your question? [get char on screen](https://stackoverflow.com/questions/7072826/get-char-on-screen) – Thomas Dickey Jun 27 '20 at 22:03

0 Answers0