Загрузка данных
import machine
import lcd_api
import pico_i2c_lcd
from time import sleep
import random
sda=machine.Pin(0)
scl=machine.Pin(1)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=750000)
print(i2c.scan())
lcd = pico_i2c_lcd.I2cLcd(i2c, 0x027, 4, 20)
joy_x = machine.ADC(machine.Pin(28))
joy_y = machine.ADC(machine.Pin(27))
button = machine.Pin(26, machine.Pin.IN, machine.Pin.PULL_UP)
gameid = 0
debug = True
#buttonA = machine.Pin(2, machine.Pin.IN)
#buttonB =
#buttonB =
#buttonB =
#Название консоли
if debug == True:
lcd.move_to(2, 1)
lcd.putstr("Debug mode!")
selectedgame = "example game"
mode = "selectgame"
sleep(0.5)
else:
sleep(1)
lcd.move_to(2, 1)
lcd.putstr("Untitled console")
sleep(1)
lcd.move_to(6, 2)
lcd.putstr("By Misha")
sleep(2)
lcd.move_to(2, 1)
lcd.putstr(" ")
sleep(2)
lcd.move_to(6, 2)
lcd.putstr(" ")
gameid = 0
mode = "selectgame"
#startMain()
def startMain():
mode = "selectgame"
gameid = 0
while True:
if mode == "selectgame":
lcd.clear()
if gameid == 0:
lcd.move_to(3, 0)
lcd.putstr(">Walk Around<")
sleep(1)
lcd.clear()
lcd.move_to(4, 0)
lcd.putstr("Walk Around")
sleep(1)
#if joy_x.read_u16() < 25000:
#gameid = gameid - 1
#print(gameid)
#sleep(0.2)
if joy_x.read_u16() > 40000:
gameid = gameid + 1
print(gameid)
sleep(0.2)
if button.value() == 0:
mode = "Walk Around"
if gameid == 1:
lcd.move_to(6, 0)
lcd.putstr(">Snake<")
lcd.move_to(6, 1)
lcd.putstr(">Snake<")
sleep(1)
lcd.clear()
lcd.move_to(7, 0)
lcd.putstr("Snake")
sleep(1)
if joy_x.read_u16() < 25000:
gameid = gameid - 1
print(gameid)
sleep(0.2)
if joy_x.read_u16() > 40000:
gameid = gameid + 1
print(gameid)
sleep(0.2)
if button.value() == 0:
mode = "Space"
print(mode)
if mode == "Walk Around":
playerX = 0
playerY = 0
while True:
#lcd.show_cursor()
lcd.move_to(playerX, playerY)
lcd.putstr("0")
sleep(0.2)
lcd.clear()
if joy_x.read_u16() > 40000:
playerX = playerX - 1
print(playerX)
sleep(0.1)
if joy_x.read_u16() < 25000:
playerX = playerX + 1
print(playerX)
sleep(0.1)
if joy_y.read_u16() < 25000:
playerY = playerY - 1
print(playerY)
sleep(0.1)
if joy_y.read_u16() > 40000:
playerY = playerY + 1
print(playerY)
sleep(0.1)
print(mode)
if mode == "Space":
playerX = 8
playerY = 0
score = 0
ast1Pos = 19
ast2Pos = 19
ast3Pos = 19
ast4Pos = 19
readytoselect = 1
while True:
lcd.move_to(0, 0)
lcd.putstr("Score:" + str(score))
#lcd.show_cursor()
lcd.move_to(playerX, playerY)
lcd.putstr(">")
sleep(0.2)
lcd.clear()
lcd.move_to(ast1Pos, 1)
lcd.putstr("o")
lcd.move_to(ast2Pos, 2)
lcd.putstr("o")
lcd.move_to(ast3Pos, 3)
lcd.putstr("o")
if readytoselect == 1:
readytoselect = 0
astN = (random.randint(1, 3))
print(astN)
if astN == 1:
ast1Pos = ast1Pos - 1
print(ast1Pos)
if ast1Pos == 0:
readytoselect = 1
ast1Pos = 19
if astN == 2:
ast2Pos = ast2Pos - 1
print(ast2Pos)
if ast2Pos == 0:
readytoselect = 1
ast2Pos = 19
if astN == 3:
ast3Pos = ast3Pos - 1
print(ast3Pos)
if ast3Pos == 0:
readytoselect = 1
ast3Pos = 19
if ast1Pos == 9:
if playerY == 1:
startMain()
print("GAME OVER")
if ast2Pos == 9:
if playerY == 2:
startMain()
mode = "selectgame"
print("GAME OVER")
if ast3Pos == 9:
if playerY == 3:
startMain()
mode = "selectgame"
print("GAME OVER")
if joy_y.read_u16() < 25000:
if playerY > 0:
playerY = playerY - 1
print(playerY)
sleep(0.05)
if joy_y.read_u16() > 40000:
if playerY < 3:
playerY = playerY + 1
print(playerY)
sleep(0.05)
startMain()