def __init__(self, scene, pos, dest, router): Entity.__init__(self) self._destroyed = False self._closing = False self._target_reached = False self._scene = scene self._map = scene.getMap() self._path = None self._dying_t = 0 self._spin = 0 self.moveTo(pos) self._scale = 1.0 self._graphics = R.loadObject("enemy.obj","diffuse") self._orient_m= T.identity_matrix() self._xform_m = N.dot(T.rotation_matrix(math.pi/2,(0,0,1)),T.scale_matrix(self._scale)) bounds = self._graphics.getObj().getBounds() router.requestJob(pos, dest, Enemy.OnRouteObtained, self) Entity.setBounds(self,bounds * self._scale) self._destroyed = False self._old_time = 0 self._old_pos = None # At t-1 self._old_pos2 = None # At t-2 self._hc = HeadingController()
def update(self, time): if self._destroyed: return False if self._closing: self._scale -= 0.01 self._scale = max(self._scale, 0) self._scale_m = T.scale_matrix(self._scale) if self._scale == 0: self._destroyed = True if self._closing == self.TARGET_REACHED: self._spin += 0.1 self.moveTo(self._pos + (0,0,0.1)) self._xform_m = N.dot(T.rotation_matrix(math.pi/2+self._spin,(0,0,1)),T.scale_matrix(self._scale)) elif not self._target_reached: if self._old_time == 0: self._old_time = time return True dt = time - self._old_time self._old_time = time if self._path: new_pos = self._path.advance(dt) if new_pos is None: self._target_reached = True else: self._orient_m= self._hc(new_pos) self.moveTo(new_pos + (0,0,2)) return True