aboutsummaryrefslogtreecommitdiff
path: root/kennel
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-09-15 17:38:02 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-09-15 17:38:02 -0700
commit8ac11eda05e7159a7f762d3396cf7bb8ee51534b (patch)
tree6e1214ceebd209f3829aac73b2dd330452079d84 /kennel
parentf7e7121fce7bd3f7fdabe836955e43b3d194c1c6 (diff)
downloadkennel.hatecomputers.club-8ac11eda05e7159a7f762d3396cf7bb8ee51534b.tar.gz
kennel.hatecomputers.club-8ac11eda05e7159a7f762d3396cf7bb8ee51534b.zip
render the spritesheet spec in the render systemHEADmain
Diffstat (limited to 'kennel')
-rw-r--r--kennel/engine/components/sprite_sheet.py17
-rw-r--r--kennel/engine/entities/cat.py35
2 files changed, 47 insertions, 5 deletions
diff --git a/kennel/engine/components/sprite_sheet.py b/kennel/engine/components/sprite_sheet.py
index 5730085..3a01f5b 100644
--- a/kennel/engine/components/sprite_sheet.py
+++ b/kennel/engine/components/sprite_sheet.py
@@ -18,6 +18,19 @@ class SpriteSpec:
self.end_x = end_x
self.end_y = end_y
+ def to_dict(self) -> dict:
+ return {
+ "ms_per_frame": self.ms_per_frame,
+ "top_x": self.top_x,
+ "top_y": self.top_y,
+ "end_x": self.end_x,
+ "end_y": self.end_y,
+ "frames": self.frames,
+ }
+
+ def __repr__(self) -> str:
+ return f"SpriteSpec(ms_per_frame={self.ms_per_frame}, top_x={self.top_x}, top_y={self.top_y}, end_x={self.end_x}, end_y={self.end_y}, frames={self.frames})"
+
class SpriteSheet(Component):
def __init__(
@@ -44,5 +57,7 @@ class SpriteSheet(Component):
"current_frame": self.current_frame,
"last_update": self.last_update,
"current_state": self.initial_state,
- "state_to_spritespec": self.state_to_spritespec,
+ "state_to_spritespec": {
+ k: v.to_dict() for k, v in self.state_to_spritespec.items()
+ },
}
diff --git a/kennel/engine/entities/cat.py b/kennel/engine/entities/cat.py
index b5a8c6c..c0acfd8 100644
--- a/kennel/engine/entities/cat.py
+++ b/kennel/engine/entities/cat.py
@@ -4,7 +4,7 @@ from enum import Enum
from .entity import Entity, EntityType
-class CatState(Enum):
+class CatState(str, Enum):
IDLE = "IDLE"
FROLICKING = "FROLICKING"
EEPY = "EEPY"
@@ -13,20 +13,47 @@ class CatState(Enum):
CHASING_CAT = "CHASING_CAT"
SCRATCHING = "SCRATCHING"
ITCHY = "ITCHY"
+ MAKING_BISCUITS = "MAKING_BISCUITS"
+
+
+class CatSpriteState(str, Enum):
+ ALERT = "ALERT"
+ MAKING_BISCUITS = "MAKING_BISCUITS"
class Cat(Entity):
def __init__(self, id: str, spritesheet_source: str):
state_to_spritespec = self.get_state_to_spritespec()
components = [
- Position(0, 0),
- SpriteSheet(spritesheet_source, state_to_spritespec, CatState.ALERT),
+ Position(50, 50),
+ SpriteSheet(
+ spritesheet_source, state_to_spritespec, CatSpriteState.MAKING_BISCUITS
+ ),
]
super().__init__(EntityType.CAT, id, components)
def get_state_to_spritespec(self):
- return {CatState.ALERT: SpriteSpec(100, 0, 0, 200, 40, 5)}
+ creature_width = 32
+ creature_height = 32
+ return {
+ CatSpriteState.ALERT: SpriteSpec(
+ 100,
+ creature_width * 7,
+ creature_height * 3,
+ creature_width * 8,
+ creature_height * 4,
+ 1,
+ ),
+ CatSpriteState.MAKING_BISCUITS: SpriteSpec(
+ 300,
+ 0,
+ 0,
+ creature_width,
+ creature_height * 2,
+ 2,
+ ),
+ }
#