|
@ -10,6 +10,7 @@ from PIL import Image |
|
|
GREEN = (0, 255, 0) |
|
|
GREEN = (0, 255, 0) |
|
|
RED = (255, 0, 0) |
|
|
RED = (255, 0, 0) |
|
|
BLUE = (0, 0, 255) |
|
|
BLUE = (0, 0, 255) |
|
|
|
|
|
YELLOW = (255, 255, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def abort(msg: str) -> NoReturn: |
|
|
def abort(msg: str) -> NoReturn: |
|
@ -17,12 +18,12 @@ def abort(msg: str) -> NoReturn: |
|
|
sys.exit(1) |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpawnPoint = Tuple[int, int] |
|
|
|
|
|
|
|
|
Point = Tuple[int, int] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_coll_map( |
|
|
def generate_coll_map( |
|
|
in_path: pathlib.Path, width: int, height: int, compress: bool = False |
|
|
in_path: pathlib.Path, width: int, height: int, compress: bool = False |
|
|
) -> Tuple[str, SpawnPoint]: |
|
|
|
|
|
|
|
|
) -> Tuple[str, Point, Point]: |
|
|
png = Image.open(in_path).convert("RGB") |
|
|
png = Image.open(in_path).convert("RGB") |
|
|
if png.width % 8 != 0 or png.height % 8 != 0: |
|
|
if png.width % 8 != 0 or png.height % 8 != 0: |
|
|
abort(f"file '{in_path}' has invalid dimensions (should be multiple of 8)") |
|
|
abort(f"file '{in_path}' has invalid dimensions (should be multiple of 8)") |
|
@ -33,6 +34,7 @@ def generate_coll_map( |
|
|
out_bytes = [] |
|
|
out_bytes = [] |
|
|
bits = [] |
|
|
bits = [] |
|
|
spawn = None |
|
|
spawn = None |
|
|
|
|
|
camera = (0, 0) |
|
|
|
|
|
|
|
|
for y in range(png.height // 8): |
|
|
for y in range(png.height // 8): |
|
|
for x in range(png.width // 8): |
|
|
for x in range(png.width // 8): |
|
@ -46,6 +48,9 @@ def generate_coll_map( |
|
|
elif pixel == BLUE: |
|
|
elif pixel == BLUE: |
|
|
bit = 1 |
|
|
bit = 1 |
|
|
spawn = (x, y) |
|
|
spawn = (x, y) |
|
|
|
|
|
elif pixel == YELLOW: |
|
|
|
|
|
bit = 1 |
|
|
|
|
|
camera = (x, y) |
|
|
else: |
|
|
else: |
|
|
abort(f"unsupported pixel in collision map: {pixel}") |
|
|
abort(f"unsupported pixel in collision map: {pixel}") |
|
|
|
|
|
|
|
@ -63,7 +68,7 @@ def generate_coll_map( |
|
|
if spawn is None: |
|
|
if spawn is None: |
|
|
abort(f"no spawn point located") |
|
|
abort(f"no spawn point located") |
|
|
|
|
|
|
|
|
return format_bytes(out_bytes, width=width), spawn |
|
|
|
|
|
|
|
|
return format_bytes(out_bytes, width=width), spawn, camera |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_bytes(data: bytes, width: int = 16) -> str: |
|
|
def format_bytes(data: bytes, width: int = 16) -> str: |
|
@ -112,7 +117,9 @@ def generate_map(pngfile: str, compress: bool = False) -> None: |
|
|
section = pngpath.name.replace(".png", "") |
|
|
section = pngpath.name.replace(".png", "") |
|
|
|
|
|
|
|
|
collpath = pngpath.parent / pngpath.name.replace(".png", "_coll.png") |
|
|
collpath = pngpath.parent / pngpath.name.replace(".png", "_coll.png") |
|
|
coll_map, spawn = generate_coll_map(collpath, width, height, compress=compress) |
|
|
|
|
|
|
|
|
coll_map, spawn, camera = generate_coll_map( |
|
|
|
|
|
collpath, width, height, compress=compress |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
with open(incpath, "w") as outf: |
|
|
with open(incpath, "w") as outf: |
|
|
outf.write( |
|
|
outf.write( |
|
@ -134,10 +141,13 @@ ASSERT {section}_MAP_SIZE == {section}_WIDTH * {section}_HEIGHT |
|
|
{section}_TILE_PTR: DW {section}_TILES |
|
|
{section}_TILE_PTR: DW {section}_TILES |
|
|
{section}_TILE_SIZE: DB ({section}_TILES_end - {section}_TILES) |
|
|
{section}_TILE_SIZE: DB ({section}_TILES_end - {section}_TILES) |
|
|
{section}_MAP_PTR: DW {section}_MAP |
|
|
{section}_MAP_PTR: DW {section}_MAP |
|
|
|
|
|
{section}_MAP_COLLISION: DW {section}_COLLISION |
|
|
{section}_MAP_WIDTH: DB {width} |
|
|
{section}_MAP_WIDTH: DB {width} |
|
|
{section}_MAP_HEIGHT: DB {height} |
|
|
{section}_MAP_HEIGHT: DB {height} |
|
|
{section}_SPAWN_X: DB {spawn[0]} |
|
|
{section}_SPAWN_X: DB {spawn[0]} |
|
|
{section}_SPAWN_Y: DB {spawn[1]} |
|
|
{section}_SPAWN_Y: DB {spawn[1]} |
|
|
|
|
|
{section}_CAMERA_X: DB {camera[0]} |
|
|
|
|
|
{section}_CAMERA_Y: DB {camera[1]} |
|
|
|
|
|
|
|
|
{section}_MAP:: |
|
|
{section}_MAP:: |
|
|
{map_data} |
|
|
{map_data} |
|
|