diff options
Diffstat (limited to 'kennel/engine')
| -rw-r--r-- | kennel/engine/components/component.py | 1 | ||||
| -rw-r--r-- | kennel/engine/components/sprite_sheet.py | 48 | ||||
| -rw-r--r-- | kennel/engine/entities/cat.py | 35 |
3 files changed, 72 insertions, 12 deletions
diff --git a/kennel/engine/components/component.py b/kennel/engine/components/component.py index 90506b9..7fd7757 100644 --- a/kennel/engine/components/component.py +++ b/kennel/engine/components/component.py @@ -6,6 +6,7 @@ class ComponentType(str, Enum): POSITION = "POSITION" CONTROLLABLE = "CONTROLLABLE" MARKOV = "MARKOV" + SPRITESHEET = "SPRITESHEET" class Component: diff --git a/kennel/engine/components/sprite_sheet.py b/kennel/engine/components/sprite_sheet.py new file mode 100644 index 0000000..5730085 --- /dev/null +++ b/kennel/engine/components/sprite_sheet.py @@ -0,0 +1,48 @@ +from .component import Component, ComponentType + + +class SpriteSpec: + def __init__( + self, + ms_per_frame: int, + top_x: int, + top_y: int, + end_x: int, + end_y: int, + frames: int, + ): + self.ms_per_frame = ms_per_frame + self.frames = frames + self.top_x = top_x + self.top_y = top_y + self.end_x = end_x + self.end_y = end_y + + +class SpriteSheet(Component): + def __init__( + self, + source: str, + state_to_spritespec: dict[str, SpriteSpec], + initial_state: str, + ): + super().__init__(ComponentType.SPRITESHEET) + self.source = source + self.state_to_spritespec = state_to_spritespec + + # these are only really used for client initialization + self.initial_state = initial_state + self.current_frame = 0 + self.last_update = 0 + + def __repr__(self) -> str: + return f"SpriteSheet(source={self.source}, state_to_spritespec={self.state_to_spritespec}, initial_state={self.initial_state}, current_frame={self.current_frame}, last_update={self.last_update})" + + def to_dict(self) -> dict: + return { + "source": self.source, + "current_frame": self.current_frame, + "last_update": self.last_update, + "current_state": self.initial_state, + "state_to_spritespec": self.state_to_spritespec, + } diff --git a/kennel/engine/entities/cat.py b/kennel/engine/entities/cat.py index edcde37..b5a8c6c 100644 --- a/kennel/engine/entities/cat.py +++ b/kennel/engine/entities/cat.py @@ -1,14 +1,33 @@ from kennel.engine.components.position import Position - +from kennel.engine.components.sprite_sheet import SpriteSheet, SpriteSpec +from enum import Enum from .entity import Entity, EntityType +class CatState(Enum): + IDLE = "IDLE" + FROLICKING = "FROLICKING" + EEPY = "EEPY" + ALERT = "ALERT" + CHASING_CURSOR = "CHASING_CURSOR" + CHASING_CAT = "CHASING_CAT" + SCRATCHING = "SCRATCHING" + ITCHY = "ITCHY" + + class Cat(Entity): - def __init__(self, id: str): - components = [Position(0, 0)] + 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), + ] super().__init__(EntityType.CAT, id, components) + def get_state_to_spritespec(self): + return {CatState.ALERT: SpriteSpec(100, 0, 0, 200, 40, 5)} + # # # IDLE, FROLICKING, EEPY, ALERT, CHASING_CURSOR, CHASING_CAT, SCRATCHING, ITCHY @@ -32,14 +51,6 @@ class Cat(Entity): # ] # # -# class CatState(Enum): -# IDLE = 0 -# FROLICKING = 1 -# EEPY = 2 -# ALERT = 3 -# CHASING_CURSOR = 4 -# CHASING_CAT = 5 -# SCRATCHING = 6 -# ITCHY = 7 + # # |
