Created
May 22, 2018 03:27
-
-
Save zrnsm/289be94bd88b3050538bc1a5206f6adf to your computer and use it in GitHub Desktop.
Hello Rogue World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import curses | |
def main(w): | |
curses.use_default_colors() | |
window_height, window_width = w.getmaxyx() | |
player_y = window_height / 2 | |
player_x = window_width / 2 | |
def redraw_player(): | |
w.delch() | |
w.move(player_y, player_x) | |
w.addch('@') | |
w.move(player_y, player_x) | |
redraw_player() | |
while True: | |
c = w.getch() | |
if c == ord('h'): | |
player_x = max(0, player_x - 1) | |
elif c == ord('j'): | |
# avoid lower right corner | |
player_y = min(window_height - 2, player_y + 1) | |
elif c == ord('k'): | |
player_y = max(0, player_y - 1) | |
elif c == ord('l'): | |
player_x = min(window_width - 1, player_x + 1) | |
redraw_player() | |
curses.wrapper(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment