flappy_box.py

Created by wperez274

Created on April 20, 2023

1.6 KB


from math import *
from random import *
from random import randint as R
from kandinsky import *
from kandinsky import fill_rect as F
from ion import *
from time import *

SW=322
SH=222
M=255


FPS=0.1



RED=(M,0,0)
GREEN=(0,M,0)
BLUE=(0,0,M)
CYAN=(0,M,M)
BLACK=(0,)*3
WHITE=(M,)*3
GRAY=(150,)*3


bg=(200,255,255)
gx=0
gy=200
gw=SW
gh=50

gc=(240,200,214)

gtop_c=(0,120,0)




r1x=R(350,500)
r1y=0
r1w=35
r1h=R(40,100)
r1c=(0,155,0)


r2x=r1x+R(45,70)
r2h=R(40,100)
r2y=gy-r2h
r2w=35
r2c=r1c



rs=1




def draw_ground():
  F(gx,gy,gw,gh,gc)
  F(gx,gy,gw,7,gtop_c)


  
  
def pause():
  draw_string("(PAUSED)",110,100,(randint(100,255),randint(100,255),randint(100,255)),BLACK)
  while keydown(KEY_OK):
    pass
  while not keydown(KEY_OK):
    pass
  while keydown(KEY_OK):
    draw_string("        ",110,100,bg,bg)
   

def key_listen():
  if keydown(KEY_OK):
    pause()
    
def paint_back():
  fill_rect(0,0,SW,SH,bg)

def show_pipe():

  F(r1x,r1y,r1w,r1h,r1c)
  F(r1x,r1y,2,r1h,BLACK)
  F(r1x+r1w-2,r1y,2,r1h,BLACK)
  F(r1x,r1y+r1h-2,r1w,2,BLACK)


  F(r2x,r2y,r2w,r2h,r2c)
  F(r2x,r2y,2,r2h,BLACK)
  F(r2x+r2w-2,r2y,2,r2h,BLACK)
  F(r2x,r2y+r2h-2,r2w,2,BLACK)






def move_pipe():

  global r1x,r1y,r1w,r1h,r1c,rs,r2x,r2y,r2w,r2h,r2c
  
  
  
  r1x-=1
  F(r1x+r1w+1,r1y,1,r1h,bg)

  r2x-=1
  F(r2x+r2w+1,r2y,1,r2h,bg)
  
  
  if r1x+r1h<-R(20,50):
    r1x=R(350,500)
    r1h=R(40,120)
    
  if r2x+r2h<-R(20,50):

    r2x=r1x+R(-80,80)

    r2h=R(40,100)
    r2y=gy-r2h
    
  
    
          

  
paint_back()

draw_ground()





while 1:
  sleep(0.01)


  show_pipe()
  move_pipe()

  
  key_listen()

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.