Merge pull request #3034 from FoamyGuy/tilepalettemapper_api_update
Tilepalettemapper api update
This commit is contained in:
commit
0b7aa5dfcb
4 changed files with 52 additions and 18 deletions
|
|
@ -14,9 +14,12 @@ import displayio
|
||||||
import supervisor
|
import supervisor
|
||||||
from displayio import Group, TileGrid
|
from displayio import Group, TileGrid
|
||||||
from tilepalettemapper import TilePaletteMapper
|
from tilepalettemapper import TilePaletteMapper
|
||||||
|
from adafruit_fruitjam.peripherals import request_display_config
|
||||||
import adafruit_imageload
|
import adafruit_imageload
|
||||||
|
|
||||||
|
|
||||||
# use the built-in HSTX display
|
# use the built-in HSTX display
|
||||||
|
request_display_config(320, 240)
|
||||||
display = supervisor.runtime.display
|
display = supervisor.runtime.display
|
||||||
|
|
||||||
# screen size in tiles, tiles are 16x16
|
# screen size in tiles, tiles are 16x16
|
||||||
|
|
@ -64,7 +67,12 @@ for i in range(0, len(COLORS)):
|
||||||
shader_palette[i + 1] = COLORS[i]
|
shader_palette[i + 1] = COLORS[i]
|
||||||
|
|
||||||
# mapper to change colors of tiles within the grid
|
# mapper to change colors of tiles within the grid
|
||||||
grid_color_shader = TilePaletteMapper(shader_palette, 2, SCREEN_WIDTH, SCREEN_HEIGHT)
|
if sys.implementation.version[0] == 9:
|
||||||
|
grid_color_shader = TilePaletteMapper(
|
||||||
|
shader_palette, 2, SCREEN_WIDTH, SCREEN_HEIGHT
|
||||||
|
)
|
||||||
|
elif sys.implementation.version[0] >= 10:
|
||||||
|
grid_color_shader = TilePaletteMapper(shader_palette, 2)
|
||||||
|
|
||||||
# load the spritesheet
|
# load the spritesheet
|
||||||
katakana_bmp, katakana_pixelshader = adafruit_imageload.load("matrix_characters.bmp")
|
katakana_bmp, katakana_pixelshader = adafruit_imageload.load("matrix_characters.bmp")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import array
|
||||||
import atexit
|
import atexit
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
@ -217,9 +218,11 @@ for i in range(2):
|
||||||
|
|
||||||
# create tile palette mappers
|
# create tile palette mappers
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
|
if sys.implementation.version[0] == 9:
|
||||||
palette_mapper = TilePaletteMapper(remap_palette, 3, 1, 1)
|
palette_mapper = TilePaletteMapper(remap_palette, 3, 1, 1)
|
||||||
# remap index 2 to each of the colors in mouse colors list
|
elif sys.implementation.version[0] >= 10:
|
||||||
palette_mapper[0] = [0, 1, i + 3]
|
palette_mapper = TilePaletteMapper(remap_palette, 3)
|
||||||
|
|
||||||
palette_mappers.append(palette_mapper)
|
palette_mappers.append(palette_mapper)
|
||||||
|
|
||||||
# create tilegrid for each mouse
|
# create tilegrid for each mouse
|
||||||
|
|
@ -228,6 +231,9 @@ for i in range(2):
|
||||||
mouse_tg.y = display.height // scale_factor // 2
|
mouse_tg.y = display.height // scale_factor // 2
|
||||||
mouse_tgs.append(mouse_tg)
|
mouse_tgs.append(mouse_tg)
|
||||||
|
|
||||||
|
# remap index 2 to each of the colors in mouse colors list
|
||||||
|
palette_mapper[0] = [0, 1, i + 3]
|
||||||
|
|
||||||
# USB info lists
|
# USB info lists
|
||||||
mouse_interface_indexes = []
|
mouse_interface_indexes = []
|
||||||
mouse_endpoint_addresses = []
|
mouse_endpoint_addresses = []
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
|
@ -133,7 +134,10 @@ class Match3Card(Group):
|
||||||
|
|
||||||
def __init__(self, card_tuple, **kwargs):
|
def __init__(self, card_tuple, **kwargs):
|
||||||
# tile palette mapper to color the card
|
# tile palette mapper to color the card
|
||||||
|
if sys.implementation.version[0] == 9:
|
||||||
self._mapper = TilePaletteMapper(kwargs["pixel_shader"], 5, 1, 1)
|
self._mapper = TilePaletteMapper(kwargs["pixel_shader"], 5, 1, 1)
|
||||||
|
elif sys.implementation.version[0] >= 10:
|
||||||
|
self._mapper = TilePaletteMapper(kwargs["pixel_shader"], 5)
|
||||||
kwargs["pixel_shader"] = self._mapper
|
kwargs["pixel_shader"] = self._mapper
|
||||||
# tile grid to for the visible sprite
|
# tile grid to for the visible sprite
|
||||||
self._tilegrid = TileGrid(**kwargs)
|
self._tilegrid = TileGrid(**kwargs)
|
||||||
|
|
@ -580,9 +584,11 @@ class Match3Game(Group):
|
||||||
# if 3 cards have been clicked
|
# if 3 cards have been clicked
|
||||||
if len(self.clicked_cards) == 3:
|
if len(self.clicked_cards) == 3:
|
||||||
# check if the 3 cards make a valid set
|
# check if the 3 cards make a valid set
|
||||||
valid_set = validate_set(self.clicked_cards[0],
|
valid_set = validate_set(
|
||||||
|
self.clicked_cards[0],
|
||||||
self.clicked_cards[1],
|
self.clicked_cards[1],
|
||||||
self.clicked_cards[2])
|
self.clicked_cards[2],
|
||||||
|
)
|
||||||
|
|
||||||
# if they are a valid set
|
# if they are a valid set
|
||||||
if valid_set:
|
if valid_set:
|
||||||
|
|
@ -660,7 +666,7 @@ class Match3Game(Group):
|
||||||
# load the game from the given game state
|
# load the game from the given game state
|
||||||
self.load_from_game_state(self.game_state)
|
self.load_from_game_state(self.game_state)
|
||||||
# hide the title screen
|
# hide the title screen
|
||||||
self.title_screen.hidden = True # pylint: disable=attribute-defined-outside-init
|
self.title_screen.hidden = True
|
||||||
# set the current state to open play
|
# set the current state to open play
|
||||||
self.cur_state = STATE_PLAYING_OPEN
|
self.cur_state = STATE_PLAYING_OPEN
|
||||||
|
|
||||||
|
|
@ -676,7 +682,7 @@ class Match3Game(Group):
|
||||||
# initialize a new game
|
# initialize a new game
|
||||||
self.init_new_game()
|
self.init_new_game()
|
||||||
# hide the title screen
|
# hide the title screen
|
||||||
self.title_screen.hidden = True # pylint: disable=attribute-defined-outside-init
|
self.title_screen.hidden = True
|
||||||
# set the current state to open play
|
# set the current state to open play
|
||||||
self.cur_state = STATE_PLAYING_OPEN
|
self.cur_state = STATE_PLAYING_OPEN
|
||||||
|
|
||||||
|
|
@ -727,6 +733,7 @@ class Match3TitleScreen(Group):
|
||||||
|
|
||||||
def __init__(self, display_size):
|
def __init__(self, display_size):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.hidden = False
|
||||||
self.display_size = display_size
|
self.display_size = display_size
|
||||||
# background bitmap color
|
# background bitmap color
|
||||||
bg_bmp = Bitmap(display_size[0] // 10, display_size[1] // 10, 1)
|
bg_bmp = Bitmap(display_size[0] // 10, display_size[1] // 10, 1)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
|
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
import sys
|
||||||
|
|
||||||
import supervisor
|
import supervisor
|
||||||
from displayio import Group, OnDiskBitmap, TileGrid
|
from displayio import Group, OnDiskBitmap, TileGrid
|
||||||
|
|
@ -20,16 +21,28 @@ display.root_group = main_group
|
||||||
spritesheet_bmp = OnDiskBitmap("match3_cards_spritesheet.bmp")
|
spritesheet_bmp = OnDiskBitmap("match3_cards_spritesheet.bmp")
|
||||||
|
|
||||||
# create a TilePaletteMapper
|
# create a TilePaletteMapper
|
||||||
|
if sys.implementation.version[0] == 9:
|
||||||
tile_palette_mapper = TilePaletteMapper(
|
tile_palette_mapper = TilePaletteMapper(
|
||||||
spritesheet_bmp.pixel_shader, # input pixel_shader
|
spritesheet_bmp.pixel_shader, # input pixel_shader
|
||||||
5, # input color count
|
5, # input color count
|
||||||
3, # grid width
|
3, # grid width
|
||||||
1 # grid height
|
1, # grid height
|
||||||
|
)
|
||||||
|
elif sys.implementation.version[0] >= 10:
|
||||||
|
tile_palette_mapper = TilePaletteMapper(
|
||||||
|
spritesheet_bmp.pixel_shader, # input pixel_shader
|
||||||
|
5, # input color count
|
||||||
)
|
)
|
||||||
|
|
||||||
# create a TileGrid to show some cards
|
# create a TileGrid to show some cards
|
||||||
cards_tilegrid = TileGrid(spritesheet_bmp, pixel_shader=tile_palette_mapper,
|
cards_tilegrid = TileGrid(
|
||||||
width=3, height=1, tile_width=24, tile_height=32)
|
spritesheet_bmp,
|
||||||
|
pixel_shader=tile_palette_mapper,
|
||||||
|
width=3,
|
||||||
|
height=1,
|
||||||
|
tile_width=24,
|
||||||
|
tile_height=32,
|
||||||
|
)
|
||||||
|
|
||||||
# set each tile in the grid to a different sprite index
|
# set each tile in the grid to a different sprite index
|
||||||
cards_tilegrid[0, 0] = 10
|
cards_tilegrid[0, 0] = 10
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue