Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/foopis23/simple-game-math
A node package for simple math functions and types for game development.
https://github.com/foopis23/simple-game-math
game game-development library math nodejs package
Last synced: about 23 hours ago
JSON representation
A node package for simple math functions and types for game development.
- Host: GitHub
- URL: https://github.com/foopis23/simple-game-math
- Owner: foopis23
- License: gpl-3.0
- Created: 2022-03-28T23:42:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-03-29T13:37:51.000Z (over 2 years ago)
- Last Synced: 2024-10-07T22:38:08.728Z (about 1 month ago)
- Topics: game, game-development, library, math, nodejs, package
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/simple-game-math
- Size: 111 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Game Math API Reference
A node package for simple math functions and types for game development.## Vector2
A module for Vector2 types and functions.### Interface: Vector2.IVector2
An interface for vectors.#### Vector2.IVector2.x : number
X component of vector.#### Vector2.IVector2.y : number
Y component of vector.```ts
import { Vector2 } from 'simple-game-math'
const newVector: Vector2.IVector2 = {
x: 0,
y: 10
}
``````ts
import { Vector2 } from 'simple-game-math'class Vector extends IVector2 {
constructor(public x: number, public y: number) {}
}
```### Vector2.distance(a: IVector2, b: IVector2): number
Returns the distance between 2 vectors points.```ts
import { Vector2 } from 'simple-game-math'
const dist = Vector2.distance({x: 0, y: 0}, {x: 10, y: 0})console.log(dist) // output: 10
```### Vector2.dot(a: IVector2, b: IVector2): number
Returns the dot product between 2 vectors.```ts
import { Vector2 } from 'simple-game-math'console.log(Vector2.dot({x: 1, y: 1}, {x: 10, y: 10})) // output: {x: 10, y: 10}
```### Vector2.mag(v: IVector2): number
Returns the magnitude of a vector.```ts
import { Vector2 } from 'simple-game-math'console.log(Vector2.mag({x: 5, y: 10})) //output: 11.180339887498949
```### Vector2.normalize(v: IVector2): IVector2
Returns a vector with a magnitude of one in the same direction as the input vector.```ts
import { Vector2 } from 'simple-game-math'console.log(Vector2.normalize({x: 5, y: 10})) // output: {x: 0.44721359549996, y: 0.89442719099992}
```### Vector2.subtract(b: IVector2, a: IVector2): IVector2
Returns a vector where the components are equal to `x = b.x - a.x and y = b.y - a.y`.```ts
import { Vector2 } from 'simple-game-math'console.log(Vector2.subtract({x: 10, y: 15}, {x: 5, y: 5})) //output: {x: 5, y: 10}
```## Math
A module for providing basic math functions.### Math.clamp(v: number, min: number, max: number): number
Returns the a V clamped between min and max.```ts
import { Math } from 'simple-game-math'console.log(Math.clamp(20, 0, 10)) //output: 10
```### Math.moveTowards(current: number, towards: number, maxStep: number): number
Returns a number that is between current and towards but will not exceed towards.```ts
import { Math } from 'simple-game-math'console.log(Math.moveTowards(0, 10, 5)) // output: 5
console.log(Math.moveTowards(0, 10, 20)) // output: 10
console.log(Math.moveTowards(0, 10, -10)) // output: 0
```### Math.lerp(start: number, end: number, step: number): number
Linearly interpolates between two numbers```ts
import { Math } from 'simple-game-math'console.log(Math.lerp(0, 10, 0.5)) // output: 5
console.log(Math.lerp(0, 10, 0.25)) // output: 2.5
console.log(Math.lerp(0, 10, 0.75)) // output: 7.5
console.log(Math.lerp(0, 10, 1)) // output: 10
```