Added game objects separate from sprite objects

This commit is contained in:
duckduckdoof 2025-02-04 14:36:55 -05:00
parent 82fb51ba3f
commit ac5bf2f757
6 changed files with 198 additions and 4 deletions

0
lib/engine/__init__.py Normal file
View file

128
lib/engine/game_objects.py Normal file
View file

@ -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)

0
lib/scene/__init__.py Normal file
View file

View file

@ -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

View file

@ -33,6 +33,37 @@
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":20,
"id":12,
"name":"Foundation",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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":[
{

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.1" orientation="orthogonal" renderorder="right-up" width="30" height="20" tilewidth="32" tileheight="32" infinite="0" nextlayerid="12" nextobjectid="3">
<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-up" width="30" height="20" tilewidth="32" tileheight="32" infinite="0" nextlayerid="13" nextobjectid="3">
<editorsettings>
<export target="default-map.json" format="json"/>
</editorsettings>
@ -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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