def update(self, inputs, t, dt, collision_detector): self.first_spawn_delay = max(self.first_spawn_delay - dt, 0) direction = Vector(0.0, 0.0) if self.target: # Adjusting position, preparing to charge. target_vector = self.target.position - self.position direction = self.target.position - self.position if abs(direction.x) > abs(direction.y): direction.x = 0 else: direction.y = 0 if self.charging or (direction.magnitude() < 30.0 and self.first_spawn_delay == 0.0): # Currently charging OR beginning a charge. direction *= 0 if not self.charging: self.charging = t elif t - (self.charge_delay + self.charge_length + self.charge_rest) > self.charging: # Done resting. self.charging = None self.charge_direction = None self.speed = self.normal_speed elif t - (self.charge_delay + self.charge_length) > self.charging: # Resting from a charge. pass elif t - self.charge_delay > self.charging: # Waited a full second, charging now. if not self.charge_direction: if abs(target_vector.x) > abs(target_vector.y): direction.x = math.copysign(1, target_vector.x) else: direction.y = math.copysign(1, target_vector.y) self.charge_direction = direction.normalized() else: direction = self.charge_direction.normalized() self.speed = self.charge_speed else: direction = kidgine.math.vector.constant_zero direction = direction.normalized() direction *= self.speed * self.slow_factor collision_info = collision_detector.collides( token=self.token, filters=self.player_filter) if collision_info is not None: self.do_damage(t, collision_info) super(MeleeEnemy, self).update(inputs, t, dt, direction, collision_detector) self.reset_slow(t)
def apply(self, t, dt, c): p1 = c.shape1.owner.position p2 = c.shape2.owner.position start_vector = Vector(p2.x - p1.x, p2.y - p1.y) eject_mag = self.force / (start_vector.magnitude() / self.size ) eject_vector = start_vector.normalized().rotate((random.random() - 0.5) * self.spread) eject_vector *= (eject_mag * dt) c.shape2.owner.apply_force(eject_vector) try: c.shape2.owner.slow(t, self.slow, self) except AttributeError: pass
def apply(self, t, dt, c): p1 = c.shape1.owner.position p2 = c.shape2.owner.position start_vector = Vector(p2.x - p1.x, p2.y - p1.y) eject_mag = self.force / (start_vector.magnitude() / self.size) eject_vector = start_vector.normalized().rotate( (random.random() - 0.5) * self.spread) eject_vector *= (eject_mag * dt) c.shape2.owner.apply_force(eject_vector) try: c.shape2.owner.slow(t, self.slow, self) except AttributeError: pass
def apply(self, t, dt, c): self.last_trigger_time = t try: # Pull is at a 45 degree slant, getting straighter and weaker toward the middle. # Slow is weak, getting stronger toward the middle. p1 = c.shape1.owner.position p2 = c.shape2.owner.position start_vector = Vector(p1.x - p2.x, p1.y - p2.y) svmag = start_vector.magnitude() pull_mag = svmag * self.force_mult * self.pulse_rate pull_vector = start_vector.normalized().rotate(math.radians(-(45*(1-(self.size / (self.size + svmag)))))) pull_vector *= pull_mag**0.5 c.shape2.owner.apply_force(pull_vector) c.shape2.owner.slow(t, min(self.min_slow, self.min_slow / (pull_mag * self.slow_scale)), self) except AttributeError: pass
def apply(self, t, dt, c): self.last_trigger_time = t try: # Pull is at a 45 degree slant, getting straighter and weaker toward the middle. # Slow is weak, getting stronger toward the middle. p1 = c.shape1.owner.position p2 = c.shape2.owner.position start_vector = Vector(p1.x - p2.x, p1.y - p2.y) svmag = start_vector.magnitude() pull_mag = svmag * self.force_mult * self.pulse_rate pull_vector = start_vector.normalized().rotate( math.radians(-(45 * (1 - (self.size / (self.size + svmag)))))) pull_vector *= pull_mag**0.5 c.shape2.owner.apply_force(pull_vector) c.shape2.owner.slow( t, min(self.min_slow, self.min_slow / (pull_mag * self.slow_scale)), self) except AttributeError: pass