Changeset 123:592477d8b09b


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

Add fps to game

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/engine.py

    r79 r123  
    1111        self._framerate = 60
    1212        self._current_scene = None
     13        self._fpss = [self._framerate] * 100
     14        self._cur_frame = 0
    1315
    1416    def change_scene(self, next_scene):
     
    3234                    break
    3335                self._current_scene.dispatch(ev)
    34             self._current_scene.draw(surface)
     36            self._current_scene.draw(surface, self)
    3537            pygame.display.flip()
    36             clock.tick(self._framerate)
     38            self._fpss[self._cur_frame] = clock.tick(self._framerate)
     39            self._cur_frame = self._cur_frame + 1 if self._cur_frame < 99 else 0
     40
     41    def get_fps(self):
     42        return sum(self._fpss) / 100
    3743
    3844
  • skaapsteker/levelscene.py

    r114 r123  
    99import physics
    1010import sprites.player
     11from skaapsteker.widgets.text import Text
    1112import pygame
    1213
     
    7172        self.frozen = False
    7273
    73     def draw(self, screen_surface):
     74    def draw(self, screen_surface, engine):
    7475        if self._clip_rect is None:
    7576            self._clip_rect = pygame.Rect((0, 0), screen_surface.get_size())
     
    8182        self._level.draw(self._level_surface)
    8283        self._world.draw(self._level_surface)
     84
     85        fps_text_pos = self._clip_rect.left + 10, self._clip_rect.top + 10
     86        fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos)
     87        fps_text.draw(self._level_surface)
    8388
    8489        screen_surface.blit(self._level_surface, (0, 0), self._clip_rect)
  • skaapsteker/menuscene.py

    r119 r123  
    3434            ChangeScene.post(self.cur_game)
    3535
    36     def draw(self, surface):
     36    def draw(self, surface, engine):
    3737        surface.fill(pygame.Color('black'))
    3838        super(MenuScene, self).draw(surface)
Note: See TracChangeset for help on using the changeset viewer.