"""为移植esp32的俄罗斯方块部分, 算法部分"""
"""由于屏幕竖置,故buf时坐标需要改动 x:原y y:原60-原x"""
import machine, random, framebuf, time, title
from machine import Pin, SoftI2C
from ssd import SSD1306_I2C
b0 = Pin(15, Pin.IN, Pin.PULL_UP)
b1 = Pin(18, Pin.IN, Pin.PULL_UP)
oled=SSD1306_I2C(128,64,SoftI2C(scl=Pin(4),sda=Pin(5)),external_vcc=1)
me = title.menu(oled)
me.initText(["俄罗斯方块","推箱子","2048","天气","返回","确认"],ways=3)
oled.show()
def scan():
if b0.value() == 0:
t0 = time.ticks_ms()
while b0.value() == 0:
continue
tt = time.ticks_ms()-t0
if tt > 1000:
me.remenu()
elif tt > 10:
me.move()
elif b1.value() == 0:
t0 = time.ticks_ms()
while b1.value() == 0:
continue
tt = time.ticks_ms()-t0
if tt > 1000:
print("长按下键")
elif tt > 10:
me.click()
while 1:
scan()