Mercurial > touhou
annotate pytouhou/ui/gamerunner.py @ 225:2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 19 Dec 2011 21:35:40 +0100 |
parents | 9bb26dbb8438 |
children | 067f6d9c562b 9d4d52793eca |
rev | line source |
---|---|
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 import pyglet |
146
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
16 import traceback |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
17 |
203
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
188
diff
changeset
|
18 from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, |
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
188
diff
changeset
|
19 glHint, glEnableClientState, glViewport, |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
20 gluPerspective, gluOrtho2D, |
203
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
188
diff
changeset
|
21 GL_MODELVIEW, GL_PROJECTION, |
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
188
diff
changeset
|
22 GL_TEXTURE_2D, GL_BLEND, GL_FOG, |
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
188
diff
changeset
|
23 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, |
df8b2ab54639
Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents:
188
diff
changeset
|
24 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
25 |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
26 from pytouhou.utils.helpers import get_logger |
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
27 |
205
ee6dfd14a785
Rename pytouhou.opengl to pytouhou.ui, makes much more sense that way.
Thibaut Girka <thib@sitedethib.com>
parents:
203
diff
changeset
|
28 from .gamerenderer import GameRenderer |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
29 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
30 |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
31 logger = get_logger(__name__) |
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
32 |
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
33 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 class GameRunner(pyglet.window.Window, GameRenderer): |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
35 def __init__(self, resource_loader, game=None, background=None, replay=None): |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
36 GameRenderer.__init__(self, resource_loader, game, background) |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
37 |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
38 width, height = (game.width, game.height) if game else (None, None) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
39 pyglet.window.Window.__init__(self, width=width, height=height, |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
40 caption='PyTouhou', resizable=False) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
41 |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
42 self.replay_level = None |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
43 if not replay or not replay.levels[game.stage-1]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
44 self.keys = pyglet.window.key.KeyStateHandler() |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
45 self.push_handlers(self.keys) |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
46 else: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
47 self.keys = 0 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
48 self.replay_level = replay.levels[game.stage-1] |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
49 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
50 self.fps_display = pyglet.clock.ClockDisplay() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
52 |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
53 def start(self, width=None, height=None): |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
54 width = width or (self.game.width if self.game else 640) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
55 height = height or (self.game.height if self.game else 480) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
56 |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
57 if (width, height) != (self.width, self.height): |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
58 self.set_size(width, height) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
59 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
60 # Initialize OpenGL |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
61 glEnable(GL_BLEND) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
62 glEnable(GL_TEXTURE_2D) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
63 glEnable(GL_FOG) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
64 glHint(GL_FOG_HINT, GL_NICEST) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
65 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
66 glEnableClientState(GL_COLOR_ARRAY) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
67 glEnableClientState(GL_VERTEX_ARRAY) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
68 glEnableClientState(GL_TEXTURE_COORD_ARRAY) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
69 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
70 # Use our own loop to ensure 60 (for now, 120) fps |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
71 pyglet.clock.set_fps_limit(120) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
72 while not self.has_exit: |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
73 pyglet.clock.tick() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
74 self.dispatch_events() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
75 self.update() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
76 self.on_draw() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
77 self.flip() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
78 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
79 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
80 def on_resize(self, width, height): |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
81 glViewport(0, 0, width, height) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
82 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
83 |
146
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
84 def _event_text_symbol(self, ev): |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
85 # XXX: Ugly workaround to a pyglet bug on X11 |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
86 #TODO: fix that bug in pyglet |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
87 try: |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
88 return pyglet.window.Window._event_text_symbol(self, ev) |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
89 except Exception as exc: |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
90 logger.warn('Pyglet error: %s', traceback.format_exc(exc)) |
146
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
91 return None, None |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
92 |
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
93 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
94 def on_key_press(self, symbol, modifiers): |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
95 if symbol == pyglet.window.key.ESCAPE: |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
96 self.has_exit = True |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
97 # XXX: Fullscreen will be enabled the day pyglet stops sucking |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
98 elif symbol == pyglet.window.key.F11: |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
99 self.set_fullscreen(not self.fullscreen) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
100 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
101 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
102 def update(self): |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
103 if self.background: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
146
diff
changeset
|
104 self.background.update(self.game.frame) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
105 if self.game: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
106 if not self.replay_level: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
107 #TODO: allow user settings |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
108 keystate = 0 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
109 if self.keys[pyglet.window.key.W]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
110 keystate |= 1 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
111 if self.keys[pyglet.window.key.X]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
112 keystate |= 2 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
113 #TODO: on some configurations, LSHIFT is Shift_L when pressed |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
114 # and ISO_Prev_Group when released, confusing the hell out of pyglet |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
115 # and leading to a always-on LSHIFT... |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
116 if self.keys[pyglet.window.key.LSHIFT]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
117 keystate |= 4 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
118 if self.keys[pyglet.window.key.UP]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
119 keystate |= 16 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
120 if self.keys[pyglet.window.key.DOWN]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
121 keystate |= 32 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
122 if self.keys[pyglet.window.key.LEFT]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
123 keystate |= 64 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
124 if self.keys[pyglet.window.key.RIGHT]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
125 keystate |= 128 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
126 if self.keys[pyglet.window.key.LCTRL]: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
127 keystate |= 256 |
188
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
128 self.game.run_iter(keystate) |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
129 else: |
188
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
130 keystate = 0 |
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
131 for frame, _keystate, unknown in self.replay_level.keys: |
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
132 if self.game.frame < frame: |
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
133 break |
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
134 else: |
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
135 keystate = _keystate |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
136 |
188
008f90ebfdc0
Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents:
187
diff
changeset
|
137 self.game.run_iter(keystate) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
138 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
139 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
140 def on_draw(self): |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
141 # Switch to game projection |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
142 #TODO: move that to GameRenderer? |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
143 glMatrixMode(GL_PROJECTION) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
144 glLoadIdentity() |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
145 gluPerspective(30, float(self.width) / float(self.height), |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
146 101010101./2010101., 101010101./10101.) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
147 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 GameRenderer.render(self) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
149 |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
150 # Get back to standard orthographic projection |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
151 glMatrixMode(GL_PROJECTION) |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
152 glLoadIdentity() |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 glMatrixMode(GL_MODELVIEW) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 glLoadIdentity() |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
155 |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
156 #TODO: draw interface |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
157 gluOrtho2D(0., float(self.game.width), 0., float(self.game.height)) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
158 self.fps_display.draw() |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
159 |