From ac5bf2f7576c7a933ddc1c94bf04f1e7acee1691 Mon Sep 17 00:00:00 2001 From: duckduckdoof Date: Tue, 4 Feb 2025 14:36:55 -0500 Subject: [PATCH] Added game objects separate from sprite objects --- lib/engine/__init__.py | 0 lib/engine/game_objects.py | 128 ++++++++++++++++++++++++++++++++++ lib/scene/__init__.py | 0 maps/colony-sim.tiled-session | 13 +++- maps/default-map.json | 35 +++++++++- maps/default-map.tmx | 26 ++++++- 6 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 lib/engine/__init__.py create mode 100644 lib/engine/game_objects.py create mode 100644 lib/scene/__init__.py diff --git a/lib/engine/__init__.py b/lib/engine/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/engine/game_objects.py b/lib/engine/game_objects.py new file mode 100644 index 0000000..bba965a --- /dev/null +++ b/lib/engine/game_objects.py @@ -0,0 +1,128 @@ +""" +game_objects.py + +author: Caleb Scott + +All game objects used in the game engine. These objects are designed +to work separately from Arcade's sprite objects, providing abstraction +between the game scene/rendering and game logic/objects. +""" + +# IMPORTS ----------------------------------------------------------- + +import math + +# CONSTANTS --------------------------------------------------------- + +MANPOWER = "Manpower" +WATER = "Water" +METALS = "Metals" +ROCKS = "Rocks" +WOOD = "Wood" +POWER = "Power" + +# CLASSES ----------------------------------------------------------- + +## Base Game object superclass +class GameObject: + + def __init__(self, name): + self.name = name + +## LAYER: Structures +## Superclasses +class Storage(GameObject): + + def __init__(self, name, resource_type, capacity, current_amount=0.0): + self.capacity = capacity + self.resource_type = resource_type + self.current_amount = current_amount + super().__init__(name) + +class Producer(GameObject): + + def __init__(self, name, production_rate): + self.production_rate = production_rate + super().__init__(name) + +## Subclasses: Junction +class Junction(GameObject): + + def __init__(self): + super().__init__("Junction") + +## Subclasses: Storage +class Housing(Storage): + + def __init__(self): + super().__init__("Housing", MANPOWER, 20.0) + +class WaterTower(Storage): + + def __init__(self): + super().__init__("WaterTower", WATER, 600.0) + +class Capacitor(Storage): + + def __init__(self): + super().__init__("Capacitor", POWER, 100.0) + +class Silo(Storage): + + ## These storage containers hold wood, metals, or rocks + def __init__(self, resource_type): + super().__init__("Silo", resource_type, 100.0) + +## Subclasses: Producers +class HydroPower(Producer): + + def __init__(self): + super().__init__("HydroPower", 0.0) + +class Sawmill(Producer): + + def __init__(self): + super().__init__("Sawmill", 0.0) + +class Mine(Producer): + + def __init__(self): + super().__init__("Mine", 0.0) + +class Quarry(Producer): + + def __init__(self): + super().__init__("Quarry", 0.0) + + +## LAYER: Foundations +class Foundation(GameObject): + + def __init__(self): + super().__init__("Foundation") + +## LAYER: Environment +class Water(Storage): + + def __init__(self): + super().__init__("Water", WATER, math.inf, math.inf) + +class Ground(GameObject): + + def __init__(self): + super().__init__("Ground") + +class Trees(Storage): + + def __init__(self): + super().__init__("Trees", WOOD, 500.0, 500.0) + +class Metals(Storage): + + def __init__(self): + super().__init__("Metals", METALS, 500.0, 500.0) + +class Rocks(Storage): + + def __init__(self): + super().__init__("Rocks", ROCKS, 500.0, 500.0) \ No newline at end of file diff --git a/lib/scene/__init__.py b/lib/scene/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/maps/colony-sim.tiled-session b/maps/colony-sim.tiled-session index e8717b0..629df53 100644 --- a/maps/colony-sim.tiled-session +++ b/maps/colony-sim.tiled-session @@ -8,7 +8,16 @@ ], "fileStates": { "bulidings.tsx": { - "dynamicWrapping": true + "dynamicWrapping": true, + "scaleInEditor": 1 + }, + "default-map.json": { + "scale": 0.938125, + "selectedLayer": 0, + "viewCenter": { + "x": 480.2131912058628, + "y": 320.3197868087942 + } }, "world-tiles.tsx": { "dynamicWrapping": false @@ -23,6 +32,8 @@ ], "project": "colony-sim.tiled-project", "recentFiles": [ + "bulidings.tsx", + "default-map.json" ], "tileset.lastUsedFormat": "tsx", "tileset.type": 1 diff --git a/maps/default-map.json b/maps/default-map.json index 358725b..1568ee1 100644 --- a/maps/default-map.json +++ b/maps/default-map.json @@ -33,6 +33,37 @@ "x":0, "y":0 }, + { + "data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, 0, 0, 0, 0, 0, 0, 0, 0, @@ -64,11 +95,11 @@ "x":0, "y":0 }], - "nextlayerid":12, + "nextlayerid":13, "nextobjectid":3, "orientation":"orthogonal", "renderorder":"right-up", - "tiledversion":"1.11.1", + "tiledversion":"1.11.2", "tileheight":32, "tilesets":[ { diff --git a/maps/default-map.tmx b/maps/default-map.tmx index db14187..43f5bb7 100644 --- a/maps/default-map.tmx +++ b/maps/default-map.tmx @@ -1,5 +1,5 @@ - + @@ -27,6 +27,30 @@ 3,4,4,4,4,4,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3, 3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,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