4444ANIMATED = [_sprite >= FIRST_CELL and _sprite <= LAST_CELL for _sprite in range (NUMBER_OF_SPRITES )]
4545
4646
47- # The chance (out of 10) that a new toaster, or toast will enter
48- CHANCE_OF_NEW_TOASTER = 5
47+ # The chance (out of 10) that toast will enter
4948CHANCE_OF_NEW_TOAST = 2
5049
5150# How many sprites to styart with
52- INITIAL_NUMBER_OF_SPRITES = 5
51+ INITIAL_NUMBER_OF_SPRITES = 4
5352
5453# Global variables
5554display = None
@@ -66,25 +65,22 @@ def make_display():
6665 pass
6766 spi .configure (baudrate = 24000000 ) # Configure SPI for 24MHz
6867 spi .unlock ()
69- tft_cs = board .D10
70- tft_dc = board .D7
71-
7268 displayio .release_displays ()
73- display_bus = displayio .FourWire (spi , command = tft_dc , chip_select = tft_cs , reset = board .D9 )
69+ display_bus = displayio .FourWire (spi , command = board . D7 , chip_select = board . D10 , reset = board .D9 )
7470
7571 return ST7789 (display_bus , width = 240 , height = 240 , rowstart = 80 , auto_refresh = True )
7672
7773def make_tilegrid ():
7874 """Construct and return the tilegrid."""
7975 group = displayio .Group (max_size = 10 )
8076
81- sprite_sheet , palette = adafruit_imageload .load ("/spritesheet.bmp" ,
77+ sprite_sheet , palette = adafruit_imageload .load ("/spritesheet-2x .bmp" ,
8278 bitmap = displayio .Bitmap ,
8379 palette = displayio .Palette )
8480 grid = displayio .TileGrid (sprite_sheet , pixel_shader = palette ,
85- width = 9 , height = 9 ,
86- tile_height = 32 , tile_width = 32 ,
87- x = 0 , y = - 32 ,
81+ width = 5 , height = 5 ,
82+ tile_height = 64 , tile_width = 64 ,
83+ x = 0 , y = - 64 ,
8884 default_tile = EMPTY )
8985 group .append (grid )
9086 display .show (group )
@@ -104,8 +100,8 @@ def seed_toasters(number_of_toasters):
104100 """Create the initial toasters so it doesn't start empty"""
105101 for _ in range (number_of_toasters ):
106102 while True :
107- row = randint (0 , 8 )
108- col = randint (0 , 8 )
103+ row = randint (0 , 4 )
104+ col = randint (0 , 4 )
109105 if evaluate_position (row , col ):
110106 break
111107 tilegrid [col , row ] = random_cell ()
@@ -117,7 +113,7 @@ def next_sprite(sprite):
117113
118114def advance_animation ():
119115 """Cycle through animation cells each time."""
120- for tile_number in range (81 ):
116+ for tile_number in range (25 ):
121117 tilegrid [tile_number ] = next_sprite (tilegrid [tile_number ])
122118
123119def slide_tiles ():
@@ -127,43 +123,39 @@ def slide_tiles():
127123
128124def shift_tiles ():
129125 """Move tiles one spot to the left, and reset the tilegrid's position"""
130- for row in range (8 , 0 , - 1 ):
131- for col in range (8 ):
126+ for row in range (4 , 0 , - 1 ):
127+ for col in range (4 ):
132128 tilegrid [col , row ] = tilegrid [col + 1 , row - 1 ]
133- tilegrid [8 , row ] = EMPTY
134- for col in range (9 ):
129+ tilegrid [4 , row ] = EMPTY
130+ for col in range (5 ):
135131 tilegrid [col , 0 ] = EMPTY
136132 tilegrid .x = 0
137- tilegrid .y = - 32
133+ tilegrid .y = - 64
138134
139135def get_entry_row ():
140136 while True :
141- row = randint (0 , 8 )
142- if tilegrid [8 , row ] == EMPTY and tilegrid [7 , row ] == EMPTY :
137+ row = randint (0 , 4 )
138+ if tilegrid [4 , row ] == EMPTY and tilegrid [3 , row ] == EMPTY :
143139 return row
144140
145141def get_entry_column ():
146142 while True :
147- col = randint (0 , 8 )
143+ col = randint (0 , 3 )
148144 if tilegrid [col , 0 ] == EMPTY and tilegrid [col , 1 ] == EMPTY :
149145 return col
150146
151147def add_toaster_or_toast ():
152148 """Maybe add a new toaster or toast on the right and/or top at a randon open location"""
153149 if randint (1 , 10 ) <= CHANCE_OF_NEW_TOAST :
154150 tile = TOAST
155- elif randint (1 , 10 ) <= CHANCE_OF_NEW_TOASTER :
156- tile = random_cell ()
157151 else :
158- tile = EMPTY
159- tilegrid [8 , get_entry_row ()] = tile
152+ tile = random_cell ()
153+ tilegrid [4 , get_entry_row ()] = tile
160154
161155 if randint (1 , 10 ) <= CHANCE_OF_NEW_TOAST :
162156 tile = TOAST
163- elif randint (1 , 8 ) <= CHANCE_OF_NEW_TOASTER :
164- tile = random_cell ()
165157 else :
166- tile = EMPTY
158+ tile = random_cell ()
167159 tilegrid [get_entry_column (), 0 ] = tile
168160
169161display = make_display ()
@@ -172,10 +164,10 @@ def add_toaster_or_toast():
172164display .refresh ()
173165
174166while True :
175- for _ in range (32 ):
167+ for _ in range (64 ):
176168 display .refresh (target_frames_per_second = 80 )
177169 advance_animation ()
178170 slide_tiles ()
179171 shift_tiles ()
180172 add_toaster_or_toast ()
181- display .refresh (target_frames_per_second = 120 )
173+ display .refresh (target_frames_per_second = 120 )
0 commit comments