summaryrefslogtreecommitdiff
path: root/riseoftodmoldren/assets.py
diff options
context:
space:
mode:
authorRoman Gräf <romangraef@loves.dicksinhisan.us>2020-08-19 23:12:42 +0200
committerRoman Gräf <romangraef@loves.dicksinhisan.us>2020-08-19 23:14:06 +0200
commitcc0fc4424363fcc2ccdbc8b0854b20147a2dd335 (patch)
treeb6bc647e47fb44faecec38d056f15a9ed207b7f4 /riseoftodmoldren/assets.py
parent37c533ae65e414ac43f3e1eb3ee04fe1760cdd46 (diff)
downloadRise-of-Todmoldren-cc0fc4424363fcc2ccdbc8b0854b20147a2dd335.tar.gz
Rise-of-Todmoldren-cc0fc4424363fcc2ccdbc8b0854b20147a2dd335.tar.bz2
Rise-of-Todmoldren-cc0fc4424363fcc2ccdbc8b0854b20147a2dd335.zip
base engine rework
Diffstat (limited to 'riseoftodmoldren/assets.py')
-rw-r--r--riseoftodmoldren/assets.py38
1 files changed, 38 insertions, 0 deletions
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')