Started separating everything away from __init__

This commit is contained in:
2025-06-19 21:23:22 +01:00
parent 86c0230b26
commit e97d55fbc3
4 changed files with 31 additions and 40 deletions

4
src/__init__.py Normal file
View File

@ -0,0 +1,4 @@
from .base import Game
from .utils import centre
from .anim import AnimatedHandler
from .anim import AnimatedObject

67
src/anim.py Normal file
View File

@ -0,0 +1,67 @@
import pygame
class AnimationHandler(pygame.Surface):
"""
TODO: Write documentation on this, it takes in a
webp file, and handles drawing it to the screen in
a way that doesn't rely on frame counters.
"""
def __init__(self, animationPath):
pass
class AnimatedObject:
"""
"""
def __init__(self, baseFrame):
"""
Args:
baseFrame: A still image that gets displayed when no other animation is playing.
"""
self._currentAnim = None
self._animStart = None
self._animations = {}
#self.baseFrame = pygame.image.load(baseFrame)
def getFrame(self) -> pygame.Surface:
"""
Gets the current frame based on which animation is playing, and the current time.
Returns:
pygame.Surface: The current frame
"""
def addAnimation(self, animation: AnimationHandler, animationID: str):
"""
Adds an animation to the object.
Args:
animation (AnimationHandler): The actual animation.
animationID (str): The ID that's later used to play the animation.
"""
self.animations.update({animationID: animation})
def playAnim(self, animationID: str):
"""
Plays an animation.
Args:
animationID (str): The animation ID to play.
"""
self._animStart = time.perf_counter()
self._currentAnim = self._animations[animationID]
def get_view(self):
print(f'get_view called')
return super().get_view()
def get_buffer(self):
print(f'get_buffer called')
return super().get_buffer()
def copy(self):
print(f'copy called')
return super().copy()

12
src/base.py Normal file
View File

@ -0,0 +1,12 @@
class Game:
def __init__(self):
pass
def update(self):
pass
def onEvent(self, event):
pass
def close(self):
pass

14
src/utils.py Normal file
View File

@ -0,0 +1,14 @@
import pygame
def centre(surface: pygame.Surface, rect: tuple[int, int, int, int]) -> pygame.Surface:
"""
Centres a surface within a given rectangle.
Args:
surface: The surface to be centred.
rect: The rectangle the surface will be centred in.
Returns:
pygame.Surface
"""
pass