Mercurial > touhou
changeset 207:709f42eaa55e
Minor refactoring
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sat, 05 Nov 2011 20:19:15 +0100 |
parents | eca53abdfeab |
children | d07506a2e16e |
files | pytouhou/game/enemy.py pytouhou/vm/eclrunner.py |
diffstat | 2 files changed, 18 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -103,14 +103,15 @@ class Enemy(object): self.bullet_launch_timer = int(value * start) - def fire(self): + def fire(self, offset=None, bullet_attributes=None, launch_pos=None): (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots, - speed, speed2, launch_angle, angle, flags) = self.bullet_attributes + speed, speed2, launch_angle, angle, flags) = bullet_attributes or self.bullet_attributes bullet_type = self._game.bullet_types[type_idx] - ox, oy = self.bullet_launch_offset - launch_pos = self.x + ox, self.y + oy + if not launch_pos: + ox, oy = offset or self.bullet_launch_offset + launch_pos = self.x + ox, self.y + oy if speed2 < 0.3: speed2 = 0.3
--- a/pytouhou/vm/eclrunner.py +++ b/pytouhou/vm/eclrunner.py @@ -886,12 +886,9 @@ class ECLRunner(object): bullet.angle = self._game.prng.rand_double() * pi #TODO bullet.delta = (cos(bullet.angle) * bullet.speed, sin(bullet.angle) * bullet.speed) elif function == 1: # Cirno - offset = self._enemy.bullet_launch_offset - self._enemy.bullet_launch_offset = ( - self._game.prng.rand_uint16() % arg - arg / 2, - self._game.prng.rand_uint16() % arg - arg / 2) - self._enemy.fire() - self._enemy.bullet_launch_offset = offset + offset = (self._game.prng.rand_uint16() % arg - arg / 2, + self._game.prng.rand_uint16() % arg - arg / 2) + self._enemy.fire(offset=offset) elif function == 13: if self._enemy.bullet_attributes is None: return @@ -899,23 +896,20 @@ class ECLRunner(object): if self._enemy.frame % 6: return - offset = self._enemy.bullet_launch_offset - pos = self._enemy.x, self._enemy.y - attributes = self._enemy.bullet_attributes - - self._enemy.x, self._enemy.y = (192, 224) - type_, anim, sprite_idx_offset, bullets_per_shot, number_of_shots, speed, speed2, launch_angle, angle, flags = attributes + (type_, anim, sprite_idx_offset, bullets_per_shot, number_of_shots, + speed, speed2, launch_angle, angle, flags) = self._enemy.bullet_attributes for i in range(arg): _angle = i*2*pi/arg _angle2 = _angle + self._getval(-10007) _distance = self._getval(-10008) - self._enemy.bullet_launch_offset = (cos(_angle2) * _distance, sin(_angle2) * _distance) - self._enemy.bullet_attributes = (type_, anim, sprite_idx_offset, bullets_per_shot, number_of_shots, speed, speed2, self._getval(-10006) + _angle, angle, flags) - self._enemy.fire() - - self._enemy.bullet_attributes = attributes - self._enemy.x, self._enemy.y = pos - self._enemy.bullet_launch_offset = offset + launch_pos = (192 + cos(_angle2) * _distance, + 224 + sin(_angle2) * _distance) + bullet_attributes = (type_, anim, sprite_idx_offset, + bullets_per_shot, number_of_shots, + speed, speed2, + self._getval(-10006) + _angle, angle, flags) + self._enemy.fire(launch_pos=launch_pos, + bullet_attributes=bullet_attributes) else: logger.warn("Unimplemented special function %d!", function)