Changeset 173:21d34f1f15b2


Ignore:
Timestamp:
04/06/11 09:52:03 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Message:

Press p to pause.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r170 r173  
    22
    33from pygame.locals import (KEYDOWN, KEYUP, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT,
    4                            K_SEMICOLON, K_UP, K_q, K_x, K_z)
     4                           K_SEMICOLON, K_UP, K_p, K_q, K_x, K_z)
    55
    66from . import options
     
    2424        self._clip_rect = None
    2525        self._world = physics.World()
     26        self._paused = False
    2627
    2728        # hackity, hack, hack
     
    4950        self._slow_key_map = {
    5051            K_ESCAPE: self._quit,
     52            K_p: self._toggle_pause,
    5153        }
    5254        if options['dvorak']:
     
    6264        engine.ChangeScene.post(menuscene.MenuScene(self.game_state, self))
    6365
     66    def _toggle_pause(self):
     67        if self._paused:
     68            self._world.thaw()
     69            self._paused = False
     70        else:
     71            self._world.freeze()
     72            self._paused = True
     73
    6474    def leave(self):
    6575        """Freeze the scene, for serialization"""
     
    7484            self._clip_rect = pygame.Rect((0, 0), screen_surface.get_size())
    7585
    76         for key in self._fast_keys_down:
    77             self._fast_key_map[key]()
     86        if not self._paused:
     87            for key in self._fast_keys_down:
     88                self._fast_key_map[key]()
     89            self._world.update()
    7890
    79         self._world.update()
    8091        self._update_clip_rect()
    8192
     
    8798        fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos)
    8899        fps_text.draw(self._level_surface)
     100
     101        if self._paused:
     102            paused_text_pos = self._clip_rect.centerx - 10, self._clip_rect.centery - 10
     103            paused_text = Text('Paused', paused_text_pos)
     104            paused_text.draw(self._level_surface)
    89105
    90106        screen_surface.blit(self._level_surface, (0, 0), self._clip_rect)
Note: See TracChangeset for help on using the changeset viewer.