|
4 | 4 | import ugame |
5 | 5 |
|
6 | 6 | display = board.DISPLAY |
7 | | -player_loc = {"x":4, "y":3} |
| 7 | +player_loc = {"x": 4, "y": 3} |
8 | 8 |
|
9 | 9 | # Load the sprite sheet (bitmap) |
10 | | -sprite_sheet, palette = adafruit_imageload.load("tilegame_assets/castle_sprite_sheet_edited.bmp", |
11 | | - bitmap=displayio.Bitmap, |
12 | | - palette=displayio.Palette) |
| 10 | +sprite_sheet, palette = adafruit_imageload.load( |
| 11 | + "tilegame_assets/castle_sprite_sheet_edited.bmp", |
| 12 | + bitmap=displayio.Bitmap, |
| 13 | + palette=displayio.Palette, |
| 14 | +) |
13 | 15 | # make the color at 0 index transparent. |
14 | 16 | palette.make_transparent(0) |
15 | 17 |
|
16 | 18 | # 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) |
| 19 | +sprite = displayio.TileGrid( |
| 20 | + sprite_sheet, |
| 21 | + pixel_shader=palette, |
| 22 | + width=1, |
| 23 | + height=1, |
| 24 | + tile_width=16, |
| 25 | + tile_height=16, |
| 26 | + default_tile=0, |
| 27 | +) |
23 | 28 |
|
24 | 29 | # Create the castle TileGrid |
25 | | -castle = displayio.TileGrid(sprite_sheet, pixel_shader=palette, |
26 | | - width=10, |
27 | | - height=8, |
28 | | - tile_width=16, |
29 | | - tile_height=16) |
| 30 | +castle = displayio.TileGrid( |
| 31 | + sprite_sheet, |
| 32 | + pixel_shader=palette, |
| 33 | + width=10, |
| 34 | + height=8, |
| 35 | + tile_width=16, |
| 36 | + tile_height=16, |
| 37 | +) |
30 | 38 |
|
31 | 39 | # Create a Group to hold the sprite and add it |
32 | 40 | sprite_group = displayio.Group() |
|
74 | 82 | while True: |
75 | 83 | cur_btn_vals = ugame.buttons.get_pressed() |
76 | 84 | if not prev_btn_vals & ugame.K_UP and cur_btn_vals & ugame.K_UP: |
77 | | - player_loc["y"] = max(1, player_loc["y"]-1) |
| 85 | + player_loc["y"] = max(1, player_loc["y"] - 1) |
78 | 86 | if not prev_btn_vals & ugame.K_DOWN and cur_btn_vals & ugame.K_DOWN: |
79 | | - player_loc["y"] = min(6, player_loc["y"]+1) |
| 87 | + player_loc["y"] = min(6, player_loc["y"] + 1) |
80 | 88 |
|
81 | 89 | if not prev_btn_vals & ugame.K_RIGHT and cur_btn_vals & ugame.K_RIGHT: |
82 | | - player_loc["x"] = min(8, player_loc["x"]+1) |
| 90 | + player_loc["x"] = min(8, player_loc["x"] + 1) |
83 | 91 | if not prev_btn_vals & ugame.K_LEFT and cur_btn_vals & ugame.K_LEFT: |
84 | | - player_loc["x"] = max(1, player_loc["x"]-1) |
| 92 | + player_loc["x"] = max(1, player_loc["x"] - 1) |
85 | 93 |
|
86 | 94 | # update the the player sprite position |
87 | 95 | sprite.x = 16 * player_loc["x"] |
|
0 commit comments