From cc0fc4424363fcc2ccdbc8b0854b20147a2dd335 Mon Sep 17 00:00:00 2001 From: Roman Gräf Date: Wed, 19 Aug 2020 23:12:42 +0200 Subject: base engine rework --- riseoftodmoldren/assets.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 riseoftodmoldren/assets.py (limited to 'riseoftodmoldren/assets.py') diff --git a/riseoftodmoldren/assets.py b/riseoftodmoldren/assets.py new file mode 100644 index 0000000..4d567a7 --- /dev/null +++ b/riseoftodmoldren/assets.py @@ -0,0 +1,38 @@ +import pathlib + +import pygame + +asset_base = pathlib.Path(__file__).parent.absolute() / 'res' + + +class ImageAsset: + def __init__(self, path: str): + self.internal = pygame.image.load(path) + self.internal.convert() + + @classmethod + def load(cls, name: str) -> 'ImageAsset': + asset_path = asset_base / name + return cls(str(asset_path)) + + def as_tiled_surface(self, size: pygame.Rect) -> pygame.SurfaceType: + surface = pygame.Surface(size.size) + for x in range(0, size.width, self.internal.get_width()): + for y in range(0, size.height, self.internal.get_height()): + surface.blit(self.internal, (x, y)) + return surface + + +class SoundAsset: + def __init__(self, path: str): + if not pygame.mixer: + return + self.internal = pygame.mixer.Sound(path) + + @classmethod + def load(cls, name: str) -> 'SoundAsset': + asset_path = asset_base / name + return cls(str(asset_path)) + + +MENU2 = ImageAsset.load('menu2.gif') -- cgit