piano.py

Created by aquaebm

Created on October 09, 2022

1.37 KB

Definitely NOT a Piano Tiles clone…

REQUIRES util.py to be downloaded onto your calculator.

Use keys ALPHA through TOOLBOX to click on the tiles the moment they touch their corresponding black pads, which will increase your score and health bar which, when empty, results in a game over. Pressing too early or too late will deplete your health bar.

Survive as long as you can and aim for the highest score! :D


from util import *
from random import choice,uniform
def draw_bar(v,x,y,w,h,col,bg=BLACK):
  l=int(h*(1-v))
  fill_rect(x,y,w,l,bg)
  fill_rect(x,y+l,w,h-l,col)
@game_func
def run(col,bg,n):
  fill_screen(bg)
  streak,hp,score=0,5,0
  def draw_stats():
    draw_string(str(score),275,5,col,bg)
    draw_bar(streak/14,10,40,15,172,(255,18*(14-streak),0))
    draw_bar(hp/10,295,40,15,172,(25*(10-hp),25*hp,0))
  draw_stats()
  hn=n>>1
  data=lambda i:(160+int(35*(i-n/2)),[],[0]*3,15-hn+i)
  column_x,tiles_y,btns,keys=zip(*map(data,range(n)))
  keys=KeyPressHandler(keys)
  timeout=Timer()
  spd=n&1|hn
  f,z,e,l=fill_rect,zip,enumerate,(0,1,2)
  while hp>0:
    if timeout():
      choice(tiles_y).append(-30)
      timeout.reset(uniform(.2,.6))
    for x,column,btn,pressed in z(column_x,tiles_y,btns,keys):
      first=(column or[0])[0]
      status=(first>164)+(first>232)
      if pressed or status==2:
        if first>130:
          column.pop(0)
          f(x+14,first,7,25,bg)
        o=status&1
        extra,streak=divmod((streak+1)*o,15)
        hp=min(10,hp+extra-(o^1))
        score+=o+(hp==10)
        draw_stats()
        btn[status]=255
      f(x+5,207,25,10,btn)
      for i in l:
        if btn[i]>=0:btn[i]-=n
      for i,y in e(column):
        column[i]+=spd
        f(x+14,y,7,spd,bg)
        f(x+14,y+25,7,spd,col)
ARGS={"col":CYAN,"bg":DARK_PURPLE,"n":4}
run(**ARGS)

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.