[refactor] Move screen class to separate file.
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.micropico
|
.micropico
|
||||||
|
breakout.code-workspace
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# Breakout Game for Raspberry Pi Pico
|
# Breakout Game for Raspberry Pi Pico
|
||||||
|
|
||||||
This is a simple Breakout game implemented in MicroPython for the Raspberry Pi Pico. The game uses the Pico-LCD-1.14 dDisplay for graphics and input.
|
This is a simple Breakout game implemented in MicroPython for the Raspberry Pi Pico. The game uses the Pico-LCD-1.14 dDisplay for graphics and input.
|
||||||
|
|
||||||
|
|
||||||
@@ -10,23 +9,19 @@ This is a simple Breakout game implemented in MicroPython for the Raspberry Pi P
|
|||||||
- Score tracking
|
- Score tracking
|
||||||
- Splash screen and game over screens
|
- Splash screen and game over screens
|
||||||
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Raspberry Pi Pico
|
- Raspberry Pi Pico
|
||||||
- Pico-LCD-1.14 display
|
- Pico-LCD-1.14 display
|
||||||
- MicroPython firmware installed on the Pico
|
- MicroPython firmware installed on the Pico
|
||||||
|
|
||||||
|
|
||||||
## Installation and Setup
|
## Installation and Setup
|
||||||
|
|
||||||
1. Connect the Pico-LCD-1.14 display to the Raspberry Pi Pico following the wiring diagram provided in the display's documentation.
|
1. Connect the Pico-LCD-1.14 display to the Raspberry Pi Pico following the wiring diagram provided in the display's documentation.
|
||||||
|
|
||||||
2. Download the MicroPython firmware for the Raspberry Pi Pico from the official MicroPython website and install it on the Pico. You can use the Thonny IDE to upload the firmware.
|
2. Download the MicroPython firmware for the Raspberry Pi Pico from the official MicroPython website and install it on the Pico. You can use the Thonny IDE to upload the firmware.
|
||||||
|
|
||||||
3. Clone or download this repository to your local machine.
|
3. Clone or download this repository to your local machine.
|
||||||
|
|
||||||
4. Open the Thonny IDE and connect to your Raspberry Pi Pico.
|
4. Open the Thonny IDE and connect to your Raspberry Pi Pico.
|
||||||
|
|
||||||
5. Copy the contents of the repository to the Pico's file system. You can do this by dragging and dropping the files from your local machine to the Thonny file explorer.
|
5. Copy the contents of the repository to the Pico's file system. You can do this by dragging and dropping the files from your local machine to the Thonny file explorer.
|
||||||
|
6. Once the files are copied, reset the Pico to start the game.
|
||||||
|
|
||||||
6. Once the files are copied, reset the Pico to start the game.
|
## .env file
|
||||||
|
In the .env file the user can control the behaviour of the joystick B-button.
|
||||||
|
DISABLE_B = 0 | 1 # Values: 0 = pressing B quits the program, 1 = pressing B does nothing.
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"folders": [
|
|
||||||
{
|
|
||||||
"path": "."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mpy Remote Workspace",
|
|
||||||
"uri": "pico:"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"settings": {
|
|
||||||
"python.languageServer": "Pylance"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+3
-4
@@ -68,7 +68,7 @@ DEBOUNCE = 300_000
|
|||||||
# ============================
|
# ============================
|
||||||
try:
|
try:
|
||||||
DISABLE_B = 0
|
DISABLE_B = 0
|
||||||
with open("env", "r") as file:
|
with open(".env", "r") as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
key, value = line.strip().split("=")
|
key, value = line.strip().split("=")
|
||||||
if key == "DISABLE_B":
|
if key == "DISABLE_B":
|
||||||
@@ -152,9 +152,8 @@ class Paddle:
|
|||||||
"""Draw paddle."""
|
"""Draw paddle."""
|
||||||
screen.fbuf.fill_rect(self.x, self.y, self.width, self.height, PADDLE_COLOR)
|
screen.fbuf.fill_rect(self.x, self.y, self.width, self.height, PADDLE_COLOR)
|
||||||
|
|
||||||
def update(self, screen: Screen):
|
def update(self, screen: Screen, joystick: Joystick):
|
||||||
"""Update paddle position."""
|
"""Update paddle position."""
|
||||||
global joystick
|
|
||||||
if joystick.joy_left() == 0:
|
if joystick.joy_left() == 0:
|
||||||
self.move(-1)
|
self.move(-1)
|
||||||
elif joystick.joy_right() == 0:
|
elif joystick.joy_right() == 0:
|
||||||
@@ -431,7 +430,7 @@ def main_loop(screen, joystick):
|
|||||||
sleep_us(DEBOUNCE) # Debounce delay
|
sleep_us(DEBOUNCE) # Debounce delay
|
||||||
|
|
||||||
elif game_state == PLAYING and lives > 0 and score < 28: # Game loop
|
elif game_state == PLAYING and lives > 0 and score < 28: # Game loop
|
||||||
paddle.update(screen)
|
paddle.update(screen, joystick)
|
||||||
if ball_stuck:
|
if ball_stuck:
|
||||||
# Keep the ball stuck to the paddle
|
# Keep the ball stuck to the paddle
|
||||||
ball.x = paddle.x + (paddle.width // 2)
|
ball.x = paddle.x + (paddle.width // 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user