changeset 217:577f45454402

Change background during spellcards.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 17 Dec 2011 21:18:39 +0100
parents a842ddd471fd
children 9634eefd2063
files pytouhou/game/game.py pytouhou/ui/gamerenderer.pyx pytouhou/vm/eclrunner.py
diffstat 3 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -60,6 +60,9 @@ class Game(object):
         ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
         self.ecl_runner = ECLMainRunner(ecl, self)
 
+        self.effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,))
+        self.effect = None
+
         # See 102h.exe@0x413220 if you think you're brave enough.
         self.deaths_count = self.prng.rand_uint16() % 3
         self.next_bonus = self.prng.rand_uint16() % 8
@@ -79,6 +82,14 @@ class Game(object):
             self.difficulty = self.difficulty_max
 
 
+    def enable_effect(self):
+        self.effect = Effect((0, 0), 0, self.effect_anm_wrapper)
+
+
+    def disable_effect(self):
+        self.effect = None
+
+
     def drop_bonus(self, x, y, _type, end_pos=None):
         player = self.players[0] #TODO
         if _type > 6:
@@ -135,6 +146,7 @@ class Game(object):
         # We have to mimic this functionnality to be replay-compatible with the official game.
 
         # Pri 6 is background
+        self.update_effect() #TODO: Pri unknown
         self.update_players(keystate) # Pri 7
         self.update_enemies() # Pri 9
         self.update_effects() # Pri 10
@@ -147,6 +159,11 @@ class Game(object):
         self.frame += 1
 
 
+    def update_effect(self):
+        if self.effect is not None:
+            self.effect.update()
+
+
     def update_enemies(self):
         for enemy in self.enemies:
             enemy.update()
--- a/pytouhou/ui/gamerenderer.pyx
+++ b/pytouhou/ui/gamerenderer.pyx
@@ -105,7 +105,21 @@ cdef class GameRenderer:
         game = self.game
         texture_manager = self.texture_manager
 
-        if back is not None:
+        if game.effect is not None:
+            glMatrixMode(GL_MODELVIEW)
+            glLoadIdentity()
+            # Some explanations on the magic constants:
+            # 192. = 384. / 2. = width / 2.
+            # 224. = 448. / 2. = height / 2.
+            # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2))
+            # This is so that objects on the (O, x, y) plane use pixel coordinates
+            gluLookAt(192., 224., - 835.979370,
+                      192., 224., 0., 0., -1., 0.)
+
+            glDisable(GL_FOG)
+            self.render_elements([game.effect])
+            glEnable(GL_FOG)
+        elif back is not None:
             fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values
             x, y, z = back.position_interpolator.values
             dx, dy, dz = back.position2_interpolator.values
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -715,10 +715,10 @@ class ECLRunner(object):
     @instruction(93)
     def set_spellcard(self, unknown, number, name):
         #TODO: display it on the game.
-        #TODO: change the background.
         #TODO: make the enemies more resistants (and find how).
         self._game.change_bullets_into_star_items()
         self._game.spellcard = number
+        self._game.enable_effect()
         print("%d - %s" % (number+1, name))
 
 
@@ -729,6 +729,7 @@ class ECLRunner(object):
         if self._game.spellcard:
             self._game.change_bullets_into_star_items()
         self._game.spellcard = None
+        self._game.disable_effect()
 
 
     @instruction(95)