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 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_jet(x,y,fire,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) rect(x-15,y-5,5,15,LINE) rect(x-13,y-2,4,fire,DEAD) else: rect(x-10,y-10,20,20,SKY) rect(x-15,y-5,5,15,SKY) rect(x-13,y-2,4,fire,SKY) 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(): option,init,choice_col,X,Y,col_titre,options= 0,1,1,10,50,[0,0,0],[[["Choice mode:"],[" "," "," "],[0]],[["Invincibility:"],["NO","YES"],[0]],[["Change mode:"],["NO","YES"],[0]],[["Auto mode:"],["NO","YES"],[0]]] while (kd(4) or kd(52)):1 rect(0,0,320,202,SKY) ds("PRESS [OK] OR [EXE] TO PLAY",25,35,BIRD,SKY) while not (kd(4) or kd(52)): if col_titre[choice_col]>=255:choice_col=randint(0,2) col_titre[choice_col]+=4 if kd(0) or kd(1) or kd(2) or kd(3) or init: option=(option+kd(2)-kd(1))%len(options) while kd(1) or kd(2):1 options[option][2][0]=(options[option][2][0]+kd(3)-kd(0))%len(options[option][1]) while kd(0) or 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) ds(" "+" ".join(options[i][1])+" ",X+len(options[i][0][0])*10,Y+30*(i+1),PILLAR,SKY) draw_bird(155,90,BIRD) draw_arrow(195,95,1,BIRD) draw_jet(237,90,20,BIRD) if options[i][2][0]>0:v=10 else:v=0 ds("[",X+len(options[i][0][0]+" ".join(options[i][1][:options[i][2][0]]))*10+v,Y+30*(i+1),TEXT,SKY) ds("]",X+len(options[i][0][0]+" ".join(options[i][1][:options[i][2][0]])+options[i][1][options[i][2][0]])*10+10+v,Y+30*(i+1),TEXT,SKY) if init:init=0 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) 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) # MAIN LOOP ############################### while 1: mode,inv,changemode,auto=menu() 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) 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 fire = 0 boost = 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() if mode==0:draw_bird(X+4,Y,SKY) elif mode==1:draw_arrow(X,Y,sens,SKY) elif mode==2:draw_jet(X,Y,fire,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%=3 # 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%=3 # 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%=3 # Bird calculating system ################# if mode==0: 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 # Arrow calculatig system ################# elif mode==1: 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 # Jet calculating system ################## elif mode==2: if kd(4) or kd(52):boost,fire=boost-1,randint(10,20) else:boost,fire=boost+1,0 Y+=boost if Y<=10:Y,boost=10,boost+1 elif Y>=192:Y,boost=192,0 # 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) elif mode==2:draw_jet(X,Y,fire,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) if pillars[0][0]==-10:score+=1 if best_s<=score:best_s=score while monotonic()-frame<T:1 if T>=0.01:T=0.04-0.0005*(score//10) # sleep(1)