Skip to content

Commit 51794ad

Browse files
committed
Remove separate groups for the castle and sprites. Add everything to the main group.
1 parent c7069c7 commit 51794ad

File tree

1 file changed

+10
-18
lines changed
  • Tilemap_Game_With_CircuitPython

1 file changed

+10
-18
lines changed

Tilemap_Game_With_CircuitPython/code.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,31 +129,23 @@ def is_tile_moveable(tile_coords):
129129
tile_height=16,
130130
)
131131

132-
# Create a Group to hold the sprites and add it
133-
sprite_group = displayio.Group(max_size=32)
134-
135-
# Create a Group to hold the castle and add it
136-
castle_group = displayio.Group()
137-
castle_group.append(castle)
138-
139132
# Create a Group to hold the sprite and castle
140-
group = displayio.Group()
133+
group = displayio.Group(max_size=33)
141134

142-
# Add the sprite and castle to the group
143-
group.append(castle_group)
144-
group.append(sprite_group)
135+
# Add castle to the group
136+
group.append(castle)
145137

146138

147139
def load_map(file_name):
148140
# pylint: disable=global-statement,too-many-statements,too-many-nested-blocks,too-many-branches
149141
global ENTITY_SPRITES, CAMERA_VIEW
150142

151-
# empty the sprite_group
143+
# empty the sprites from the group
152144
for cur_s in ENTITY_SPRITES:
153-
sprite_group.remove(cur_s)
145+
group.remove(cur_s)
154146
# remove player sprite
155147
try:
156-
sprite_group.remove(GAME_STATE["PLAYER_SPRITE"])
148+
group.remove(GAME_STATE["PLAYER_SPRITE"])
157149
except ValueError:
158150
pass
159151

@@ -223,7 +215,7 @@ def load_map(file_name):
223215
GAME_STATE["PLAYER_LOC"] = (x, y)
224216

225217
# add sprite to the group
226-
sprite_group.append(GAME_STATE["PLAYER_SPRITE"])
218+
group.append(GAME_STATE["PLAYER_SPRITE"])
227219
else: # not the player
228220
# Create the sprite TileGrid
229221
entity_srite = displayio.TileGrid(
@@ -270,7 +262,7 @@ def load_map(file_name):
270262
# add all entity sprites to the group
271263
print("appending {} sprites".format(len(ENTITY_SPRITES)))
272264
for entity in ENTITY_SPRITES:
273-
sprite_group.append(entity)
265+
group.append(entity)
274266

275267

276268
print("loading map")
@@ -605,18 +597,18 @@ def show_splash(new_text, color, vertical_offset=18):
605597
if GAME_STATE["MAP_INDEX"] >= len(MAPS):
606598
GAME_STATE["MAP_INDEX"] = 0
607599
GAME_STATE["STATE"] = STATE_WAITING
600+
load_map(MAPS[GAME_STATE["MAP_INDEX"]])
608601
show_splash(
609602
"You Win \n =D \nCongratulations. \nStart Over?", 0x29C1CF
610603
)
611-
load_map(MAPS[GAME_STATE["MAP_INDEX"]])
612604
else:
613605
# prompt to start next
614606
GAME_STATE["STATE"] = STATE_WAITING
607+
load_map(MAPS[GAME_STATE["MAP_INDEX"]])
615608
show_splash(
616609
"You beat this level\n =D \nCongratulations. \nStart Next?",
617610
0x29C1CF,
618611
)
619-
load_map(MAPS[GAME_STATE["MAP_INDEX"]])
620612
# game over from sparky
621613
elif GAME_STATE["STATE"] == STATE_LOST_SPARKY:
622614
GAME_STATE["MAP_INDEX"] = 0

0 commit comments

Comments
 (0)