Skip to content

Instantly share code, notes, and snippets.

@x13machine
Created January 1, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x13machine/eba468daf58b2c57ef0c to your computer and use it in GitHub Desktop.
Save x13machine/eba468daf58b2c57ef0c to your computer and use it in GitHub Desktop.
not working
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