from kandinsky import * from time import * playercolor=(255,10,0)#! startpos=[160,200,10]#! posx=startpos[0] posy=startpos[1] size=startpos[2] oldpos=[posx,posy,size] drawpos=[160,112,get_pixel(160,112)] forcex=0#! forcey=0#! gravity=0.02#! jump=8#! jumpforce=0#! speed=0.5#! speedlimit=5#! onground=0#! onice=0#! #slopes=1 key={} #def toolbox(): def touch(): touched=[[],[],[],[]] for i in range(size): d=get_pixel(posx+i,posy+1) u=get_pixel(posx+i,posy-size) l=get_pixel(posx-1,posy-i) r=get_pixel(posx+size,posy-i) if not d in touched[0]: touched[0].append(d) if not u in touched[1]: touched[1].append(u) if not l in touched[2]: touched[2].append(l) if not r in touched[3] : touched[3].append(r) return touched fill_rect(posx,posy+1,size,-size,playercolor) #while not "onOff" in key: # key=get_keys() # if key: set_pixel(drawpos[0],drawpos[1],drawpos[2]) # if "left" in key: drawpos[0]-=1 # if "right" in key: drawpos[0]+=1 # if "up" in key: drawpos[1]-=1 # if "down" in key: drawpos[1]+=1 # drawpos[2]=get_pixel(drawpos[0],drawpos[1]) # if "OK" in key: drawpos[2]=(0,0,0) # set_pixel(drawpos[0],drawpos[1],(0,0,255)) # sleep(0.1) draw_line(0,210,30,210,(0,0,0))#! draw_line(60,180,100,180,(0,0,0))#! draw_line(100,150,130,150,(0,0,0))#! draw_line(160,120,200,120,(0,255,255))#! draw_line(200,90,230,90,(0,0,0))#! draw_line(210,60,180,60,(0,0,0))#! draw_line(160,30,130,30,(0,0,0))#! draw_line(200,210,320,210,(0,255,255))#! draw_line(200,210,205,210,(255,0,255))#! draw_line(160,1,130,1,(255,0,0))#! draw_line(80,30,100,30,(0,255,0))#! #draw_line(300,222,300,0,(0,0,0))#! #draw_line(50,222,50,0,(0,0,0))#! key={} #sleep(1) while not "onOff" in key: key=get_keys() if key or forcex or forcey: oldpos=[posx,posy,size] if "left" in key and not posx==0: forcex-=speed+(forcex>0)*speed if "right" in key and not posx==320-size: forcex+=speed+(forcex<0)*speed if not onice: if not "left" in key and not "right" in key and ((jumpforce and onground) or (not jumpforce)): if forcex>0: forcex-=speed if forcex<0: forcex+=speed if forcex>speedlimit: forcex-=speed*4 if forcex<-speedlimit: forcex+=speed*4 if "OK" in key and onground: forcey=-jump onground=0 # if "toolbox" in key: toolbox() for i in range(forcey): for j in range(size): if get_pixel(posx+j,posy+i+1)!=(248,252,248) and not onground: onground=1 posy+=i forcey=0 # for i in range(0,forcey+(posy+forcey<0)*(-(forcey+posy)),-1): for i in range(0,forcey,-1): for j in range(size): if get_pixel(posx+j,posy-size+i)!=(248,252,248) and forcey: onground=0 posy+=i forcey=0 under=0 for i in range(size): if get_pixel(posx+i,posy+1)!=(248,252,248): under=1 if not under: onground=0 posy+=int(forcey) if not onground: forcey+=1 # for i in range(forcex-(posx+forcex>320)*((posx+forcex)-320)): for i in range(forcex): for j in range(size): if get_pixel(posx+size+i,posy-j)!=(248,252,248) and forcex: posx+=i forcex=0 for i in range(0,forcex,-1): for j in range(size): if get_pixel(posx+i-1,posy-j)!=(248,252,248) and forcex: posx+=i forcex=0 posx+=int(forcex) touched=touch() if (0,252,248) in touched[0]: onice=1 if (0,0,0) in touched[0]: onice=0 if (248,0,248) in touched[0] and onground: forcey-=jump*1.25 onground=0 death=(248,0,0) if death in touched[0] or death in touched[1] or death in touched[2] or death in touched[3]: forcex,forcey=0,0 posx,posy=startpos[0],startpos[1] size=startpos[2] win=(0,252,0) if win in touched[0] or win in touched[1] or win in touched[2] or win in touched[3]: draw_string("You win !",230,0) key={"onOff"} # if slopes and onground: # under=[] # for i in range(int(size/2)): # if get_pixel(,) if oldpos: fill_rect(oldpos[0],oldpos[1]+1,oldpos[2],-oldpos[2],(255,255,255)) fill_rect(posx,posy+1,size,-size,playercolor) oldpos=[] sleep(gravity) #draw_line(160,179,200,179,(0,0,0)) #set_pixel(posx,posy,(0,0,255)) #for i in range(size): # set_pixel(posx+i,posy+1,(0,0,255)) # set_pixel(posx+i,posy-size,(0,0,255)) # set_pixel(posx-1,posy-i,(0,0,255)) # set_pixel(posx+size,posy-i,(0,0,255))