Une versions minimaliste(sans menue) du jeux pong crée pour les calculatrices sur une calculatrice.
from math import * from kandinsky import * from ion import * from time import * from random import * gameOver=False delay=0.0175 time=monotonic() posPlayer=50 posBot=50 alphaBall=0#angle en rad vectBall=[0,0]#[x,y] posBall=[156,107] speed=1 last=0.785 point=[0,0] def play(x): fill_rect(5,x-speed,5,speed,(0,10,50)) fill_rect(5,x,5,30,(255,255,0)) fill_rect(5,x+30,5,speed,(0,10,50)) def ball(x,y): x=int(x) y=int(y) fill_rect(x-2,y-2,12,2,(0,10,50)) fill_rect(x-2,y,2,10,(0,10,50)) fill_rect(x+8,y,2,10,(0,10,50)) fill_rect(x,y+8,10,2,(0,10,50)) fill_rect(x,y,8,8,(255,255,0)) def bot(x): fill_rect(310,x-speed,5,speed,(0,10,50)) fill_rect(310,x,5,30,(255,255,0)) fill_rect(310,x+30,5,speed,(0,10,50)) while True: fill_rect(0,0,320,222,(0,10,50)) fill_rect(0,0,320,20,(255,255,255)) sleep(0.2) alphaBall=randint(0,1571) alphaBall/=1000 vectBall[0]=sin(alphaBall+last)*2 vectBall[1]=cos(alphaBall+last)*2 posBall=[156,107] gameOver=False draw_string(str(point[0]),0,0) draw_string(str(point[1]),280,0) draw_string(":",155,0) while gameOver==False: if delay+time<=monotonic(): if keydown(KEY_DOWN) and posPlayer<190: posPlayer+=1 elif keydown(KEY_UP) and posPlayer>22: posPlayer-=1 play(posPlayer) if posBall[0]+vectBall[0]>302: if posBall[1]-posBot<-8 or posBall[1]-posBot>30: point[0]+=1 gameOver=True last=-2.356 else: vectBall[0]=-vectBall[0] #ajouter un angle proportionnele a la zone de touche vectBall[1]=(posBall[1]-posBot-11)/19*1.5 if posBall[0]+vectBall[0]<12: if posBall[1]-posPlayer<-8 or posBall[1]-posPlayer>30: point[1]+=1 gameOver=True last=0.785 else: vectBall[0]=-vectBall[0] #idem vectBall[1]=(posBall[1]-posPlayer-11)/19*1.5 if posBall[1]+vectBall[1]>214 or posBall[1]+vectBall[1]<22: vectBall[1]=-vectBall[1] posBall[0]+=vectBall[0] posBall[1]+=vectBall[1] ball(posBall[0],posBall[1]) if posBall[1]-posBot>9 and posBot<190: posBot+=1 elif posBall[1]-posBot<13 and posBot>22: posBot-=1 bot(posBot) time=monotonic()