html2d
Version:
A Typescript game engine to build HTML5 games for the web using webcomponents.
29 lines (26 loc) • 692 B
JavaScript
export class Vector2D {
/**
* Representation of 2D vectors and points.
* @param {number} x - X component of the vector.
* @param {number} y - Y component of the vector.
*/
constructor(x, y) {
this.x = x ?? 0
this.y = y ?? 0
}
}
export class Input2D {
/**
* @param {( "Horizontal" | "Vertical" )} direction - a virtual axis name.
* */
static getAxis(direction) {
if (direction === "Horizontal") {
return 1
}
if (direction === "Vertical") {
return -1
}
console.error(`${direction} is not a valid axis name.`)
}
}