Skip to content

Commit b19a020

Browse files
committed
running black on py files
1 parent 730e6ee commit b19a020

File tree

7 files changed

+127
-126
lines changed

7 files changed

+127
-126
lines changed

Tilemap_Game_With_CircuitPython/basic_movement.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
import board
22
import displayio
33
import adafruit_imageload
4-
#from tilegame_assets.controls_helper import controls
4+
5+
# from tilegame_assets.controls_helper import controls
56
import ugame
67

78
display = board.DISPLAY
89
player_loc = {"x": 4, "y": 3}
910

1011
# Load the sprite sheet (bitmap)
11-
sprite_sheet, palette = adafruit_imageload.load("tilegame_assets/castle_sprite_sheet.bmp",
12-
bitmap=displayio.Bitmap,
13-
palette=displayio.Palette)
12+
sprite_sheet, palette = adafruit_imageload.load(
13+
"tilegame_assets/castle_sprite_sheet.bmp",
14+
bitmap=displayio.Bitmap,
15+
palette=displayio.Palette,
16+
)
1417

1518
# Create the sprite TileGrid
16-
sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
17-
width=1,
18-
height=1,
19-
tile_width=16,
20-
tile_height=16,
21-
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+
)
2228

2329
# Create the castle TileGrid
24-
castle = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
25-
width=10,
26-
height=8,
27-
tile_width=16,
28-
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+
)
2938

3039
# Create a Group to hold the sprite and add it
3140
sprite_group = displayio.Group()
@@ -73,14 +82,14 @@
7382
while True:
7483
cur_btn_vals = ugame.buttons.get_pressed()
7584
if not prev_btn_vals & ugame.K_UP and cur_btn_vals & ugame.K_UP:
76-
player_loc["y"] = max(1, player_loc["y"]-1)
85+
player_loc["y"] = max(1, player_loc["y"] - 1)
7786
if not prev_btn_vals & ugame.K_DOWN and cur_btn_vals & ugame.K_DOWN:
78-
player_loc["y"] = min(6, player_loc["y"]+1)
87+
player_loc["y"] = min(6, player_loc["y"] + 1)
7988

8089
if not prev_btn_vals & ugame.K_RIGHT and cur_btn_vals & ugame.K_RIGHT:
81-
player_loc["x"] = min(8, player_loc["x"]+1)
90+
player_loc["x"] = min(8, player_loc["x"] + 1)
8291
if not prev_btn_vals & ugame.K_LEFT and cur_btn_vals & ugame.K_LEFT:
83-
player_loc["x"] = max(1, player_loc["x"]-1)
92+
player_loc["x"] = max(1, player_loc["x"] - 1)
8493

8594
# update the the player sprite position
8695
sprite.x = 16 * player_loc["x"]

Tilemap_Game_With_CircuitPython/basic_movement_transparent_sprite.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,37 @@
44
import ugame
55

66
display = board.DISPLAY
7-
player_loc = {"x":4, "y":3}
7+
player_loc = {"x": 4, "y": 3}
88

99
# 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+
)
1315
# make the color at 0 index transparent.
1416
palette.make_transparent(0)
1517

1618
# 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+
)
2328

2429
# 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+
)
3038

3139
# Create a Group to hold the sprite and add it
3240
sprite_group = displayio.Group()
@@ -74,14 +82,14 @@
7482
while True:
7583
cur_btn_vals = ugame.buttons.get_pressed()
7684
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)
7886
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)
8088

8189
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)
8391
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)
8593

8694
# update the the player sprite position
8795
sprite.x = 16 * player_loc["x"]

Tilemap_Game_With_CircuitPython/basic_rendering.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,32 @@
55
display = board.DISPLAY
66

77
# Load the sprite sheet (bitmap)
8-
sprite_sheet, palette = adafruit_imageload.load("tilegame_assets/castle_sprite_sheet.bmp",
9-
bitmap=displayio.Bitmap,
10-
palette=displayio.Palette)
8+
sprite_sheet, palette = adafruit_imageload.load(
9+
"tilegame_assets/castle_sprite_sheet.bmp",
10+
bitmap=displayio.Bitmap,
11+
palette=displayio.Palette,
12+
)
1113

