Skip to content

Commit b8c1989

Browse files
authored
Merge pull request #2236 from FoamyGuy/octopus_game_and_watch
Octopus game and watch
2 parents e37750b + 76475fe commit b8c1989

29 files changed

+1510
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SPDX-FileCopyrightText: 2022 Tim C, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import board
5+
import keypad
6+
from displayio import Group
7+
from octopus_game_helpers import OctopusGame
8+
9+
# built-in display
10+
display = board.DISPLAY
11+
12+
# display.brightness = 0.3
13+
14+
# main group that we'll show in the display
15+
main_group = Group()
16+
17+
# create instance of OctopusGame
18+
octopus_game = OctopusGame()
19+
20+
# uncomment this instead, to use NVM highscore
21+
#octopus_game = OctopusGame(high_score_type=OctopusGame.HIGH_SCORE_NVM)
22+
23+
# uncomment this instead, to use SDCard highscore
24+
#octopus_game = OctopusGame(high_score_type=OctopusGame.HIGH_SCORE_NVM)
25+
26+
27+
# add octopus game to main group
28+
main_group.append(octopus_game)
29+
30+
# initialize the shiftregister keys to read hardware buttons
31+
buttons = keypad.ShiftRegisterKeys(
32+
clock=board.BUTTON_CLOCK,
33+
data=board.BUTTON_OUT,
34+
latch=board.BUTTON_LATCH,
35+
key_count=4,
36+
value_when_pressed=True,
37+
)
38+
39+
# show the main group on the display
40+
display.show(main_group)
41+
42+
# main loop
43+
while True:
44+
45+
# get event from hardware buttons
46+
event = buttons.events.get()
47+
48+
# if anything is pressed
49+
if event:
50+
51+
# if the event is for the start button
52+
if event.key_number == 2:
53+
# if it's a pressed event
54+
if event.pressed:
55+
# trigger the right button press action function
56+
octopus_game.right_button_press()
57+
58+
# if the event is for the select button
59+
elif event.key_number == 3:
60+
# if it's a pressed event
61+
if event.pressed:
62+
# trigger the left button press action function
63+
octopus_game.left_button_press()
64+
65+
# if the event is for the b button
66+
elif event.key_number == 0:
67+
# if it's a pressed event
68+
if event.pressed:
69+
# trigger the b button press action function
70+
octopus_game.b_button_press()
71+
72+
# if the event is for the a button
73+
elif event.key_number == 1:
74+
# if it's a pressed event
75+
if event.pressed:
76+
# trigger the a button press action function
77+
octopus_game.a_button_press()
78+
79+
# call the game tick function
80+
octopus_game.tick()

0 commit comments

Comments
 (0)