Mercurial > touhou
changeset 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 | 5c5913b889bc |
files | pytouhou/game/game.py pytouhou/game/player.py pytouhou/ui/gamerunner.py |
diffstat | 3 files changed, 42 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -26,9 +26,12 @@ from pytouhou.game.effect import Particl class Game(object): def __init__(self, resource_loader, players, stage, rank, difficulty, - bullet_types, item_types, prng=None, nb_bullets_max=None): + bullet_types, item_types, + nb_bullets_max=None, width=384, height=448, prng=None): self.resource_loader = resource_loader + self.width, self.height = width, height + self.nb_bullets_max = nb_bullets_max self.bullet_types = bullet_types self.item_types = item_types @@ -174,12 +177,12 @@ class Game(object): player.update(keystate) #TODO: differentiate keystates (multiplayer mode) if player.state.x < 8.: player.state.x = 8. - if player.state.x > 384.-8: #TODO - player.state.x = 384.-8 + if player.state.x > self.width - 8: + player.state.x = self.width - 8 if player.state.y < 16.: player.state.y = 16. - if player.state.y > 448.-16: #TODO - player.state.y = 448.-16 + if player.state.y > self.height - 16: + player.state.y = self.height -16 for bullet in self.players_bullets: bullet.update() @@ -253,7 +256,7 @@ class Game(object): def cleanup(self): # Filter out non-visible enemies for enemy in tuple(self.enemies): - if enemy.is_visible(384, 448): #TODO + if enemy.is_visible(self.width, self.height): enemy._was_visible = True elif enemy._was_visible: # Filter out-of-screen enemy @@ -262,9 +265,12 @@ class Game(object): # Filter out-of-scren bullets # TODO: was_visible thing - self.bullets = [bullet for bullet in self.bullets if bullet.is_visible(384, 448)] - self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if bullet.is_visible(384, 448)] - self.players_bullets = [bullet for bullet in self.players_bullets if bullet.is_visible(384, 448)] + self.bullets = [bullet for bullet in self.bullets + if bullet.is_visible(self.width, self.height)] + self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets + if bullet.is_visible(self.width, self.height)] + self.players_bullets = [bullet for bullet in self.players_bullets + if bullet.is_visible(self.width, self.height)] # Filter out-of-scren items items = []
--- a/pytouhou/game/player.py +++ b/pytouhou/game/player.py @@ -178,8 +178,8 @@ class Player(object): self._sprite.scale_in(26, 0.00, 2.5, lambda x: x) elif time == 32: - self.state.x = 192.0 - self.state.y = 384.0 + self.state.x = float(self._game.width) / 2. #TODO + self.state.y = float(self._game.width) #TODO self.direction = None self._sprite = Sprite()
--- a/pytouhou/ui/gamerunner.py +++ b/pytouhou/ui/gamerunner.py @@ -17,7 +17,7 @@ import traceback from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, glHint, glEnableClientState, glViewport, - gluPerspective, gluLookAt, + gluPerspective, gluOrtho2D, GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE_2D, GL_BLEND, GL_FOG, GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, @@ -34,7 +34,11 @@ logger = get_logger(__name__) class GameRunner(pyglet.window.Window, GameRenderer): def __init__(self, resource_loader, game=None, background=None, replay=None): GameRenderer.__init__(self, resource_loader, game, background) - pyglet.window.Window.__init__(self, caption='PyTouhou', resizable=False) + + width, height = (game.width, game.height) if game else (None, None) + pyglet.window.Window.__init__(self, width=width, height=height, + caption='PyTouhou', resizable=False) + self.replay_level = None if not replay or not replay.levels[game.stage-1]: self.keys = pyglet.window.key.KeyStateHandler() @@ -46,15 +50,14 @@ class GameRunner(pyglet.window.Window, G self.fps_display = pyglet.clock.ClockDisplay() - def start(self, width=384, height=448): - self.set_size(width, height) + def start(self, width=None, height=None): + width = width or (self.game.width if self.game else 640) + height = height or (self.game.height if self.game else 480) + + if (width, height) != (self.width, self.height): + self.set_size(width, height) # Initialize OpenGL - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - gluPerspective(30, float(width)/float(height), - 101010101./2010101., 101010101./10101.) - glEnable(GL_BLEND) glEnable(GL_TEXTURE_2D) glEnable(GL_FOG) @@ -135,12 +138,22 @@ class GameRunner(pyglet.window.Window, G def on_draw(self): + # Switch to game projection + #TODO: move that to GameRenderer? + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + gluPerspective(30, float(self.width) / float(self.height), + 101010101./2010101., 101010101./10101.) + GameRenderer.render(self) - #TODO + # Get back to standard orthographic projection + glMatrixMode(GL_PROJECTION) + glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() - gluLookAt(192., 224., 835.979370, - 192, 224., 0., 0., 1., 0.) + + #TODO: draw interface + gluOrtho2D(0., float(self.game.width), 0., float(self.game.height)) self.fps_display.draw()