diff options
author | Roman Gräf <romangraef@loves.dicksinhisan.us> | 2020-08-19 23:12:42 +0200 |
---|---|---|
committer | Roman Gräf <romangraef@loves.dicksinhisan.us> | 2020-08-19 23:14:06 +0200 |
commit | cc0fc4424363fcc2ccdbc8b0854b20147a2dd335 (patch) | |
tree | b6bc647e47fb44faecec38d056f15a9ed207b7f4 /riseoftodmoldren | |
parent | 37c533ae65e414ac43f3e1eb3ee04fe1760cdd46 (diff) | |
download | Rise-of-Todmoldren-cc0fc4424363fcc2ccdbc8b0854b20147a2dd335.tar.gz Rise-of-Todmoldren-cc0fc4424363fcc2ccdbc8b0854b20147a2dd335.tar.bz2 Rise-of-Todmoldren-cc0fc4424363fcc2ccdbc8b0854b20147a2dd335.zip |
base engine rework
Diffstat (limited to 'riseoftodmoldren')
32 files changed, 174 insertions, 0 deletions
diff --git a/riseoftodmoldren/__init__.py b/riseoftodmoldren/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/riseoftodmoldren/__init__.py diff --git a/riseoftodmoldren/__main__.py b/riseoftodmoldren/__main__.py new file mode 100644 index 0000000..32e5622 --- /dev/null +++ b/riseoftodmoldren/__main__.py @@ -0,0 +1,4 @@ +from .app import TheRiseOfTodmoldren + +if __name__ == '__main__': + TheRiseOfTodmoldren().run() diff --git a/riseoftodmoldren/app.py b/riseoftodmoldren/app.py new file mode 100644 index 0000000..76ad43e --- /dev/null +++ b/riseoftodmoldren/app.py @@ -0,0 +1,19 @@ +import pygame + +from .base import StateApp +from .screens.start import StartScreen + + +class TheRiseOfTodmoldren(StateApp): + name = "The Rise Of Todmoldren" + size = (1280, 720) + + def __init__(self): + super().__init__() + + if not pygame.image.get_extended(): + raise SystemExit("Sorry, extended image module required") + + def on_init(self): + super().on_init() + self.push_state(StartScreen()) 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') diff --git a/riseoftodmoldren/base.py b/riseoftodmoldren/base.py new file mode 100644 index 0000000..c3549e5 --- /dev/null +++ b/riseoftodmoldren/base.py @@ -0,0 +1,96 @@ +import typing + +import pygame +from pygame.event import Event + + +class BaseApp: + name: str + size: typing.Tuple[int, int] + + def __init__(self): + self.paused = False + self.weight, self.height = self.size + self.screen_rect = pygame.Rect(0, 0, *self.size) + self.screen: pygame.SurfaceType = None + self.should_close = False + self.initialized = False + + def on_init(self): + if self.initialized: + return + self.initialized = True + pygame.init() + pygame.display.set_caption(self.name) + self.screen = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF) + + def pull_events(self): + for event in pygame.event.get(): + self.on_event(event) + + def on_event(self, event): + pass + + def on_update(self): + pass + + def on_render(self): + pass + + def on_cleanup(self): + pass + + def run(self): + self.on_init() + while not self.should_close: + self.pull_events() + self.on_update() + self.on_render() + pygame.display.flip() + self.on_cleanup() + pygame.quit() + + +class State: + def on_event(self, app: 'StateApp', event): + pass + + def on_update(self, app: 'StateApp'): + pass + + def on_render(self, app: 'StateApp'): + pass + + def on_start(self, app: 'StateApp'): + pass + + +class StateApp(BaseApp): + + def __init__(self): + super().__init__() + self.states: typing.List[State] = [] + + def on_event(self, event): + self.states[-1].on_event(self, event) + + def on_start(self): + self.states[-1].on_start(self) + + def on_update(self): + self.states[-1].on_update(self) + + def on_render(self): + self.states[-1].on_render(self) + + def push_state(self, state: State): + self.states.append(state) + self.on_start() + + def replace_state(self, new_state: State): + self.states[-1] = new_state + self.on_start() + + def pop_state(self): + self.states.pop() + self.on_start() diff --git a/riseoftodmoldren/res/castle1.gif b/riseoftodmoldren/res/castle1.gif Binary files differnew file mode 100644 index 0000000..7867d71 --- /dev/null +++ b/riseoftodmoldren/res/castle1.gif diff --git a/riseoftodmoldren/res/cave1.gif b/riseoftodmoldren/res/cave1.gif Binary files differnew file mode 100644 index 0000000..608cfad --- /dev/null +++ b/riseoftodmoldren/res/cave1.gif diff --git a/riseoftodmoldren/res/cave2.gif b/riseoftodmoldren/res/cave2.gif Binary files differnew file mode 100644 index 0000000..09aba2a --- /dev/null +++ b/riseoftodmoldren/res/cave2.gif diff --git a/riseoftodmoldren/res/cave3.gif b/riseoftodmoldren/res/cave3.gif Binary files differnew file mode 100644 index 0000000..bbf4a74 --- /dev/null +++ b/riseoftodmoldren/res/cave3.gif diff --git a/riseoftodmoldren/res/cave_enternace.gif b/riseoftodmoldren/res/cave_enternace.gif Binary files differnew file mode 100644 index 0000000..5ff3aaf --- /dev/null +++ b/riseoftodmoldren/res/cave_enternace.gif diff --git a/riseoftodmoldren/res/cave_exit.gif b/riseoftodmoldren/res/cave_exit.gif Binary files differnew file mode 100644 index 0000000..d12e383 --- /dev/null +++ b/riseoftodmoldren/res/cave_exit.gif diff --git a/riseoftodmoldren/res/chest1.gif b/riseoftodmoldren/res/chest1.gif Binary files differnew file mode 100644 index 0000000..6adbae9 --- /dev/null +++ b/riseoftodmoldren/res/chest1.gif diff --git a/riseoftodmoldren/res/chest2.gif b/riseoftodmoldren/res/chest2.gif Binary files differnew file mode 100644 index 0000000..9200cc8 --- /dev/null +++ b/riseoftodmoldren/res/chest2.gif diff --git a/riseoftodmoldren/res/d_sword.gif b/riseoftodmoldren/res/d_sword.gif Binary files differnew file mode 100644 index 0000000..57ab08a --- /dev/null +++ b/riseoftodmoldren/res/d_sword.gif diff --git a/riseoftodmoldren/res/d_sword2.gif b/riseoftodmoldren/res/d_sword2.gif Binary files differnew file mode 100644 index 0000000..5dc41ac --- /dev/null +++ b/riseoftodmoldren/res/d_sword2.gif diff --git a/riseoftodmoldren/res/d_sword_icon.gif b/riseoftodmoldren/res/d_sword_icon.gif Binary files differnew file mode 100644 index 0000000..71e2dcd --- /dev/null +++ b/riseoftodmoldren/res/d_sword_icon.gif diff --git a/riseoftodmoldren/res/forest1.gif b/riseoftodmoldren/res/forest1.gif Binary files differnew file mode 100644 index 0000000..bef0017 --- /dev/null +++ b/riseoftodmoldren/res/forest1.gif diff --git a/riseoftodmoldren/res/forest2.gif b/riseoftodmoldren/res/forest2.gif Binary files differnew file mode 100644 index 0000000..bfd4d6b --- /dev/null +++ b/riseoftodmoldren/res/forest2.gif diff --git a/riseoftodmoldren/res/forest3.gif b/riseoftodmoldren/res/forest3.gif Binary files differnew file mode 100644 index 0000000..c8166dc --- /dev/null +++ b/riseoftodmoldren/res/forest3.gif diff --git a/riseoftodmoldren/res/forest4.gif b/riseoftodmoldren/res/forest4.gif Binary files differnew file mode 100644 index 0000000..1e2df0d --- /dev/null +++ b/riseoftodmoldren/res/forest4.gif diff --git a/riseoftodmoldren/res/forest5.gif b/riseoftodmoldren/res/forest5.gif Binary files differnew file mode 100644 index 0000000..92d988e --- /dev/null +++ b/riseoftodmoldren/res/forest5.gif diff --git a/riseoftodmoldren/res/forest6.gif b/riseoftodmoldren/res/forest6.gif Binary files differnew file mode 100644 index 0000000..c013c24 --- /dev/null +++ b/riseoftodmoldren/res/forest6.gif diff --git a/riseoftodmoldren/res/forest7.gif b/riseoftodmoldren/res/forest7.gif Binary files differnew file mode 100644 index 0000000..54fefa6 --- /dev/null +++ b/riseoftodmoldren/res/forest7.gif diff --git a/riseoftodmoldren/res/forest8.gif b/riseoftodmoldren/res/forest8.gif Binary files differnew file mode 100644 index 0000000..7430d09 --- /dev/null +++ b/riseoftodmoldren/res/forest8.gif diff --git a/riseoftodmoldren/res/heal_potion_icon.gif b/riseoftodmoldren/res/heal_potion_icon.gif Binary files differnew file mode 100644 index 0000000..0013ccf --- /dev/null +++ b/riseoftodmoldren/res/heal_potion_icon.gif diff --git a/riseoftodmoldren/res/menu1.gif b/riseoftodmoldren/res/menu1.gif Binary files differnew file mode 100644 index 0000000..fec6da6 --- /dev/null +++ b/riseoftodmoldren/res/menu1.gif diff --git a/riseoftodmoldren/res/menu2.gif b/riseoftodmoldren/res/menu2.gif Binary files differnew file mode 100644 index 0000000..79a7dfb --- /dev/null +++ b/riseoftodmoldren/res/menu2.gif diff --git a/riseoftodmoldren/res/sack.gif b/riseoftodmoldren/res/sack.gif Binary files differnew file mode 100644 index 0000000..b9ace16 --- /dev/null +++ b/riseoftodmoldren/res/sack.gif diff --git a/riseoftodmoldren/res/sword.gif b/riseoftodmoldren/res/sword.gif Binary files differnew file mode 100644 index 0000000..20b7418 --- /dev/null +++ b/riseoftodmoldren/res/sword.gif diff --git a/riseoftodmoldren/res/sword2.gif b/riseoftodmoldren/res/sword2.gif Binary files differnew file mode 100644 index 0000000..6f5de1b --- /dev/null +++ b/riseoftodmoldren/res/sword2.gif diff --git a/riseoftodmoldren/res/towel_icon.gif b/riseoftodmoldren/res/towel_icon.gif Binary files differnew file mode 100644 index 0000000..52e64d5 --- /dev/null +++ b/riseoftodmoldren/res/towel_icon.gif diff --git a/riseoftodmoldren/screens/start.py b/riseoftodmoldren/screens/start.py new file mode 100644 index 0000000..cc33a47 --- /dev/null +++ b/riseoftodmoldren/screens/start.py @@ -0,0 +1,17 @@ +from ..base import State, StateApp + + +class StartScreen(State): + def __init__(self): + self.background = None + + def on_start(self, app: 'StateApp'): + if self.background is None: + from .. import assets + self.background = assets.MENU2.as_tiled_surface(app.screen_rect) + + def on_event(self, app: 'StateApp', event): + pass + + def on_render(self, app: 'StateApp'): + app.screen.blit(self.background, (0, 0)) |