from math import * from random import randint as rd from kandinsky import fill_rect as fr, draw_string as dt, color as c from ion import keydown as kd, KEY_OK as ko, KEY_UP as ku, KEY_DOWN as kdn,KEY_SHIFT from time import * level=1 x_e=[] y_e=[] color=["red",c(0,0,0),c(0,255,50),"orange","grey","brown"] nb_e=[0,10,15,20,20,22,24,26,28,30,32,1] delay=320/nb_e[level] score=0 step_e=[0,1,2,3,4,5,6,6,7,7,8,5] step=step_e[level] color_lvl=[0,"red","blue","orange","green",c(173,216,230),"yellow","grey","pink","brown",c(25,25,25)] color_e=color_lvl[level] x=50 y=120 death=0 life=4 heart=[150,165,180,195,210,225,240,255,270] deathl=[0,40,20,15,10,8.5,7,6.5,5,4.5,4,3.75,3.5,3.25,3.1,3] time_p=[0,0.02,0.02,0.03,0.03,0.04,0.04,0.05,0.05,0.06,0.06,0.07,0.07,0.08,0.08] stars=[(50,50,1,1,"white"),(0,35,1,1,"white"),(300,50,1,1,"white"),(50,100,1,1,"white") ,(100,50,1,1,"white"),(200,200,1,1,"white"),(0,160,1,1,"white"),(180,200,1,1,"white"), (100,100,1,1,"white"),(150,150,1,1,"white"),(120,150,1,1,"white"),(70,250,5,5,"white"), (35,300,1,1,"white"),(100,280,1,1,"white"),(150,40,1,1,"white")] xg=320 yg=120 time=0 gift_p=0 xb=x+23 yb=y+2 stop=0 time_s=190 xr=x+30 yr=y-5 movement=0 e=0 xf=320 endp=0 def e(xe,ye): fr(xe+4,ye,3,1,color_e) fr(xe+3,ye+1,1,1,color_e) fr(xe+2,ye+2,1,2,color_e) fr(xe+1,ye+4,8,3,color_e) fr(xe,ye+5,1,1,color_e) fr(xe+6,ye+1,5,1,color_e) fr(xe+6,ye+2,7,2,color_e) fr(xe+9,ye+4,2,2,color_e) fr(xe+11,ye+4,2,1,color_e) fr(xe+4,ye+1,2,3,color[1]) fr(xe+3,ye+2,1,2,color[1]) fr(xe+13,ye+3,step,2,color[1]) fr(xe+14,ye+4,1,1,color[1]) fr(xe+15,ye+4,2,1,color[3]) fr(xe+17,ye+4,3,1,color[0]) fr(xe+7,ye,step,1,color[1]) fr(xe+11,ye+1,step,1,color[1]) fr(xe+13,ye+2,step,1,color[1]) fr(xe+19,ye+4,step,1,color[1]) fr(xe+11,ye+5,step,1,color[1]) fr(xe+9,ye+6,step,1,color[1]) def player(xp,yp): fr(xp+4,yp,13,2,color[4]) fr(xp+6,yp+2,13,3,c(100,100,100)) fr(xp+4,yp+5,13,2,color[4]) fr(xp+5,yp+2,1,3,color[1]) fr(xp+3,yp,1,2,color[1]) fr(xp+3,yp+5,1,2,color[1]) fr(xp+10,yp+3,2,2,color[1]) fr(xp+16,yp+3,2,2,color[1]) fr(xp+18,yp-step+2,4,step,color[1]) fr(xp+18,yp+5,3,step,color[1]) fr(xp+17,yp,1,2,color[5]) fr(xp+19,yp+2,2,3,color[5]) fr(xp+17,yp+5,1,2,color[5]) fr(xp+2,yp,1,2,color[3]) fr(xp+4,yp+2,1,2,color[3]) fr(xp+2,yp+5,1,2,color[3]) fr(xp+1,yp,1,2,color[0]) fr(xp+3,yp+2,1,2,color[0]) fr(xp+1,yp+5,1,2,color[0]) fr(xp+1,yp+2,2,3,color[1]) fr(xp+1,yp-step,18,step,color[1]) fr(xp+1,yp+7,18,step,color[1]) def coeur(xc,yc): fr(xc,yc+2,1,1,color[0]) fr(xc+1,yc,3,2,color[0]) fr(xc+1,yc+2,8,3,color[0]) fr(xc+2,yc+5,6,1,color[0]) fr(xc+3,yc+6,4,1,color[0]) fr(xc+4,yc+7,2,1,color[0]) fr(xc+5,yc+1,1,1,color[0]) fr(xc+6,yc,2,2,color[0]) fr(xc+8,yc+1,1,1,color[0]) def gift(xg,yg): fr(xg,yg+2,7,7,color[0]) fr(xg+2,yg,3,2,color[2]) fr(xg+3,yg+2,1,7,color[2]) fr(xg,yg+5,7,1,color[2]) fr(xg+5,yg,step,2,color[1]) fr(xg+7,yg,step,9,color[1]) fr(0,0,320,240,color[1]) for i in range(0,life): coeur(heart[i],8) while True: fr(0,25,320,1,color_e) for i in range(0,len(stars)): fr(*stars[i]) if not len(x_e)>nb_e[level] and delay<0: x_e.append(320) y_e.append(rd(30,210)) delay=320/nb_e[level] delay=delay-1 for i in range(0,len(x_e)): if x_e[i]<-19: x_e[i]=320 y_e[i]=rd(30,210) else: x_e[i]=x_e[i]-step for i in range(0,len(x_e)): e(x_e[i],y_e[i]) score=score+time_p[level] if score>50: level=level+1 score=0 dt("level:"+str(level)+" "+str(round(score*2)*1)+"% ",5,5,color_e,color[1]) dt("shift",268,5,color_e,color[1]) step=step_e[level] color_e=color_lvl[level] if kd(ku) and y>35: y=y-step movement=1 else: movement=0 if kd(kdn) and y<210: y=y+step movement=1 elif not kd(ku): movement=0 player(x,y) for i in range(0,len(x_e)): if x>x_e[i]-20 and x<x_e[i]+13 and y>y_e[i]-7 and y<y_e[i]+7 and death<0: for i in range(0,3): sleep(0.1) fr(x,y,23,7,color[1]) sleep(0.1) player(x,y) death=deathl[step] life=life-1 fr(0,0,320,20,color[1]) for i in range(0,life): coeur(heart[i],8) death=death-1 time=time+0.01 if round(time%20)==0: xg=330 yg=rd(30,200) if xg<-10 and yg>=30: xg=330 yg=-20 else: xg=xg-round((level/2))*1 gift(xg,yg) if x>xg-23 and x<xg+7 and y>yg-7 and y<yg+9: fr(xg,yg,7,9,color[1]) fr(xb,yb,3,3,color[1]) fr(xr,yr,4,13,color[1]) xg=-10 gift_p=rd(1,3) time_s=190 if gift_p==1: if life<8: life=life+2 fr(0,0,320,20,color[1]) for i in range(0,life): coeur(heart[i],8) if gift_p==1: gift_p=0 if gift_p!=2: xb=x+10 yb=y if gift_p==2 and time_s>0: if xb>325: stop=1 for i in range(0,len(x_e)): if xb>x_e[i]-5 and x<x_e[i]+15 and y>y_e[i]-5 and y<y_e[i]+9: stop=1 fr(x_e[i],y_e[i],19,7,color[1]) x_e[i]=320 y_e[i]=rd(30,240) if stop==1: fr(xb,yb,3,3,color[1]) xb=x+23 yb=y+2 stop=0 else: xb=xb+10 fr(xb,yb,3,3,color[0]) fr(xb-10,yb,10,3,color[1]) time_s=time_s-0.1 if gift_p==3 and time_s>0 and movement==1: xr=x+30 yr=y-3 fr(xr,yr,4,13,"blue") fr(xr,yr,2,13,c(50,49,143)) fr(xr,yr-step,4,step,"black") fr(xr,yr+13,4,step,"black") time_s=time_s-0.1 for i in range(0,len(x_e)): if xr>x_e[i]-4 and xr<x_e[i]+15 and yr>y_e[i]-13 and yr<y_e[i]+7 and movement==1: stop=1 fr(x_e[i],y_e[i],19,7,color[1]) x_e[i]=320 y_e[i]=rd(30,240) if gift_p==3 and time_s>0 and movement==0: fr(xr,yr,4,13,"black") if time_s<1 and time_s>-1: gift_p=0 fr(xb,yb,3,3,color[1]) fr(xr,yr,4,13,color[1]) time_s=-1 if level==10 and score*2>=90: endp=1 if level>=10 and endp==1: xf=xf-int(step/2) fr(xf,31,5,250,color_e) fr(xf+5,31,5,250,"black") if x+15>xf: end=1 fr(xf,31,5,320,"black") break if life<=0: end=0 break if kd(KEY_SHIFT): sleep(0.3) while not kd(KEY_SHIFT): pass sleep(0.3) x,y,w,h=140,110,50,0 for i in range(35): x,y,w,h=x-2,y-2,w+4,h+4 fr(int(x),int(y),int(w),int(h),"orange") fr(int(x+2),int(y+2),int(w-4),int(h-4),"black") sleep(0.02) dt("Game by Aubin",95,70,"orange","black") if end==0: dt("YOU LOST!",120,50,"orange","black") dt("Level:"+str(level)+"/"+"10"+" - "+str(round(score*2))+"%",83,90,"orange","black") dt("************",100,130,"orange","black") else: dt("CONGRATULATION!",90,50,"orange","black") dt("Level:10/10",103,90,"orange","black") dt("Game finished!!",90,110,"orange","black") dt("************",100,145,"orange","black")