@inglorious/engine 0.9.0 → 0.11.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 (39) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/src/ai/movement/dynamic/arrive.js +2 -5
  4. package/src/ai/movement/dynamic/evade.js +2 -6
  5. package/src/ai/movement/dynamic/face.js +2 -5
  6. package/src/ai/movement/dynamic/flee.js +2 -2
  7. package/src/ai/movement/dynamic/look-where-youre-going.js +1 -5
  8. package/src/ai/movement/dynamic/match-velocity.js +2 -2
  9. package/src/ai/movement/dynamic/pursue.js +2 -6
  10. package/src/ai/movement/dynamic/seek.js +2 -2
  11. package/src/ai/movement/dynamic/wander.js +2 -2
  12. package/src/ai/movement/kinematic/arrive.js +2 -2
  13. package/src/ai/movement/kinematic/face.js +2 -5
  14. package/src/ai/movement/kinematic/flee.js +2 -2
  15. package/src/ai/movement/kinematic/seek.js +2 -2
  16. package/src/ai/movement/kinematic/seek.test.js +13 -12
  17. package/src/ai/movement/kinematic/wander-as-seek.js +2 -5
  18. package/src/ai/movement/kinematic/wander.js +2 -6
  19. package/src/behaviors/controls/dynamic/modern.js +1 -1
  20. package/src/behaviors/controls/dynamic/shooter.js +1 -1
  21. package/src/behaviors/controls/dynamic/tank.js +1 -1
  22. package/src/behaviors/controls/kinematic/modern.js +1 -1
  23. package/src/behaviors/controls/kinematic/shooter.js +1 -1
  24. package/src/behaviors/controls/kinematic/tank.js +1 -1
  25. package/src/behaviors/game.js +8 -0
  26. package/src/behaviors/input/mouse.js +8 -11
  27. package/src/behaviors/physics/clamped.js +1 -1
  28. package/src/behaviors/physics/jumpable.js +1 -5
  29. package/src/collision/detection.js +8 -8
  30. package/src/core/engine.js +9 -4
  31. package/src/core/middlewares/entity-pool/entity-pool-middleware.js +1 -1
  32. package/src/main.js +1 -1
  33. package/src/movement/dynamic/modern.js +1 -4
  34. package/src/movement/dynamic/tank.js +2 -7
  35. package/src/movement/kinematic/modern.js +1 -4
  36. package/src/movement/kinematic/modern.test.js +7 -6
  37. package/src/movement/kinematic/tank.js +2 -7
  38. package/src/physics/bounds.js +20 -19
  39. package/src/physics/position.test.js +10 -9
package/README.md CHANGED
@@ -71,7 +71,7 @@ Here is a complete example showing how to set up and run a game using the engine
71
71
  <!DOCTYPE html>
72
72
  <html lang="en">
73
73
  <body>
74
- <canvas id="canvas"></canvas>
74
+ <canvas id="canvas" width="800" height="600"></canvas>
75
75
 
76
76
  <script type="text/javascript">
77
77
  window.process = { env: "development" }
@@ -84,7 +84,7 @@ Here is a complete example showing how to set up and run a game using the engine
84
84
  "@inglorious/utils/": "https://unpkg.com/@inglorious%2Futils@latest/src/",
85
85
  "@inglorious/store/": "https://unpkg.com/@inglorious%2Fstore@latest/src/",
86
86
  "@inglorious/engine/": "https://unpkg.com/@inglorious%2Fengine@latest/src/",
87
- "@inglorious/renderers/": "https://unpkg.com/@inglorious%2Frenderer-2d@latest/src/",
87
+ "@inglorious/renderer-2d/": "https://unpkg.com/@inglorious%2Frenderer-2d@latest/src/",
88
88
  "game": "/game.js"
89
89
  }
90
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/engine",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@inglorious/store": "3.0.0",
34
- "@inglorious/utils": "2.1.0"
34
+ "@inglorious/utils": "3.0.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "prettier": "^3.5.3",
@@ -1,9 +1,6 @@
1
1
  import { matchVelocity } from "@inglorious/engine/ai/movement/dynamic/match-velocity.js"
