comparison pytouhou/game/enemymanager.py @ 50:811cefefb5c8

Fix a few bugs and add support for a few instructions
author Thibaut Girka <thib@sitedethib.com>
date Mon, 22 Aug 2011 21:16:47 +0200
parents cbe1cb50f2fd
children ab826bc29aa2
comparison
equal deleted inserted replaced
49:cbe1cb50f2fd 50:811cefefb5c8
4 from struct import unpack, pack 4 from struct import unpack, pack
5 from pytouhou.utils.interpolator import Interpolator 5 from pytouhou.utils.interpolator import Interpolator
6 from pytouhou.game.eclrunner import ECLRunner 6 from pytouhou.game.eclrunner import ECLRunner
7 from pytouhou.game.sprite import Sprite 7 from pytouhou.game.sprite import Sprite
8 from math import cos, sin, atan2 8 from math import cos, sin, atan2
9
10
11 from pytouhou.utils.random import Random
12 random = Random(0x39f4)
13 9
14 10
15 class Enemy(object): 11 class Enemy(object):
16 def __init__(self, pos, life, _type, anm_wrapper): 12 def __init__(self, pos, life, _type, anm_wrapper):
17 self._anm_wrapper = anm_wrapper 13 self._anm_wrapper = anm_wrapper
46 self.speed = 0. 42 self.speed = 0.
47 self.rotation_speed = 0. 43 self.rotation_speed = 0.
48 self.acceleration = 0. 44 self.acceleration = 0.
49 45
50 self.hitbox = (0, 0) 46 self.hitbox = (0, 0)
47 self.screen_box = None
51 48
52 49
53 def set_bullet_attributes(self, bullet_anim, launch_anim, bullets_per_shot, 50 def set_bullet_attributes(self, bullet_anim, launch_anim, bullets_per_shot,
54 number_of_shots, speed, unknown, launch_angle, 51 number_of_shots, speed, unknown, launch_angle,
55 angle, flags): 52 angle, flags):
57 number_of_shots, speed, unknown, launch_angle, 54 number_of_shots, speed, unknown, launch_angle,
58 angle, flags) 55 angle, flags)
59 if not self.delay_attack: 56 if not self.delay_attack:
60 pass 57 pass
61 #TODO: actually fire 58 #TODO: actually fire
59
60
61 def select_player(self, players):
62 return players[0] #TODO
63
64
65 def get_player_angle(self, player):
66 return atan2(player.y - self.y, player.x - self.x)
62 67
63 68
64 def set_anim(self, index): 69 def set_anim(self, index):
65 self._anm, self._sprite = self._anm_wrapper.get_sprite(index) 70 self._anm, self._sprite = self._anm_wrapper.get_sprite(index)
66 71
109 return objects_by_texture 114 return objects_by_texture
110 115
111 116
112 def update(self, frame): 117 def update(self, frame):
113 x, y = self.x, self.y 118 x, y = self.x, self.y
114 if self.interpolator: 119 if self.interpolator and self.interpolator.update(self.frame):
115 self.interpolator.update(self.frame)
116 x, y = self.interpolator.values 120 x, y = self.interpolator.values
117 121
118 self.speed += self.acceleration #TODO: units? Execution order? 122 self.speed += self.acceleration #TODO: units? Execution order?
119 self.angle += self.rotation_speed #TODO: units? Execution order? 123 self.angle += self.rotation_speed #TODO: units? Execution order?
120 124
135 self.direction = +1 139 self.direction = +1
136 elif self.direction is not None: 140 elif self.direction is not None:
137 self.set_anim(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]]) 141 self.set_anim(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]])
138 self.direction = None 142 self.direction = None
139 143
144
145 if self.screen_box:
146 xmin, ymin, xmax, ymax = self.screen_box
147 x = max(xmin, min(x, xmax))
148 y = max(ymin, min(y, ymax))
149
150
140 self.x, self.y = x, y 151 self.x, self.y = x, y
141 if self._sprite: 152 if self._sprite:
142 changed = self._sprite.update() 153 changed = self._sprite.update()
143 visible = self.is_visible(384, 448) 154 visible = self.is_visible(384, 448)
144 if changed and visible: 155 if changed and visible:
178 if self.main and self.main[0][0] == frame: 189 if self.main and self.main[0][0] == frame:
179 for sub, instr_type, args in self.main.pop(0)[1]: 190 for sub, instr_type, args in self.main.pop(0)[1]:
180 if instr_type in (0, 2, 4, 6): # Normal/mirrored enemy 191 if instr_type in (0, 2, 4, 6): # Normal/mirrored enemy
181 x, y, z, life, unknown1, unknown2, unknown3 = args 192 x, y, z, life, unknown1, unknown2, unknown3 = args
182 if instr_type & 4: 193 if instr_type & 4:
183 if x < -990: 194 if x < -990: #102h.exe@0x411820
184 x = random.rand_double() * 368 #102h.exe@0x411820 195 x = self._game_state.prng.rand_double() * 368
185 if y < -990: 196 if y < -990: #102h.exe@0x41184b
186 y = random.rand_double() * 416 #102h.exe@0x41184b 197 y = self._game_state.prng.rand_double() * 416
187 if z < -990: 198 if z < -990: #102h.exe@0x411881
188 y = random.rand_double() * 800 #102h.exe@0x411881 199 y = self._game_state.prng.rand_double() * 800
189 enemy = Enemy((x, y), life, instr_type, self.anm_wrapper) 200 enemy = Enemy((x, y), life, instr_type, self.anm_wrapper)
190 self.enemies.append(enemy) 201 self.enemies.append(enemy)
191 self.processes.append(ECLRunner(self.ecl, sub, enemy, self._game_state)) 202 self.processes.append(ECLRunner(self.ecl, sub, enemy, self._game_state))
192 203
193 204