code.py
1 # SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import board 6 import displayio 7 import adafruit_imageload 8 9 display = board.DISPLAY 10 11 # Load the sprite sheet (bitmap) 12 sprite_sheet, palette = adafruit_imageload.load("/castle_sprite_sheet.bmp", 13 bitmap=displayio.Bitmap, 14 palette=displayio.Palette) 15 16 # Create the sprite TileGrid 17 sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette, 18 width = 1, 19 height = 1, 20 tile_width = 16, 21 tile_height = 16, 22 default_tile = 0) 23 24 # Create the castle TileGrid 25 castle = displayio.TileGrid(sprite_sheet, pixel_shader=palette, 26 width = 6, 27 height = 5, 28 tile_width = 16, 29 tile_height = 16) 30 31 # Create a Group to hold the sprite and add it 32 sprite_group = displayio.Group() 33 sprite_group.append(sprite) 34 35 # Create a Group to hold the castle and add it 36 castle_group = displayio.Group(scale=3) 37 castle_group.append(castle) 38 39 # Create a Group to hold the sprite and castle 40 group = displayio.Group() 41 42 # Add the sprite and castle to the group 43 group.append(castle_group) 44 group.append(sprite_group) 45 46 # Castle tile assignments 47 # corners 48 castle[0, 0] = 3 # upper left 49 castle[5, 0] = 5 # upper right 50 castle[0, 4] = 9 # lower left 51 castle[5, 4] = 11 # lower right 52 # top / bottom walls 53 for x in range(1, 5): 54 castle[x, 0] = 4 # top 55 castle[x, 4] = 10 # bottom 56 # left/ right walls 57 for y in range(1, 4): 58 castle[0, y] = 6 # left 59 castle[5, y] = 8 # right 60 # floor 61 for x in range(1, 5): 62 for y in range(1, 4): 63 castle[x, y] = 7 # floor 64 65 # put the sprite somewhere in the castle 66 sprite.x = 110 67 sprite.y = 70 68 69 # Add the Group to the Display 70 display.show(group) 71 72 # Loop forever so you can enjoy your image 73 while True: 74 pass