From 007549dca743054e50032682324e54f39c6744fa Mon Sep 17 00:00:00 2001 From: EasyJBL Date: Thu, 19 Jan 2023 00:08:25 +0100 Subject: [PATCH] LNX-64 Bmp map parsing --- requirements.txt | 3 ++- src/init_files/config.json | 7 ++++++ src/maps/map1.bmp | Bin 0 -> 222 bytes src/scene.py | 50 ++++++++++++++++++------------------- 4 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 src/init_files/config.json create mode 100644 src/maps/map1.bmp diff --git a/requirements.txt b/requirements.txt index d636e90..9fe4d43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pytest==7.2.0 -transitions==0.9.0 \ No newline at end of file +transitions==0.9.0 +pillow==9.0 \ No newline at end of file diff --git a/src/init_files/config.json b/src/init_files/config.json new file mode 100644 index 0000000..4fc5fc1 --- /dev/null +++ b/src/init_files/config.json @@ -0,0 +1,7 @@ +{ + "floor_colour": "(34, 177, 76)", + "functions" : [ + {"(0, 0, 0)" : "TrainingDummy"}, + {"(237, 28, 36)" : "Portal"}, + {"(255, 201, 14)" : "self._init_agent"} ] + } \ No newline at end of file diff --git a/src/maps/map1.bmp b/src/maps/map1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..038260a459f3fc56a1ba18fa6cbb460039fe5998 GIT binary patch literal 222 zcmZ?ry~h9nWTB!DCX!wMii%m=|>0U+VCQ3)4<%3)Q6MW2eyTZl None: self._objects_id_map = {} self.agent_locals = {} self.runtime = runtime - - self._generate_scene_small() - - self.__player = Agent(self) + self._generate_scene() + self.__player = None def _generate_scene_small(self): """ Small scene for tests """ points = [Point(0, 0), Point(0, 1), Point(1, 0), Point(1, 1), Point(0, 2), Point(1, 2)] - for point in points: Floor(self, point) - #Portal(self, random.choice(points)) #TrainingDummy(self, Point(1, 0)) @@ -49,24 +45,23 @@ def _generate_scene(self): For now it'll generate scene layout Subject to be changed """ - STEPS = 20 - pos = Point(0, 0) - points = [pos] - for _ in range(STEPS): - pos += Point(random.choice([-1, 0, 1]), random.choice([-1, 0, 1])) - points.append(pos) - points.append(pos + Point(-1, 0)) - points.append(pos + Point(1, 0)) - points.append(pos + Point(0, -1)) - points.append(pos + Point(0, 1)) - - points = list(dict.fromkeys(points)) # remove duplicates - - for point in points: - Floor(self, point) - Portal(self, random.choice(points)) - TrainingDummy(self, Point(1, 0)) + with open(PATH_TO_CONFIG) as json_file: + config = json.load(json_file) + floor_colour = config["floor_colour"] + colour_to_function_dict = {} + for dict_row in config["functions"]: + colour_to_function_dict.update(dict_row) + map = Image.open("./src/maps/map1.bmp") + image_width, image_height = map.size + for width in range(image_width): + for height in range(image_height): + pixel_colour = str(map.getpixel((width, height))) + if pixel_colour in colour_to_function_dict or pixel_colour == floor_colour: + Floor(self, Point(width, height)) + if pixel_colour != floor_colour: + eval(colour_to_function_dict[pixel_colour])(self, Point(width, height)) + map.close() def run(self): """ @@ -144,3 +139,6 @@ def add_object_to_id_map(self, new_object: Object) -> None: Add object to per scene storage indexed by objects `id`. """ self._objects_id_map[new_object.properties.id] = new_object + + def _init_agent(self, _, points): + self.__player = Agent(self, points) \ No newline at end of file