from math import * from kandinsky import * from ion import * from time import * def terrain(): fill_rect(0,190,330,50,color(0,200,0)) def clear(): h=0 for i in range(25): draw_string(" ",0,h) h=h+15 tmpsmax=10 def menu(tmpsmax): fleche=0 tmpsmax=10 draw_string("play",3,0) draw_string("edit",3,20) draw_string("Temps:"+str(tmpsmax)+"s",3,40) while True: if keydown(KEY_PLUS)==True: tmpsmax=tmpsmax+1 draw_string(" ",3,40) draw_string("Temps:"+str(tmpsmax)+"s",3,40) sleep(0.1) if keydown(KEY_MINUS)==True: tmpsmax=tmpsmax-1 draw_string(" ",3,40) draw_string("Temps:"+str(tmpsmax)+"s",0,40) sleep(0.1) if tmpsmax<5: tmpsmax=5 if keydown(KEY_DOWN)==True: fleche=fleche+1 sleep(0.1) if keydown(KEY_UP)==True: fleche=fleche-1 sleep(0.1) if fleche>1: fleche=0 if fleche<0: fleche=1 sleep(0.1) if fleche==0: fill_rect(3,0,1,20,color(0,175,0)) fill_rect(3,20,1,20,color(255,255,255)) if fleche==1: fill_rect(3,20,1,20,color(0,175,0)) fill_rect(3,0,1,20,color(255,255,255)) if keydown(KEY_OK)==True: draw_string(" ",3,0) draw_string(" ",3,20) draw_string(" ",3,40) if fleche==0: print(play(tmpsmax)) if fleche==1: print(edit()) def perso(x,y,x2,y2): fill_rect(x2,y2,10,10,color(255,255,255)) fill_rect(x,y,10,10,color(100,0,0)) x2=x y2=y return x2,y2 def persoedit(x,y,x2,y2,taille): if keydown(KEY_OK)!=True: fill_rect(x2,y2,taille,taille,color(255,255,255)) fill_rect(x,y,taille,taille,color(0,0,0)) x2=x y2=y return x2,y2 def edit(): x=150 y=100 x2=0 y2=0 taille=10 couleur=0 fill_rect(0,0,90,60,color(255,200,200)) draw_string("Vert",0,0) draw_string("Taille:10",0,20) while True: x2,y2=persoedit(x,y,x2,y2,taille) if keydown(KEY_RIGHT)==True: x=x+1 if keydown(KEY_LEFT)==True: x=x-1 if keydown(KEY_UP)==True: y=y-1 if keydown(KEY_DOWN)==True: y=y+1 if keydown(KEY_PLUS)==True: fill_rect(x,y,taille,taille,color(255,255,255)) taille=taille+5 draw_string("Taille:"+str(taille),0,20) sleep(0.1) if keydown(KEY_MINUS)==True: fill_rect(x,y,taille,taille,color(255,255,255)) taille=taille-5 draw_string("Taille:"+str(taille),0,20) sleep(0.1) if keydown(KEY_LEFTPARENTHESIS)==True: couleur=couleur-1 sleep(0.1) if keydown(KEY_RIGHTPARENTHESIS)==True: couleur=couleur+1 sleep(0.1) if couleur<0: couleur=2 if couleur>2: couleur=0 if keydown(KEY_OK)==True: if couleur==0: draw_string("Vert",0,0) fill_rect(x2,y2,taille,taille,color(0,200,0)) if couleur==1: draw_string("Bleue",0,0) fill_rect(x2,y2,taille,taille,color(0,0,200)) if couleur==2: draw_string("Rouge",0,0) fill_rect(x2,y2,taille,taille,color(200,0,0)) if keydown(KEY_SQRT)==True: print(clear()) print(terrain()) sleep(0.1) if keydown(KEY_BACKSPACE)==True: fill_rect(x,y,taille,taille,color(255,255,255)) fill_rect(0,0,90,60,color(255,255,255)) print(menu(tmpsmax)) def play(tmax): fin=0 speed=0.005 psaut=0 saut=0 boucle=0 boucle2=0 x=10 y=0 x2=0 y2=0 tmps=0 tmps2=0 while True: draw_string(str(tmps2),0,0) tmps=tmps+1 if tmps==120: tmps2=tmps2+1 tmps=0 if tmps2==tmax+1: fin=1 if x<0: x=x+1 if x>310: x=x-1 if y<0: y=y+1 saut=0 if y>250: fin=1 if saut==1: if get_pixel(x,y-2)==(0,200,0) or get_pixel(x+10,y-2)==(0,200,0): saut=0 if get_pixel(x,y+10)==(0,200,0): x=x+1 if get_pixel(x+10,y+10)==(0,200,0): x=x-1 y=y-1 boucle=boucle+1 boucle2=boucle2+1 if boucle2==10: speed=speed+0.001 boucle2=0 if boucle>100: boucle=0 saut=0 x2,y2=perso(x,y,x2,y2) sleep(speed) if saut==0: if get_pixel(x+10,y+10)!=(0,200,0) and get_pixel(x,y+10)!=(0,200,0): y=y+1 x2,y2=perso(x,y,x2,y2) speed=speed-0.0002 psaut= 0 if get_pixel(x+10,y+10)==(0,200,0) and get_pixel(x+10,y+10)==(0,200,0): psaut=1 speed=0.005 if get_pixel(x-1,y)==(0,200,0): x=x+1 if get_pixel(x+10,y)==(0,200,0): x=x-1 if get_pixel(x-1,y)==(0,0,200) or get_pixel(x+10,y)==(0,0,200) or get_pixel(x-1,y+10)==(0,0,200) or get_pixel(x+10,y+10)==(0,0,200): fin=1 if get_pixel(x,y+10)==(200,0,0) or get_pixel(x+10,y+10)==(200,0,0): y=y-1 if get_pixel(x,y-1)==(200,0,0) or get_pixel(x+10,y-1)==(200,0,0): y=y-1 saut=0 if keydown(KEY_RIGHT)==True: if get_pixel(x,y+10)==(200,0,0) or get_pixel(x+10,y+10)==(200,0,0): x=x+2 else: x=x+1 if saut==1: boucle=boucle-0.3 if keydown(KEY_LEFT)==True: if get_pixel(x,y+10)==(200,0,0) or get_pixel(x+10,y+10)==(200,0,0): x=x-2 else: x=x-1 if saut==1: boucle=boucle-0.3 if psaut==1: if keydown(KEY_UP)==True: speed=0.0001 saut=1 psaut=0 if fin==1: fill_rect(x,y,10,10,color(255,255,255)) draw_string(" ",0,0) print(menu(tmpsmax)) while True: draw_string("SPRINT",125,60) fill_rect(125,75,65,1,color(255,0,0)) draw_string("[OK] pour commencer",65,90) draw_string("M.R.",280,200) if keydown(KEY_OK) == True: fill_rect(0,0,400,300,color(255,255,255)) break print(terrain()) print(menu(tmpsmax))