Skip to content

Commit

Permalink
Add comments to pygame example
Browse files Browse the repository at this point in the history
  • Loading branch information
Snarr committed Mar 18, 2024
1 parent 92cb3b0 commit 0c258b8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions examples/GPIOZero_PyGame/example.py
@@ -1,31 +1,39 @@
from gpiozero import Button
import pygame

from Player import Player

# Initialize pygame
pygame.init()

# Create screen of 500x500 pixels
screen = pygame.display.set_mode([500, 500])

# Initialize the physical GPIO inputs
left_button = Button(5)
down_button = Button(6)
up_button = Button(13)
right_button = Button(19)

# Initialize Player sprite class
player = Player()


# Run continous game loop
while True:
# Check state of physical inputs
if left_button.is_pressed:
player.move_left(2)
elif down_button.is_pressed:
if down_button.is_pressed:
player.move_down(2)
elif right_button.is_pressed:
if right_button.is_pressed:
player.move_right(2)
elif up_button.is_pressed:
if up_button.is_pressed:
player.move_up(2)

# Fill screen with black background
screen.fill((0, 0, 0))

# Place the player on the screen
screen.blit(player.surf, player.rect)

# Flip the display
Expand Down

0 comments on commit 0c258b8

Please sign in to comment.