Are you new to using CircuitPython? No worries, there is a full getting-started guide here.
Plug the PyGamer into your computer with a known good USB cable (not a charge-only cable). The PyGamer will appear to your computer as a flash drive named CIRCUITPY. If the drive does not appear, you can install CircuitPython on your PyGamer and then return here.
Download the project files with the Download Project Bundle button below. Unzip the file and copy/paste the code.py and other project files to your CIRCUITPY drive using File Explorer or Finder (depending on your operating system).
Drive Structure
After copying the files, your drive should look like the listing below. It can contain other files as well, but must contain these at a minimum:
High Score Configuration
The game supports different configurations for high score. It can be disabled entirely, or it can be enabled and store data with either NVM, or SDCard storage. To configure it uncomment the appropriate version of the constructor call with configuration argument.
# create instance of OctopusGame octopus_game = OctopusGame() # uncomment this instead, to use NVM highscore #octopus_game = OctopusGame(high_score_type=OctopusGame.HIGH_SCORE_NVM) # uncomment this instead, to use SDCard highscore #octopus_game = OctopusGame(high_score_type=OctopusGame.HIGH_SCORE_SDCARD)
# SPDX-FileCopyrightText: 2022 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import board
import keypad
from displayio import Group
from octopus_game_helpers import OctopusGame
# built-in display
display = board.DISPLAY
# display.brightness = 0.3
# main group that we'll show in the display
main_group = Group()
# create instance of OctopusGame, high score disabled
octopus_game = OctopusGame()
# uncomment this instead, to use NVM highscore
#octopus_game = OctopusGame(high_score_type=OctopusGame.HIGH_SCORE_NVM)
# uncomment this instead, to use SDCard highscore
#octopus_game = OctopusGame(high_score_type=OctopusGame.HIGH_SCORE_SDCARD)
# add octopus game to main group
main_group.append(octopus_game)
# initialize the shiftregister keys to read hardware buttons
buttons = keypad.ShiftRegisterKeys(
clock=board.BUTTON_CLOCK,
data=board.BUTTON_OUT,
latch=board.BUTTON_LATCH,
key_count=4,
value_when_pressed=True,
)
# show the main group on the display
display.root_group = main_group
# main loop
while True:
# get event from hardware buttons
event = buttons.events.get()
# if anything is pressed
if event:
# if the event is for the start button
if event.key_number == 2:
# if it's a pressed event
if event.pressed:
# trigger the right button press action function
octopus_game.right_button_press()
# if the event is for the select button
elif event.key_number == 3:
# if it's a pressed event
if event.pressed:
# trigger the left button press action function
octopus_game.left_button_press()
# if the event is for the b button
elif event.key_number == 0:
# if it's a pressed event
if event.pressed:
# trigger the b button press action function
octopus_game.b_button_press()
# if the event is for the a button
elif event.key_number == 1:
# if it's a pressed event
if event.pressed:
# trigger the a button press action function
octopus_game.a_button_press()
# call the game tick function
octopus_game.tick()
Page last edited January 20, 2025
Text editor powered by tinymce.