flappy_cube.py

Created by squarepoint

Created on September 25, 2022

3.38 KB

Flappy Bird but cube - get over 1K score for a surprise ;)


from kandinsky import *
from ion import *
from random import *
from time import *
def drawscreen(theme):
  if theme==1:
    fill_rect(0,0,320,215,color(0,0,0))
    fill_rect(0,215,320,10,color(255,255,255))
  else:
    fill_rect(0,0,320,215,color(29,207,207))
    fill_rect(0,215,320,10,color(0,150,50))
def drawpipes(height,x,theme):
  if theme==1:
    fill_rect(x,0,50,230,color(50,180,255))
    fill_rect(x-10,height,70,140,color(50,180,255))
    fill_rect(x-10,height+30,70,80,color(0,0,0))
  else:
    fill_rect(x,0,50,height,color(29,207,35))
    fill_rect(x,height+110,50,200,color(29,207,35))
    fill_rect(x+10,0,5,height,color(50,255,50))
    fill_rect(x-10,height,70,30,color(29,207,35))
    fill_rect(x,height+5,5,25,color(50,255,50))
    fill_rect(x+10,height+110,5,200,color(50,255,50))
    fill_rect(x-10,height+110,70,30,color(29,207,35))
    fill_rect(x,height+110,5,25,color(50,255,50))
def drawplayer(y,theme):
  if theme==1:
    fill_rect(100,y,20,20,color(255,255,254))
  else:
    fill_rect(100,y,20,20,color(255,50,50))
    fill_rect(102,y+2,16,16,color(200,0,0))
def drawsun(time,theme):
  if theme==1:
    fill_rect(int(320+((-320/1000)+time-1000)),20,20,20,color(255,255,254))
  else:
    fill_rect(int(320+((-320/1000)*time)),20,20,20,color(200,200,0))
gamemode=0
drawscreen(0)
draw_string("Flappy Cube",100,50)
draw_string("Press OK",115,100)
sleep(0.5)
while True:
  if gamemode==0:
    if keydown(KEY_OK):
      gamemode=1
    pipex=340
    playery=100
    pipeheight=0
    flap=0
    flapcooldown=0
    score=0
    pipespeed=5
    theme=0
  elif gamemode==1:
    if pipex<=-50:
      pipex=340
      pipeheight=randint(30,100)
    if score>=1000 and score<=1010:
      theme=((score-1000)%2)
    else:
      theme=int(score/1000)  
    drawscreen(theme)
    drawsun(score,theme)
    drawpipes(pipeheight,pipex,theme)
    drawplayer(playery,theme)
    draw_string("Score: "+str(score),0,0)
    if keydown(KEY_OK) and flapcooldown<=0:
      flap=-9
      flapcooldown=10
    flap=flap+1
    playery=playery+flap
    flapcooldown=flapcooldown-1
    pipex=pipex-int(pipespeed)
    score=score+1
    pipespeed=pipespeed+0.01
    if score>=1001:
      if playery>=210 or get_pixel(100,playery)==color(50,180,255) or get_pixel(100,playery+20)==color(50,180,255) or get_pixel(120,playery)==color(50,180,255) or get_pixel(120,playery+20)==color(50,180,255):
        gamemode=2
    else:
      if playery>=210 or get_pixel(100,playery)==color(29,207,35) or get_pixel(100,playery+20)==color(29,207,35) or get_pixel(120,playery)==color(29,207,35) or get_pixel(120,playery+20)==color(29,207,35):
        gamemode=2
    if playery<=0:
      flap=0
      playery=1
    sleep(0.05)
  elif gamemode==2:
    drawscreen(theme)
    fill_rect(70,10,180,180,color(255,255,255))
    draw_string("You Died!",110,20)
    draw_string("Your Score: " + str(score),90,60)
    if score<=100:
      draw_string("Rank: Big S*IT",90,120)
    elif score<=250:
      draw_string("Rank: Kinda Noob",85,120)
    elif score<=750:
      draw_string("Rank: Preety cool man!",60,120)
    elif score<=1500:
      draw_string("Rank: gg, pr0",95,120)
    else:
      draw_string("Rank: Mr Thebest.",85,120)
    draw_string("Press OK",115,150)
    if keydown(KEY_OK):
      gamemode=1
      pipex=340
      playery=100
      pipeheight=0
      flap=0
      flapcooldown=0
      score=0
      pipespeed=5
      theme=0
      drawscreen(0)
    sleep(0.05)

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.