Mercurial > touhou
comparison 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 |
comparison
equal
deleted
inserted
replaced
224:9bb26dbb8438 | 225:2d35565b5608 |
---|---|
15 import pyglet | 15 import pyglet |
16 import traceback | 16 import traceback |
17 | 17 |
18 from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, | 18 from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, |
19 glHint, glEnableClientState, glViewport, | 19 glHint, glEnableClientState, glViewport, |
20 gluPerspective, gluLookAt, | 20 gluPerspective, gluOrtho2D, |
21 GL_MODELVIEW, GL_PROJECTION, | 21 GL_MODELVIEW, GL_PROJECTION, |
22 GL_TEXTURE_2D, GL_BLEND, GL_FOG, | 22 GL_TEXTURE_2D, GL_BLEND, GL_FOG, |
23 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, | 23 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, |
24 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY) | 24 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY) |
25 | 25 |
32 | 32 |
33 | 33 |
34 class GameRunner(pyglet.window.Window, GameRenderer): | 34 class GameRunner(pyglet.window.Window, GameRenderer): |
35 def __init__(self, resource_loader, game=None, background=None, replay=None): | 35 def __init__(self, resource_loader, game=None, background=None, replay=None): |
36 GameRenderer.__init__(self, resource_loader, game, background) | 36 GameRenderer.__init__(self, resource_loader, game, background) |
37 pyglet.window.Window.__init__(self, caption='PyTouhou', resizable=False) | 37 |
38 width, height = (game.width, game.height) if game else (None, None) | |
39 pyglet.window.Window.__init__(self, width=width, height=height, | |
40 caption='PyTouhou', resizable=False) | |
41 | |
38 self.replay_level = None | 42 self.replay_level = None |
39 if not replay or not replay.levels[game.stage-1]: | 43 if not replay or not replay.levels[game.stage-1]: |
40 self.keys = pyglet.window.key.KeyStateHandler() | 44 self.keys = pyglet.window.key.KeyStateHandler() |
41 self.push_handlers(self.keys) | 45 self.push_handlers(self.keys) |
42 else: | 46 else: |
44 self.replay_level = replay.levels[game.stage-1] | 48 self.replay_level = replay.levels[game.stage-1] |
45 | 49 |
46 self.fps_display = pyglet.clock.ClockDisplay() | 50 self.fps_display = pyglet.clock.ClockDisplay() |
47 | 51 |
48 | 52 |
49 def start(self, width=384, height=448): | 53 def start(self, width=None, height=None): |
50 self.set_size(width, height) | 54 width = width or (self.game.width if self.game else 640) |
55 height = height or (self.game.height if self.game else 480) | |
56 | |
57 if (width, height) != (self.width, self.height): | |
58 self.set_size(width, height) | |
51 | 59 |
52 # Initialize OpenGL | 60 # Initialize OpenGL |
53 glMatrixMode(GL_PROJECTION) | |
54 glLoadIdentity() | |
55 gluPerspective(30, float(width)/float(height), | |
56 101010101./2010101., 101010101./10101.) | |
57 | |
58 glEnable(GL_BLEND) | 61 glEnable(GL_BLEND) |
59 glEnable(GL_TEXTURE_2D) | 62 glEnable(GL_TEXTURE_2D) |
60 glEnable(GL_FOG) | 63 glEnable(GL_FOG) |
61 glHint(GL_FOG_HINT, GL_NICEST) | 64 glHint(GL_FOG_HINT, GL_NICEST) |
62 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) | 65 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) |
133 | 136 |
134 self.game.run_iter(keystate) | 137 self.game.run_iter(keystate) |
135 | 138 |
136 | 139 |
137 def on_draw(self): | 140 def on_draw(self): |
141 # Switch to game projection | |
142 #TODO: move that to GameRenderer? | |
143 glMatrixMode(GL_PROJECTION) | |
144 glLoadIdentity() | |
145 gluPerspective(30, float(self.width) / float(self.height), | |
146 101010101./2010101., 101010101./10101.) | |
147 | |
138 GameRenderer.render(self) | 148 GameRenderer.render(self) |
139 | 149 |
140 #TODO | 150 # Get back to standard orthographic projection |
151 glMatrixMode(GL_PROJECTION) | |
152 glLoadIdentity() | |
141 glMatrixMode(GL_MODELVIEW) | 153 glMatrixMode(GL_MODELVIEW) |
142 glLoadIdentity() | 154 glLoadIdentity() |
143 gluLookAt(192., 224., 835.979370, | 155 |
144 192, 224., 0., 0., 1., 0.) | 156 #TODO: draw interface |
157 gluOrtho2D(0., float(self.game.width), 0., float(self.game.height)) | |
145 self.fps_display.draw() | 158 self.fps_display.draw() |
146 | 159 |