like2d 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +66 -0
  2. package/dist/audio.d.ts +52 -0
  3. package/dist/audio.d.ts.map +1 -0
  4. package/dist/audio.js +250 -0
  5. package/dist/events.d.ts +36 -0
  6. package/dist/events.d.ts.map +1 -0
  7. package/dist/events.js +1 -0
  8. package/dist/gamecontrollerdb.txt +2219 -0
  9. package/dist/gamepad-button-map.d.ts +5 -0
  10. package/dist/gamepad-button-map.d.ts.map +1 -0
  11. package/dist/gamepad-button-map.js +56 -0
  12. package/dist/gamepad-db.d.ts +49 -0
  13. package/dist/gamepad-db.d.ts.map +1 -0
  14. package/dist/gamepad-db.js +192 -0
  15. package/dist/gamepad-mapping.d.ts +31 -0
  16. package/dist/gamepad-mapping.d.ts.map +1 -0
  17. package/dist/gamepad-mapping.js +191 -0
  18. package/dist/gamepad.d.ts +56 -0
  19. package/dist/gamepad.d.ts.map +1 -0
  20. package/dist/gamepad.js +216 -0
  21. package/dist/graphics.d.ts +80 -0
  22. package/dist/graphics.d.ts.map +1 -0
  23. package/dist/graphics.js +388 -0
  24. package/dist/index.d.ts +45 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +250 -0
  27. package/dist/input-state.d.ts +14 -0
  28. package/dist/input-state.d.ts.map +1 -0
  29. package/dist/input-state.js +50 -0
  30. package/dist/input.d.ts +36 -0
  31. package/dist/input.d.ts.map +1 -0
  32. package/dist/input.js +127 -0
  33. package/dist/keyboard.d.ts +9 -0
  34. package/dist/keyboard.d.ts.map +1 -0
  35. package/dist/keyboard.js +33 -0
  36. package/dist/mouse.d.ts +20 -0
  37. package/dist/mouse.d.ts.map +1 -0
  38. package/dist/mouse.js +84 -0
  39. package/dist/rect.d.ts +27 -0
  40. package/dist/rect.d.ts.map +1 -0
  41. package/dist/rect.js +132 -0
  42. package/dist/scene.d.ts +10 -0
  43. package/dist/scene.d.ts.map +1 -0
  44. package/dist/scene.js +1 -0
  45. package/dist/timer.d.ts +19 -0
  46. package/dist/timer.d.ts.map +1 -0
  47. package/dist/timer.js +86 -0
  48. package/dist/vector2.d.ts +32 -0
  49. package/dist/vector2.d.ts.map +1 -0
  50. package/dist/vector2.js +105 -0
  51. package/package.json +64 -0
