This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we are showing it without any
pretty colors.
Highlight
it anyway.
1 |
#!/usr/bin/python |
2 |
import pygame |
3 |
import gtk |
4 |
|
5 |
class TestGame: |
6 |
def __init__(self): |
7 |
# Set up a clock for managing the frame rate. |
8 |
self.clock = pygame.time.Clock() |
9 |
|
10 |
# Set up a font for rendering. |
11 |
pygame.font.init() |
12 |
self.font = pygame.font.Font(None, 24) |
13 |
|
14 |
def set_paused(self, paused): |
15 |
self.paused = paused |
16 |
|
17 |
# Called to save the state of the game to the Journal. |
18 |
def write_file(self, file_path): |
19 |
pass |
20 |
|
21 |
# Called to load the state of the game from the Journal. |
22 |
def read_file(self, file_path): |
23 |
pass |
24 |
|
25 |
# The main game loop. |
26 |
def run(self): |
27 |
self.running = True |
28 |
|
29 |
screen = pygame.display.get_surface() |
30 |
|
31 |
while self.running: |
32 |
# Pump GTK messages. |
33 |
while gtk.events_pending(): |
34 |
gtk.main_iteration() |
35 |
|
36 |
# Pump PyGame messages. |
37 |
for event in pygame.event.get(): |
38 |
if event.type == pygame.QUIT: |
39 |
return |
40 |
|
41 |
# Clear Display |
42 |
screen.fill((255,255,255)) #255 for white |
43 |
|
44 |
# Flip Display |
45 |
pygame.display.flip() |
46 |
|
47 |
# Try to stay at 30 FPS |
48 |
self.clock.tick(30) |
49 |
|
50 |
# This function is called when the game is run directly from the command line: |
51 |
# ./TestGame.py |
52 |
def main(): |
53 |
pygame.init() |
54 |
pygame.display.set_mode((0, 0), pygame.RESIZABLE) |
55 |
game = TestGame() |
56 |
game.run() |
57 |
|
58 |
if __name__ == '__main__': |
59 |
main() |