sprite sheep:

跑效果
import boardimport displayiotime = 0# hero (dino) sprite sheephero_frame_max = 5hero_frame_current = 0hero_sprite_sheet, palette = adafruit_imageload.load("images/dino.bmp",bitmap=displayio.Bitmap,palette=displayio.Palette)# Create a sprite (tilegrid)hero = displayio.TileGrid(hero_sprite_sheet, pixel_shader=palette,width = 1,height = 1,tile_width = 49,tile_height = 53)hero[0] = hero_frame_currenthero.y = 80hero.x = 20group = displayio.Group()group.append(hero)board.DISPLAY.show(group)while True:if time % 2000 == 0:time = 0hero_frame_current += 1if hero_frame_current == hero_frame_max :hero_frame_current = 0hero[0] = hero_frame_currentpass
加上分数、按键
import boardimport displayioimport adafruit_imageloadfrom adafruit_display_text import labelfrom adafruit_bitmap_font import bitmap_fontimport neopixelimport digitaliobutton = digitalio.DigitalInOut(board.BUTTON) #board.IO21button_press = Falsebutton_releast = Falsetime = 0score = 0text_score = label.Label(font, text=str(score), color=color)text_score.anchor_point = (0, 0)text_score.anchored_position = (10, 10)# hero (dino) sprite sheephero_frame_max = 5hero_frame_current = 0hero_sprite_sheet, palette = adafruit_imageload.load("images/dino.bmp",bitmap=displayio.Bitmap,palette=displayio.Palette)# Create a sprite (tilegrid)hero = displayio.TileGrid(hero_sprite_sheet, pixel_shader=palette,width = 1,height = 1,tile_width = 49,tile_height = 53)hero[0] = hero_frame_currenthero.y = 80hero.x = 20group = displayio.Group()group.append(text_score)group.append(hero)board.DISPLAY.show(group)while True:time += 1if button.value == 0:button_press = Trueif button_press :if button.value == 1 :button_releast = Trueif button_releast :# if game not over then jump# else restart gamebutton_releast = Falsebutton_press = Falseif time % 2000 == 0:score += 1text_score.text = str(score)time = 0hero_frame_current += 1if hero_frame_current == hero_frame_max :hero_frame_current = 0hero[0] = hero_frame_currentpass
