piano_bug_showcase.py

Created by aquaebm

Created on August 24, 2022

1.45 KB

Script made to easily reproduce a bug (python app crash on occasional presses to the shift key) REQUIRES util.py to be downloaded onto your calculator.


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,m=fill_rect,zip,enumerate,(0,1,2),max
  while hp>0:
    if timeout():
      tiles_y[0].append(-30)
      # Only spawn tiles on the first colum to reproduce the bug quicker
      timeout.reset(.3)
    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":6}
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.