0

So I'm currently writing a roguelike game using only ascii characters, and I can't figure out how to check if there are walls in front of my characters (So ideally whatever method I use returns a '#'). My idea was to check after each move if the character is trying to move into a wall, but I can't find code that lets me check the specific character already printed out in the terminal at an (x, y) location.

Image

Any help would be appreciated! I'm currently using

sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text)) 

to print characters at specific locations.

blondelg
  • 916
  • 1
  • 8
  • 25
Jag
  • 1

1 Answers1

2

you need to store you "map" in a 2d array

consider

map = [[1,1,1,1,1,1,1],
       [1,0,0,0,0,0,1],
       [1,0,0,0,0,0,1],
       [1,1,1,1,1,1,1]]

in this map 1 would be a wall ... 0 is a walkable tile... now as long as you know the X,Y of the target where the character will move... you can tell if you are walking into a wall

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179