vec.jamo (built in)

vec: 2D points and directions for games. use "vec.jamo"

A Vec2 is an x and a y. Every method gives back a new Vec2 and leaves the one it's called on alone, so p.plus(speed) doesn't change p. Angles are in radians, counting from the x axis toward the y axis, so on a screen, where y goes down, a growing angle turns clockwise.

structVec2

struct Vec2
    x: float
    y: float
end

funcvec2

func vec2(x: float, y: float): Vec2

funcvec2_from_angle

func vec2_from_angle(angle: float, length: float): Vec2

A direction of the given length, like vec2_from_angle(pi() / 2.0, 3.0) for 3 straight down a screen

funcVec2.plus

func Vec2.plus(other: Vec2): Vec2

funcVec2.minus

func Vec2.minus(other: Vec2): Vec2

funcVec2.times

func Vec2.times(amount: float): Vec2

funcVec2.dot

func Vec2.dot(other: Vec2): float

funcVec2.length

func Vec2.length(): float

funcVec2.distance

func Vec2.distance(other: Vec2): float

funcVec2.normalized

func Vec2.normalized(): Vec2

The same direction with a length of 1. A Vec2 of length 0 has no direction, so it stays 0

funcVec2.angle

func Vec2.angle(): float

The angle it points at, from -pi to pi

funcVec2.rotated

func Vec2.rotated(angle: float): Vec2

funcVec2.lerp_to

func Vec2.lerp_to(other: Vec2, part: float): Vec2

Part of the way to other: 0.0 gives this one, 1.0 gives other

funcVec2.limited

func Vec2.limited(longest: float): Vec2

At most this long, keeping its direction, for things like a top speed