1214
# Create the sprite TileGrid
13-
sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
14-
width=1,
15-
height=1,
16-
tile_width=16,
17-
tile_height=16,
18-
default_tile=0)
15+
sprite = displayio.TileGrid(
16+
sprite_sheet,
17+
pixel_shader=palette,
18+
width=1,
19+
height=1,
20+
tile_width=16,
21+
tile_height=16,
22+
default_tile=0,
23+
)
1924

2025
# Create the castle TileGrid
21-
castle = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
22-
width=10,
23-
height=8,
24-
tile_width=16,
25-
tile_height=16)
26+
castle = displayio.TileGrid(
27+
sprite_sheet,
28+
pixel_shader=palette,
29+
width=10,
30+
height=8,
31+
tile_width=16,
32+
tile_height=16,
33+
)
2634

2735
# Create a Group to hold the sprite and add it
2836
sprite_group = displayio.Group()

Tilemap_Game_With_CircuitPython/code.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
from adafruit_display_text import label
1111
from tilegame_assets.tiles import TILES
1212
from tilegame_assets.tiles import take_item
13-
from tilegame_assets.states import *
13+
from tilegame_assets.states import (
14+
STATE_PLAYING,
15+
STATE_MAPWIN,
16+
STATE_WAITING,
17+
STATE_LOST_SPARKY,
18+
STATE_MINERVA,
19+
)
1420
from tilegame_assets.fun_facts import FACTS
1521
from tilegame_assets.text_helper import wrap_nicely
1622

@@ -76,14 +82,17 @@
7682
def get_tile(coords):
7783
return GAME_STATE["CURRENT_MAP"][coords[0], coords[1]]
7884

85+
7986
# return from TILES dict the tile object with stats and behavior for the tile at the given coords.
8087
def get_tile_obj(coords):
8188
return TILES[GAME_STATE["CURRENT_MAP"][coords[0], coords[1]]]
8289

90+
8391
# check the can_walk property of the tile at the given coordinates
8492
def is_tile_moveable(tile_coords):
8593
return TILES[GAME_STATE["CURRENT_MAP"][tile_coords[0], tile_coords[1]]]["can_walk"]
8694

95+
8796
print("after funcs {}".format(gc.mem_free()))
8897

8998
# display object variable

Tilemap_Game_With_CircuitPython/tilegame_assets/fun_facts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"Circuitpython was initially released July 19, 2017.",
1010
"The displayio module was introducted in Circuipython 4.0. It simplified drawing images and text on screens.",
1111
"The adafruit_dotstar and neopixel libraries make it easy control dazzling addressable RGB LEDs.",
12-
"You can sense human touch on an IO pin with the touchio module."
12+
"You can sense human touch on an IO pin with the touchio module.",
1313
]

Tilemap_Game_With_CircuitPython/tilegame_assets/text_helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ def wrap_nicely(string, max_chars):
44
:param str string: The text to be wrapped.
55
:param int max_chars: The maximum number of characters on a line before wrapping.
66
"""
7-
string = string.replace('\n', '').replace('\r', '') # strip confusing newlines
8-
words = string.split(' ')
7+
string = string.replace("\n", "").replace("\r", "") # strip confusing newlines
8+
words = string.split(" ")
99
the_lines = []
1010
the_line = ""
1111
for w in words:
12-
if len(the_line+' '+w) <= max_chars:
13-
the_line += ' '+w
12+
if len(the_line + " " + w) <= max_chars:
13+
the_line += " " + w
1414
else:
1515
the_lines.append(the_line)
1616
the_line = w
@@ -19,5 +19,5 @@ def wrap_nicely(string, max_chars):
1919
the_lines[0] = the_lines[0][1:]
2020
the_newline = ""
2121
for w in the_lines:
22-
the_newline += '\n'+w
22+
the_newline += "\n" + w
2323
return the_newline

0 commit comments

Comments
 (0)