From d9ce3fd3ab7abea637a75c82078144f09c5d8b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Sun, 7 Apr 2024 01:38:06 +0500 Subject: [PATCH] Start making this thing into an actual game engine. --- games/squareroom/__init__.py | 11 +++++++++++ games/squareroom/squareroom.json | 1 + main.py | 7 +++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 games/squareroom/__init__.py create mode 100644 games/squareroom/squareroom.json diff --git a/games/squareroom/__init__.py b/games/squareroom/__init__.py new file mode 100644 index 0000000..79485b1 --- /dev/null +++ b/games/squareroom/__init__.py @@ -0,0 +1,11 @@ +import importlib.resources as impr +import sys +import json + +def init(serialize): + curm = sys.modules[__name__] + files = impr.files(curm) + level = None + with files.joinpath("squareroom.json").open('r') as leveldir: + level = json.loads(leveldir.read(), object_hook=serialize.object_hook) + return level diff --git a/games/squareroom/squareroom.json b/games/squareroom/squareroom.json new file mode 100644 index 0000000..5c94cc5 --- /dev/null +++ b/games/squareroom/squareroom.json @@ -0,0 +1 @@ +[{"__type__": "objSegment", "isFinite": true, "pointA": {"__type__": "complex", "real": 0.6, "imag": 0.0}, "pointB": {"__type__": "complex", "real": 0.0, "imag": 0.6}, "color": [255, 0, 0]}, {"__type__": "objSegment", "isFinite": true, "pointA": {"__type__": "complex", "real": 0.6, "imag": 0.0}, "pointB": {"__type__": "complex", "real": 0.0, "imag": -0.6}, "color": [0, 255, 0]}, {"__type__": "objSegment", "isFinite": true, "pointA": {"__type__": "complex", "real": -0.6, "imag": 0.0}, "pointB": {"__type__": "complex", "real": 0.0, "imag": -0.6}, "color": [0, 0, 255]}, {"__type__": "objSegment", "isFinite": true, "pointA": {"__type__": "complex", "real": -0.6, "imag": 0.0}, "pointB": {"__type__": "complex", "real": 0.0, "imag": 0.6}, "color": [255, 255, 0]}] \ No newline at end of file diff --git a/main.py b/main.py index 5fe1596..c8ac338 100755 --- a/main.py +++ b/main.py @@ -11,6 +11,7 @@ from levels import open_level, save_level, make_wall from constants import I, WHITE, BLACK, IROT, ROT, OFFSET from draw import draw from alert import Alert +from importlib import import_module gOrigin = GyroVector(0,1) @@ -113,9 +114,11 @@ def mainLoop(): alert.start_hide_thread(alerts, delay) try: - level = open_level(sys.argv[1]) + game = import_module(sys.argv[1]) except IndexError: - level = open_level("maps/squareroom.json") + game = import_module("games.squareroom") + + level = game.init(import_module('serialize')) while bCont: aoEngineEvents = fvControl_ao()