Changeset 104:12ce1d131a72


Ignore:
Timestamp:
Apr 4, 2011, 6:53:45 PM (9 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Hack in resume game option

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r102 r104  
    2929        self._pos = (0, 0)
    3030        self._world = physics.World()
     31        self.frozen = False
    3132
    3233        # hackity, hack, hack
     
    4849    def _quit(self):
    4950        import menuscene # avoid circular import
    50         engine.ChangeScene.post(menuscene.MenuScene())
     51        self.freeze()
     52        engine.ChangeScene.post(menuscene.MenuScene(self))
     53
     54    def freeze(self):
     55        """Freeze the scene, for serialization"""
     56        self.frozen = True
     57        self._world.freeze()
     58
     59    def thaw(self):
     60        """Unfreeze"""
     61        self._world.thaw()
     62        self.frozen = False
    5163
    5264    def draw(self, screen_surface):
  • skaapsteker/menuscene.py

    r79 r104  
    77
    88class MenuScene(Scene):
    9     def __init__(self):
     9    def __init__(self, cur_game=None):
    1010        super(MenuScene, self).__init__()
    1111        self.widgets.append(Text("MENU:", (50, 50), color='white', size=48))
    12         choice = TextChoice(("level1", "level2", "Quit"), (50, 100), color='white')
    13         choice.callbacks.append(self.selected)
    14         self.widgets.append(choice)
     12        self.cur_game = cur_game
     13        if cur_game is None:
     14            self.choice = TextChoice(("level1", "level2", "Quit"), (50, 100), color='white')
     15        else:
     16            self.choice = TextChoice(("level1", "level2", "Resume Game", "Quit"), (50, 100), color='white')
     17        self.choice.callbacks.append(self.selected)
     18        self.widgets.append(self.choice)
    1519
    1620    def selected(self, option):
     
    2024        elif option == 1:
    2125            ChangeScene.post(LevelScene('level2'))
    22         elif option == 2:
     26        elif option == len(self.choice.options) - 1:
    2327            pygame.event.post(pygame.event.Event(QUIT))
     28        elif option == 2 and self.cur_game is not None:
     29            self.cur_game.thaw()
     30            ChangeScene.post(self.cur_game)
    2431
    2532    def draw(self, surface):
  • skaapsteker/physics.py

    r103 r104  
    9191        self._last_time = None
    9292
     93    def freeze(self):
     94        self._last_time = None
     95
     96    def thaw(self):
     97        self._last_time = time.time()
     98
    9399    def add(self, sprite):
    94100        sprite.init_pos()
Note: See TracChangeset for help on using the changeset viewer.