essai de platformer mais non abouti
from math import * from kandinsky import * from random import * from ion import * from time import * import micropython as mp mp.kbd_intr(KEY_EXE) lvls=[[ "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "22222000000000000000000000000000", "33334220000000000000000000000000", "43443432200000000000000000000000", "01166003300000000000000000000000", "01100060002220000000000000000000", "34366022223332222200000000000000", "33306034333333333320000000000000", "34306643333334443330000000000000", "33360633333343333432000000000000", "43306034334434333343000000000000", "34360003333433433300000000000000", "34406600060660666060022000000000", "43360634334433334066034000000000", "34443344333334433422040000000000", "33333333343433433334000000000000", "44333344333443333443200000000000", "34333443333333333344300000000000", "34433333333333333333300000000000", "33333333333333333333400000000000", "33333333333333333333000000000000", "33333333333333333333000000000000", "33333333333333333333000000000000", "33333333333333333333000000000000", ]] def Drw_Blocks(x,y,t,l): if t=="0": fill_rect(x,y,20,20,(140,40,4)) elif t=="1": fill_rect(x,y,20,20,(140,40,4)) if l%6==0: fill_rect(x+2,y+2,16,16,(250,180,20)) fill_rect(x+4,y+4,12,12,(250,210,30)) elif l%6 in(1,5): fill_rect(x+3,y+2,14,16,(250,180,20)) fill_rect(x+5,y+4,10,12,(250,210,30)) elif l%6 in(2,4): fill_rect(x+5,y+2,10,16,(250,180,20)) fill_rect(x+7,y+4,6,12,(250,210,30)) elif l%6==3: fill_rect(x+8,y+2,4,16,(250,180,20)) elif t=="2": fill_rect(x,y,20,4,(100,90,5)) fill_rect(x,y+4,20,16,(170,70,7)) elif t=="3": fill_rect(x,y,20,20,(170,70,7)) elif t=="4": fill_rect(x,y,20,20,(170,70,7)) fill_rect(x+4,y+4,4,4,(180,)*3) fill_rect(x+12,y+12,4,4,(180,)*3) fill_rect(x+6,y+12,2,2,(180,)*3) fill_rect(x+12,y+6,2,2,(180,)*3) elif t=="6": fill_rect(x,y,20,20,(140,40,4)) fill_rect(x+4,y+4,4,4,(130,)*3) fill_rect(x+12,y+12,4,4,(130,)*3) fill_rect(x+6,y+12,2,2,(130,)*3) fill_rect(x+12,y+6,2,2,(130,)*3) def Drw_Ground(List,x,y,l): for Y in range(-1,12): for X in range(-1,16): Drw_Blocks((X*20)+(x%20),(Y*20)+(y%20),List[Y-(y//20)][X-(x//20)],l) def HitBoxBlocks(t): if t in"016":return 0 else:return 1 def Drw_Player(x,y): fill_rect(x-5,y-5,10,10,(255,0,0)) def Play(Liste): x,y,l=0,0,0 speed=[0,0] Coin=0 Time=monotonic() GameOver=False for i in (0,len(Liste)-1): Liste[i]=list(Liste[i]) while not GameOver: l+=1 Drw_Ground(Liste,x,y,l) Drw_Player(160,111) if monotonic()-Time>0.1: if keydown(KEY_LEFT): speed[0]=5 if keydown(KEY_RIGHT): speed[0]=-5 else:speed[0]/=1.5 if (keydown(KEY_OK)or keydown(KEY_UP))and Liste[(int(111-y)//20)+1][(int(160-x)//20)]not in"016" and speed[1]==0: speed[1]=15 if abs(speed[0])<1:speed[0]=0 x+=int(speed[0]) y+=int(speed[1]) if y%20>15 and Liste[(int(111-y)//20)][(int(160-x)//20)]in "016" and Liste[(int(111-y)//20)+1][(int(160-x)//20)]not in"016":y+=13-(y%20);speed[1]=0 elif Liste[(int(111-y)//20)][(int(160-x)//20)] not in"016"and Liste[(int(111-y)//20)+1][(int(160-x)//20)] not in"016": while Liste[(int(111-y)//20)][(int(160-x)//20)] not in"016":y+=1 speed[1]=0 y+=15-(y%20) if x%20>15 and HitBoxBlocks(Liste[(int(111-y)//20)][(int(160-x)//20)-1])==1: x+=15-(x%20) speed[0]=0 elif x%20<6 and HitBoxBlocks(Liste[(int(111-y)//20)][(int(160-x)//20)+1])==1: x+=6-(x%20) speed[0]=0 if y%20<15 and Liste[(int(111-y)//20)][(int(160-x)//20)]in"016"and Liste[(int(111-y)//20)-1][(int(160-x)//20)]not in "016": speed[1]=-5 if Liste[(int(111-y)//20)+1][(int(160-x)//20)]in"016": speed[1]-=3 if Liste[(int(111-y)//20)][(int(160-x)//20)]=="1": #Liste[(int(111-y)//20)][(int(160-x)//20)]="0" Coin+=1 Play(lvls[0])