package/dist/mouse.js ADDED
@@ -0,0 +1,84 @@
1
+ export class Mouse {
2
+ constructor() {
3
+ Object.defineProperty(this, "x", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: 0
8
+ });
9
+ Object.defineProperty(this, "y", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: 0
14
+ });
15
+ Object.defineProperty(this, "buttons", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: new Set()
20
+ });
21
+ Object.defineProperty(this, "canvas", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: null
26
+ });
27
+ this.setupEventListeners();
28
+ }
29
+ setCanvas(canvas) {
30
+ this.canvas = canvas;
31
+ }
32
+ setupEventListeners() {
33
+ window.addEventListener('mousemove', (e) => {
34
+ if (this.canvas) {
35
+ const rect = this.canvas.getBoundingClientRect();
36
+ this.x = e.clientX - rect.left;
37
+ this.y = e.clientY - rect.top;
38
+ }
39
+ else {
40
+ this.x = e.clientX;
41
+ this.y = e.clientY;
42
+ }
43
+ });
44
+ window.addEventListener('mousedown', (e) => {
45
+ this.buttons.add(e.button + 1);
46
+ });
47
+ window.addEventListener('mouseup', (e) => {
48
+ this.buttons.delete(e.button + 1);
49
+ });
50
+ window.addEventListener('blur', () => {
51
+ this.buttons.clear();
52
+ });
53
+ }
54
+ getPosition() {
55
+ return [this.x, this.y];
56
+ }
57
+ getX() {
58
+ return this.x;
59
+ }
60
+ getY() {
61
+ return this.y;
62
+ }
63
+ isDown(button) {
64
+ return this.buttons.has(button);
65
+ }
66
+ getPressedButtons() {
67
+ return new Set(this.buttons);
68
+ }
69
+ isVisible() {
70
+ return document.pointerLockElement === null;
71
+ }
72
+ setVisible(visible) {
73
+ if (!visible && this.canvas) {
74
+ this.canvas.requestPointerLock();
75
+ }
76
+ else if (visible && document.pointerLockElement === this.canvas) {
77
+ document.exitPointerLock();
78
+ }
79
+ }
80
+ getRelativeMode() {
81
+ return document.pointerLockElement !== null;
82
+ }
83
+ }
84
+ export const mouse = new Mouse();
package/dist/rect.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { Vector2 } from './vector2';
2
+ export type Rect = [number, number, number, number];
3
+ export declare namespace R {
4
+ function create(x: number, y: number, w: number, h: number): Rect;
5
+ function fromPoints(a: Vector2, b: Vector2): Rect;
6
+ function fromCenter(center: Vector2, size: Vector2): Rect;
7
+ function position(r: Rect): Vector2;
8
+ function size(r: Rect): Vector2;
9
+ function center(r: Rect): Vector2;
10
+ function topLeft(r: Rect): Vector2;
11
+ function topRight(r: Rect): Vector2;
12
+ function bottomLeft(r: Rect): Vector2;
13
+ function bottomRight(r: Rect): Vector2;
14
+ function area(r: Rect): number;
15
+ function isEmpty(r: Rect): boolean;
16
+ function containsPoint(r: Rect, point: Vector2): boolean;
17
+ function containsRect(r: Rect, other: Rect): boolean;
18
+ function intersects(r: Rect, other: Rect): boolean;
19
+ function intersection(r: Rect, other: Rect): Rect;
20
+ function union(r: Rect, other: Rect): Rect;
21
+ function inflate(r: Rect, amount: number): Rect;
22
+ function offset(r: Rect, delta: Vector2): Rect;
23
+ function setPosition(r: Rect, pos: Vector2): Rect;
24
+ function setSize(r: Rect, size: Vector2): Rect;
25
+ function setCenter(r: Rect, center: Vector2): Rect;
26
+ }
27
+ //# sourceMappingURL=rect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rect.d.ts","sourceRoot":"","sources":["../src/rect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM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EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAWvD;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAMhD;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAOrD;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEpD;IAED,SAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAEvD;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAEpD;IAED,SAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAOxD;CACF"}
package/dist/rect.js ADDED
@@ -0,0 +1,132 @@
1
+ export var R;
2
+ (function (R) {
3
+ function create(x, y, w, h) {
4
+ return [x, y, w, h];
5
+ }
6
+ R.create = create;
7
+ function fromPoints(a, b) {
8
+ const minX = Math.min(a[0], b[0]);
9
+ const minY = Math.min(a[1], b[1]);
10
+ const maxX = Math.max(a[0], b[0]);
11
+ const maxY = Math.max(a[1], b[1]);
12
+ return [minX, minY, maxX - minX, maxY - minY];
13
+ }
14
+ R.fromPoints = fromPoints;
15
+ function fromCenter(center, size) {
16
+ return [
17
+ center[0] - size[0] / 2,
18
+ center[1] - size[1] / 2,
19
+ size[0],
20
+ size[1],
21
+ ];
22
+ }
23
+ R.fromCenter = fromCenter;
24
+ function position(r) {
25
+ return [r[0], r[1]];
26
+ }
27
+ R.position = position;
28
+ function size(r) {
29
+ return [r[2], r[3]];
30
+ }
31
+ R.size = size;
32
+ function center(r) {
33
+ return [r[0] + r[2] / 2, r[1] + r[3] / 2];
34
+ }
35
+ R.center = center;
36
+ function topLeft(r) {
37
+ return [r[0], r[1]];
38
+ }
39
+ R.topLeft = topLeft;
40
+ function topRight(r) {
41
+ return [r[0] + r[2], r[1]];
42
+ }
43
+ R.topRight = topRight;
44
+ function bottomLeft(r) {
45
+ return [r[0], r[1] + r[3]];
46
+ }
47
+ R.bottomLeft = bottomLeft;
48
+ function bottomRight(r) {
49
+ return [r[0] + r[2], r[1] + r[3]];
50
+ }
51
+ R.bottomRight = bottomRight;
52
+ function area(r) {
53
+ return r[2] * r[3];
54
+ }
55
+ R.area = area;
56
+ function isEmpty(r) {
57
+ return r[2] <= 0 || r[3] <= 0;
58
+ }
59
+ R.isEmpty = isEmpty;
60
+ function containsPoint(r, point) {
61
+ return (point[0] >= r[0] &&
62
+ point[0] <= r[0] + r[2] &&
63
+ point[1] >= r[1] &&
64
+ point[1] <= r[1] + r[3]);
65
+ }
66
+ R.containsPoint = containsPoint;
67
+ function containsRect(r, other) {
68
+ return (other[0] >= r[0] &&
69
+ other[0] + other[2] <= r[0] + r[2] &&
70
+ other[1] >= r[1] &&
71
+ other[1] + other[3] <= r[1] + r[3]);
72
+ }
73
+ R.containsRect = containsRect;
74
+ function intersects(r, other) {
75
+ return (r[0] < other[0] + other[2] &&
76
+ r[0] + r[2] > other[0] &&
77
+ r[1] < other[1] + other[3] &&
78
+ r[1] + r[3] > other[1]);
79
+ }
80
+ R.intersects = intersects;
81
+ function intersection(r, other) {
82
+ const x1 = Math.max(r[0], other[0]);
83
+ const y1 = Math.max(r[1], other[1]);
84
+ const x2 = Math.min(r[0] + r[2], other[0] + other[2]);
85
+ const y2 = Math.min(r[1] + r[3], other[1] + other[3]);
86
+ const w = x2 - x1;
87
+ const h = y2 - y1;
88
+ if (w <= 0 || h <= 0) {
89
+ return [0, 0, 0, 0];
90
+ }
91
+ return [x1, y1, w, h];
92
+ }
93
+ R.intersection = intersection;
94
+ function union(r, other) {
95
+ const x1 = Math.min(r[0], other[0]);
96
+ const y1 = Math.min(r[1], other[1]);
97
+ const x2 = Math.max(r[0] + r[2], other[0] + other[2]);
98
+ const y2 = Math.max(r[1] + r[3], other[1] + other[3]);
99
+ return [x1, y1, x2 - x1, y2 - y1];
100
+ }
101
+ R.union = union;
102
+ function inflate(r, amount) {
103
+ return [
104
+ r[0] - amount,
105
+ r[1] - amount,
106
+ r[2] + amount * 2,
107
+ r[3] + amount * 2,
108
+ ];
109
+ }
110
+ R.inflate = inflate;
111
+ function offset(r, delta) {
112
+ return [r[0] + delta[0], r[1] + delta[1], r[2], r[3]];
113
+ }
114
+ R.offset = offset;
115
+ function setPosition(r, pos) {
116
+ return [pos[0], pos[1], r[2], r[3]];
117
+ }
118
+ R.setPosition = setPosition;
119
+ function setSize(r, size) {
120
+ return [r[0], r[1], size[0], size[1]];
121
+ }
122
+ R.setSize = setSize;
123
+ function setCenter(r, center) {
124
+ return [
125
+ center[0] - r[2] / 2,
126
+ center[1] - r[3] / 2,
127
+ r[2],
128
+ r[3],
129
+ ];
130
+ }
131
+ R.setCenter = setCenter;
132
+ })(R || (R = {}));
@@ -0,0 +1,10 @@
1
+ import type { Event } from './events';
2
+ export interface Scene {
3
+ width: number;
4
+ height: number;
5
+ load?: () => void;
6
+ update: (dt: number) => void;
7
+ draw: () => void;
8
+ handleEvent?: (event: Event) => void;
9
+ }
10
+ //# sourceMappingURL=scene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../src/scene.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACtC"}
package/dist/scene.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ export declare class Timer {
2
+ private currentDelta;
3
+ private totalTime;
4
+ private frameCount;
5
+ private fps;
6
+ private fpsAccumulator;
7
+ private sleepUntil;
8
+ private sceneStartTime;
9
+ update(dt: number): void;
10
+ resetSceneTime(): void;
11
+ getDelta(): number;
12
+ getFPS(): number;
13
+ getTime(): number;
14
+ getSceneTime(): number;
15
+ isSleeping(): boolean;
16
+ sleep(duration: number): void;
17
+ }
18
+ export declare const timer: Timer;
19
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IAChB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,cAAc,CAAK;IAE3B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAaxB,cAAc,IAAI,IAAI;IAItB,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,MAAM;IAIjB,YAAY,IAAI,MAAM;IAItB,UAAU,IAAI,OAAO;IAUrB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAG9B;AAED,eAAO,MAAM,KAAK,OAAc,CAAC"}
package/dist/timer.js ADDED
@@ -0,0 +1,86 @@
1
+ export class Timer {
2
+ constructor() {
3
+ Object.defineProperty(this, "currentDelta", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: 0
8
+ });
9
+ Object.defineProperty(this, "totalTime", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: 0
14
+ });
15
+ Object.defineProperty(this, "frameCount", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: 0
20
+ });
21
+ Object.defineProperty(this, "fps", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: 0
26
+ });
27
+ Object.defineProperty(this, "fpsAccumulator", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: 0
32
+ });
33
+ Object.defineProperty(this, "sleepUntil", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: null
38
+ });
39
+ Object.defineProperty(this, "sceneStartTime", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: 0
44
+ });
45
+ }
46
+ update(dt) {
47
+ this.currentDelta = dt;
48
+ this.totalTime += dt;
49
+ this.frameCount++;
50
+ this.fpsAccumulator += dt;
51
+ if (this.fpsAccumulator >= 1) {
52
+ this.fps = Math.round(this.frameCount / this.fpsAccumulator);
53
+ this.frameCount = 0;
54
+ this.fpsAccumulator = 0;
55
+ }
56
+ }
57
+ resetSceneTime() {
58
+ this.sceneStartTime = this.totalTime;
59
+ }
60
+ getDelta() {
61
+ return this.currentDelta;
62
+ }
63
+ getFPS() {
64
+ return this.fps;
65
+ }
66
+ getTime() {
67
+ return this.totalTime;
68
+ }
69
+ getSceneTime() {
70
+ return this.totalTime - this.sceneStartTime;
71
+ }
72
+ isSleeping() {
73
+ if (this.sleepUntil === null)
74
+ return false;
75
+ const currentTime = performance.now();
76
+ if (currentTime < this.sleepUntil) {
77
+ return true;
78
+ }
79
+ this.sleepUntil = null;
80
+ return false;
81
+ }
82
+ sleep(duration) {
83
+ this.sleepUntil = performance.now() + (duration * 1000);
84
+ }
85
+ }
86
+ export const timer = new Timer();
@@ -0,0 +1,32 @@
1
+ export type Vector2 = [number, number];
2
+ export declare namespace V2 {
3
+ function add(a: Vector2, b: Vector2): Vector2;
4
+ function sub(a: Vector2, b: Vector2): Vector2;
5
+ function mul(v: Vector2, s: number): Vector2;
6
+ function div(v: Vector2, s: number): Vector2;
7
+ function dot(a: Vector2, b: Vector2): number;
8
+ function cross(a: Vector2, b: Vector2): number;
9
+ function lengthSq(v: Vector2): number;
10
+ function length(v: Vector2): number;
11
+ function normalize(v: Vector2): Vector2;
12
+ function distance(a: Vector2, b: Vector2): number;
13
+ function lerp(a: Vector2, b: Vector2, t: number): Vector2;
14
+ function angle(v: Vector2): number;
15
+ function rotate(v: Vector2, angle: number): Vector2;
16
+ function perpendicular(v: Vector2): Vector2;
17
+ function negate(v: Vector2): Vector2;
18
+ function floor(v: Vector2): Vector2;
19
+ function ceil(v: Vector2): Vector2;
20
+ function round(v: Vector2): Vector2;
21
+ function min(a: Vector2, b: Vector2): Vector2;
22
+ function max(a: Vector2, b: Vector2): Vector2;
23
+ function clamp(v: Vector2, min: Vector2, max: Vector2): Vector2;
24
+ function fromAngle(angle: number, len?: number): Vector2;
25
+ const zero: Vector2;
26
+ const one: Vector2;
27
+ const up: Vector2;
28
+ const down: Vector2;
29
+ const left: Vector2;
30
+ const right: Vector2;
31
+ }
32
+ //# sourceMappingURL=vector2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector2.d.ts","sourceRoot":"","sources":["../src/vector2.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvC,yBAAiB,EAAE,CAAC;IAClB,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAElD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAElD;IAED,SAAgB,GAAG,CAAC,CAAC,EAA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AG,OAAO,CAKrE;IAED,SAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,GAAG,OAAO,CAEjE;IAEM,MAAM,IAAI,EAAE,OAAgB,CAAC;IAC7B,MAAM,GAAG,EAAE,OAAgB,CAAC;IAC5B,MAAM,EAAE,EAAE,OAAiB,CAAC;IAC5B,MAAM,IAAI,EAAE,OAAgB,CAAC;IAC7B,MAAM,IAAI,EAAE,OAAiB,CAAC;IAC9B,MAAM,KAAK,EAAE,OAAgB,CAAC;CACtC"}
@@ -0,0 +1,105 @@
1
+ export var V2;
2
+ (function (V2) {
3
+ function add(a, b) {
4
+ return [a[0] + b[0], a[1] + b[1]];
5
+ }
6
+ V2.add = add;
7
+ function sub(a, b) {
8
+ return [a[0] - b[0], a[1] - b[1]];
9
+ }
10
+ V2.sub = sub;
11
+ function mul(v, s) {
12
+ return [v[0] * s, v[1] * s];
13
+ }
14
+ V2.mul = mul;
15
+ function div(v, s) {
16
+ return [v[0] / s, v[1] / s];
17
+ }
18
+ V2.div = div;
19
+ function dot(a, b) {
20
+ return a[0] * b[0] + a[1] * b[1];
21
+ }
22
+ V2.dot = dot;
23
+ function cross(a, b) {
24
+ return a[0] * b[1] - a[1] * b[0];
25
+ }
26
+ V2.cross = cross;
27
+ function lengthSq(v) {
28
+ return v[0] * v[0] + v[1] * v[1];
29
+ }
30
+ V2.lengthSq = lengthSq;
31
+ function length(v) {
32
+ return Math.sqrt(lengthSq(v));
33
+ }
34
+ V2.length = length;
35
+ function normalize(v) {
36
+ const len = length(v);
37
+ if (len === 0)
38
+ return [0, 0];
39
+ return div(v, len);
40
+ }
41
+ V2.normalize = normalize;
42
+ function distance(a, b) {
43
+ return length(sub(a, b));
44
+ }
45
+ V2.distance = distance;
46
+ function lerp(a, b, t) {
47
+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
48
+ }
49
+ V2.lerp = lerp;
50
+ function angle(v) {
51
+ return Math.atan2(v[1], v[0]);
52
+ }
53
+ V2.angle = angle;
54
+ function rotate(v, angle) {
55
+ const cos = Math.cos(angle);
56
+ const sin = Math.sin(angle);
57
+ return [v[0] * cos - v[1] * sin, v[0] * sin + v[1] * cos];
58
+ }
59
+ V2.rotate = rotate;
60
+ function perpendicular(v) {
61
+ return [-v[1], v[0]];
62
+ }
63
+ V2.perpendicular = perpendicular;
64
+ function negate(v) {
65
+ return [-v[0], -v[1]];
66
+ }
67
+ V2.negate = negate;
68
+ function floor(v) {
69
+ return [Math.floor(v[0]), Math.floor(v[1])];
70
+ }
71
+ V2.floor = floor;
72
+ function ceil(v) {
73
+ return [Math.ceil(v[0]), Math.ceil(v[1])];
74
+ }
75
+ V2.ceil = ceil;
76
+ function round(v) {
77
+ return [Math.round(v[0]), Math.round(v[1])];
78
+ }
79
+ V2.round = round;
80
+ function min(a, b) {
81
+ return [Math.min(a[0], b[0]), Math.min(a[1], b[1])];
82
+ }
83
+ V2.min = min;
84
+ function max(a, b) {
85
+ return [Math.max(a[0], b[0]), Math.max(a[1], b[1])];
86
+ }
87
+ V2.max = max;
88
+ function clamp(v, min, max) {
89
+ return [
90
+ Math.max(min[0], Math.min(v[0], max[0])),
91
+ Math.max(min[1], Math.min(v[1], max[1])),
92
+ ];
93
+ }
94
+ V2.clamp = clamp;
95
+ function fromAngle(angle, len = 1) {
96
+ return [Math.cos(angle) * len, Math.sin(angle) * len];
97
+ }
98
+ V2.fromAngle = fromAngle;
99
+ V2.zero = [0, 0];
100
+ V2.one = [1, 1];
101
+ V2.up = [0, -1];
102
+ V2.down = [0, 1];
103
+ V2.left = [-1, 0];
104
+ V2.right = [1, 0];
105
+ })(V2 || (V2 = {}));
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "like2d",
3
+ "version": "1.0.0",
4
+ "description": "A web-native game framework inspired by Love2D",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./graphics": {
15
+ "import": "./dist/graphics.js",
16
+ "types": "./dist/graphics.d.ts"
17
+ },
18
+ "./audio": {
19
+ "import": "./dist/audio.js",
20
+ "types": "./dist/audio.d.ts"
21
+ },
22
+ "./input": {
23
+ "import": "./dist/input.js",
24
+ "types": "./dist/input.d.ts"
25
+ },
26
+ "./scene": {
27
+ "import": "./dist/scene.js",
28
+ "types": "./dist/scene.d.ts"
29
+ },
30
+ "./vector2": {
31
+ "import": "./dist/vector2.js",
32
+ "types": "./dist/vector2.d.ts"
33
+ },
34
+ "./rect": {
35
+ "import": "./dist/rect.js",
36
+ "types": "./dist/rect.d.ts"
37
+ }
38
+ },
39
+ "files": [
40
+ "dist/**/*",
41
+ "README.md",
42
+ "LICENSE"
43
+ ],
44
+ "scripts": {
45
+ "build": "tsc && cp src/gamecontrollerdb.txt dist/",
46
+ "typecheck": "tsc --noEmit",
47
+ "lint": "echo 'No linting configured'",
48
+ "clean": "rm -rf dist"
49
+ },
50
+ "keywords": [
51
+ "game",
52
+ "framework",
53
+ "2d",
54
+ "love2d",
55
+ "canvas",
56
+ "web",
57
+ "typescript"
58
+ ],
59
+ "author": "",
60
+ "license": "MIT",
61
+ "devDependencies": {
62
+ "typescript": "^5.9.3"
63
+ }
64
+ }