Le jeu Flappy Bird. Ce programme n’est pas terminé, merci de me prévenir en cas de bugs sur discord: Elnix90#0116
# Modules from kandinsky import fill_rect as rect,draw_string as ds from ion import keydown as kd from time import sleep,monotonic from random import randint ########################################### # Colors: SKY = (0,0,0) # Black PILLAR = (0,255,0) # Green DEAD = (255,0,0) # Red BIRD = (0,100,255) # Cyan LINE = (0,255,255) # Grey SHIELD = (255,255,0) # yellow TEXT = (255,255,255) # White ########################################### def draw_bird(x,y,col): if col!=SKY: rect(x-10,y-10,20,20,LINE) rect(x-8,y-8,16,16,col) rect(x,y-5,5,5,LINE) else:rect(x-10,y-10,20,20,SKY) ########################################### def draw_arrow(x,y,type,col): if type==0: rect(x-10,y-6,12,12,col) rect(x-2,y+2,8,8,col) rect(x+6,y+10,4,4,col) rect(x-10,y-6,8,4,SKY) rect(x-10,y-2,4,4,SKY) elif type==1: rect(x-10,y+6,12,-12,col) rect(x-2,y-2,8,-8,col) rect(x+6,y-10,4,-4,col) rect(x-10,y+2,8,4,SKY) rect(x-10,y-2,4,4 ,SKY) elif type==2: rect(x-10,y-8,6,16,col) rect(x-5,y-4,6,8,col) rect(x+1,y-2,8,4,col) ########################################### def draw_pillar(x,y,espace,type): if type: rect(x,0,50,y-espace//2,LINE) rect(x+2,0,46,y-espace//2-2,PILLAR) rect(x,y+espace//2,50,202-(y+espace//2),LINE) rect(x+2,y+espace//2+2,46,198-(y+espace//2-2),PILLAR) else: rect(x,0,50,y-espace//2,SKY) rect(x,y+espace//2,50,202-(y+espace//2),SKY) ########################################### def draw_trail(list_Y,col): if len(list_Y)>1: for i in range(len(list_Y)-1):rect(X-10-4*i,list_Y[len(list_Y)-i-2]-2,4,4,col) ########################################### def menu(): rect(0,0,320,202,SKY) # Variables col_titre = [0,0,0] choice_col = 1 X,Y = 10,50 w = 1 option = 0 options = [ [["Choice mode:"],["BIRD","ARROW"],[0]], [["Invincibility:"],["NO","YES"],[0]], [["Change mode:"],["NO","YES"],[0]], [["Auto mode:"],["NO","YES"],[0]] ] while (kd(4) or kd(52)):1 # Show options for i in range(len(options)): if options[i][2][0]>0:v=10+10*len(" ".join(options[i][1][:len(options[option][1])-options[option][2][0]])) else:v=0 ds("[",X+len(options[i][0][0])*10+v,Y+30*(i+1),TEXT,SKY) ds("]",X+10+len(options[i][0][0])*10+v+10*len(options[i][1][options[i][2][0]]),Y+30*(i+1),TEXT,SKY) ds("PRESS [OK] OR [EXE] TO PLAY",25,35,BIRD,SKY) while not (kd(4) or kd(52)): # Rainbow title system if col_titre[choice_col]>=255:choice_col=randint(0,2) col_titre[choice_col]+=5 rect(95,0,130,2,col_titre[:]) rect(95,0,2,27,col_titre[:]) rect(225,27,-130,-2,col_titre[:]) rect(225,27,-2,-27,col_titre[:]) ds("FLAPPY JULES",100,5,col_titre[:],SKY) # Choice option system if kd(0) or kd(1) or kd(2) or kd(3) or w: if kd(1): option-=1 option%=len(options) while kd(1):1 elif kd(2): option+=1 option%=len(options) while kd(2):1 if kd(0) or kd(3) or w: ds("[",X+len(options[option][0][0])*10+v,Y+30*(option+1),SKY,SKY) ds("]",X+10+len(options[option][0][0])*10+v+10*len(options[option][1][options[option][2][0]]),Y+30*(option+1),SKY,SKY) if kd(0): options[option][2][0]-=1 options[option][2][0]%=len(options[option][1]) while kd(0):1 if kd(3): options[option][2][0]+=1 options[option][2][0]%=len(options[option][1]) while kd(3):1 for i in range(len(options)): if i==option:ds(options[i][0][0],X,Y+30*(i+1),TEXT,SKY) else:ds(options[i][0][0],X,Y+30*(i+1),PILLAR,SKY) for j in range(len(options[i][1])): if j>0:z=len(options[i][1][j-1])*10+10 else:z=0 ds(options[i][1][j],X+len(options[i][0][0])*10+10+z,Y+30*(i+1),PILLAR,SKY) if options[option][2][0]>0:v=10+10*len(" ".join(options[option][1][:len(options[option][1])-options[option][2][0]])) else:v=0 ds("[",X+len(options[option][0][0])*10+v,Y+30*(option+1),TEXT,SKY) ds("]",X+10+len(options[option][0][0])*10+v+10*len(options[option][1][options[option][2][0]]),Y+30*(option+1),TEXT,SKY) if w:w=0 return options[0][2][0],options[1][2][0],options[2][2][0],options[3][2][0] ########################################### score,best_s=0,0 rect(0,0,320,222,SKY) # NEW GAME LOOP ########################### while 1: mode,inv,changemode,auto=menu() # Init screen rect(0,0,320,222,SKY) rect(0,202,320,2,LINE) ds("SCORE: "+str(score),0,205,TEXT,SKY) ds("BEST SCORE: "+str(best_s),150,205,TEXT,SKY) ds(str(score),70,205,SKY,SKY) # Variables score = 0 jump = 0 sens = 0 press = 0 paused = 0 press_sh = 0 press_ch = 0 press_au = 0 shield_on = 0 auto_on = 0 T = 0.04 Ec = 1 speed = 4 pixels = 5 ecart_max = 30 X = 50 Y = 100 espace = 120 pillars = [[320,101,120]] list_Y = [] # GAME LOOP ############################### while 1: frame=monotonic() # Erase sprites if mode==0:draw_bird(X+4,Y,SKY) elif mode==1:draw_arrow(X,Y,sens,SKY) draw_trail(list_Y,SKY) for i in range(len(pillars)):draw_pillar(pillars[i][0]+50-pixels,pillars[i][1],pillars[i][2],0) # Shield system if not kd(24):press_sh=1 if inv and kd(24) and press_sh:press_sh,shield_on=0,shield_on+1 shield_on%=2 # Change mode system if not kd(25):press_ch=1 if changemode and kd(25) and press_ch:press_ch,mode=0,mode+1 mode%=2 # Auto system if not kd(26):press_au=1 if auto and kd(26) and press_au:press_au,auto_on=0,auto_on+1 auto_on%=2 if mode==0: # Bird calculating system if not (kd(4) or kd(52)):press=0 if auto_on: if pillars[0][0]>X-45:i=0 else:i=1 if Y>pillars[i][1]+15:jump,press,Ec=16,1,1 else: if (kd(4) or kd(52)) and press==0:jump,press,Ec=16,1,1 if jump>0:Y-=jump jump,Y=jump-jump//9,Y+int(speed+Ec) Ec+=1 if Y<=10:Y,jump=10,0 if Y>=192:Y=192 elif mode==1: # Arrow calculatig system if auto_on: if pillars[0][0]>X-45:i=0 else:i=1 if Y>pillars[i][1]:Y,sens=Y-speed,1 else:Y,sens=Y+speed,0 else: if (kd(4) or kd(52)):Y,sens=Y-speed,1 else:Y,sens=Y+speed,0 if Y<=10:Y,sens=10,2 elif Y>=192:Y,sens=192,2 # Trail calculating system if len(list_Y)>(X-10)//4+4:list_Y.pop(0) list_Y.append(Y) # Pillars calculating system if pillars[-1][0]<200: new_pillar=[320] y=randint(pillars[-1][1]-ecart_max,pillars[-1][1]+ecart_max) if y+espace//2>182:y=182-espace//2 elif y-espace//2<20:y=20+espace//2 new_pillar.append(y) new_pillar.append(espace) pillars.append(new_pillar) if pillars[0][0]<-50:pillars.pop(0) for i in range(len(pillars)):pillars[i][0]-=pixels if ecart_max<80:ecart_max=10+score//10 if espace>0:espace=120-score//10 # Drawing objects and score if shield_on:COLOR=SHIELD elif (not shield_on) and (pillars[0][1]-espace//2>Y-5 or pillars[0][1]+espace//2<Y+5) and (pillars[0][0]>=X-45 and pillars[0][0]<=X):COLOR=DEAD else:COLOR=BIRD if mode==0:draw_bird(X+4,Y,COLOR) elif mode==1:draw_arrow(X,Y,sens,COLOR) draw_trail(list_Y,COLOR) if COLOR==DEAD: sleep(1) break for i in range(len(pillars)):draw_pillar(pillars[i][0],pillars[i][1],pillars[i][2],1) ds(str(score),70,205,TEXT,SKY) ds(str(best_s),270,205,TEXT,SKY) # Game pause system if kd(17): ds("[ GAME PAUSED ]",80,100,TEXT,SKY) ds("GO TO MENU: [OK] OR [EXE]",35,130,BIRD,SKY) while kd(17):1 while not kd(17): if kd(4):break if kd(4):break while kd(17):1 rect(35,100,250,50,SKY) # Scoreboard calculating system if pillars[0][0]==-10:score+=1 if best_s<=score:best_s=score # Frame and movement system while monotonic()-frame<T:1 if T>=0.01:T=0.04-0.0005*(score//10) # sleep(1)