2
- import {
3
- magnitude,
4
- setMagnitude,
5
- } from "@inglorious/utils/math/linear-algebra/vector.js"
6
- import { subtract } from "@inglorious/utils/math/linear-algebra/vectors.js"
2
+ import { magnitude, setMagnitude } from "@inglorious/utils/math/vector.js"
3
+ import { subtract } from "@inglorious/utils/math/vectors.js"
7
4
 
8
5
  export const DEFAULT_TARGET_RADIUS = 1
9
6
  export const DEFAULT_SLOW_RADIUS = 100
@@ -1,10 +1,6 @@
1
1
  import { flee } from "@inglorious/engine/ai/movement/dynamic/flee.js"
2
- import {
3
- magnitude,
4
- multiply,
5
- zero,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
7
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
2
+ import { magnitude, multiply, zero } from "@inglorious/utils/math/vector.js"
3
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
8
4
 
9
5
  export const DEFAULT_MAX_PREDICTION = 10
10
6
 
@@ -1,9 +1,6 @@
1
1
  import { align } from "@inglorious/engine/ai/movement/dynamic/align.js"
2
- import {
3
- angle,
4
- magnitude,
5
- } from "@inglorious/utils/math/linear-algebra/vector.js"
6
- import { subtract } from "@inglorious/utils/math/linear-algebra/vectors.js"
2
+ import { angle, magnitude } from "@inglorious/utils/math/vector.js"
3
+ import { subtract } from "@inglorious/utils/math/vectors.js"
7
4
 
8
5
  export function face(entity, target, dt, options) {
9
6
  const direction = subtract(target.position, entity.position)
@@ -5,8 +5,8 @@ import {
5
5
  multiply,
6
6
  setMagnitude,
7
7
  zero,
8
- } from "@inglorious/utils/math/linear-algebra/vector.js"
9
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
8
+ } from "@inglorious/utils/math/vector.js"
9
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
10
10
 
11
11
  const DEFAULT_MAX_ACCELERATION = 0
12
12
  const DEFAULT_MAX_SPEED = 0
@@ -1,9 +1,5 @@
1
1
  import { align } from "@inglorious/engine/ai/movement/dynamic/align.js"
2
- import {
3
- angle,
4
- magnitude,
5
- zero,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
2
+ import { angle, magnitude, zero } from "@inglorious/utils/math/vector.js"
7
3
 
8
4
  export function lookWhereYoureGoing(entity, dt, options) {
9
5
  const velocity = entity.velocity ?? zero()
@@ -5,8 +5,8 @@ import {
5
5
  magnitude,
6
6
  multiply,
7
7
  zero,
8
- } from "@inglorious/utils/math/linear-algebra/vector.js"
9
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
8
+ } from "@inglorious/utils/math/vector.js"
9
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
10
10
 
11
11
  export const DEFAULT_TIME_TO_TARGET = 0.1
12
12
 
@@ -1,10 +1,6 @@
1
1
  import { seek } from "@inglorious/engine/ai/movement/dynamic/seek.js"
2
- import {
3
- magnitude,
4
- multiply,
5
- zero,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
7
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
2
+ import { magnitude, multiply, zero } from "@inglorious/utils/math/vector.js"
3
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
8
4
 
9
5
  export const DEFAULT_MAX_PREDICTION = 10
10
6
 
@@ -5,8 +5,8 @@ import {
5
5
  multiply,
6
6
  setMagnitude,
7
7
  zero,
8
- } from "@inglorious/utils/math/linear-algebra/vector.js"
9
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
8
+ } from "@inglorious/utils/math/vector.js"
9
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
10
10
 
11
11
  const DEFAULT_MAX_ACCELERATION = 0
12
12
  const DEFAULT_MAX_SPEED = 0
@@ -1,7 +1,7 @@
1
1
  import { seek } from "@inglorious/engine/ai/movement/dynamic/seek.js"
2
- import { createVector } from "@inglorious/utils/math/linear-algebra/vector.js"
3
- import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
4
2
  import { randomBinomial } from "@inglorious/utils/math/rng.js"
3
+ import { createVector } from "@inglorious/utils/math/vector.js"
4
+ import { sum } from "@inglorious/utils/math/vectors.js"
5
5
 
6
6
  export const DEFAULT_WANDER_OFFSET = 100
7
7
  export const DEFAULT_WANDER_RADIUS = 100
@@ -4,8 +4,8 @@ import {
4
4
  divide,
5
5
  magnitude,
6
6
  multiply,
7
- } from "@inglorious/utils/math/linear-algebra/vector.js"
8
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
7
+ } from "@inglorious/utils/math/vector.js"
8
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
9
9
 
10
10
  export const DEFAULT_TARGET_RADIUS = 1
11
11
  export const DEFAULT_TIME_TO_TARGET = 0.1
@@ -1,9 +1,6 @@
1
1
  import { align } from "@inglorious/engine/ai/movement/kinematic/align.js"
2
- import {
3
- angle,
4
- magnitude,
5
- } from "@inglorious/utils/math/linear-algebra/vector.js"
6
- import { subtract } from "@inglorious/utils/math/linear-algebra/vectors.js"
2
+ import { angle, magnitude } from "@inglorious/utils/math/vector.js"
3
+ import { subtract } from "@inglorious/utils/math/vectors.js"
7
4
 
8
5
  export function face(entity, target, dt, options) {
9
6
  const direction = subtract(target.position, entity.position)
@@ -3,8 +3,8 @@ import {
3
3
  magnitude,
4
4
  multiply,
5
5
  setMagnitude,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
7
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
6
+ } from "@inglorious/utils/math/vector.js"
7
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
8
8
 
9
9
  const DEFAULT_MAX_SPEED = 0
10
10
 
@@ -3,8 +3,8 @@ import {
3
3
  magnitude,
4
4
  multiply,
5
5
  setMagnitude,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
7
- import { subtract, sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
6
+ } from "@inglorious/utils/math/vector.js"
7
+ import { subtract, sum } from "@inglorious/utils/math/vectors.js"
8
8
 
9
9
  const DEFAULT_MAX_SPEED = 0
10
10
 
@@ -1,14 +1,15 @@
1
+ import { v } from "@inglorious/utils/v.js"
1
2
  import { expect, test } from "vitest"
2
3
 
3
4
  import { seek } from "./seek.js"
4
5
 
5
6
  test("it should move toward the target", () => {
6
- const entity = { maxSpeed: 1, position: [0, 0, 0] }
7
- const target = { position: [2, 0, 0] }
7
+ const entity = { maxSpeed: 1, position: v(0, 0, 0) }
8
+ const target = { position: v(2, 0, 0) }
8
9
  const dt = 1
9
10
  const expectedResult = {
10
- position: [1, 0, 0],
11
- velocity: [1, 0, 0],
11
+ position: v(1, 0, 0),
12
+ velocity: v(1, 0, 0),
12
13
  orientation: 0,
13
14
  }
14
15
 
@@ -16,12 +17,12 @@ test("it should move toward the target", () => {
16
17
  })
17
18
 
18
19
  test("it should eventually reach the target", () => {
19
- const entity = { maxSpeed: 1, position: [0, 0, 0] }
20
- const target = { position: [2, 0, 0] }
20
+ const entity = { maxSpeed: 1, position: v(0, 0, 0) }
21
+ const target = { position: v(2, 0, 0) }
21
22
  const dt = 2
22
23
  const expectedResult = {
23
- position: [2, 0, 0],
24
- velocity: [1, 0, 0],
24
+ position: v(2, 0, 0),
25
+ velocity: v(1, 0, 0),
25
26
  orientation: 0,
26
27
  }
27
28
 
@@ -29,12 +30,12 @@ test("it should eventually reach the target", () => {
29
30
  })
30
31
 
31
32
  test("it should overshoot when speed is too high", () => {
32
- const entity = { maxSpeed: 10, position: [0, 0, 0] }
33
- const target = { position: [2, 0, 0] }
33
+ const entity = { maxSpeed: 10, position: v(0, 0, 0) }
34
+ const target = { position: v(2, 0, 0) }
34
35
  const dt = 1
35
36
  const expectedResult = {
36
- position: [10, 0, 0],
37
- velocity: [10, 0, 0],
37
+ position: v(10, 0, 0),
38
+ velocity: v(10, 0, 0),
38
39
  orientation: 0,
39
40
  }
40
41
 
@@ -1,10 +1,7 @@
1
1
  import { seek } from "@inglorious/engine/ai/movement/kinematic/seek.js"
2
- import {
3
- fromAngle,
4
- multiply,
5
- } from "@inglorious/utils/math/linear-algebra/vector.js"
6
- import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
7
2
  import { randomBinomial } from "@inglorious/utils/math/rng.js"
3
+ import { fromAngle, multiply } from "@inglorious/utils/math/vector.js"
4
+ import { sum } from "@inglorious/utils/math/vectors.js"
8
5
 
9
6
  export const DEFAULT_WANDER_RADIUS = 10
10
7
 
@@ -1,10 +1,6 @@
1
- import {
2
- angle,
3
- createVector,
4
- multiply,
5
- } from "@inglorious/utils/math/linear-algebra/vector.js"
6
- import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
7
1
  import { randomBinomial } from "@inglorious/utils/math/rng.js"
2
+ import { angle, createVector, multiply } from "@inglorious/utils/math/vector.js"
3
+ import { sum } from "@inglorious/utils/math/vectors.js"
8
4
 
9
5
  const DEFAULT_MAX_SPEED = 0
10
6
  const DEFAULT_MAX_ANGULAR_SPEED = 0
@@ -1,6 +1,6 @@
1
1
  import { modernMove } from "@inglorious/engine/movement/dynamic/modern.js"
2
2
  import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
3
+ import { zero } from "@inglorious/utils/math/vector.js"
4
4
 
5
5
  import { createMovementEventHandlers } from "../event-handlers.js"
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { face } from "@inglorious/engine/ai/movement/dynamic/face.js"
2
2
  import { tankMove } from "@inglorious/engine/movement/dynamic/tank.js"
3
3
  import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
4
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
5
4
  import { pi } from "@inglorious/utils/math/trigonometry.js"
5
+ import { zero } from "@inglorious/utils/math/vector.js"
6
6
 
7
7
  import { createMovementEventHandlers } from "../event-handlers.js"
8
8
 
@@ -1,6 +1,6 @@
1
1
  import { tankMove } from "@inglorious/engine/movement/dynamic/tank.js"
2
2
  import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
3
+ import { zero } from "@inglorious/utils/math/vector.js"
4
4
 
5
5
  import { createMovementEventHandlers } from "../event-handlers.js"
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { modernMove } from "@inglorious/engine/movement/kinematic/modern.js"
2
2
  import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
3
+ import { zero } from "@inglorious/utils/math/vector.js"
4
4
 
5
5
  import { createMovementEventHandlers } from "../event-handlers.js"
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { face } from "@inglorious/engine/ai/movement/kinematic/face.js"
2
2
  import { tankMove } from "@inglorious/engine/movement/kinematic/tank.js"
3
3
  import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
4
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
5
4
  import { pi } from "@inglorious/utils/math/trigonometry.js"
5
+ import { zero } from "@inglorious/utils/math/vector.js"
6
6
 
7
7
  import { createMovementEventHandlers } from "../event-handlers.js"
8
8
 
@@ -1,6 +1,6 @@
1
1
  import { tankMove } from "@inglorious/engine/movement/kinematic/tank.js"
2
2
  import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
3
+ import { zero } from "@inglorious/utils/math/vector.js"
4
4
 
5
5
  import { createMovementEventHandlers } from "../event-handlers.js"
6
6
 
@@ -1,5 +1,13 @@
1
1
  export function game() {
2
2
  return {
3
+ pause(entity) {
4
+ entity.paused = true
5
+ },
6
+
7
+ resume(entity) {
8
+ entity.paused = false
9
+ },
10
+
3
11
  keyboardKeyUp(entity, code) {
4
12
  switch (code) {
5
13
  case "KeyC":
@@ -1,6 +1,6 @@
1
1
  import { findCollision } from "@inglorious/engine/collision/detection.js"
2
2
  import { clampToBounds } from "@inglorious/engine/physics/bounds.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
3
+ import { zero } from "@inglorious/utils/math/vector.js"
4
4
 
5
5
  const DEFAULT_PARAMS = {
6
6
  name: "mouse",
@@ -22,7 +22,7 @@ export function mouse() {
22
22
 
23
23
  entity.position = position
24
24
 
25
- clampToBounds(entity, game.bounds)
25
+ clampToBounds(entity, game.size)
26
26
  },
27
27
 
28
28
  mouseClick(entity, position, api) {
@@ -74,20 +74,17 @@ function createHandler(type, parent, api) {
74
74
  }
75
75
 
76
76
  // For move and click events, the payload is the calculated position.
77
- const payload = calculatePosition({
78
- clientX: event.clientX,
79
- clientY: event.clientY,
80
- parent,
81
- })
77
+ const payload = calculatePosition(event, parent)
82
78
  api.notify(type, payload)
83
79
  }
84
80
  }
85
81
 
86
- function calculatePosition({ clientX, clientY, parent }) {
87
- const bounds = parent.getBoundingClientRect()
82
+ function calculatePosition(event, parent) {
83
+ const { clientX, clientY } = event
84
+ const { left, bottom } = parent.getBoundingClientRect()
88
85
 
89
- const x = clientX - bounds.left
90
- const z = bounds.bottom - clientY
86
+ const x = clientX - left
87
+ const z = bottom - clientY
91
88
 
92
89
  return [x, NO_Y, z]
93
90
  }
@@ -28,7 +28,7 @@ export function clamped(params) {
28
28
  merge(entity, {
29
29
  position: clampToBounds(
30
30
  entity,
31
- game.bounds,
31
+ game.size,
32
32
  params.collisionGroup,
33
33
  params.depthAxis,
34
34
  ),
@@ -1,10 +1,6 @@
1
1
  import { findCollision } from "@inglorious/engine/collision/detection.js"
2
2
  import { defaults, extend } from "@inglorious/utils/data-structures/objects.js"
3
- import {
4
- angle,
5
- magnitude,
6
- zero,
7
- } from "@inglorious/utils/math/linear-algebra/vector.js"
3
+ import { angle, magnitude, zero } from "@inglorious/utils/math/vector.js"
8
4
  import { applyGravity } from "@inglorious/utils/physics/gravity.js"
9
5
  import { jump } from "@inglorious/utils/physics/jump.js"
10
6
 
@@ -1,12 +1,12 @@
1
1
  import { filter } from "@inglorious/utils/data-structures/object.js"
2
- import * as circle from "@inglorious/utils/math/geometry/circle.js"
3
- import * as hitmask from "@inglorious/utils/math/geometry/hitmask.js"
4
- import * as line from "@inglorious/utils/math/geometry/line.js"
5
- import * as point from "@inglorious/utils/math/geometry/point.js"
6
- import * as rectangle from "@inglorious/utils/math/geometry/rectangle.js"
7
- import * as segment from "@inglorious/utils/math/geometry/segment.js"
8
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
9
- import { add } from "@inglorious/utils/math/linear-algebra/vectors.js"
2
+ import * as circle from "@inglorious/utils/math/circle.js"
3
+ import * as hitmask from "@inglorious/utils/math/hitmask.js"
4
+ import * as line from "@inglorious/utils/math/line.js"
5
+ import * as point from "@inglorious/utils/math/point.js"
6
+ import * as rectangle from "@inglorious/utils/math/rectangle.js"
7
+ import * as segment from "@inglorious/utils/math/segment.js"
8
+ import { zero } from "@inglorious/utils/math/vector.js"
9
+ import { add } from "@inglorious/utils/math/vectors.js"
10
10
 
11
11
  const Z = 2 // Z-axis index.
12
12
 
@@ -5,6 +5,8 @@ import { createStore } from "@inglorious/store/store.js"
5
5
  import { augmentType } from "@inglorious/store/types.js"
6
6
  import { isArray } from "@inglorious/utils/data-structures/array.js"
7
7
  import { extendWith } from "@inglorious/utils/data-structures/objects.js"
8
+ import { isVector } from "@inglorious/utils/math/vector.js"
9
+ import { v } from "@inglorious/utils/v.js"
8
10
 
9
11
  import { coreEvents } from "./core-events.js"
10
12
  import { disconnectDevTools, initDevTools, sendAction } from "./dev-tools.js"
@@ -28,7 +30,7 @@ const DEFAULT_GAME_CONFIG = {
28
30
 
29
31
  entities: {
30
32
  // eslint-disable-next-line no-magic-numbers
31
- game: { type: "game", bounds: [0, 0, 800, 600] },
33
+ game: { type: "game", size: v(800, 600) },
32
34
  audio: { type: "audio", sounds: {} },
33
35
  },
34
36
  }
@@ -100,7 +102,6 @@ export class Engine {
100
102
  start() {
101
103
  this._api.notify("start")
102
104
  this._loop.start(this, ONE_SECOND / this._config.loop.fps)
103
- this.isRunning = true
104
105
  }
105
106
 
106
107
  /**
@@ -110,7 +111,6 @@ export class Engine {
110
111
  this._api.notify("stop")
111
112
  this._store.update(this._api)
112
113
  this._loop.stop()
113
- this.isRunning = false
114
114
  }
115
115
 
116
116
  /**
@@ -148,7 +148,12 @@ export class Engine {
148
148
  }
149
149
 
150
150
  function merger(targetValue, sourceValue) {
151
- if (isArray(targetValue) && isArray(sourceValue)) {
151
+ if (
152
+ isArray(targetValue) &&
153
+ !isVector(targetValue) &&
154
+ isArray(sourceValue) &&
155
+ !isVector(sourceValue)
156
+ ) {
152
157
  return [...targetValue, ...sourceValue]
153
158
  }
154
159
  }
@@ -1,4 +1,4 @@
1
- import { EventMap } from "@inglorious/store/event-map"
1
+ import { EventMap } from "@inglorious/store/event-map.js"
2
2
 
3
3
  export function entityPoolMiddleware(pools) {
4
4
  return (api) => {
package/src/main.js CHANGED
@@ -2,8 +2,8 @@ import { Engine } from "@inglorious/engine/core/engine.js"
2
2
  import { createRenderer } from "@inglorious/renderer-2d/index.js"
3
3
  import game from "game"
4
4
 
5
- const canvas = document.getElementById("canvas")
6
5
  window.addEventListener("load", async () => {
6
+ const canvas = document.getElementById("canvas")
7
7
  const renderer = createRenderer(canvas)
8
8
  const engine = new Engine(renderer, game)
9
9
  await engine.init()
@@ -1,7 +1,4 @@
1
- import {
2
- angle,
3
- magnitude,
4
- } from "@inglorious/utils/math/linear-algebra/vector.js"
1
+ import { angle, magnitude } from "@inglorious/utils/math/vector.js"
5
2
  import { applyAcceleration } from "@inglorious/utils/physics/acceleration.js"
6
3
 
7
4
  const DEFAULT_ORIENTATION = 0
@@ -1,11 +1,6 @@
1
- import {
2
- clamp,
3
- multiply,
4
- rotate,
5
- zero,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
7
- import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
8
1
  import { toRange } from "@inglorious/utils/math/trigonometry.js"
2
+ import { clamp, multiply, rotate, zero } from "@inglorious/utils/math/vector.js"
3
+ import { sum } from "@inglorious/utils/math/vectors.js"
9
4
  import { applyFriction } from "@inglorious/utils/physics/friction.js"
10
5
 
11
6
  const DEFAULT_MAX_ACCELERATION = 0
@@ -1,7 +1,4 @@
1
- import {
2
- angle,
3
- magnitude,
4
- } from "@inglorious/utils/math/linear-algebra/vector.js"
1
+ import { angle, magnitude } from "@inglorious/utils/math/vector.js"
5
2
  import { applyVelocity } from "@inglorious/utils/physics/velocity.js"
6
3
 
7
4
  const DEFAULT_ORIENTATION = 0
@@ -1,13 +1,14 @@
1
+ import { v } from "@inglorious/utils/v.js"
1
2
  import { expect, test } from "vitest"
2
3
 
3
4
  import { modernMove } from "./modern.js"
4
5
 
5
6
  test("it should move following its velocity", () => {
6
- const entity = { maxSpeed: 1, velocity: [1, 0, 0], position: [0, 0, 0] }
7
+ const entity = { maxSpeed: 1, velocity: v(1, 0, 0), position: v(0, 0, 0) }
7
8
  const dt = 1
8
9
  const expectedResult = {
9
- velocity: [1, 0, 0],
10
- position: [1, 0, 0],
10
+ velocity: v(1, 0, 0),
11
+ position: v(1, 0, 0),
11
12
  orientation: 0,
12
13
  }
13
14
 
@@ -15,11 +16,11 @@ test("it should move following its velocity", () => {
15
16
  })
16
17
 
17
18
  test("it should limit the velocity to the max speed", () => {
18
- const entity = { maxSpeed: 1, velocity: [10, 0, 0], position: [0, 0, 0] }
19
+ const entity = { maxSpeed: 1, velocity: v(10, 0, 0), position: v(0, 0, 0) }
19
20
  const dt = 1
20
21
  const expectedResult = {
21
- velocity: [1, 0, 0],
22
- position: [1, 0, 0],
22
+ velocity: v(1, 0, 0),
23
+ position: v(1, 0, 0),
23
24
  orientation: 0,
24
25
  }
25
26
 
@@ -1,11 +1,6 @@
1
- import {
2
- clamp,
3
- multiply,
4
- rotate,
5
- zero,
6
- } from "@inglorious/utils/math/linear-algebra/vector.js"
7
- import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
8
1
  import { toRange } from "@inglorious/utils/math/trigonometry.js"
2
+ import { clamp, multiply, rotate, zero } from "@inglorious/utils/math/vector.js"
3
+ import { sum } from "@inglorious/utils/math/vectors.js"
9
4
 
10
5
  const DEFAULT_MAX_SPEED = 0
11
6
 
@@ -1,3 +1,4 @@
1
+ import { abs } from "@inglorious/utils/math/numbers.js"
1
2
  import {
2
3
  angle,
3
4
  clamp,
@@ -5,24 +6,24 @@ import {
5
6
  fromAngle,
6
7
  multiply,
7
8
  zero,
8
- } from "@inglorious/utils/math/linear-algebra/vector.js"
9
- import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
10
- import { abs } from "@inglorious/utils/math/numbers.js"
9
+ } from "@inglorious/utils/math/vector.js"
10
+ import { sum } from "@inglorious/utils/math/vectors.js"
11
11
 
12
+ const ORIGIN = 0
12
13
  const DOUBLE = 2
13
14
  const HALF = 2
14
15
  const X = 0
15
16
  const Z = 2
16
17
 
17
- export function bounce(entity, dt, [minX, minZ, maxX, maxZ]) {
18
+ export function bounce(entity, dt, [maxX, maxZ]) {
18
19
  const [x, , z] = entity.position
19
20
 
20
21
  const velocity = createVector(entity.maxSpeed, entity.orientation)
21
- if (x < minX || x >= maxX) {
22
+ if (x < ORIGIN || x >= maxX) {
22
23
  velocity[X] = -velocity[X]
23
24
  }
24
25
 
25
- if (z < minZ || z >= maxZ) {
26
+ if (z < ORIGIN || z >= maxZ) {
26
27
  velocity[Z] = -velocity[Z]
27
28
  }
28
29
 
@@ -33,7 +34,7 @@ export function bounce(entity, dt, [minX, minZ, maxX, maxZ]) {
33
34
  }
34
35
 
35
36
  const ClampToBoundsByShape = {
36
- rectangle(entity, [minX, minZ, maxX, maxZ], collisionGroup) {
37
+ rectangle(entity, [maxX, maxZ], collisionGroup) {
37
38
  const [width, height, depth] =
38
39
  entity.collisions[collisionGroup].size ?? entity.size
39
40
 
@@ -43,31 +44,31 @@ const ClampToBoundsByShape = {
43
44
 
44
45
  return clamp(
45
46
  entity.position,
46
- [minX + halfWidth, minZ + halfHeight, minZ + halfDepth],
47
+ [halfWidth, halfHeight, halfDepth],
47
48
  [maxX - halfWidth, maxZ - halfHeight, maxZ - halfDepth],
48
49
  )
49
50
  },
50
51
 
51
- circle(entity, [minX, minY, maxX, maxY], collisionGroup, depthAxis = "y") {
52
+ circle(entity, [maxX, maxY], collisionGroup, depthAxis = "y") {
52
53
  const radius = entity.collisions[collisionGroup].radius ?? entity.radius
53
54
 
54
55
  if (depthAxis === "z") {
55
56
  return clamp(
56
57
  entity.position,
57
- [minX + radius, minY + radius, minY],
58
+ [radius, radius, ORIGIN],
58
59
  [maxX - radius, maxY - radius, maxY],
59
60
  )
60
61
  }
61
62
 
62
63
  return clamp(
63
64
  entity.position,
64
- [minX + radius, minY, minY + radius],
65
+ [radius, ORIGIN, radius],
65
66
  [maxX - radius, maxY, maxY - radius],
66
67
  )
67
68
  },
68
69
 
69
- point(entity, [minX, minZ, maxX, maxZ]) {
70
- return clamp(entity.position, [minX, minZ, minZ], [maxX, maxZ, maxZ])
70
+ point(entity, [maxX, maxZ]) {
71
+ return clamp(entity.position, zero(), [maxX, maxZ, maxZ])
71
72
  },
72
73
  }
73
74
 
@@ -82,7 +83,7 @@ export function clampToBounds(
82
83
  return handler(entity, bounds, collisionGroup, depthAxis)
83
84
  }
84
85
 
85
- export function flip(entity, [minX, minZ, maxX, maxZ]) {
86
+ export function flip(entity, [maxX, maxZ]) {
86
87
  const [x, , z] = entity.position
87
88
 
88
89
  entity.collisions ??= {}
@@ -111,20 +112,20 @@ export function flip(entity, [minX, minZ, maxX, maxZ]) {
111
112
  const direction = fromAngle(entity.orientation)
112
113
 
113
114
  if (
114
- left < minX ||
115
+ left < ORIGIN ||
115
116
  right >= maxX ||
116
- bottom < minZ ||
117
+ bottom < ORIGIN ||
117
118
  top >= maxZ ||
118
- back < minZ ||
119
+ back < ORIGIN ||
119
120
  front >= maxZ
120
121
  ) {
121
- if (left < minX) {
122
+ if (left < ORIGIN) {
122
123
  direction[X] = abs(direction[X])
123
124
  } else if (right >= maxX) {
124
125
  direction[X] = -abs(direction[X])
125
126
  }
126
127
 
127
- if (back < minZ) {
128
+ if (back < ORIGIN) {
128
129
  direction[Z] = abs(direction[Z])
129
130
  } else if (front >= maxZ) {
130
131
  direction[Z] = -abs(direction[Z])
@@ -1,3 +1,4 @@
1
+ import { v } from "@inglorious/utils/v.js"
1
2
  import { expect, test } from "vitest"
2
3
 
3
4
  import { calculateLandingPosition } from "./position.js"
@@ -9,9 +10,9 @@ test("it should calculate the landing position for a point entity on a platform"
9
10
  },
10
11
  }
11
12
  const target = {
12
- position: [0, 0, 0],
13
+ position: v(0, 0, 0),
13
14
  collisions: {
14
- platform: { size: [20, 10, 0] },
15
+ platform: { size: v(20, 10, 0) },
15
16
  },
16
17
  }
17
18
  const collisionGroup = "platform"
@@ -28,9 +29,9 @@ test("it should calculate the landing position for a circular entity on a platfo
28
29
  },
29
30
  }
30
31
  const target = {
31
- position: [0, 0, 0],
32
+ position: v(0, 0, 0),
32
33
  collisions: {
33
- platform: { size: [20, 10, 0] },
34
+ platform: { size: v(20, 10, 0) },
34
35
  },
35
36
  }
36
37
  const collisionGroup = "platform"
@@ -42,15 +43,15 @@ test("it should calculate the landing position for a circular entity on a platfo
42
43
 
43
44
  test("it should calculate the landing position for a rectangular entity on a platform", () => {
44
45
  const entity = {
45
- size: [10, 10, 0],
46
+ size: v(10, 10, 0),
46
47
  collisions: {
47
48
  platform: { shape: "rectangle" },
48
49
  },
49
50
  }
50
51
  const target = {
51
- position: [0, 0, 0],
52
+ position: v(0, 0, 0),
52
53
  collisions: {
53
- platform: { size: [20, 10, 0] },
54
+ platform: { size: v(20, 10, 0) },
54
55
  },
55
56
  }
56
57
  const collisionGroup = "platform"
@@ -67,9 +68,9 @@ test("it should fallback to a rectangular calculation for an unknown entity shap
67
68
  },
68
69
  }
69
70
  const target = {
70
- position: [0, 0, 0],
71
+ position: v(0, 0, 0),
71
72
  collisions: {
72
- platform: { size: [20, 10, 0] },
73
+ platform: { size: v(20, 10, 0) },
73
74
  },
74
75
  }
75
76
  const collisionGroup = "platform"