1+ import gc
2+ import time
3+ import board
4+ import keypad
5+ from displayio import OnDiskBitmap , TileGrid , Group
6+ import adafruit_imageload
7+ from octopus_game_helpers import DiverPlayer , 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+ # add octopus game to main group
21+ main_group .append (octopus_game )
22+
23+ # initialize the shiftregister keys to read hardware buttons
24+ buttons = keypad .ShiftRegisterKeys (
25+ clock = board .BUTTON_CLOCK ,
26+ data = board .BUTTON_OUT ,
27+ latch = board .BUTTON_LATCH ,
28+ key_count = 4 ,
29+ value_when_pressed = True ,
30+ )
31+
32+ # show the main group on the display
33+ display .show (main_group )
34+
35+ # main loop
36+ while True :
37+
38+ # get event from hardware buttons
39+ event = buttons .events .get ()
40+
41+ # if anything is pressed
42+ if event :
43+
44+ # if the event is for the start button
45+ if event .key_number == 2 :
46+ # if it's a pressed event
47+ if event .pressed :
48+ # trigger the right button press action function
49+ octopus_game .right_button_press ()
50+
51+ # if the event is for the select button
52+ elif event .key_number == 3 :
53+ # if it's a pressed event
54+ if event .pressed :
55+ # trigger the left button press action function
56+ octopus_game .left_button_press ()
57+
58+ # if the event is for the b button
59+ elif event .key_number == 0 :
60+ # if it's a pressed event
61+ if event .pressed :
62+ # trigger the b button press action function
63+ octopus_game .b_button_press ()
64+
65+ # if the event is for the a button
66+ elif event .key_number == 1 :
67+ # if it's a pressed event
68+ if event .pressed :
69+ # trigger the a button press action function
70+ octopus_game .a_button_press ()
71+
72+ # call the game tick function
73+ octopus_game .tick ()
0 commit comments