changeset 59:4fe37a620b22

Handle set_random_angle properly! At last!
author Thibaut Girka <thib@sitedethib.com>
date Wed, 24 Aug 2011 01:34:11 +0200
parents 3da4de9decd0
children af7914413b89
files eclviewer.py pytouhou/formats/ecl.py pytouhou/game/eclrunner.py
diffstat 3 files changed, 29 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/eclviewer.py
+++ b/eclviewer.py
@@ -102,6 +102,8 @@ def main(path, stage_num):
             enemy_manager.update(frame)
             background.update(frame)
 
+            frame += 1
+
             # Draw everything
 #            glClearColor(0.0, 0.0, 1.0, 0)
             glClear(GL_DEPTH_BUFFER_BIT)
@@ -158,7 +160,6 @@ def main(path, stage_num):
 
             pygame.display.flip()
             clock.tick(120)
-            frame += 1
 
 
 
--- a/pytouhou/formats/ecl.py
+++ b/pytouhou/formats/ecl.py
@@ -29,7 +29,7 @@ class ECL(object):
                      5: ('if', 'set_float'),
                      6: ('ii', 'set_random_int'),
                      8: ('if', 'set_random_float'),
-                     9: ('iff', None),
+                     9: ('iff', 'set_random_float2'),
                      10: ('i', None),
                      13: ('iii', None),
                      14: ('iii', None),
@@ -59,7 +59,7 @@ class ECL(object):
                      47: ('f', 'set_speed'),
                      48: ('f', 'set_acceleration'),
                      49: ('ff', None),
-                     50: ('ff', None),
+                     50: ('ff', 'set_random_angle'),
                      51: ('ff', 'set_speed_towards_player'),
                      52: ('iff', None),
                      56: ('iffi', None),
--- a/pytouhou/game/eclrunner.py
+++ b/pytouhou/game/eclrunner.py
@@ -218,6 +218,11 @@ class ECLRunner(object):
         self._setval(variable_id, self._getval(maxval) * self._game_state.prng.rand_double())
 
 
+    @instruction(9)
+    def set_random_float2(self, variable_id, minval, amp):
+        self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game_state.prng.rand_double())
+
+
     @instruction(20)
     def add(self, variable_id, a, b):
         #TODO: int vs float thing
@@ -297,9 +302,27 @@ class ECLRunner(object):
 
     @instruction(50)
     def set_random_angle(self, min_angle, max_angle):
-        #TODO: This thing is really odd, check, double check, triple check, disassemble...
+        if self._enemy.screen_box:
+            minx, miny, maxx, maxy = self._enemy.screen_box
+        else:
+            minx, miny, maxx, maxy = (0., 0., 0., 0.)
+
         angle = self._game_state.prng.rand_double() * (max_angle - min_angle) + min_angle
-        self._enemy.angle = atan2(-abs(sin(angle)), -abs(cos(angle)))
+        sa, ca = sin(angle), cos(angle)
+
+        distx = min(96.0, (maxx - minx) / 2.)
+        disty = min(96.0, (maxy - miny) / 2.)
+
+        if self._enemy.x > maxx - 96.0:
+            ca = -abs(ca)
+        elif self._enemy.x < minx + 96.0:
+            ca = abs(ca)
+
+        if self._enemy.y > maxy - 48.0:
+            sa = -abs(sa)
+        elif self._enemy.y < miny + 48.0:
+            sa = abs(sa)
+        self._enemy.angle = atan2(sa, ca)
 
 
     @instruction(51)