Skip to content

Commit 2baf7aa

Browse files
committed
case-insensitive rest of the keys, and support uppercase binding values
1 parent 96fa902 commit 2baf7aa

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Metro/Metro_RP2350_Snake/code.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,31 @@
177177
# if game is being played
178178
elif CURRENT_STATE == STATE_PLAYING:
179179
# if up button was pressed
180-
if cur_btn_val == KEY_UP:
180+
if cur_btn_val == KEY_UP.lower():
181181
# if the snake is not already moving up or down
182182
if snake.direction not in (snake.DIRECTION_DOWN, snake.DIRECTION_UP):
183183
# change the direction to up
184184
snake.direction = snake.DIRECTION_UP
185185
# if down button was pressed
186-
if cur_btn_val == KEY_DOWN:
186+
if cur_btn_val == KEY_DOWN.lower():
187187
# if the snake is not already moving up or down
188188
if snake.direction not in (snake.DIRECTION_DOWN, snake.DIRECTION_UP):
189189
# change the direction to down
190190
snake.direction = snake.DIRECTION_DOWN
191191
# if right button was pressed
192-
if cur_btn_val == KEY_RIGHT:
192+
if cur_btn_val == KEY_RIGHT.lower():
193193
# if the snake is not already moving left or right
194194
if snake.direction not in (snake.DIRECTION_LEFT, snake.DIRECTION_RIGHT):
195195
# change the direction to right
196196
snake.direction = snake.DIRECTION_RIGHT
197197
# if left button was pressed
198-
if cur_btn_val == KEY_LEFT:
198+
if cur_btn_val == KEY_LEFT.lower():
199199
# if the snake is not already moving left or right
200200
if snake.direction not in (snake.DIRECTION_LEFT, snake.DIRECTION_RIGHT):
201201
# change direction to left
202202
snake.direction = snake.DIRECTION_LEFT
203203
# if the pause button was pressed
204-
if cur_btn_val == KEY_PAUSE:
204+
if cur_btn_val == KEY_PAUSE.lower():
205205
# change the state to paused
206206
CURRENT_STATE = STATE_PAUSED
207207

@@ -249,19 +249,19 @@
249249
# if the game is paused
250250
elif CURRENT_STATE == STATE_PAUSED:
251251
# if the pause button was pressed
252-
if cur_btn_val == KEY_PAUSE:
252+
if cur_btn_val == KEY_PAUSE.lower():
253253
# change the state to playing so the game resumes
254254
CURRENT_STATE = STATE_PLAYING
255255

256256
# if the current state is game over
257257
elif CURRENT_STATE == STATE_GAME_OVER:
258258
# if the p button is pressed for play again
259-
if cur_btn_val == "p":
259+
if cur_btn_val in {"p", "P"}:
260260
# set next code file to this one
261261
supervisor.set_next_code_file(__file__)
262262
# reload
263263
supervisor.reload()
264264
# if the q button is pressed for exit
265-
if cur_btn_val == "q":
265+
if cur_btn_val in {"q", "Q"}:
266266
# break out of main while True loop.
267267
break

0 commit comments

Comments
 (0)