sprite sheep:

    dino.bmp

    跑效果

    1. import board
    2. import displayio
    3. time = 0
    4. # hero (dino) sprite sheep
    5. hero_frame_max = 5
    6. hero_frame_current = 0
    7. hero_sprite_sheet, palette = adafruit_imageload.load("images/dino.bmp",bitmap=displayio.Bitmap,palette=displayio.Palette)
    8. # Create a sprite (tilegrid)
    9. hero = displayio.TileGrid(hero_sprite_sheet, pixel_shader=palette,width = 1,height = 1,tile_width = 49,tile_height = 53)
    10. hero[0] = hero_frame_current
    11. hero.y = 80
    12. hero.x = 20
    13. group = displayio.Group()
    14. group.append(hero)
    15. board.DISPLAY.show(group)
    16. while True:
    17. if time % 2000 == 0:
    18. time = 0
    19. hero_frame_current += 1
    20. if hero_frame_current == hero_frame_max :
    21. hero_frame_current = 0
    22. hero[0] = hero_frame_current
    23. pass

    加上分数、按键

    1. import board
    2. import displayio
    3. import adafruit_imageload
    4. from adafruit_display_text import label
    5. from adafruit_bitmap_font import bitmap_font
    6. import neopixel
    7. import digitalio
    8. button = digitalio.DigitalInOut(board.BUTTON) #board.IO21
    9. button_press = False
    10. button_releast = False
    11. time = 0
    12. score = 0
    13. text_score = label.Label(font, text=str(score), color=color)
    14. text_score.anchor_point = (0, 0)
    15. text_score.anchored_position = (10, 10)
    16. # hero (dino) sprite sheep
    17. hero_frame_max = 5
    18. hero_frame_current = 0
    19. hero_sprite_sheet, palette = adafruit_imageload.load("images/dino.bmp",bitmap=displayio.Bitmap,palette=displayio.Palette)
    20. # Create a sprite (tilegrid)
    21. hero = displayio.TileGrid(hero_sprite_sheet, pixel_shader=palette,width = 1,height = 1,tile_width = 49,tile_height = 53)
    22. hero[0] = hero_frame_current
    23. hero.y = 80
    24. hero.x = 20
    25. group = displayio.Group()
    26. group.append(text_score)
    27. group.append(hero)
    28. board.DISPLAY.show(group)
    29. while True:
    30. time += 1
    31. if button.value == 0:
    32. button_press = True
    33. if button_press :
    34. if button.value == 1 :
    35. button_releast = True
    36. if button_releast :
    37. # if game not over then jump
    38. # else restart game
    39. button_releast = False
    40. button_press = False
    41. if time % 2000 == 0:
    42. score += 1
    43. text_score.text = str(score)
    44. time = 0
    45. hero_frame_current += 1
    46. if hero_frame_current == hero_frame_max :
    47. hero_frame_current = 0
    48. hero[0] = hero_frame_current
    49. pass