changeset 182:20843875ad8f

(Hopefully) use difficulty as it should. The difficulty[0] (also called rank) varies from 0 to 32 and affects various parts of the game. The difficulty now impact those parts, but how it is modified during the gameplay is not clear. Such changes to the difficulty are not handled yet. [0] http://en.touhouwiki.net/wiki/Embodiment_of_Scarlet_Devil/Gameplay#Rank
author Thibaut Girka <thib@sitedethib.com>
date Tue, 25 Oct 2011 01:29:40 +0200
parents 184196480f59
children b6d7ce644f34
files pytouhou/game/enemy.py pytouhou/vm/eclrunner.py
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -42,6 +42,7 @@ class Enemy(object):
         self.damageable = True
         self.death_flags = 0
         self.boss = False
+        self.difficulty_coeffs = (-.5, .5, 0, 0, 0, 0)
         self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.)
         self.bullet_attributes = None
         self.bullet_launch_offset = (0, 0)
@@ -77,6 +78,16 @@ class Enemy(object):
     def set_bullet_attributes(self, type_, anim, sprite_idx_offset,
                               bullets_per_shot, number_of_shots, speed, speed2,
                               launch_angle, angle, flags):
+
+        # Apply difficulty-specific modifiers
+        speed_a, speed_b, nb_a, nb_b, shots_a, shots_b = self.difficulty_coeffs
+        diff_coeff = self._game.difficulty / 32.
+
+        speed += speed_a * (1. - diff_coeff) + speed_b * diff_coeff
+        speed2 += (speed_a * (1. - diff_coeff) + speed_b * diff_coeff) / 2.
+        bullets_per_shot += int(nb_a * (1. - diff_coeff) + nb_b * diff_coeff)
+        number_of_shots += int(shots_a * (1. - diff_coeff) + shots_b * diff_coeff)
+
         self.bullet_attributes = (type_, anim, sprite_idx_offset, bullets_per_shot,
                                   number_of_shots, speed, speed2, launch_angle,
                                   angle, flags)
@@ -84,6 +95,15 @@ class Enemy(object):
             self.fire()
 
 
+    def set_bullet_launch_interval(self, value, start=0.):
+        # Apply difficulty-specific modifiers:
+        value *= 1. - .4 * (self._game.difficulty - 16.) / 32.
+
+        self.bullet_launch_interval = int(value)
+        self.bullet_launch_timer = int(value * start)
+        print(self.bullet_launch_interval, self.bullet_launch_timer)
+
+
     def fire(self):
         (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots,
          speed, speed2, launch_angle, angle, flags) = self.bullet_attributes
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -665,13 +665,12 @@ class ECLRunner(object):
 
     @instruction(76)
     def set_bullet_interval(self, value):
-        self._enemy.bullet_launch_interval = value
+        self._enemy.set_bullet_launch_interval(value)
 
 
     @instruction(77)
     def set_bullet_interval_ex(self, value):
-        self._enemy.bullet_launch_interval = value
-        self._enemy.bullet_launch_timer = int(self._game.prng.rand_double() * value) #TODO: check
+        self._enemy.set_bullet_launch_interval(value, self._game.prng.rand_double()) #TODO: check
 
 
     @instruction(78)
@@ -923,3 +922,8 @@ class ECLRunner(object):
     def set_remaining_lives(self, lives):
         self._enemy.remaining_lives = lives
 
+
+    @instruction(131)
+    def set_difficulty_coeffs(self, speed_a, speed_b, nb_a, nb_b, shots_a, shots_b):
+        self._enemy.difficulty_coeffs = (speed_a, speed_b, nb_a, nb_b, shots_a, shots_b)
+