Updated Flying Clouds

Updated Flying Clouds
This commit is contained in:
Noe Ruiz 2019-11-06 10:00:05 -05:00
parent 18e6ea738e
commit 4d4d78039e
3 changed files with 23 additions and 31 deletions

View file

@ -44,12 +44,11 @@ NUMBER_OF_CELLS = (LAST_CELL - FIRST_CELL) + 1
ANIMATED = [_sprite >= FIRST_CELL and _sprite <= LAST_CELL for _sprite in range(NUMBER_OF_SPRITES)]
# The chance (out of 10) that a new toaster, or toast will enter
CHANCE_OF_NEW_TOASTER = 5
# The chance (out of 10) that toast will enter
CHANCE_OF_NEW_TOAST = 2
# How many sprites to styart with
INITIAL_NUMBER_OF_SPRITES= 5
INITIAL_NUMBER_OF_SPRITES = 4
# Global variables
display = None
@ -66,11 +65,8 @@ def make_display():
pass
spi.configure(baudrate=24000000) # Configure SPI for 24MHz
spi.unlock()
tft_cs = board.D10
tft_dc = board.D7
displayio.release_displays()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
display_bus = displayio.FourWire(spi, command=board.D7, chip_select=board.D10, reset=board.D9)
return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)
@ -78,13 +74,13 @@ def make_tilegrid():
"""Construct and return the tilegrid."""
group = displayio.Group(max_size=10)
sprite_sheet, palette = adafruit_imageload.load("/spritesheet.bmp",
sprite_sheet, palette = adafruit_imageload.load("/spritesheet-2x.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
width=9, height=9,
tile_height=32, tile_width=32,
x=0, y=-32,
width=5, height=5,
tile_height=64, tile_width=64,
x=0, y=-64,
default_tile=EMPTY)
group.append(grid)
display.show(group)
@ -104,8 +100,8 @@ def seed_toasters(number_of_toasters):
"""Create the initial toasters so it doesn't start empty"""
for _ in range(number_of_toasters):
while True:
row = randint(0, 8)
col = randint(0, 8)
row = randint(0, 4)
col = randint(0, 4)
if evaluate_position(row, col):
break
tilegrid[col, row] = random_cell()
@ -117,7 +113,7 @@ def next_sprite(sprite):
def advance_animation():
"""Cycle through animation cells each time."""
for tile_number in range(81):
for tile_number in range(25):
tilegrid[tile_number] = next_sprite(tilegrid[tile_number])
def slide_tiles():
@ -127,24 +123,24 @@ def slide_tiles():
def shift_tiles():
"""Move tiles one spot to the left, and reset the tilegrid's position"""
for row in range(8, 0, -1):
for col in range(8):
for row in range(4, 0, -1):
for col in range(4):
tilegrid[col, row] = tilegrid[col + 1, row - 1]
tilegrid[8, row] = EMPTY
for col in range(9):
tilegrid[4, row] = EMPTY
for col in range(5):
tilegrid[col, 0] = EMPTY
tilegrid.x = 0
tilegrid.y = -32
tilegrid.y = -64
def get_entry_row():
while True:
row = randint(0, 8)
if tilegrid[8, row] == EMPTY and tilegrid[7, row] == EMPTY:
row = randint(0, 4)
if tilegrid[4, row] == EMPTY and tilegrid[3, row] == EMPTY:
return row
def get_entry_column():
while True:
col = randint(0, 8)
col = randint(0, 3)
if tilegrid[col, 0] == EMPTY and tilegrid[col, 1] == EMPTY:
return col
@ -152,18 +148,14 @@ def add_toaster_or_toast():
"""Maybe add a new toaster or toast on the right and/or top at a randon open location"""
if randint(1, 10) <= CHANCE_OF_NEW_TOAST:
tile = TOAST
elif randint(1, 10) <= CHANCE_OF_NEW_TOASTER:
tile = random_cell()
else:
tile = EMPTY
tilegrid[8, get_entry_row()] = tile
tile = random_cell()
tilegrid[4, get_entry_row()] = tile
if randint(1, 10) <= CHANCE_OF_NEW_TOAST:
tile = TOAST
elif randint(1, 8) <= CHANCE_OF_NEW_TOASTER:
tile = random_cell()
else:
tile = EMPTY
tile = random_cell()
tilegrid[get_entry_column(), 0] = tile
display = make_display()
@ -172,10 +164,10 @@ seed_toasters(INITIAL_NUMBER_OF_SPRITES)
display.refresh()
while True:
for _ in range(32):
for _ in range(64):
display.refresh(target_frames_per_second=80)
advance_animation()
slide_tiles()
shift_tiles()
add_toaster_or_toast()
display.refresh(target_frames_per_second=120)
display.refresh(target_frames_per_second=120)

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB