Mercurial > touhou
comparison pytouhou/game/enemymanager.py @ 79:ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sat, 03 Sep 2011 18:17:39 +0200 |
parents | b3bd421bb895 |
children | fc0294c745b6 |
comparison
equal
deleted
inserted
replaced
78:bcf965ede96c | 79:ffe2c2b9912c |
---|---|
19 from struct import unpack, pack | 19 from struct import unpack, pack |
20 from pytouhou.utils.interpolator import Interpolator | 20 from pytouhou.utils.interpolator import Interpolator |
21 from pytouhou.vm.eclrunner import ECLRunner | 21 from pytouhou.vm.eclrunner import ECLRunner |
22 from pytouhou.vm.anmrunner import ANMRunner | 22 from pytouhou.vm.anmrunner import ANMRunner |
23 from pytouhou.game.sprite import Sprite | 23 from pytouhou.game.sprite import Sprite |
24 from math import cos, sin, atan2 | 24 from math import cos, sin, atan2, pi |
25 | 25 |
26 | 26 |
27 class Enemy(object): | 27 class Enemy(object): |
28 def __init__(self, pos, life, _type, anm_wrapper): | 28 def __init__(self, pos, life, _type, anm_wrapper, game_state): |
29 self._game_state = game_state | |
29 self._anm_wrapper = anm_wrapper | 30 self._anm_wrapper = anm_wrapper |
30 self._sprite = None | 31 self._sprite = None |
31 self._anmrunner = None | 32 self._anmrunner = None |
32 self._removed = False | 33 self._removed = False |
33 self._type = _type | 34 self._type = _type |
40 self.max_life = life | 41 self.max_life = life |
41 self.touchable = True | 42 self.touchable = True |
42 self.damageable = True | 43 self.damageable = True |
43 self.death_flags = 0 | 44 self.death_flags = 0 |
44 self.pending_bullets = [] | 45 self.pending_bullets = [] |
46 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.) | |
45 self.bullet_attributes = None | 47 self.bullet_attributes = None |
46 self.bullet_launch_offset = (0, 0) | 48 self.bullet_launch_offset = (0, 0) |
47 self.death_callback = None | 49 self.death_callback = None |
48 self.low_life_callback = None | 50 self.low_life_callback = None |
49 self.low_life_trigger = None | 51 self.low_life_trigger = None |
69 self.hitbox = (0, 0) | 71 self.hitbox = (0, 0) |
70 self.screen_box = None | 72 self.screen_box = None |
71 | 73 |
72 | 74 |
73 def set_bullet_attributes(self, type_, bullet_anim, launch_anim, | 75 def set_bullet_attributes(self, type_, bullet_anim, launch_anim, |
74 bullets_per_shot, number_of_shots, speed, unknown, | 76 bullets_per_shot, number_of_shots, speed, speed2, |
75 launch_angle, angle, flags): | 77 launch_angle, angle, flags): |
76 self.bullet_attributes = (type_, bullet_anim, launch_anim, bullets_per_shot, | 78 self.bullet_attributes = (type_, bullet_anim, launch_anim, bullets_per_shot, |
77 number_of_shots, speed, unknown, launch_angle, | 79 number_of_shots, speed, speed2, launch_angle, |
78 angle, flags) | 80 angle, flags) |
79 if not self.delay_attack: | 81 if not self.delay_attack: |
80 self.fire() | 82 self.fire() |
81 | 83 |
82 | 84 |
83 def fire(self): | 85 def fire(self): |
86 (type_, bullet_anim, launch_anim, bullets_per_shot, number_of_shots, | |
87 speed, speed2, launch_angle, angle, flags) = self.bullet_attributes | |
88 if type_ in (67, 69, 71): | |
89 launch_angle += self.get_player_angle() | |
90 if type_ in (69, 70, 71): | |
91 angle = 2. * pi / bullets_per_shot | |
92 if type_ == 71: | |
93 launch_angle += pi / bullets_per_shot | |
84 #TODO | 94 #TODO |
85 pass | 95 pass |
86 | 96 |
87 | 97 |
88 def select_player(self, players): | 98 def select_player(self, players=None): |
89 return players[0] #TODO | 99 return (players or self._game_state.players)[0] #TODO |
90 | 100 |
91 | 101 |
92 def get_player_angle(self, player): | 102 def get_player_angle(self, player=None): |
103 player = player or self.select_player() | |
93 return atan2(player.y - self.y, player.x - self.x) | 104 return atan2(player.y - self.y, player.x - self.x) |
94 | 105 |
95 | 106 |
96 def set_anim(self, index): | 107 def set_anim(self, index): |
97 self._sprite = Sprite() | 108 self._sprite = Sprite() |
253 x = self._game_state.prng.rand_double() * 368 | 264 x = self._game_state.prng.rand_double() * 368 |
254 if y < -990: #102h.exe@0x41184b | 265 if y < -990: #102h.exe@0x41184b |
255 y = self._game_state.prng.rand_double() * 416 | 266 y = self._game_state.prng.rand_double() * 416 |
256 if z < -990: #102h.exe@0x411881 | 267 if z < -990: #102h.exe@0x411881 |
257 y = self._game_state.prng.rand_double() * 800 | 268 y = self._game_state.prng.rand_double() * 800 |
258 enemy = Enemy((x, y), life, instr_type, self.anm_wrapper) | 269 enemy = Enemy((x, y), life, instr_type, self.anm_wrapper, self._game_state) |
259 self.enemies.append(enemy) | 270 self.enemies.append(enemy) |
260 self.processes.append(ECLRunner(self.ecl, sub, enemy, self._game_state)) | 271 self.processes.append(ECLRunner(self.ecl, sub, enemy, self._game_state)) |
261 | 272 |
262 | 273 |
263 # Run processes | 274 # Run processes |