diff options
-rw-r--r-- | Game Test.py | 6 | ||||
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | riseoftodmoldren/__init__.py | 0 | ||||
-rw-r--r-- | riseoftodmoldren/__main__.py | 4 | ||||
-rw-r--r-- | riseoftodmoldren/app.py | 19 | ||||
-rw-r--r-- | riseoftodmoldren/assets.py | 38 | ||||
-rw-r--r-- | riseoftodmoldren/base.py | 96 | ||||
-rw-r--r-- | riseoftodmoldren/res/castle1.gif (renamed from castle1.gif) | bin | 274812 -> 274812 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/cave1.gif (renamed from cave1.gif) | bin | 73550 -> 73550 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/cave2.gif (renamed from cave2.gif) | bin | 79223 -> 79223 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/cave3.gif (renamed from cave3.gif) | bin | 60235 -> 60235 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/cave_enternace.gif (renamed from cave_enternace.gif) | bin | 245898 -> 245898 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/cave_exit.gif (renamed from cave_exit.gif) | bin | 94032 -> 94032 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/chest1.gif (renamed from chest1.gif) | bin | 1401 -> 1401 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/chest2.gif (renamed from chest2.gif) | bin | 1463 -> 1463 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/d_sword.gif (renamed from d_sword.gif) | bin | 4998 -> 4998 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/d_sword2.gif (renamed from d_sword2.gif) | bin | 7481 -> 7481 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/d_sword_icon.gif (renamed from d_sword_icon.gif) | bin | 1217 -> 1217 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest1.gif (renamed from forest1.gif) | bin | 256312 -> 256312 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest2.gif (renamed from forest2.gif) | bin | 247560 -> 247560 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest3.gif (renamed from forest3.gif) | bin | 263212 -> 263212 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest4.gif (renamed from forest4.gif) | bin | 258816 -> 258816 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest5.gif (renamed from forest5.gif) | bin | 254847 -> 254847 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest6.gif (renamed from forest6.gif) | bin | 258935 -> 258935 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest7.gif (renamed from forest7.gif) | bin | 247677 -> 247677 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/forest8.gif (renamed from forest8.gif) | bin | 249470 -> 249470 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/heal_potion_icon.gif (renamed from heal_potion_icon.gif) | bin | 1370 -> 1370 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/menu1.gif (renamed from menu1.gif) | bin | 46545 -> 46545 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/menu2.gif (renamed from menu2.gif) | bin | 48953 -> 48953 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/sack.gif (renamed from sack.gif) | bin | 1001 -> 1001 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/sword.gif (renamed from sword.gif) | bin | 4921 -> 4921 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/sword2.gif (renamed from sword2.gif) | bin | 7730 -> 7730 bytes | |||
-rw-r--r-- | riseoftodmoldren/res/towel_icon.gif (renamed from towel_icon.gif) | bin | 1353 -> 1353 bytes | |||
-rw-r--r-- | riseoftodmoldren/screens/start.py | 17 |
34 files changed, 179 insertions, 2 deletions
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/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 --- /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/castle1.gif b/riseoftodmoldren/res/castle1.gif Binary files differindex 7867d71..7867d71 100644 --- a/castle1.gif +++ b/riseoftodmoldren/res/castle1.gif diff --git a/cave1.gif b/riseoftodmoldren/res/cave1.gif Binary files differindex 608cfad..608cfad 100644 --- a/cave1.gif +++ b/riseoftodmoldren/res/cave1.gif diff --git a/cave2.gif b/riseoftodmoldren/res/cave2.gif Binary files differindex 09aba2a..09aba2a 100644 --- a/cave2.gif +++ b/riseoftodmoldren/res/cave2.gif diff --git a/cave3.gif b/riseoftodmoldren/res/cave3.gif Binary files differindex bbf4a74..bbf4a74 100644 --- a/cave3.gif +++ b/riseoftodmoldren/res/cave3.gif diff --git a/cave_enternace.gif b/riseoftodmoldren/res/cave_enternace.gif Binary files differindex 5ff3aaf..5ff3aaf 100644 --- a/cave_enternace.gif +++ b/riseoftodmoldren/res/cave_enternace.gif diff --git a/cave_exit.gif b/riseoftodmoldren/res/cave_exit.gif Binary files differindex d12e383..d12e383 100644 --- a/cave_exit.gif +++ b/riseoftodmoldren/res/cave_exit.gif diff --git a/chest1.gif b/riseoftodmoldren/res/chest1.gif Binary files differindex 6adbae9..6adbae9 100644 --- a/chest1.gif +++ b/riseoftodmoldren/res/chest1.gif diff --git a/chest2.gif b/riseoftodmoldren/res/chest2.gif Binary files differindex 9200cc8..9200cc8 100644 --- a/chest2.gif +++ b/riseoftodmoldren/res/chest2.gif diff --git a/d_sword.gif b/riseoftodmoldren/res/d_sword.gif Binary files differindex 57ab08a..57ab08a 100644 --- a/d_sword.gif +++ b/riseoftodmoldren/res/d_sword.gif diff --git a/d_sword2.gif b/riseoftodmoldren/res/d_sword2.gif Binary files differindex 5dc41ac..5dc41ac 100644 --- a/d_sword2.gif +++ b/riseoftodmoldren/res/d_sword2.gif diff --git a/d_sword_icon.gif b/riseoftodmoldren/res/d_sword_icon.gif Binary files differindex 71e2dcd..71e2dcd 100644 --- a/d_sword_icon.gif +++ b/riseoftodmoldren/res/d_sword_icon.gif diff --git a/forest1.gif b/riseoftodmoldren/res/forest1.gif Binary files differindex bef0017..bef0017 100644 --- a/forest1.gif +++ b/riseoftodmoldren/res/forest1.gif diff --git a/forest2.gif b/riseoftodmoldren/res/forest2.gif Binary files differindex bfd4d6b..bfd4d6b 100644 --- a/forest2.gif +++ b/riseoftodmoldren/res/forest2.gif diff --git a/forest3.gif b/riseoftodmoldren/res/forest3.gif Binary files differindex c8166dc..c8166dc 100644 --- a/forest3.gif +++ b/riseoftodmoldren/res/forest3.gif diff --git a/forest4.gif b/riseoftodmoldren/res/forest4.gif Binary files differindex 1e2df0d..1e2df0d 100644 --- a/forest4.gif +++ b/riseoftodmoldren/res/forest4.gif diff --git a/forest5.gif b/riseoftodmoldren/res/forest5.gif Binary files differindex 92d988e..92d988e 100644 --- a/forest5.gif +++ b/riseoftodmoldren/res/forest5.gif diff --git a/forest6.gif b/riseoftodmoldren/res/forest6.gif Binary files differindex c013c24..c013c24 100644 --- a/forest6.gif +++ b/riseoftodmoldren/res/forest6.gif diff --git a/forest7.gif b/riseoftodmoldren/res/forest7.gif Binary files differindex 54fefa6..54fefa6 100644 --- a/forest7.gif +++ b/riseoftodmoldren/res/forest7.gif diff --git a/forest8.gif b/riseoftodmoldren/res/forest8.gif Binary files differindex 7430d09..7430d09 100644 --- a/forest8.gif +++ b/riseoftodmoldren/res/forest8.gif diff --git a/heal_potion_icon.gif b/riseoftodmoldren/res/heal_potion_icon.gif Binary files differindex 0013ccf..0013ccf 100644 --- a/heal_potion_icon.gif +++ b/riseoftodmoldren/res/heal_potion_icon.gif diff --git a/menu1.gif b/riseoftodmoldren/res/menu1.gif Binary files differindex fec6da6..fec6da6 100644 --- a/menu1.gif +++ b/riseoftodmoldren/res/menu1.gif diff --git a/menu2.gif b/riseoftodmoldren/res/menu2.gif Binary files differindex 79a7dfb..79a7dfb 100644 --- a/menu2.gif +++ b/riseoftodmoldren/res/menu2.gif diff --git a/sack.gif b/riseoftodmoldren/res/sack.gif Binary files differindex b9ace16..b9ace16 100644 --- a/sack.gif +++ b/riseoftodmoldren/res/sack.gif diff --git a/sword.gif b/riseoftodmoldren/res/sword.gif Binary files differindex 20b7418..20b7418 100644 --- a/sword.gif +++ b/riseoftodmoldren/res/sword.gif diff --git a/sword2.gif b/riseoftodmoldren/res/sword2.gif Binary files differindex 6f5de1b..6f5de1b 100644 --- a/sword2.gif +++ b/riseoftodmoldren/res/sword2.gif diff --git a/towel_icon.gif b/riseoftodmoldren/res/towel_icon.gif Binary files differindex 52e64d5..52e64d5 100644 --- a/towel_icon.gif +++ 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)) |