Class Vector2D

java.lang.Object
org.collebol.shared.math.Vector2D

public class Vector2D extends Object
This 2D game Vector represents a quantity with both direction and magnitude (length), typically used for movement, velocity, and position. It is described by two components: x (horizontal) and y (vertical).
Since:
1.0-dev
Author:
ColleBol - contact@collebol.org
  • Constructor Details

    • Vector2D

      public Vector2D(float x, float y)
  • Method Details

    • getX

      public float getX()
    • setX

      public void setX(float x)
    • getY

      public float getY()
    • setY

      public void setY(float y)
    • add

      public Vector2D add(Vector2D other)
      Add up two vectors.
      Parameters:
      other - the other vector you want to add up.
      Returns:
      new vector with the combined vector values.
    • subtract

      public Vector2D subtract(Vector2D other)
      Subtract two vectors.
      Parameters:
      other - vector you want to subtract.
      Returns:
      new vector. ( x - other ).
    • scale

      public Vector2D scale(float scalar)
      Multiply vector values with scalar.
      Parameters:
      scalar - the value you want to multiply with
      Returns:
      new vector with multiplied values.
    • length

      public float length()
      Calculate the length (magnitude) of the vector.
      Returns:
      magnitude
    • distance

      public float distance(Vector2D other)
      Calculate the distance between another vector.
      Parameters:
      other - the other vector
      Returns:
      the distance between the two points.