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 --- Game Test.py | 6 +- castle1.gif | Bin 274812 -> 0 bytes cave1.gif | Bin 73550 -> 0 bytes cave2.gif | Bin 79223 -> 0 bytes cave3.gif | Bin 60235 -> 0 bytes cave_enternace.gif | Bin 245898 -> 0 bytes cave_exit.gif | Bin 94032 -> 0 bytes chest1.gif | Bin 1401 -> 0 bytes chest2.gif | Bin 1463 -> 0 bytes d_sword.gif | Bin 4998 -> 0 bytes d_sword2.gif | Bin 7481 -> 0 bytes d_sword_icon.gif | Bin 1217 -> 0 bytes forest1.gif | Bin 256312 -> 0 bytes forest2.gif | Bin 247560 -> 0 bytes forest3.gif | Bin 263212 -> 0 bytes forest4.gif | Bin 258816 -> 0 bytes forest5.gif | Bin 254847 -> 0 bytes forest6.gif | Bin 258935 -> 0 bytes forest7.gif | Bin 247677 -> 0 bytes forest8.gif | Bin 249470 -> 0 bytes heal_potion_icon.gif | Bin 1370 -> 0 bytes menu1.gif | Bin 46545 -> 0 bytes menu2.gif | Bin 48953 -> 0 bytes requirements.txt | 1 + riseoftodmoldren/__init__.py | 0 riseoftodmoldren/__main__.py | 4 ++ riseoftodmoldren/app.py | 19 ++++++ riseoftodmoldren/assets.py | 38 ++++++++++++ riseoftodmoldren/base.py | 96 ++++++++++++++++++++++++++++++ riseoftodmoldren/res/castle1.gif | Bin 0 -> 274812 bytes riseoftodmoldren/res/cave1.gif | Bin 0 -> 73550 bytes riseoftodmoldren/res/cave2.gif | Bin 0 -> 79223 bytes riseoftodmoldren/res/cave3.gif | Bin 0 -> 60235 bytes riseoftodmoldren/res/cave_enternace.gif | Bin 0 -> 245898 bytes riseoftodmoldren/res/cave_exit.gif | Bin 0 -> 94032 bytes riseoftodmoldren/res/chest1.gif | Bin 0 -> 1401 bytes riseoftodmoldren/res/chest2.gif | Bin 0 -> 1463 bytes riseoftodmoldren/res/d_sword.gif | Bin 0 -> 4998 bytes riseoftodmoldren/res/d_sword2.gif | Bin 0 -> 7481 bytes riseoftodmoldren/res/d_sword_icon.gif | Bin 0 -> 1217 bytes riseoftodmoldren/res/forest1.gif | Bin 0 -> 256312 bytes riseoftodmoldren/res/forest2.gif | Bin 0 -> 247560 bytes riseoftodmoldren/res/forest3.gif | Bin 0 -> 263212 bytes riseoftodmoldren/res/forest4.gif | Bin 0 -> 258816 bytes riseoftodmoldren/res/forest5.gif | Bin 0 -> 254847 bytes riseoftodmoldren/res/forest6.gif | Bin 0 -> 258935 bytes riseoftodmoldren/res/forest7.gif | Bin 0 -> 247677 bytes riseoftodmoldren/res/forest8.gif | Bin 0 -> 249470 bytes riseoftodmoldren/res/heal_potion_icon.gif | Bin 0 -> 1370 bytes riseoftodmoldren/res/menu1.gif | Bin 0 -> 46545 bytes riseoftodmoldren/res/menu2.gif | Bin 0 -> 48953 bytes riseoftodmoldren/res/sack.gif | Bin 0 -> 1001 bytes riseoftodmoldren/res/sword.gif | Bin 0 -> 4921 bytes riseoftodmoldren/res/sword2.gif | Bin 0 -> 7730 bytes riseoftodmoldren/res/towel_icon.gif | Bin 0 -> 1353 bytes riseoftodmoldren/screens/start.py | 17 ++++++ sack.gif | Bin 1001 -> 0 bytes sword.gif | Bin 4921 -> 0 bytes sword2.gif | Bin 7730 -> 0 bytes towel_icon.gif | Bin 1353 -> 0 bytes 60 files changed, 179 insertions(+), 2 deletions(-) delete mode 100644 castle1.gif delete mode 100644 cave1.gif delete mode 100644 cave2.gif delete mode 100644 cave3.gif delete mode 100644 cave_enternace.gif delete mode 100644 cave_exit.gif delete mode 100644 chest1.gif delete mode 100644 chest2.gif delete mode 100644 d_sword.gif delete mode 100644 d_sword2.gif delete mode 100644 d_sword_icon.gif delete mode 100644 forest1.gif delete mode 100644 forest2.gif delete mode 100644 forest3.gif delete mode 100644 forest4.gif delete mode 100644 forest5.gif delete mode 100644 forest6.gif delete mode 100644 forest7.gif delete mode 100644 forest8.gif delete mode 100644 heal_potion_icon.gif delete mode 100644 menu1.gif delete mode 100644 menu2.gif create mode 100644 requirements.txt create mode 100644 riseoftodmoldren/__init__.py create mode 100644 riseoftodmoldren/__main__.py create mode 100644 riseoftodmoldren/app.py create mode 100644 riseoftodmoldren/assets.py create mode 100644 riseoftodmoldren/base.py create mode 100644 riseoftodmoldren/res/castle1.gif create mode 100644 riseoftodmoldren/res/cave1.gif create mode 100644 riseoftodmoldren/res/cave2.gif create mode 100644 riseoftodmoldren/res/cave3.gif create mode 100644 riseoftodmoldren/res/cave_enternace.gif create mode 100644 riseoftodmoldren/res/cave_exit.gif create mode 100644 riseoftodmoldren/res/chest1.gif create mode 100644 riseoftodmoldren/res/chest2.gif create mode 100644 riseoftodmoldren/res/d_sword.gif create mode 100644 riseoftodmoldren/res/d_sword2.gif create mode 100644 riseoftodmoldren/res/d_sword_icon.gif create mode 100644 riseoftodmoldren/res/forest1.gif create mode 100644 riseoftodmoldren/res/forest2.gif create mode 100644 riseoftodmoldren/res/forest3.gif create mode 100644 riseoftodmoldren/res/forest4.gif create mode 100644 riseoftodmoldren/res/forest5.gif create mode 100644 riseoftodmoldren/res/forest6.gif create mode 100644 riseoftodmoldren/res/forest7.gif create mode 100644 riseoftodmoldren/res/forest8.gif create mode 100644 riseoftodmoldren/res/heal_potion_icon.gif create mode 100644 riseoftodmoldren/res/menu1.gif create mode 100644 riseoftodmoldren/res/menu2.gif create mode 100644 riseoftodmoldren/res/sack.gif create mode 100644 riseoftodmoldren/res/sword.gif create mode 100644 riseoftodmoldren/res/sword2.gif create mode 100644 riseoftodmoldren/res/towel_icon.gif create mode 100644 riseoftodmoldren/screens/start.py delete mode 100644 sack.gif delete mode 100644 sword.gif delete mode 100644 sword2.gif delete mode 100644 towel_icon.gif diff --git a/Game Test.py b/Game Test.py index a03ce50..4efee38 100644 --- a/Game Test.py +++ b/Game Test.py @@ -1,7 +1,9 @@ -import turtle -import time +import os import random +import time +import turtle +os.chdir('riseoftodmoldren/res') # Moved assets window = turtle.Screen() window.setup(1280, 720) window.bgcolor("black") diff --git a/castle1.gif b/castle1.gif deleted file mode 100644 index 7867d71..0000000 Binary files a/castle1.gif and /dev/null differ diff --git a/cave1.gif b/cave1.gif deleted file mode 100644 index 608cfad..0000000 Binary files a/cave1.gif and /dev/null differ diff --git a/cave2.gif b/cave2.gif deleted file mode 100644 index 09aba2a..0000000 Binary files a/cave2.gif and /dev/null differ diff --git a/cave3.gif b/cave3.gif deleted file mode 100644 index bbf4a74..0000000 Binary files a/cave3.gif and /dev/null differ diff --git a/cave_enternace.gif b/cave_enternace.gif deleted file mode 100644 index 5ff3aaf..0000000 Binary files a/cave_enternace.gif and /dev/null differ diff --git a/cave_exit.gif b/cave_exit.gif deleted file mode 100644 index d12e383..0000000 Binary files a/cave_exit.gif and /dev/null differ diff --git a/chest1.gif b/chest1.gif deleted file mode 100644 index 6adbae9..0000000 Binary files a/chest1.gif and /dev/null differ diff --git a/chest2.gif b/chest2.gif deleted file mode 100644 index 9200cc8..0000000 Binary files a/chest2.gif and /dev/null differ diff --git a/d_sword.gif b/d_sword.gif deleted file mode 100644 index 57ab08a..0000000 Binary files a/d_sword.gif and /dev/null differ diff --git a/d_sword2.gif b/d_sword2.gif deleted file mode 100644 index 5dc41ac..0000000 Binary files a/d_sword2.gif and /dev/null differ diff --git a/d_sword_icon.gif b/d_sword_icon.gif deleted file mode 100644 index 71e2dcd..0000000 Binary files a/d_sword_icon.gif and /dev/null differ diff --git a/forest1.gif b/forest1.gif deleted file mode 100644 index bef0017..0000000 Binary files a/forest1.gif and /dev/null differ diff --git a/forest2.gif b/forest2.gif deleted file mode 100644 index bfd4d6b..0000000 Binary files a/forest2.gif and /dev/null differ diff --git a/forest3.gif b/forest3.gif deleted file mode 100644 index c8166dc..0000000 Binary files a/forest3.gif and /dev/null differ diff --git a/forest4.gif b/forest4.gif deleted file mode 100644 index 1e2df0d..0000000 Binary files a/forest4.gif and /dev/null differ diff --git a/forest5.gif b/forest5.gif deleted file mode 100644 index 92d988e..0000000 Binary files a/forest5.gif and /dev/null differ diff --git a/forest6.gif b/forest6.gif deleted file mode 100644 index c013c24..0000000 Binary files a/forest6.gif and /dev/null differ diff --git a/forest7.gif b/forest7.gif deleted file mode 100644 index 54fefa6..0000000 Binary files a/forest7.gif and /dev/null differ diff --git a/forest8.gif b/forest8.gif deleted file mode 100644 index 7430d09..0000000 Binary files a/forest8.gif and /dev/null differ diff --git a/heal_potion_icon.gif b/heal_potion_icon.gif deleted file mode 100644 index 0013ccf..0000000 Binary files a/heal_potion_icon.gif and /dev/null differ diff --git a/menu1.gif b/menu1.gif deleted file mode 100644 index fec6da6..0000000 Binary files a/menu1.gif and /dev/null differ diff --git a/menu2.gif b/menu2.gif deleted file mode 100644 index 79a7dfb..0000000 Binary files a/menu2.gif and /dev/null differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0cb7ff1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pygame diff --git a/riseoftodmoldren/__init__.py b/riseoftodmoldren/__init__.py new file mode 100644 index 0000000..e69de29 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 new file mode 100644 index 0000000..7867d71 Binary files /dev/null and b/riseoftodmoldren/res/castle1.gif differ diff --git a/riseoftodmoldren/res/cave1.gif b/riseoftodmoldren/res/cave1.gif new file mode 100644 index 0000000..608cfad Binary files /dev/null and b/riseoftodmoldren/res/cave1.gif differ diff --git a/riseoftodmoldren/res/cave2.gif b/riseoftodmoldren/res/cave2.gif new file mode 100644 index 0000000..09aba2a Binary files /dev/null and b/riseoftodmoldren/res/cave2.gif differ diff --git a/riseoftodmoldren/res/cave3.gif b/riseoftodmoldren/res/cave3.gif new file mode 100644 index 0000000..bbf4a74 Binary files /dev/null and b/riseoftodmoldren/res/cave3.gif differ diff --git a/riseoftodmoldren/res/cave_enternace.gif b/riseoftodmoldren/res/cave_enternace.gif new file mode 100644 index 0000000..5ff3aaf Binary files /dev/null and b/riseoftodmoldren/res/cave_enternace.gif differ diff --git a/riseoftodmoldren/res/cave_exit.gif b/riseoftodmoldren/res/cave_exit.gif new file mode 100644 index 0000000..d12e383 Binary files /dev/null and b/riseoftodmoldren/res/cave_exit.gif differ diff --git a/riseoftodmoldren/res/chest1.gif b/riseoftodmoldren/res/chest1.gif new file mode 100644 index 0000000..6adbae9 Binary files /dev/null and b/riseoftodmoldren/res/chest1.gif differ diff --git a/riseoftodmoldren/res/chest2.gif b/riseoftodmoldren/res/chest2.gif new file mode 100644 index 0000000..9200cc8 Binary files /dev/null and b/riseoftodmoldren/res/chest2.gif differ diff --git a/riseoftodmoldren/res/d_sword.gif b/riseoftodmoldren/res/d_sword.gif new file mode 100644 index 0000000..57ab08a Binary files /dev/null and b/riseoftodmoldren/res/d_sword.gif differ diff --git a/riseoftodmoldren/res/d_sword2.gif b/riseoftodmoldren/res/d_sword2.gif new file mode 100644 index 0000000..5dc41ac Binary files /dev/null and b/riseoftodmoldren/res/d_sword2.gif differ diff --git a/riseoftodmoldren/res/d_sword_icon.gif b/riseoftodmoldren/res/d_sword_icon.gif new file mode 100644 index 0000000..71e2dcd Binary files /dev/null and b/riseoftodmoldren/res/d_sword_icon.gif differ diff --git a/riseoftodmoldren/res/forest1.gif b/riseoftodmoldren/res/forest1.gif new file mode 100644 index 0000000..bef0017 Binary files /dev/null and b/riseoftodmoldren/res/forest1.gif differ diff --git a/riseoftodmoldren/res/forest2.gif b/riseoftodmoldren/res/forest2.gif new file mode 100644 index 0000000..bfd4d6b Binary files /dev/null and b/riseoftodmoldren/res/forest2.gif differ diff --git a/riseoftodmoldren/res/forest3.gif b/riseoftodmoldren/res/forest3.gif new file mode 100644 index 0000000..c8166dc Binary files /dev/null and b/riseoftodmoldren/res/forest3.gif differ diff --git a/riseoftodmoldren/res/forest4.gif b/riseoftodmoldren/res/forest4.gif new file mode 100644 index 0000000..1e2df0d Binary files /dev/null and b/riseoftodmoldren/res/forest4.gif differ diff --git a/riseoftodmoldren/res/forest5.gif b/riseoftodmoldren/res/forest5.gif new file mode 100644 index 0000000..92d988e Binary files /dev/null and b/riseoftodmoldren/res/forest5.gif differ diff --git a/riseoftodmoldren/res/forest6.gif b/riseoftodmoldren/res/forest6.gif new file mode 100644 index 0000000..c013c24 Binary files /dev/null and b/riseoftodmoldren/res/forest6.gif differ diff --git a/riseoftodmoldren/res/forest7.gif b/riseoftodmoldren/res/forest7.gif new file mode 100644 index 0000000..54fefa6 Binary files /dev/null and b/riseoftodmoldren/res/forest7.gif differ diff --git a/riseoftodmoldren/res/forest8.gif b/riseoftodmoldren/res/forest8.gif new file mode 100644 index 0000000..7430d09 Binary files /dev/null and b/riseoftodmoldren/res/forest8.gif differ diff --git a/riseoftodmoldren/res/heal_potion_icon.gif b/riseoftodmoldren/res/heal_potion_icon.gif new file mode 100644 index 0000000..0013ccf Binary files /dev/null and b/riseoftodmoldren/res/heal_potion_icon.gif differ diff --git a/riseoftodmoldren/res/menu1.gif b/riseoftodmoldren/res/menu1.gif new file mode 100644 index 0000000..fec6da6 Binary files /dev/null and b/riseoftodmoldren/res/menu1.gif differ diff --git a/riseoftodmoldren/res/menu2.gif b/riseoftodmoldren/res/menu2.gif new file mode 100644 index 0000000..79a7dfb Binary files /dev/null and b/riseoftodmoldren/res/menu2.gif differ diff --git a/riseoftodmoldren/res/sack.gif b/riseoftodmoldren/res/sack.gif new file mode 100644 index 0000000..b9ace16 Binary files /dev/null and b/riseoftodmoldren/res/sack.gif differ diff --git a/riseoftodmoldren/res/sword.gif b/riseoftodmoldren/res/sword.gif new file mode 100644 index 0000000..20b7418 Binary files /dev/null and b/riseoftodmoldren/res/sword.gif differ diff --git a/riseoftodmoldren/res/sword2.gif b/riseoftodmoldren/res/sword2.gif new file mode 100644 index 0000000..6f5de1b Binary files /dev/null and b/riseoftodmoldren/res/sword2.gif differ diff --git a/riseoftodmoldren/res/towel_icon.gif b/riseoftodmoldren/res/towel_icon.gif new file mode 100644 index 0000000..52e64d5 Binary files /dev/null and b/riseoftodmoldren/res/towel_icon.gif differ 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)) diff --git a/sack.gif b/sack.gif deleted file mode 100644 index b9ace16..0000000 Binary files a/sack.gif and /dev/null differ diff --git a/sword.gif b/sword.gif deleted file mode 100644 index 20b7418..0000000 Binary files a/sword.gif and /dev/null differ diff --git a/sword2.gif b/sword2.gif deleted file mode 100644 index 6f5de1b..0000000 Binary files a/sword2.gif and /dev/null differ diff --git a/towel_icon.gif b/towel_icon.gif deleted file mode 100644 index 52e64d5..0000000 Binary files a/towel_icon.gif and /dev/null differ -- cgit