comparison nagslang/enemies.py @ 307:c2bbb1e70d6f

Rename animate to update and pass seconds, for future fun
author Neil Muller <drnlmuller@gmail.com>
date Fri, 06 Sep 2013 00:32:38 +0200
parents ce11e1cae0ed
children 3dee86b6c216
comparison
equal deleted inserted replaced
306:3118589aeb11 307:c2bbb1e70d6f
108 def set_direction(self, dx, dy): 108 def set_direction(self, dx, dy):
109 self.angle = pymunk.Vec2d((dx, dy)).angle 109 self.angle = pymunk.Vec2d((dx, dy)).angle
110 self._body.apply_impulse( 110 self._body.apply_impulse(
111 (dx * self.impulse_factor, dy * self.impulse_factor)) 111 (dx * self.impulse_factor, dy * self.impulse_factor))
112 112
113 def animate(self): 113 def update(self, seconds):
114 # Calculate the step every frame 114 # Calculate the step every frame
115 if self._direction == 'away': 115 if self._direction == 'away':
116 target = self._end_pos 116 target = self._end_pos
117 else: 117 else:
118 target = self._start_pos 118 target = self._start_pos
131 if abs(y_step) < 0.5: 131 if abs(y_step) < 0.5:
132 y_step = 0 132 y_step = 0
133 if abs(x_step) < 1 and abs(y_step) < 1: 133 if abs(x_step) < 1 and abs(y_step) < 1:
134 self._switch_direction() 134 self._switch_direction()
135 self.set_direction(x_step, y_step) 135 self.set_direction(x_step, y_step)
136 super(PatrollingAlien, self).animate() 136 super(PatrollingAlien, self).update(seconds)
137 137
138 def collide_with_protagonist(self, protagonist): 138 def collide_with_protagonist(self, protagonist):
139 protagonist.lose_health(15) 139 protagonist.lose_health(15)
140 140
141 def hit(self, weapon): 141 def hit(self, weapon):
191 def set_direction(self, dx, dy): 191 def set_direction(self, dx, dy):
192 self.angle = pymunk.Vec2d((dx, dy)).angle 192 self.angle = pymunk.Vec2d((dx, dy)).angle
193 self._body.apply_impulse( 193 self._body.apply_impulse(
194 (dx * self.impulse_factor, dy * self.impulse_factor)) 194 (dx * self.impulse_factor, dy * self.impulse_factor))
195 195
196 def animate(self): 196 def update(self, seconds):
197 # Calculate the step every frame 197 # Calculate the step every frame
198 # Distance to the protagonist 198 # Distance to the protagonist
199 pos = self._body.position 199 pos = self._body.position
200 target = self.world.protagonist.get_shape().body.position 200 target = self.world.protagonist.get_shape().body.position
201 if pos.get_distance(target) > self._range: 201 if pos.get_distance(target) > self._range:
216 elif (target[1] > pos[1]): 216 elif (target[1] > pos[1]):
217 y_step = min(1, target[1] - pos[1]) 217 y_step = min(1, target[1] - pos[1])
218 if abs(y_step) < 0.5: 218 if abs(y_step) < 0.5:
219 y_step = 0 219 y_step = 0
220 self.set_direction(x_step, y_step) 220 self.set_direction(x_step, y_step)
221 super(ChargingAlien, self).animate() 221 super(ChargingAlien, self).update(seconds)
222 222
223 def collide_with_protagonist(self, protagonist): 223 def collide_with_protagonist(self, protagonist):
224 protagonist.lose_health(20) 224 protagonist.lose_health(20)
225 225
226 @classmethod 226 @classmethod