def step(self, units): """Performs a time step for this missile Moves towards target and damages if collision occurs If target is dead, this missile expires Parameters: units.enemies (UnitManager): The unit manager to select targets from Return: (persist, new_obstacles) pair, where: - persist (bool): True if the obstacle should persist in the game (else will be removed) - new_obstacles (list[AbstractObstacle]): A list of new obstacles to add to the game, or None """ if self.target.is_dead(): return False, None # move toward the target radius = euclidean_distance(self.position, self.target.position) if radius <= self.speed: self.target.damage(self.damage, 'explosive') return False, None # Rotate toward target and move angle = angle_between(self.position, self.target.position) self.rotation = rotate_toward(self.rotation, angle, self.rotation_threshold) dx, dy = polar_to_rectangular(self.speed, self.rotation) x, y = self.position self.position = x + dx, y + dy return True, None
def step(self, units): """Performs a time step for this missile Moves towards target and damages if collision occurs If target is dead, this missile expires Parameters: units.enemies (UnitManager): The unit manager to select targets from Return: (persist, new_obstacles) pair, where: - persist (bool): True if the obstacle should persist in the game (else will be removed) - new_obstacles (list[AbstractObstacle]): A list of new obstacles to add to the game, or None """ if self.target == None: return False, None if self.target.is_dead(): return False, None # move toward the target #for enemy in units.enemies: # radius = euclidean_distance(self.position, enemy.position) #if radius <= self.speed: #enemy.damage(self.damage, 'energy') #return False, None # new approach to laser x, y = old_position = self.position dx, dy = polar_to_rectangular(self.speed, self._rotation) self.position = new_position = x + dx, y + dy self._hit_count = 1000 try: old_bucket = units.enemies.get_bucket_for_position(old_position) new_bucket = units.enemies.get_bucket_for_position(self.position) except IndexError: return False, None for enemy in old_bucket.union(new_bucket): if -0.5 <= euclidean_distance(self.position, enemy.position) >= 0.5: enemy.damage(self.damage, 'energy') return True, None
def step(self, units): if self.target.is_dead(): return False, None # move toward the target radius = euclidean_distance(self.position, self.target.position) if radius <= self.speed: self.target.damage(self.damage, 'fire') return False, None # Rotate toward target and move angle = angle_between(self.position, self.target.position) self.rotation = rotate_toward(self.rotation, angle, self.rotation_threshold) dx, dy = polar_to_rectangular(self.speed, self.rotation) x, y = self.position self.position = x + dx, y + dy return True, None