Flèches pour se déplacer
from math import * from kandinsky import * from ion import * from random import * de,c,l,vie,s=20,7,60,3,0 co=[(0,0,0),(255,255,255),(125,125,125)] def init(c,l): return(160-floor(c/2),220-floor(c),pi/1.5,160-floor(l/2),randint(1,3)) def iniv(ni): if ni==1: return([0,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1]) if ni==2: return([0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,1]) if ni==3: return([0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1]) def niv(n): fill_rect(0,de,320,240,co[0]) for i in range(1,len(n)): if n[i]==1: fill_rect(32*((i-1)%10)+2,de+16*floor((i-1)/10)+2,28,12,co[1]) if len(n)-10>i: if n[i+10]==0: fill_rect(32*((i-1)%10)+2,de+16*floor((i-1)/10)+14,28,10,(100,100,100)) else: fill_rect(32*((i-1)%10)+2,de+16*floor((i-1)/10)+14,28,10,(100,100,100)) elif n[i]==2: fill_rect(32*(i%10)+2,de+16*floor(i/10)+2,28,12,co[2]) fill_rect(floor(160-l/2),210,l,5,co[1]) def to(x,y,n): z,su=0,[1000,1000] for i in range(len(n)-1,0,-1): if z==0: if n[i]==0: n[i]=-1 su.append(i) else: z=1 if n[i]>0: if x+c>32*((i-1)%10)+2 and x<32*((i-1)%10)+28: if y+c>16*floor((i-1)/10)+2+de and y<16*floor((i-1)/10)+de+12: if n[i]==1: n[i]=0 fill_rect(32*((i-1)%10)+2,16*floor((i-1)/10)+2+de,28,12,co[0]) if len(n)-10>i: if n[i+10]==0: fill_rect(32*((i-1)%10)+2,16*floor((i-1)/10)+14+de,28,10,(0,0,0)) else: fill_rect(32*((i-1)%10)+2,16*floor((i-1)/10)+14+de,28,10,(0,0,0)) for w in range(2,len(su)): if i<len(su)-1: if len(n)>su[i]-1: n.pop(su[i]) return(1,n) for i in range(2,len(su)): if i<=len(n): n.pop(su[i]) return(0,n) x,y,d,px,ni=init(c,l) n,b=iniv(ni),0 niv(n) def fin(n): for i in range(0,len(n)): if n[i]==1: return False return True def barre(vie,s): fill_rect(0,0,320,de,co[0]) if vie>0: for z in range(0,vie): fill_rect(15+z*20,5,10,10,co[1]) fill_rect(0,de-2,320,2,co[1]) return(0) def game(x,y,s,d,px,n,ni,vie,v): t,b,ap,ax,ay,ad=0,1,px,floor(x),floor(y),d x=x+sin(d)*v t,n=to(x,y,n) if t==1: x,s,d=x-sin(d)*v,s+10,-d if fin(n): x,y,d,px,ni=init(c,l) n,b=iniv(ni),0 niv(n) y=y+cos(ad)*v t,n=to(x,y,n) if t==1: y,s,d=y-cos(ad)*v,s+10,pi-d if fin(n): x,y,d,px,ni=init(c,l) n,b=iniv(ni),b niv(n) if x<0: x,d=0,-d if x>320-c: x,d=320-c,-d if y<de: y,d=de+1,pi-d m=0 if y>230-c: x,y,d,px,ni=init(c,l) b,m,vie=0,1,vie-1 barre(vie,s) if keydown(KEY_LEFT): px=px-v if keydown(KEY_RIGHT): px=px+v if px<0: px=0 if px>320-l: px=320-l if x+c>px and x<px+l: if y>210-c: y=210-c if keydown(KEY_LEFT): d=-(d-pi)+pi/100 elif keydown(KEY_RIGHT): d=-(d-pi)-pi/100 else: d=pi-d fill_rect(ax,ay,c,c,co[0]) fill_rect(floor(x),floor(y),c,c,co[1]) if ap!=px: fill_rect(floor(ap),210,l,5,co[0]) fill_rect(floor(px),210,l,5,co[1]) return(x,y,s,d,px,n,vie,ni,b,m) def score(s): dd,b=20,10 draw_string(str(s),320-b*len(str(s)),de-dd,(255,255,255),(0,0,0)) barre(vie,s) def attt(): while keydown(KEY_LEFT) or keydown(KEY_RIGHT): pass def att(): while True: if keydown(KEY_LEFT) or keydown(KEY_RIGHT): return None def res(): while True: if keydown(KEY_EXE) or keydown(KEY_OK): return None bb,m,vu=1,0,0 def adv(): for o in range(0,3000,10): c=(o/((o%10)+1),o,o/((o%3)+1)) fill_rect(0,0,50,240,c) fill_rect(0,0,320,50,c) fill_rect(0,65,320,240,c) fill_rect(50+10*len("dkfe123"),50,320,240,c) draw_string("dkfe123",50,50,(0,0,0),c) while True: score(s) for i in range(1,len(n)): if n[i]>0: if len(n)-10>i: if n[i+10]==0: fill_rect(32*((i-1)%10)+2,16*floor((i-1)/10)+14+de,28,10,(100,100,100)) else: fill_rect(32*((i-1)%10)+2,16*floor((i-1)/10)+14+de,28,10,(100,100,100)) if b==1: x,y,s,d,px,n,vie,ni,b,m=game(x,y,s,d,px,n,ni,vie,5) if m==1: score(s) if vie>-1: attt() att() if b==0: if keydown(KEY_LEFT) or keydown(KEY_RIGHT): b=1 if keydown(KEY_LEFT): d=-pi/4 else: d=pi/4 if keydown(KEY_ZERO): if bb==0: draw_string("Pause 0",80,0,(255,255,255),(0,0,0)) while keydown(KEY_ZERO): pass while not keydown(KEY_ZERO): pass fill_rect(80,0,20*len("Pause 0"),15,(0,0,0)) bb=1 else: bb=0 if vie==-1: if vu==0: fill_rect(20,50,280,110,(125,125,125)) draw_string("Watch ad to have new life",25,60,(255,255,255),(125,125,125)) draw_string("Press OK",100,80,(255,255,255),(125,125,125)) draw_string("EXE pour rejouer",50,100,(255,255,255),(125,125,125)) else: draw_string("EXE pour rejouer",50,100,(255,255,255),(0,0,0)) score(s) kp,b=False,0 res() if keydown(KEY_EXE): kp=True if vu==0: if keydown(KEY_OK): adv() vu,kp=1,True else: s=0 else: print(s) s=0 if kp: ani=ni x,y,d,px,ni=init(c,l) vie,ni=3,ani if keydown(KEY_EXE): n=iniv(ni) niv(n) barre(vie,s) if keydown(KEY_EXE): vu=0