Advertisement
Guest User

'wasd' movement

a guest
Oct 23rd, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import sys
  2.  
  3. class Utilities():
  4. def __init__(self):
  5. pass
  6.  
  7. def get_arrow_win(self):
  8. import msvcrt
  9. buttonPress = ""
  10. while True:
  11. if msvcrt.kbhit():
  12. buttonPress = msvcrt.getch()
  13. if buttonPress in arrowDictWin:
  14. print(arrowDictWin.get(buttonPress))
  15.  
  16. def get_arrow_lin(self):
  17. import tty, termios
  18. buttonPress = 0
  19. orig_settings = termios.tcgetattr(sys.stdin)
  20. tty.setcbreak(sys.stdin)
  21. while buttonPress != chr(27):
  22. buttonPress = sys.stdin.read(1)[0]
  23. if buttonPress.lower() in arrowDictLin:
  24. print(arrowDictLin.get(buttonPress.lower()))
  25. termios.tcsetattr(sys.stdin, termios.TCSADRAIN, orig_settings)
  26.  
  27. def clearTile(self):
  28. maze[playerPosRow][playerPosColumn] = " "
  29.  
  30. def screen_clear(self):
  31. if name == 'nt':
  32. _ = system('cls')
  33. else:
  34. _ = system('clear')
  35.  
  36. arrowDictWin = {b'w': 'UP', b'a': 'LEFT', b's': 'DOWN', b'd': 'RIGHT'}
  37. arrowDictLin = {'w': 'UP', 'a': 'LEFT', 's': 'DOWN', 'd': 'RIGHT'}
  38.  
  39. obj = Utilities()
  40.  
  41. if sys.platform == 'win32':
  42. obj.get_arrow_win()
  43. else:
  44. obj.get_arrow_lin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement