floppy_birb.py

Created by mathieu-croslacoste

Created on January 03, 2025

4.36 KB

Amélioraton (j’espère) du script “floppy_birb” par zecake (https://my.numworks.com/python/zecake/floppy_birb)


from math import*
from kandinsky import fill_rect as F,get_pixel as G,draw_string as ds,color as C
from ion import keydown as kd
from random import*
from time import*
colb=(150,200,250)
l=[[0]*19,[0]*7+[1]*6+[0]*6,
[0]*5+[1,1,2,2,2,1,6,6,1]+[0]*5,
[0]*4+[1,2,2,2,2,1,6,6,6,6,1]+[0]*4,
[0,0,1,1,1,1,2,2,2,1,6,6,6,1,6,1,0,0,0],
[0,1,5,5,5,5,1,2,2,1,6,6,6,1,6,1,0,0,0],
[0,1]+[5]*5+[1,2,2,1,6,6,6,6,1,0,0,0],
[0,1,2,5,5,5,2,1,2,2,2]+[0]*6+[0,0],
[0,0,1,2,2,2,1,2,2,2,1]+[4]*6+[1,0],
[0,0,0,1,1,1,3,3,3,1,4]+[0]*6+[0,0],
[0,0,0,1]+[3]*6+[1]+[4]*5+[1,0,0],
[0,0,0,0,1,1]+[3]*5+[1]*5+[0,0,0],
[0]*6+[1]*5+[0]*8,[0]*19]
cols=[(150,200,250),(10,)*3,(249,241,36),(249,194,44),(253,104,75),(250,252,233),(253,255,250)]
altCols=[(150,200,250),(10,)*3]+[(255,0,0)]*5
bl=(0,)*3;wh=(255,)*3
def draw(y,last_y,px,py,score,deltad,rt,lrt,move=1):
 if last_y<y:F(11,last_y-18,38,y-last_y,colb)
 elif last_y>y:F(11,y+15,38,last_y-y+5,colb)
 rt=radians(rt);lrt=radians(lrt)
 for idx in range(5):cx=ceil(px[idx]);cy=py[idx];ccf=ceil(68*config[2]/100);F(cx+32,cy+15,deltad,240-cy,colb);F(cx+32,cy-15-ccf,deltad,-240,colb);F(cx+1,cy+15,29,240-cy,'green');F(cx+1,cy-15-ccf,29,-240,'green');F(cx-1,cy+15,2,240-cy,bl);F(cx-1,cy-ccf-15,2,-240,bl);F(cx+30,cy+15,2,240-cy,bl);F(cx+30,cy-15-ccf,2,-240,bl);F(cx+36,cy,deltad,15,colb);F(cx+36,cy-ccf,deltad,-15,colb);F(cx-5,cy+13,40,2,bl);F(cx-5,cy,40,2,bl);F(cx-6,cy,2,15,bl);F(cx+35,cy,2,15,bl);F(cx-5,cy-ccf-2,40,2,bl);F(cx-5,cy-ccf-15,40,2,bl);F(cx-6,cy-ccf-15,2,15,bl);F(cx+35,cy-ccf-15,2,15,bl);F(cx-4,cy-ccf-2,39,-11,'green');F(cx-4,cy+2,39,11,'green')
 srt,crt=sin(rt)*2,cos(rt)*2
 for ys in range(14):
  for xs in range(19):
   p_x=30+floor((xs-9.5)*srt)+floor((ys-7)*crt);p_y=y+floor((ys-7)*srt)-floor((xs-9.5)*crt);cur_pix=G(p_x,p_y)
   if cur_pix==(82,195,0)or cur_pix==(0,0,0):break
   F(p_x,p_y,2,2,move and cols[l[ys][xs]]or altCols[l[ys][xs]])
 if not(G(155,20)==C(82,195,0)or G(165+len(str(score))*10,20)==C(82,195,0)):ds(str(score),155,20,wh,colb)
def menu(sel,config):
 ds("Floppy Birb",100,30,wh,colb)
 if sel==2:ds(">Start [OK]  ",70,60,wh,colb);ds("Config   ",70,80,wh,colb)
 elif sel==1:ds("Start      ",70,60,wh,colb);ds(">Config [>]  ",70,80,wh,colb)
 elif sel>=3:ds("Gravity : "+str(config[0])+"%     ",20,80,wh,colb);ds("Jump force : "+str(config[1])+"%     ",20,100,wh,colb);ds("Spaced pipes : "+str(config[2])+"%     ",20,120,wh,colb);ds("Speed : "+str(config[3])+"%     ",20,140,wh,colb);ds("Config",120,50,wh,colb);ds("[<] Back",10,10,wh,colb);ds(">",10,80+20*(sel-3),wh,colb)
config=[100,]*4
def main():
 F(0,0,320,222,colb);y=120.0;vy=0.0;r=90;px,py=[100.0,200.0,300.0,400.0,500.0],[randrange(100,200),randrange(100,200),randrange(100,200),randrange(100,200),randrange(100,200)];last_y=y;last_r=90;score=0;sel=2;end=0;move=1;cooldown=0;hasScored=0
 while kd(4)|kd(52):0
 while(kd(4)|kd(52))^1:
  if kd(2)and sel==2:sel=1
  while sel!=2:
   K=-1
   if kd(1)and sel==1:sel=2;F(0,0,320,222,colb);K=1
   elif kd(3)and sel==1:sel=3;F(0,0,320,222,colb);K=3
   elif kd(0)and sel>=3:F(0,0,320,222,colb);sel=1;K=0
   elif sel-2<len(config)and kd(2)and sel>=3:sel+=1;F(10,40,8,200,colb);K=2
   elif kd(1)and sel>=3:sel-=1;F(10,40,8,200,colb);K=1
   elif kd(45)and sel>=3:config[sel-3]+=5;sleep(.15)
   elif kd(46)and sel>=3:config[sel-3]-=5;sleep(.15)
   menu(sel,config)
   while kd(K):0
  menu(sel,config)
 while kd(4)|kd(52):F(0,0,320,222,colb)
 mt=monotonic();draw(ceil(y),ceil(last_y),px,py,score,2,r,last_r);delta=monotonic()-mt;g=config[0]
 while end^1:
  mt=monotonic()
  if kd(4)|kd(52):cooldown+=1
  if cooldown==1 and move:vy=(-9*config[1]/100);r=30
  if(kd(4)|kd(52))^1:cooldown=0
  for i in range(5):
   if move:px[i]=px[i]-(60*delta*(config[3]/100))
   if px[i]<-40:px[i]=480;py[i]=randrange(100,200)
   if px[i]<=45 and px[i]>=-17:
    if not hasScored:score+=1;hasScored=0
    if y+13>py[i]or y-13<py[i]-ceil(68*config[2]/100):move=0
   if px[i]<-17:hasScored=0
  draw(ceil(y),ceil(last_y),px,py,score,ceil(1+delta*60*(config[3]/100)),r,last_r,move);last_r,last_y=r,y;y+=vy*delta*30
  if vy<10:vy+=(config[0]/100)*delta*45
  if r<179:r+=delta*150
  if y>=215:end=1
  if y<=-10:
   if config[0]==0:config[0]=100
   else:config[0]=abs(config[0])
  delta=monotonic()-mt
 ds("Score : %s"%score,108,80,bl,wh);ds("Press OK to go back",60,100,bl,wh);ds("to main menu",90,120,bl,wh)
 while kd(4)|kd(52):0
 while(kd(4)|kd(52))^1:0
 return g
try:
 while 1:config[0]=main()
except KeyboardInterrupt:0

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.