The Game library provides essential utilities for game development, physics, and gameplay logic.
Game.intersectRect(x1, y1, w1, h1, x2, y2, w2, h2)- Returnstrueif two rectangles overlap.Game.pointInRect(px, py, rx, ry, rw, rh)- Returnstrueif a point is inside a rectangle.
Game.moveTowards(current, target, maxDelta)- Movescurrenttowardstargetwithout overshooting.Game.lerp(a, b, t)- Linearly interpolates betweenaandb.Game.smoothstep(edge0, edge1, x)- Smooth interpolation between 0 and 1.Game.angleTo(x1, y1, x2, y2)- Returns the angle (radians) from point 1 to point 2.Game.deltaAngle(a, b)- Shortest distance between two angles (radians).
Game.chance(p)- Returnstruewith probabilityp(0.0 to 1.0).Game.shake(mag)- Returns a random value between-magand+mag.Game.choose(args...)- Returns a random element from the provided arguments.Game.deadzone(val, threshold)- Returns 0 ifabs(val) < threshold.Game.repeat(t, length)- Loopstso it is never larger thanlengthand never smaller than 0.Game.pingPong(t, length)- Returns a value that oscillates between 0 andlength.
Game.degToRad(deg)- Converts degrees to radians.Game.radToDeg(rad)- Converts radians to degrees.