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