Voici un billard utilisant plusieurs fonctionnalités: en premier tant, on peut déplacer la balle plus appuyer sur exe pour valider la position, puis on peut tirer grâce aux flèches directionnels en restant plus ou moins longtemps appuyé pour gaugé la force. Il n’y a pas de but précis si ce n’est que de tirer la balle dans les trous (un compteur et placé en haut à gauche).
BON JEU !
from random import * from kandinsky import * from ion import * from time import * fill_rect(0,0,320,222,'red') for i in range(11): fill_rect(0,i*38-22,320,3,'black') for i in range(11): fill_rect(i*38-13,0,3,222,'black') fill_rect(30,35,260,152,'brown') fill_rect(40,45,240,132,'green') def trou(): fill_rect(38,43,15,15,'black') fill_rect(267,43,15,15,'black') fill_rect(155,43,15,15,'black') fill_rect(38,164,15,15,'black') fill_rect(267,164,15,15,'black') fill_rect(155,164,15,15,'black') a=92 b=108 score=0 def left(): while a>40 and c>0: global a,c fill_rect(int(a),int(b),8,8,'green') a-=1*c if c>=0: c-=0.08 if a<40: a=40 trou() fill_rect(int(a),int(b),8,8,'white') if (43<b+4<58 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)) or (164<b+4<179 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)): break sleep(0.05) def right(): while a<272 and c>0: global a,c fill_rect(int(a),int(b),8,8,'green') a+=1*c if c>=0: c-=0.08 if a>272: a=272 trou() fill_rect(int(a),int(b),8,8,'white') if (43<b+4<58 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)) or (164<b+4<179 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)): break sleep(0.05) def up(): while b>45 and c>0: global b,c fill_rect(int(a),int(b),8,8,'green') b-=1*c if c>=0: c-=0.08 if b<45: b=45 trou() fill_rect(int(a),int(b),8,8,'white') if (43<b+4<58 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)) or (164<b+4<179 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)): break sleep(0.05) def down(): while b<169 and c>0: global b,c fill_rect(int(a),int(b),8,8,'green') b+=1*c if c>=0: c-=0.08 if b>169: b=169 trou() fill_rect(int(a),int(b),8,8,'white') if (43<b+4<58 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)) or (164<b+4<179 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)): break sleep(0.05) while True: draw_string("score: "+str(score),0,0,'white','red') fill_rect(0,18,80,1,'red') trou() fill_rect(a,b,8,8,'white') if keydown(KEY_UP) and b>45: b-=1 fill_rect(a,b+8,8,1,'green') if keydown(KEY_DOWN) and b<169: b+=1 fill_rect(a,b-1,8,1,'green') if keydown(KEY_LEFT) and a>40: a-=1 fill_rect(a+8,b,1,8,'green') if keydown(KEY_RIGHT) and a<272: a+=1 fill_rect(a-1,b,1,8,'green') if keydown(KEY_EXE): while True: c=0 if keydown(KEY_LEFT) and a>40: while keydown(KEY_LEFT): if c<10: c+=0.03 left() while True: if a==40: right() elif a==272: left() else: break if keydown(KEY_RIGHT) and a<272: while keydown(KEY_RIGHT): if c<10: c+=0.03 right() while True: if a==40: right() elif a==272: left() else: break if keydown(KEY_UP) and b>45: while keydown(KEY_UP): if c<10: c+=0.03 up() while True: if b==45: down() elif b==169: up() else: break if keydown(KEY_DOWN) and b<169: while keydown(KEY_DOWN): if c<10: c+=0.03 down() while True: if b==45: down() elif b==169: up() else: break if (43<b+4<58 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)) or (164<b+4<179 and (38<a+4<53 or 267<a+4<282 or 155<a+4<170)): fill_rect(int(a),int(b),8,8,'green') trou() if 43<b+4<58 and 38<a+4<53: fill_rect(41,46,8,8,'white') if 43<b+4<58 and 267<a+4<282: fill_rect(270,46,8,8,'white') if 43<b+4<58 and 155<a+4<170: fill_rect(158,46,8,8,'white') if 164<b+4<179 and 38<a+4<53: fill_rect(41,167,8,8,'white') if 164<b+4<179 and 267<a+4<282: fill_rect(270,167,8,8,'white') if 164<b+4<179 and 155<a+4<170: fill_rect(158,167,8,8,'white') sleep(0.05) trou() sleep(1) a=92 b=108 score+=1 break