@@ -68,7 +68,7 @@ def __init__(self, col, start_time):
6868
6969# Create 3 displayio groups -- one each for the title, play and end screens.
7070
71- TITLE_GROUP = displayio .Group (max_size = 1 )
71+ TITLE_GROUP = displayio .Group ()
7272TITLE_BITMAP , TITLE_PALETTE = adafruit_imageload .load (PATH + 'title.bmp' ,
7373 bitmap = displayio .Bitmap ,
7474 palette = displayio .Palette )
@@ -82,7 +82,7 @@ def __init__(self, col, start_time):
8282 PATH + 'sprites.bmp' , bitmap = displayio .Bitmap , palette = displayio .Palette )
8383SPRITE_PALETTE .make_transparent (0 )
8484
85- PLAY_GROUP = displayio .Group (max_size = MAX_EGGS + 10 )
85+ PLAY_GROUP = displayio .Group ()
8686# Bitmap containing five shadow tiles ('no shadow' through 'max shadow')
8787SHADOW_BITMAP , SHADOW_PALETTE = adafruit_imageload .load (
8888 PATH + 'shadow.bmp' , bitmap = displayio .Bitmap , palette = displayio .Palette )
@@ -99,19 +99,19 @@ def __init__(self, col, start_time):
9999 fill_color = 0 , margin_size = 1 )
100100PLAY_GROUP .append (LIFE_BAR )
101101# Score is last object in PLAY_GROUP, can be indexed as -1
102- PLAY_GROUP .append (label .Label (FONT , text = '0' , max_glyphs = 10 , color = 0xFFFFFF ,
102+ PLAY_GROUP .append (label .Label (FONT , text = '0' , color = 0xFFFFFF ,
103103 anchor_point = (0.5 , 0.0 ),
104104 anchored_position = (MACROPAD .display .width // 2 ,
105105 10 )))
106106
107- END_GROUP = displayio .Group (max_size = 1 )
107+ END_GROUP = displayio .Group ()
108108END_BITMAP , END_PALETTE = adafruit_imageload .load (
109109 PATH + 'gameover.bmp' , bitmap = displayio .Bitmap , palette = displayio .Palette )
110110END_GROUP .append (displayio .TileGrid (END_BITMAP , pixel_shader = END_PALETTE ,
111111 width = 1 , height = 1 ,
112112 tile_width = END_BITMAP .width ,
113113 tile_height = END_BITMAP .height ))
114- END_GROUP .append (label .Label (FONT , text = '0' , max_glyphs = 10 , color = 0xFFFFFF ,
114+ END_GROUP .append (label .Label (FONT , text = '0' , color = 0xFFFFFF ,
115115 anchor_point = (0.5 , 0.0 ),
116116 anchored_position = (MACROPAD .display .width // 2 ,
117117 90 )))
@@ -258,6 +258,18 @@ def __init__(self, col, start_time):
258258 MACROPAD ._speaker_enable .value = False
259259 gc .collect ()
260260
261+ # Encoder button pauses/resumes game.
262+ MACROPAD .encoder_switch_debounced .update ()
263+ if MACROPAD .encoder_switch_debounced .pressed :
264+ for n in (True , False , True ): # Press, release, press
265+ while n == MACROPAD .encoder_switch_debounced .pressed :
266+ MACROPAD .encoder_switch_debounced .update ()
267+ # Sprite start times must be offset by pause duration
268+ # because time.monotonic() is used for drop physics.
269+ NOW = time .monotonic () - NOW # Pause duration
270+ for sprite in SPRITES :
271+ sprite .start_time += NOW
272+
261273 # GAME OVER ------------------------
262274
263275 time .sleep (1.5 ) # Pause display for a moment
@@ -269,3 +281,5 @@ def __init__(self, col, start_time):
269281 PLAY_GROUP .pop (1 )
270282 END_GROUP [- 1 ].text = str (SCORE )
271283 show_screen (END_GROUP )
284+ # pylint: disable=protected-access
285+ MACROPAD ._speaker_enable .value = False
0 commit comments