106 lines
2.6 KiB
Python
106 lines
2.6 KiB
Python
import pygame
|
|
import time
|
|
|
|
# Oclaim, I know we talked about putting everything
|
|
# in __init__.py and how it's a bad thing, and I
|
|
# will move things at some point, but as of right now,
|
|
# I'm still unsure exactly how I'm supposed to
|
|
# separate all of this.
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
class Game:
|
|
def __init__(self):
|
|
pass
|
|
|
|
def update(self):
|
|
pass
|
|
|
|
def onEvent(self, event):
|
|
pass
|
|
|
|
def close(self):
|
|
pass
|
|
|
|
if __name__ == '__main__':
|
|
screen = pygame.display.set_mode((500, 500))
|
|
anim = AnimatedObject('')
|
|
screen.blit(anim.getFrame(), (0, 0))
|
|
pygame.quit() |