Example #1
0
	def get_alignment(self):
		sumVector = Vector(0, 0)
		count = 0

		for b in self.friends:
			d = np.linalg.norm(self.position - b.position)

			if d > 0 and d < NEARBY_RADIUS:
				copy = Vector(b.velocity.x, b.velocity.y)
				copy.normalize()
				copy /= d
				sumVector += copy
				count += 1

		return sumVector
Example #2
0
 def predict_next_state(self, x, y, velocity: pg.Vector2):
     vector_norm = velocity.normalize()
     predicted_x = int(round(x + vector_norm[0]))
     predicted_y = int(round(y + vector_norm[1]))
     predicted_x = max(min(predicted_x, self.resolution[0] - 1), 0)
     predicted_y = max(min(predicted_y, self.resolution[1] - 1), 0)
     return predicted_x, predicted_y
    def __init__(self, size: (int, int), direction: Vector2, force: float):
        surface = Surface(size)

        RigidPhysicsAwareGameObject.__init__(self, surface, 0)
        AnimatedSprite.__init__(
            self,
            ResourceManagement.get_environment_wind_stream_sprites(size),
            2, WindDirection.UP)
        self._direction = direction.normalize()
        self._force = force
        if abs(direction.x) > abs(direction.y):
            if direction.x > 0:
                self._state = WindDirection.RIGHT
            else:
                self._state = WindDirection.LEFT
        else:
            if direction.y > 0:
                self._state = WindDirection.DOWN
            else:
                self._state = WindDirection.UP
Example #4
0
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, direction: ImpactSide, delta_time: float):
     if isinstance(other, RigidPhysicsAwareGameObject):
         other.apply_force(
             direction_of_impact.normalize() * PlayerSettings.Ability.TornadoJump.KNOCKBACK_STRENGTH * self.level)
Example #5
0
def angle_between(vec1: Vector2, vec2: Vector2) -> float:
    """Returns the angle between the two vectors in the interval (0,180]"""
    cos_angle = dot_prod(vec1.normalize(), vec2.normalize())
    return math.acos(round(cos_angle, 5))
Example #6
0
def proj_vec(vec1: Vector2, vec2: Vector2) -> Vector2:
    return dot_prod(vec1, vec2.normalize()) * vec2.normalize()