[refactor] Cleanup code
- Rename joystick library to helpers - Put color565 function in helpers.py - Switch screen width and height names as game runs in landscrape - Enumerate levels for readability - Update docstrings - Rework splash screen to use binary operators - Extract create bricks and create lives functions - Reowrk main game loop logic to support next level
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
from machine import Pin
|
||||
|
||||
# Joystick class to handle joystick input
|
||||
class Joystick:
|
||||
def __init__(self):
|
||||
# Map buttons
|
||||
self.button_a = Pin(15, Pin.IN, Pin.PULL_UP)
|
||||
self.button_b = Pin(17, Pin.IN, Pin.PULL_UP)
|
||||
# Map joystick
|
||||
self.joy_up = Pin(2, Pin.IN, Pin.PULL_UP)
|
||||
self.joy_down = Pin(18, Pin.IN, Pin.PULL_UP)
|
||||
self.joy_left = Pin(16, Pin.IN, Pin.PULL_UP)
|
||||
self.joy_right = Pin(20, Pin.IN, Pin.PULL_UP)
|
||||
self.joy_click = Pin(3, Pin.IN, Pin.PULL_UP)
|
||||
|
||||
|
||||
def color565(red: int, green: int, blue: int) -> int:
|
||||
"""Convert RGB888 to RGB565."""
|
||||
return (
|
||||
(((green & 0b00011100) << 3) + ((red & 0b11111000) >> 3) << 8)
|
||||
+ (blue & 0b11111000)
|
||||
+ ((green & 0b11100000) >> 5)
|
||||
)
|
||||
Reference in New Issue
Block a user