#Version 1.2 from kandinsky import * from time import * #change colors by atleast 8 #black=(0,0,0) / white=(248,252,248) c={"normal":(0,0,0),"ice":(0,252,248),"bouncy":(248,0,248),"sticky":(248,252,0),"lava":(248,0,0),"goal":(0,252,0)}#! playercolor=(255,10,0)#! bgcolor=(200,200,200)#! startpos=[310,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#! olforcex=forcex onground=0#? onice=0#? #slopes=1 key={} #errors=0 if playercolor in c.values(): print("[!] Player color is equal to a platform color") if bgcolor in c.values(): print("[!] Background color is equal to a platform color") if startpos[0]>320 or startpos[0]<0: print("[!] X start position out of limits") if startpos[1]>222 or startpos[0]<0: print("[!] Y start position out of limits") if startpos[2]<1: print("[!] Start size is too small") if startpos[2]>222: print("[!] Start size is too big") if gravity>=1: print("[!] Gravity is too slow") if jump>222: print("[!] Jump is too big") if speed>320: print("[!] Speed is too big") if speedlimit/speed!=int(speedlimit/speed): print("[!] Speed can't reach speed limit") #def toolbox(): def touch(): touched=[[],[],[],[]] #down,up,left,right 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(0,0,320,222,bgcolor) 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,31,210,c["normal"])#! draw_line(60,180,100,180,c["normal"])#! draw_line(100,148,130,148,c["normal"])#! draw_line(160,120,200,120,c["ice"])#! draw_line(200,90,230,90,c["normal"])#! draw_line(210,60,180,60,c["normal"])#! draw_line(160,30,130,30,c["normal"])#! draw_line(200,210,320,210,c["ice"])#! draw_line(200,210,205,210,c["bouncy"])#! draw_line(160,1,130,1,c["lava"])#! draw_line(80,30,100,30,c["goal"])#! draw_line(30,211,30,222,c["bouncy"]) draw_line(200,211,200,222,c["bouncy"]) draw_line(100,149,130,149,c["bouncy"])#! draw_line(1,0,1,210,c["sticky"]) draw_line(220,180,250,180,c["sticky"]) #draw_line(300,222,300,0,c["normal"])#! #draw_line(50,222,50,0,c["normal"])#! key={} #sleep(1) touched=touch() while not "onOff" in key: key=get_keys() touched=touch() 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 if forcex<-speedlimit: forcex+=speed if "OK" in key and onground: forcey=-jump if c["sticky"] in touched[2] or c["sticky"] in touched[3] and not forcex: forcey+=jump else: 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)!=bgcolor 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)!=bgcolor and forcey: onground=0 posy+=i forcey=0 under=0 for i in range(size): if get_pixel(posx+i,posy+1)!=bgcolor: under=1 if not under: onground=0 if c["sticky"] in touched[2] or c["sticky"] in touched[3]: if forcey>1: forcey=1 if forcey<0: forcey=0 onground=1 if not "OK" in key: onground=0 if c["sticky"] in touched[0]: forcey=0 if c["sticky"] in touched[1]: forcey=0 onground=1 onice=0 posy+=int(forcey) if not onground: forcey+=1 olforcex=forcex # 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)!=bgcolor 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)!=bgcolor and forcex: posx+=i forcex=0 if c["sticky"] in touched[0] or c["sticky"] in touched[1]: if forcex>1: forcex=1 if forcex<-1: forcex=-1 posx+=int(forcex) touched=touch() if c["ice"] in touched[0]: onice=1 elif not bgcolor in touched[0]: onice=0 if c["bouncy"] in touched[0] and onground: forcey-=jump*1.25 onground=0 if c["bouncy"] in touched[1] and not onground: forcey+=jump*1.25 if c["bouncy"] in touched[2] and onground and olforcex: forcex=-olforcex+(speed*(forcex==speed)*2) if c["bouncy"] in touched[3] and onground and olforcex: forcex=-olforcex-(speed*(forcex==-speed)*2) # if forcex=speed death=c["lava"] 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=c["goal"] 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,(0,0,0),bgcolor) 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],bgcolor) fill_rect(posx,posy+1,size,-size,playercolor) oldpos=[] # draw_string(" "*20,220,0) # draw_string(str(forcex)+","+str(olforcex),220,0) 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))