Un jeu de Pong, avec des bonus, un menu et des animations ! Clain industrie.
from math import * from kandinsky import * from ion import * from random import * import time #dessine le padle def draw_pdl(): fill_rect(xp,yp,60,10,"blue") def clear_pdl(): fill_rect(xp,yp,60,10,"white") #dessine la balle def draw_bll(): fill_rect(xb,yb,10,10,'green') def clear_bll(): fill_rect(xb,yb,10,10,"white") #fait rebondir la balle def d_bll(): global sx global sy global xb global yb global score if yb<1: sy*=-1 if xb<1: sx*=-1 if xb>305: sx*=-1 if get_pixel(xb,yb+11)==(0,0,248): if yb+10>200: clear_bll() yb-=5 sy*=-1 score+=1 fill_rect(xp,yp,60,10,color(0,0,148)) time.sleep(0.01) if yb>210: fill_rect(0,0,320,240,"white") draw_string("Game over",115,50) draw_string("Score:",130,80) size=score n=0 if score>0: while size<1: size/10 n+1 draw_string(str(score),150-(n*10),100) clear_bll() clear_pdl() fill_rect(131,156,58,26,"blue") fill_rect(133,158,54,22,"white") fill_rect(113,163,10,10,"green") fill_rect(197,163,10,10,"green") draw_string("Menue",135,160) while not keydown(KEY_EXE): pass fill_rect(0,0,320,240,"white") menue() initsuite() def compte(): draw_string("Preparez-vous",90,80) draw_string("3",150,110,) time.sleep(1) draw_string("2",150,110) time.sleep(1) draw_string("1",150,110) time.sleep(1) draw_string("0",150,110) time.sleep(1) fill_rect(0,0,320,200,"white") def menue(): fill_rect(95,75,139,26,color1) fill_rect(97,77,135,22,"white") fill_rect(77,83,10,10,color3) fill_rect(242,83,10,10,color3) draw_string("Comment jouer",99,79) fill_rect(135,115,58,26,color2) fill_rect(137,117,54,22,"white") fill_rect(117,123,10,10,color4) fill_rect(201,123,10,10,color4) draw_string("Start",139,119) def anination(): global xanim fill_rect(0,0,1,1,"white") time.sleep(0.6) draw_string("Pong v1.9",117,50,"green") draw_string("Clain Industrie",85,80,"orange") draw_string("Production",110,100,"blue") fill_rect(110,142,100,8,"blue") fill_rect(112,144,96,4,"white") fill_rect(113,145,8,2,"green") time.sleep(1.4) fill_rect(113,145,64,2,"green") time.sleep(0.2) fill_rect(113,145,94,2,"green") time.sleep(1.4) anination1() def anination1(): global xanim fill_rect(0,0,320,240,"white") fill_rect(148,81,14,14,"green") time.sleep(0.3) fill_rect(148,81,14,14,"white") while not xanim==74: fill_rect(0,83,320,10,"white") fill_rect(155+xanim,83,10,10,"green") fill_rect(155-xanim,83,10,10,"green") xanim+=1 time.sleep(0.003) fill_rect(0,0,320,240,"white") #animation def anination2(): xanim=73 fill_rect(0,0,320,240,"white") if color1=="blue": while not xanim<1: fill_rect(0,83,320,10,"white") fill_rect(155+xanim,83,10,10,color3) fill_rect(155-xanim,83,10,10,color3) xanim-=1 time.sleep(0.003) else: xanim=51 while not xanim<1: fill_rect(0,123,320,10,"white") fill_rect(155+xanim,123,10,10,color4) fill_rect(155-xanim,123,10,10,color4) xanim-=1 time.sleep(0.003) time.sleep(0.3) fill_rect(0,0,320,240,"white") def cubes(): global ok global xb global yb global score global recom global va fill_rect(ok,5,10,10,"orange") if int(ok/10)==int(xb/10) and yb<15: fill_rect(ok,5,10,10,"white") draw_bll() time.sleep(0.2) va="+0"+str(recom) if recom>0: draw_string(va,150,5,"green") else: va="-0"+str(recom*-1) draw_string(va,150,5,"red") ok=randint(5,315) score+=recom recom=randint(-4,5) time.sleep(1) fill_rect(150,5,30,15,"white") va=0 recom=randint(2,5) ok=randint(5,315) xanim=0 color1="blue" color2="black" color3="green" color4="white" size=0 n=0 temps=0.015 score=0 sx=2 sy=2 xp=125 yp=200 xb=140 yb=110 fill_rect(0,0,320,240,"white") anination() menue() time.sleep(0.5) def initsuite(): print("suite ok") global color1 global color2 global color3 global color4 global score global sx global sy global xp global yp global xb global yb global va global recom global ok global xanim global size global n global temps time.sleep(0.2) while not keydown(KEY_EXE): if keydown(KEY_DOWN) and color1=="blue": color1="black" color2="blue" color3="white" color4="green" menue() if keydown(KEY_UP) and color1=="black": color1="blue" color2="black" color3="green" color4="white" menue() pass print("interaction ok") anination2() score=0 sx=2 sy=2 xp=125 yp=200 xb=140 yb=110 va=0 recom=randint(2,5) ok=randint(5,315) xanim=0 size=0 n=0 temps=0.015 if color1=="blue": fill_rect(0,0,320,240,"white") draw_string("[EXE]pour mettre pause",7,20) draw_string("Deplace toi avec[<-][->]",10,60) draw_string("Les cubes oranges donnent",10,100) draw_string("jusqu a 5 points en plus mais",10,120) draw_string("attention tu peut aussi en",10,140) draw_string("perdre",10,160) draw_string("Presse[EXE]pour jouer",10,200,"green") time.sleep(1) while not keydown(KEY_EXE): pass fill_rect(0,0,320,240,"white") fill_rect(0,0,320,240,"white") print(xb,yb,xp,yp) draw_pdl() compte() draw_bll() else: fill_rect(0,0,320,240,"white") draw_pdl() compte() draw_bll() initsuite() while 1==1: cubes() #deplacement du padle if keydown(KEY_RIGHT): if xp<255: clear_pdl() xp+=6 draw_pdl() if keydown(KEY_LEFT): if 5<xp: clear_pdl() xp-=6 draw_pdl() draw_pdl() #balle d_bll() clear_bll() xb+=sx yb+=sy draw_bll() time.sleep(temps) #vitesse if score>10: temps=score*100 temps=15/temps #afficher le score if keydown(KEY_EXE): size=score n=0 if score>0: while size<1: size/=10 n+=1 draw_string("Score:",132,100) draw_string("[OK]pour continuer",70,5,'gray','white') draw_string(str(score),153-(n*10),120,) fill_rect(0,55,300,15,'white') fill_rect(152,75,5,15,"black") fill_rect(162,75,5,15,"black") time.sleep(0.5) while not keydown(KEY_OK): pass fill_rect(0,0,320,180,"white")