Skip to content

Commit 730e6ee

Browse files
committed
change to ugame buttons in the main code and movement_transparent_sprite example
1 parent 101e919 commit 730e6ee

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

Tilemap_Game_With_CircuitPython/basic_movement_transparent_sprite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import board
22
import displayio
33
import adafruit_imageload
4-
from tilegame_assets.controls_helper import controls
4+
import ugame
55

66
display = board.DISPLAY
77
player_loc = {"x":4, "y":3}
@@ -69,18 +69,18 @@
6969
# Add the Group to the Display
7070
display.show(group)
7171

72-
prev_btn_vals = controls.button
72+
prev_btn_vals = ugame.buttons.get_pressed()
7373

7474
while True:
75-
cur_btn_vals = controls.button
76-
if not prev_btn_vals.up and cur_btn_vals.up:
75+
cur_btn_vals = ugame.buttons.get_pressed()
76+
if not prev_btn_vals & ugame.K_UP and cur_btn_vals & ugame.K_UP:
7777
player_loc["y"] = max(1, player_loc["y"]-1)
78-
if not prev_btn_vals.down and cur_btn_vals.down:
78+
if not prev_btn_vals & ugame.K_DOWN and cur_btn_vals & ugame.K_DOWN:
7979
player_loc["y"] = min(6, player_loc["y"]+1)
8080

81-
if not prev_btn_vals.right and cur_btn_vals.right:
81+
if not prev_btn_vals & ugame.K_RIGHT and cur_btn_vals & ugame.K_RIGHT:
8282
player_loc["x"] = min(8, player_loc["x"]+1)
83-
if not prev_btn_vals.left and cur_btn_vals.left:
83+
if not prev_btn_vals & ugame.K_LEFT and cur_btn_vals & ugame.K_LEFT:
8484
player_loc["x"] = max(1, player_loc["x"]-1)
8585

8686
# update the the player sprite position

Tilemap_Game_With_CircuitPython/code.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import displayio
66
import adafruit_imageload
77
from displayio import Palette
8-
8+
import ugame
99
import terminalio
1010
from adafruit_display_text import label
11-
from tilegame_assets.controls_helper import controls
1211
from tilegame_assets.tiles import TILES
1312
from tilegame_assets.tiles import take_item
1413
from tilegame_assets.states import *
@@ -433,12 +432,12 @@ def show_splash(new_text, color, vertical_offset=18):
433432
# main loop
434433
while True:
435434
# set the current button values into variables
436-
cur_btn_vals = controls.button
437-
cur_up = cur_btn_vals.up
438-
cur_down = cur_btn_vals.down
439-
cur_right = cur_btn_vals.right
440-
cur_left = cur_btn_vals.left
441-
cur_a = cur_btn_vals.a
435+
cur_btn_vals = ugame.buttons.get_pressed()
436+
cur_up = cur_btn_vals & ugame.K_UP
437+
cur_down = cur_btn_vals & ugame.K_DOWN
438+
cur_right = cur_btn_vals & ugame.K_RIGHT
439+
cur_left = cur_btn_vals & ugame.K_LEFT
440+
cur_a = cur_btn_vals & ugame.K_O
442441

443442
if GAME_STATE["STATE"] == STATE_WAITING:
444443
print(cur_a)

0 commit comments

Comments
 (0)