Created
January 1, 2015 18:58
-
-
Save x13machine/eba468daf58b2c57ef0c to your computer and use it in GitHub Desktop.
not working
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, math, signal, time,thread | |
#init | |
screen = curses.initscr() | |
#curses.noecho() | |
curses.curs_set(0) | |
curses.start_color(); | |
curses.use_default_colors() | |
#colors | |
for i in range(0, curses.COLORS): | |
curses.init_pair(i + 1,-1,i) | |
#ctrl-c handler | |
running=True | |
def signal_handler(signal, frame): | |
global running | |
running=False | |
signal.signal(signal.SIGINT, signal_handler) | |
#player | |
pos=[0,0] | |
direction=[0,-1] | |
parts=[] | |
screen.timeout(-1) | |
screen.nodelay(1) | |
#game loop | |
while running: | |
#update | |
dims=screen.getmaxyx() | |
pos[0]+=direction[0] | |
pos[1]+=direction[1] | |
if pos[0]<0: pos[0]=dims[1] | |
if pos[0]>dims[1]: pos[0]=0 | |
if pos[1]<0: pos[1]=dims[0] | |
if pos[1]>dims[0]: pos[1]=0 | |
ch=screen.getch() | |
if ch==ord('w'): direction=[0,-1] | |
if ch==ord('s'): direction=[0,1] | |
if ch==ord('a'): direction=[-1,0] | |
if ch==ord('d'): direction=[1,0] | |
#render | |
screen.clear() | |
screen.addstr(pos[1],pos[0],' ',curses.color_pair(4)) | |
screen.refresh() | |
curses.endwin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment