Changeset 454:95527fd29872


Ignore:
Timestamp:
04/09/11 18:47:35 (12 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

More complete game load/save/restart.

Location:
skaapsteker
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/engine.py

    r447 r454  
    2323        if self.game_state.can_resume():
    2424            self.game_state.load_game()
    25         else:
    26             self.game_state.new_game()
    2725        self.soundsystem = soundsystem
    2826
     
    4543                if ev.type is QUIT:
    4644                    return
     45                if NewGameEvent.matches(ev):
     46                    self.game_state.new_game()
     47                    fox = self.game_state.world.fox
     48                    ChangeScene.post((ev.scene_type, '.'.join([fox.level, fox.doorway])))
    4749                if ChangeScene.matches(ev):
    4850                    next_scene = ev.next_scene
     
    103105    def matches(cls, ev):
    104106        return ev.type is USEREVENT and ev.utype == cls.utype
     107
     108class NewGameEvent(UserEvent):
     109
     110    utype = "NEW_GAME_EVENT"
     111
     112    @classmethod
     113    def post(cls, scene_type):
     114        super(NewGameEvent, cls).post(scene_type=scene_type)
    105115
    106116class ChangeScene(UserEvent):
  • skaapsteker/gamestate.py

    r447 r454  
    3838    def __init__(self, game_file):
    3939        self._game_file = game_file
     40        self.world = None
    4041
    4142    def can_resume(self):
  • skaapsteker/levelscene.py

    r446 r454  
    119119        import menuscene # avoid circular import
    120120        if pause:
    121             engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self._soundsystem, self))
     121            engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self._soundsystem))
    122122        else:
    123123            # FIXME: When starting the game, we shoudl ensure we have sane
     
    125125            if self._player_dead:
    126126                self._player.restore()
    127             engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self._soundsystem, None))
     127            engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self._soundsystem))
    128128
    129129    def _restart(self):
  • skaapsteker/menuscene.py

    r448 r454  
    33
    44from .cutscene import OpeningCutScene, UsageCutScene, CreditsCutScene
    5 from .engine import ChangeScene, Scene
     5from .engine import ChangeScene, Scene, NewGameEvent
    66from .levelscene import LevelScene
    77from .widgets.text import Text, TextChoice
     
    99
    1010class MenuScene(Scene):
    11     def __init__(self, game_state, soundsystem, cur_game=None):
     11    def __init__(self, game_state, soundsystem):
    1212        super(MenuScene, self).__init__(game_state, soundsystem)
    1313        self.widgets.append(Text("MENU:", (50, 50), color='white', size=48))
    14         self.cur_game = cur_game
    1514        menu_options = [
     15            ('Start new game', 'restart'),
    1616            ('Starting Cutscene', 'cutscene'),
    1717            ('Temple', 'temple.starting'),
     
    2929            ('Quit', 'quit'),
    3030        ]
    31         if cur_game is not None:
     31        if self.game_state.world is not None:
    3232            menu_options.insert(0, ('Resume Game', 'resume'))
    3333        self.choice = TextChoice(menu_options, (50, 100), color='white')
     
    3535        self.widgets.append(self.choice)
    3636
     37    def resume_game(self):
     38        fox = self.game_state.world.fox
     39        ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
     40
    3741    def selected(self, option, data):
    3842        "Callback from menu TextChoice"
    3943        if data == 'resume':
    40             ChangeScene.post(self.cur_game)
     44            self.resume_game()
     45        elif data == 'restart':
     46            NewGameEvent.post(LevelScene)
    4147        elif data == 'cutscene':
    4248            ChangeScene.post(OpeningCutScene(self.game_state, self._soundsystem))
Note: See TracChangeset for help on using the changeset viewer.