from kandinsky import * from ion import * from time import * from math import * fr=monotonic() map=[0,0,66,66,0,126,60,0] def cubecol(x,y,xvel,yvel,onground,x1,y1,x2,y2): if x+10>x1 and x-10<x2 and y+10-yvel>y1 and y-10-yvel<y2: if yvel<0: y=y1-10 onground=1 else: y=y2+10 yvel=0 if y+10>y1 and y-10<y2 and x+10+xvel>x1 and x-10+xvel<x2: onground=1 x=x-xvel return (x,y,xvel,yvel,onground) def player(x,y,state): if state==0: fill_rect(x-10,y-10,20,20,color(255,100,0)) #fill_rect(x-10,y-10,20,20,color(0,100,0)) elif state==1: #fill_rect(x-10,y-10,20,20,color(255,255,255)) fill_rect(x-10,y-10,20,20,color(100,100,100)) elif state==-1: fill_rect(x-10,y-10,20,20,color(255,255,255)) fill_rect(x-20,y-5,40,10,color(0,0,255)) def noplayer(x,y,state): if state==-1: fill_rect(x-20,y-5,40,10,color(255,255,255)) else: if yvel!=0 or xvel!=0 or onground==0: fill_rect(x-10,y-10,20,20,color(255,255,255)) def zero(n): if n>0: return 1 if n<0: return -1 if n==0: return 0 x=100 xvel=0 onground=1 y=50 yvel=10 time=0 maxvel=5 state=0 fill_rect(100,70,100,60,color(0,0,0)) while (1): if keydown(KEY_LEFT)and xvel>-maxvel: xvel=xvel-1 elif keydown(KEY_RIGHT)and xvel<maxvel: xvel=xvel+1 else: xvel=xvel-zero(xvel) noplayer(x,y,state) if keydown(KEY_UP): #fill_rect(x-10,y-10,20,20,color(255,255,255)) if state!=1: if onground==1: fill_rect(x-10,y-10,20,20,color(255,255,255)) state=1 maxvel=0 onground=0 yvel=10 fill_rect(x-10,y-10,20,20,color(255,255,255)) else: onground=0 state=1 elif keydown(KEY_DOWN): state=-1 maxvel=10 onground=0 else: maxvel=5 state=0 if keydown(KEY_OK) and onground==1: fill_rect(x-10,y-10,20,20,color(255,255,255)) yvel=10 else: if state!=1: yvel=yvel-1 elif yvel>0: yvel=yvel-0.5 onground=0 x,y,xvel,yvel,onground=cubecol(x,y,xvel,yvel,onground,0,200,320,300) x,y,xvel,yvel,onground=cubecol(x,y,xvel,yvel,onground,100,70,200,130) x=x+xvel y=y-int(yvel) player(x,y,state) if monotonic()<(fr+(1/30)): sleep((fr+(1/30))-monotonic()) fr=monotonic() fr=monotonic()