@inglorious/engine 0.1.1 → 0.3.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 (201) hide show
  1. package/README.md +75 -72
  2. package/package.json +15 -37
  3. package/src/{engine/ai → ai}/movement/dynamic/align.js +9 -9
  4. package/src/{engine/ai → ai}/movement/dynamic/arrive.js +9 -10
  5. package/src/{engine/ai → ai}/movement/dynamic/evade.js +9 -9
  6. package/src/{engine/ai → ai}/movement/dynamic/face.js +5 -6
  7. package/src/{engine/ai/movement/dynamic/seek.js → ai/movement/dynamic/flee.js} +8 -7
  8. package/src/ai/movement/dynamic/look-where-youre-going.js +16 -0
  9. package/src/{engine/ai → ai}/movement/dynamic/match-velocity.js +9 -8
  10. package/src/{engine/ai → ai}/movement/dynamic/pursue.js +9 -9
  11. package/src/{engine/ai/movement/dynamic/flee.js → ai/movement/dynamic/seek.js} +7 -8
  12. package/src/{engine/ai → ai}/movement/dynamic/wander.js +9 -10
  13. package/src/{engine/ai → ai}/movement/kinematic/align.js +7 -7
  14. package/src/{engine/ai → ai}/movement/kinematic/arrive.js +8 -8
  15. package/src/{engine/ai → ai}/movement/kinematic/face.js +5 -6
  16. package/src/{engine/ai → ai}/movement/kinematic/flee.js +5 -5
  17. package/src/{engine/ai → ai}/movement/kinematic/seek.js +5 -5
  18. package/src/{engine/ai → ai}/movement/kinematic/seek.test.js +10 -10
  19. package/src/{engine/ai → ai}/movement/kinematic/wander-as-seek.js +9 -9
  20. package/src/{engine/ai → ai}/movement/kinematic/wander.js +5 -5
  21. package/src/animation/sprite.js +101 -0
  22. package/src/animation/ticker.js +38 -0
  23. package/src/behaviors/camera.js +68 -0
  24. package/src/behaviors/controls/dynamic/modern.js +76 -0
  25. package/src/behaviors/controls/dynamic/shooter.js +84 -0
  26. package/src/behaviors/controls/dynamic/tank.js +69 -0
  27. package/src/behaviors/controls/event-handlers.js +17 -0
  28. package/src/behaviors/controls/kinematic/modern.js +76 -0
  29. package/src/behaviors/controls/kinematic/shooter.js +82 -0
  30. package/src/behaviors/controls/kinematic/tank.js +67 -0
  31. package/src/behaviors/debug/collision.js +29 -0
  32. package/src/behaviors/fps.js +29 -0
  33. package/src/behaviors/fsm.js +33 -0
  34. package/src/{game/decorators → behaviors}/fsm.test.js +15 -22
  35. package/src/behaviors/game.js +15 -0
  36. package/src/behaviors/input/controls.js +37 -0
  37. package/src/behaviors/input/gamepad.js +114 -0
  38. package/src/behaviors/input/input.js +48 -0
  39. package/src/behaviors/input/keyboard.js +64 -0
  40. package/src/behaviors/input/mouse.js +91 -0
  41. package/src/behaviors/physics/bouncy.js +25 -0
  42. package/src/behaviors/physics/clamped.js +36 -0
  43. package/src/{game/decorators/collisions.js → behaviors/physics/collidable.js} +3 -7
  44. package/src/behaviors/physics/jumpable.js +145 -0
  45. package/src/behaviors/ui/button.js +17 -0
  46. package/src/collision/detection.js +110 -0
  47. package/src/core/api.js +34 -0
  48. package/src/core/dev-tools.js +135 -0
  49. package/src/core/engine.js +119 -0
  50. package/src/core/loop.js +15 -0
  51. package/src/{engine/loop → core/loops}/animation-frame.js +1 -2
  52. package/src/{engine/loop → core/loops}/elapsed.js +1 -2
  53. package/src/{engine/loop → core/loops}/fixed.js +1 -2
  54. package/src/{engine/loop → core/loops}/flash.js +1 -2
  55. package/src/{engine/loop → core/loops}/lag.js +1 -2
  56. package/src/core/select.js +26 -0
  57. package/src/core/store.js +178 -0
  58. package/src/core/store.test.js +110 -0
  59. package/src/main.js +7 -2
  60. package/src/{engine/movement → movement}/dynamic/modern.js +3 -6
  61. package/src/{engine/movement → movement}/dynamic/tank.js +9 -9
  62. package/src/{engine/movement → movement}/kinematic/modern.js +3 -3
  63. package/src/movement/kinematic/modern.test.js +27 -0
  64. package/src/{engine/movement → movement}/kinematic/tank.js +5 -5
  65. package/src/physics/bounds.js +138 -0
  66. package/src/physics/position.js +43 -0
  67. package/src/physics/position.test.js +80 -0
  68. package/src/systems/sprite-animation.js +27 -0
  69. package/src/engine/ai/movement/dynamic/look-where-youre-going.js +0 -17
  70. package/src/engine/collision/detection.js +0 -115
  71. package/src/engine/loop.js +0 -15
  72. package/src/engine/movement/kinematic/modern.test.js +0 -27
  73. package/src/engine/store.js +0 -174
  74. package/src/engine/store.test.js +0 -256
  75. package/src/engine.js +0 -74
  76. package/src/game/animation.js +0 -26
  77. package/src/game/bounds.js +0 -66
  78. package/src/game/decorators/character.js +0 -5
  79. package/src/game/decorators/clamp-to-bounds.js +0 -15
  80. package/src/game/decorators/controls/dynamic/modern.js +0 -48
  81. package/src/game/decorators/controls/dynamic/shooter.js +0 -47
  82. package/src/game/decorators/controls/dynamic/tank.js +0 -55
  83. package/src/game/decorators/controls/kinematic/modern.js +0 -49
  84. package/src/game/decorators/controls/kinematic/shooter.js +0 -45
  85. package/src/game/decorators/controls/kinematic/tank.js +0 -52
  86. package/src/game/decorators/debug/collisions.js +0 -32
  87. package/src/game/decorators/double-jump.js +0 -70
  88. package/src/game/decorators/fps.js +0 -30
  89. package/src/game/decorators/fsm.js +0 -27
  90. package/src/game/decorators/game.js +0 -11
  91. package/src/game/decorators/image/image.js +0 -5
  92. package/src/game/decorators/image/sprite.js +0 -5
  93. package/src/game/decorators/image/tilemap.js +0 -5
  94. package/src/game/decorators/input/controls.js +0 -27
  95. package/src/game/decorators/input/gamepad.js +0 -74
  96. package/src/game/decorators/input/input.js +0 -41
  97. package/src/game/decorators/input/keyboard.js +0 -49
  98. package/src/game/decorators/input/mouse.js +0 -65
  99. package/src/game/decorators/jump.js +0 -72
  100. package/src/game/decorators/platform.js +0 -5
  101. package/src/game/decorators/ui/button.js +0 -21
  102. package/src/game/sprite.js +0 -119
  103. package/src/ui/canvas/absolute-position.js +0 -17
  104. package/src/ui/canvas/character.js +0 -35
  105. package/src/ui/canvas/form/button.js +0 -25
  106. package/src/ui/canvas/fps.js +0 -18
  107. package/src/ui/canvas/image/hitmask.js +0 -37
  108. package/src/ui/canvas/image/image.js +0 -37
  109. package/src/ui/canvas/image/sprite.js +0 -49
  110. package/src/ui/canvas/image/tilemap.js +0 -64
  111. package/src/ui/canvas/mouse.js +0 -37
  112. package/src/ui/canvas/shapes/circle.js +0 -31
  113. package/src/ui/canvas/shapes/rectangle.js +0 -31
  114. package/src/ui/canvas.js +0 -81
  115. package/src/ui/react/game/character/character.module.scss +0 -17
  116. package/src/ui/react/game/character/index.jsx +0 -30
  117. package/src/ui/react/game/cursor/cursor.module.scss +0 -47
  118. package/src/ui/react/game/cursor/index.jsx +0 -20
  119. package/src/ui/react/game/form/fields/field/field.module.scss +0 -5
  120. package/src/ui/react/game/form/fields/field/index.jsx +0 -56
  121. package/src/ui/react/game/form/fields/fields.module.scss +0 -48
  122. package/src/ui/react/game/form/fields/index.jsx +0 -12
  123. package/src/ui/react/game/form/form.module.scss +0 -18
  124. package/src/ui/react/game/form/index.jsx +0 -22
  125. package/src/ui/react/game/fps/index.jsx +0 -16
  126. package/src/ui/react/game/game.jsx +0 -71
  127. package/src/ui/react/game/index.jsx +0 -29
  128. package/src/ui/react/game/platform/index.jsx +0 -30
  129. package/src/ui/react/game/platform/platform.module.scss +0 -7
  130. package/src/ui/react/game/scene/index.jsx +0 -25
  131. package/src/ui/react/game/scene/scene.module.scss +0 -9
  132. package/src/ui/react/game/sprite/index.jsx +0 -58
  133. package/src/ui/react/game/sprite/sprite.module.css +0 -3
  134. package/src/ui/react/game/stats/index.jsx +0 -22
  135. package/src/ui/react/hocs/with-absolute-position/index.jsx +0 -20
  136. package/src/ui/react/hocs/with-absolute-position/with-absolute-position.module.scss +0 -5
  137. package/src/ui/react/index.jsx +0 -9
  138. package/src/utils/algorithms/decision-tree.js +0 -24
  139. package/src/utils/algorithms/decision-tree.test.js +0 -102
  140. package/src/utils/algorithms/path-finding.js +0 -155
  141. package/src/utils/algorithms/path-finding.test.js +0 -151
  142. package/src/utils/algorithms/types.d.ts +0 -28
  143. package/src/utils/data-structures/array.js +0 -83
  144. package/src/utils/data-structures/array.test.js +0 -173
  145. package/src/utils/data-structures/board.js +0 -159
  146. package/src/utils/data-structures/board.test.js +0 -242
  147. package/src/utils/data-structures/boolean.js +0 -9
  148. package/src/utils/data-structures/heap.js +0 -164
  149. package/src/utils/data-structures/heap.test.js +0 -103
  150. package/src/utils/data-structures/object.js +0 -102
  151. package/src/utils/data-structures/object.test.js +0 -121
  152. package/src/utils/data-structures/objects.js +0 -48
  153. package/src/utils/data-structures/objects.test.js +0 -99
  154. package/src/utils/data-structures/tree.js +0 -36
  155. package/src/utils/data-structures/tree.test.js +0 -33
  156. package/src/utils/data-structures/types.d.ts +0 -4
  157. package/src/utils/functions/functions.js +0 -19
  158. package/src/utils/functions/functions.test.js +0 -23
  159. package/src/utils/math/geometry/circle.js +0 -117
  160. package/src/utils/math/geometry/circle.test.js +0 -97
  161. package/src/utils/math/geometry/hitmask.js +0 -39
  162. package/src/utils/math/geometry/hitmask.test.js +0 -84
  163. package/src/utils/math/geometry/line.js +0 -35
  164. package/src/utils/math/geometry/line.test.js +0 -49
  165. package/src/utils/math/geometry/platform.js +0 -42
  166. package/src/utils/math/geometry/platform.test.js +0 -133
  167. package/src/utils/math/geometry/point.js +0 -71
  168. package/src/utils/math/geometry/point.test.js +0 -81
  169. package/src/utils/math/geometry/rectangle.js +0 -45
  170. package/src/utils/math/geometry/rectangle.test.js +0 -42
  171. package/src/utils/math/geometry/segment.js +0 -80
  172. package/src/utils/math/geometry/segment.test.js +0 -183
  173. package/src/utils/math/geometry/triangle.js +0 -15
  174. package/src/utils/math/geometry/triangle.test.js +0 -11
  175. package/src/utils/math/geometry/types.d.ts +0 -23
  176. package/src/utils/math/linear-algebra/2d.js +0 -28
  177. package/src/utils/math/linear-algebra/2d.test.js +0 -17
  178. package/src/utils/math/linear-algebra/quaternion.js +0 -22
  179. package/src/utils/math/linear-algebra/quaternion.test.js +0 -25
  180. package/src/utils/math/linear-algebra/quaternions.js +0 -20
  181. package/src/utils/math/linear-algebra/quaternions.test.js +0 -29
  182. package/src/utils/math/linear-algebra/types.d.ts +0 -4
  183. package/src/utils/math/linear-algebra/vector.js +0 -302
  184. package/src/utils/math/linear-algebra/vector.test.js +0 -257
  185. package/src/utils/math/linear-algebra/vectors.js +0 -122
  186. package/src/utils/math/linear-algebra/vectors.test.js +0 -65
  187. package/src/utils/math/numbers.js +0 -90
  188. package/src/utils/math/numbers.test.js +0 -137
  189. package/src/utils/math/rng.js +0 -44
  190. package/src/utils/math/rng.test.js +0 -39
  191. package/src/utils/math/statistics.js +0 -43
  192. package/src/utils/math/statistics.test.js +0 -47
  193. package/src/utils/math/trigonometry.js +0 -89
  194. package/src/utils/math/trigonometry.test.js +0 -52
  195. package/src/utils/physics/acceleration.js +0 -63
  196. package/src/utils/physics/friction.js +0 -30
  197. package/src/utils/physics/friction.test.js +0 -44
  198. package/src/utils/physics/gravity.js +0 -71
  199. package/src/utils/physics/gravity.test.js +0 -80
  200. package/src/utils/physics/jump.js +0 -41
  201. package/src/utils/physics/velocity.js +0 -38
@@ -1,256 +0,0 @@
1
- import { expect, test } from "vitest"
2
-
3
- import { createStore } from "./store.js"
4
-
5
- test("it should add an event to the event queue", () => {
6
- const event = { id: "something:happened" }
7
- const config = {
8
- types: {
9
- kitty: {
10
- [event.id](instance) {
11
- return { ...instance, wasNotified: true }
12
- },
13
- },
14
- },
15
- instances: {
16
- instance1: { type: "kitty" },
17
- },
18
- }
19
- const store = createStore(config)
20
- const afterState = {
21
- events: [],
22
- instances: {
23
- game: {
24
- id: "game",
25
- type: "game",
26
- layer: 0,
27
- bounds: [0, 0, 800, 600],
28
- },
29
- instance1: {
30
- id: "instance1",
31
- type: "kitty",
32
- layer: 0,
33
- wasNotified: true,
34
- },
35
- },
36
- }
37
-
38
- store.notify(event)
39
- store.update()
40
-
41
- const state = store.getState()
42
- expect(state).toStrictEqual(afterState)
43
- })
44
-
45
- test("it should process the event queue", () => {
46
- const event = { id: "something:happened" }
47
- const config = {
48
- types: {
49
- kitty: {
50
- "game:update"(instance) {
51
- return { ...instance, wasUpdated: true }
52
- },
53
-
54
- [event.id](instance) {
55
- return { ...instance, wasNotified: true }
56
- },
57
- },
58
- },
59
- instances: {
60
- instance1: { type: "kitty" },
61
- },
62
- }
63
- const store = createStore(config)
64
- store.notify(event)
65
- const afterState = {
66
- events: [],
67
- instances: {
68
- game: {
69
- id: "game",
70
- type: "game",
71
- layer: 0,
72
- bounds: [0, 0, 800, 600],
73
- },
74
- instance1: {
75
- id: "instance1",
76
- type: "kitty",
77
- layer: 0,
78
- wasNotified: true,
79
- wasUpdated: true,
80
- },
81
- },
82
- }
83
-
84
- store.update()
85
-
86
- const state = store.getState()
87
- expect(state).toStrictEqual(afterState)
88
- })
89
-
90
- test("it should send an event from an instance", () => {
91
- const event = {
92
- id: "doge:message",
93
- payload: { id: "inu", message: "Woof!" },
94
- }
95
- const config = {
96
- types: {
97
- doge: {
98
- "game:update"(instance, event, { instances, notify }) {
99
- if (instances.instance2.position === "near") {
100
- notify(event)
101
- }
102
- },
103
- },
104
- kitty: {
105
- [event.id](instance) {
106
- if (event.payload.id === "inu" && event.payload.message === "Woof!") {
107
- instance.position = "far"
108
- }
109
- },
110
- },
111
- },
112
-
113
- instances: {
114
- instance1: {
115
- type: "doge",
116
- },
117
- instance2: {
118
- type: "kitty",
119
- position: "near",
120
- },
121
- },
122
- }
123
- const store = createStore(config)
124
- const afterState = {
125
- events: [],
126
- instances: {
127
- game: {
128
- id: "game",
129
- type: "game",
130
- layer: 0,
131
- bounds: [0, 0, 800, 600],
132
- },
133
- instance1: {
134
- id: "instance1",
135
- type: "doge",
136
- layer: 0,
137
- },
138
- instance2: {
139
- id: "instance2",
140
- type: "kitty",
141
- layer: 0,
142
- position: "near", // should do nothing at first
143
- },
144
- },
145
- }
146
-
147
- store.update()
148
-
149
- const state = store.getState()
150
- expect(state).toStrictEqual(afterState)
151
- })
152
-
153
- test("it should receive an event from an instance", () => {
154
- const event = {
155
- id: "doge:message",
156
- payload: { id: "inu", message: "Woof!" },
157
- }
158
- const config = {
159
- types: {
160
- doge: {
161
- "game:update"(instance, event, { instances, notify }) {
162
- if (instances.instance2.position === "near") {
163
- notify(event)
164
- }
165
- },
166
- },
167
- kitty: {
168
- [event.id](instance, event) {
169
- if (event.payload.id === "inu" && event.payload.message === "Woof!") {
170
- instance.position = "far"
171
- }
172
- },
173
- },
174
- },
175
-
176
- instances: {
177
- instance1: {
178
- type: "doge",
179
- },
180
- instance2: {
181
- type: "kitty",
182
- position: "near",
183
- },
184
- },
185
- }
186
- const store = createStore(config)
187
- store.notify(event)
188
- const afterState = {
189
- events: [],
190
- instances: {
191
- game: {
192
- id: "game",
193
- type: "game",
194
- layer: 0,
195
- bounds: [0, 0, 800, 600],
196
- },
197
- instance1: {
198
- id: "instance1",
199
- type: "doge",
200
- layer: 0,
201
- },
202
- instance2: {
203
- id: "instance2",
204
- type: "kitty",
205
- layer: 0,
206
- position: "far", // position changed
207
- },
208
- },
209
- }
210
-
211
- store.update()
212
-
213
- const state = store.getState()
214
- expect(state).toStrictEqual(afterState)
215
- })
216
-
217
- test("it should mutate state in an immutable way", () => {
218
- const config = {
219
- types: {
220
- kitty: {
221
- "game:update"(instance) {
222
- instance.wasUpdated = true
223
- },
224
- },
225
- },
226
-
227
- instances: {
228
- instance1: {
229
- type: "kitty",
230
- },
231
- },
232
- }
233
- const store = createStore(config)
234
- const afterState = {
235
- events: [],
236
- instances: {
237
- game: {
238
- id: "game",
239
- type: "game",
240
- layer: 0,
241
- bounds: [0, 0, 800, 600],
242
- },
243
- instance1: {
244
- id: "instance1",
245
- type: "kitty",
246
- layer: 0,
247
- wasUpdated: true,
248
- },
249
- },
250
- }
251
-
252
- store.update()
253
-
254
- const state = store.getState()
255
- expect(state).toStrictEqual(afterState)
256
- })
package/src/engine.js DELETED
@@ -1,74 +0,0 @@
1
- import { extend } from "@inglorious/utils/data-structures/objects.js"
2
-
3
- import Loop from "./engine/loop.js"
4
- import { createStore } from "./engine/store.js"
5
-
6
- // Default configuration for the engine
7
- // loop.type specifies the type of loop to use (defaults to "animationFrame").
8
- const DEFAULT_CONFIG = {
9
- loop: { type: "animationFrame" },
10
- }
11
- const ONE_SECOND = 1000 // Number of milliseconds in one second.
12
-
13
- /**
14
- * Engine class responsible for managing the game loop, state, and rendering.
15
- */
16
- export default class Engine {
17
- /**
18
- * @param {Object} game - Game-specific configuration.
19
- * @param {Object} ui - UI instance responsible for rendering.
20
- */
21
- constructor(game, ui) {
22
- this._config = extend(DEFAULT_CONFIG, game)
23
- this._store = createStore(this._config)
24
- this._loop = new Loop[this._config.loop.type]()
25
- this._ui = ui
26
- }
27
-
28
- /**
29
- * Starts the game engine, initializing the loop and notifying the store.
30
- */
31
- start() {
32
- this._store.notify({ id: "game:start" })
33
- this._loop.start(this, ONE_SECOND / this._config.loop.fps)
34
- this.isRunning = true
35
- }
36
-
37
- /**
38
- * Updates the game state.
39
- * @param {number} dt - Delta time since the last update in milliseconds.
40
- */
41
- update(dt) {
42
- this._store.update(dt)
43
- }
44
-
45
- /**
46
- * Renders the game state using the UI.
47
- * @param {number} dt - Delta time since the last render in milliseconds.
48
- */
49
- render(dt) {
50
- this._ui?.render({
51
- dt,
52
- types: this._store.getTypes(),
53
- instances: this._store.getState().instances,
54
- })
55
- }
56
-
57
- /**
58
- * Notifies the store of an event.
59
- * @param {Object} event - Event object to notify the store with.
60
- */
61
- notify = (event) => {
62
- this._store.notify(event)
63
- }
64
-
65
- /**
66
- * Stops the game engine, halting the loop and notifying the store.
67
- */
68
- stop() {
69
- this._store.notify({ id: "game:stop" })
70
- this._store.update()
71
- this._loop.stop()
72
- this.isRunning = false
73
- }
74
- }
@@ -1,26 +0,0 @@
1
- const COUNTER_RESET = 0
2
- const DEFAULT_VALUE = 0
3
-
4
- export const Animation = { play }
5
-
6
- function play(what, state, instance, options) {
7
- const { dt, onTick } = options
8
- const {
9
- speed,
10
- defaultValue = DEFAULT_VALUE,
11
- value = DEFAULT_VALUE,
12
- } = instance[what]
13
-
14
- if (state !== instance[what].state) {
15
- instance[what].state = state
16
- instance[what].counter = COUNTER_RESET
17
- instance[what].value = defaultValue
18
- }
19
-
20
- instance[what].counter += dt
21
- if (instance[what].counter >= speed) {
22
- instance[what].counter = COUNTER_RESET
23
- instance[what].value = value
24
- onTick && onTick(instance, options)
25
- }
26
- }
@@ -1,66 +0,0 @@
1
- import {
2
- angle,
3
- clamp,
4
- createVector,
5
- fromAngle,
6
- multiply,
7
- 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"
11
-
12
- const X = 0
13
- const Z = 2
14
-
15
- export function bounce(instance, { dt, instances }) {
16
- const [minX, minZ, maxX, maxZ] = instances.game.bounds
17
- const [x, , z] = instance.position
18
-
19
- const velocity = createVector(instance.maxSpeed, instance.orientation)
20
- if (x < minX || x >= maxX) {
21
- velocity[X] = -velocity[X]
22
- }
23
-
24
- if (z < minZ || z >= maxZ) {
25
- velocity[Z] = -velocity[Z]
26
- }
27
-
28
- const position = sum(instance.position, multiply(velocity, dt))
29
- const orientation = angle(velocity)
30
-
31
- return { velocity, position, orientation }
32
- }
33
-
34
- // TODO: make the following functions pure
35
- export function clampToBounds(instance, [minX, minZ, maxX, maxZ]) {
36
- instance.position = clamp(
37
- instance.position,
38
- [minX, minZ, minZ],
39
- [maxX, maxZ, maxZ],
40
- )
41
- }
42
-
43
- export function flip(instance, [minX, minZ, maxX, maxZ]) {
44
- const [x, , z] = instance.position
45
-
46
- const direction = fromAngle(instance.orientation)
47
-
48
- if (x < minX || x >= maxX || z < minZ || z >= maxZ) {
49
- if (x < minX) {
50
- direction[X] = abs(direction[X])
51
- } else if (x >= maxX) {
52
- direction[X] = -abs(direction[X])
53
- }
54
-
55
- if (z < minZ) {
56
- direction[Z] = abs(direction[Z])
57
- } else if (z >= maxZ) {
58
- direction[Z] = -abs(direction[Z])
59
- }
60
-
61
- instance.acceleration = zero()
62
- instance.velocity = zero()
63
- }
64
-
65
- instance.orientation = angle(direction)
66
- }
@@ -1,5 +0,0 @@
1
- import draw from "@inglorious/ui/canvas/character.js"
2
-
3
- export function enableCharacter() {
4
- return { draw }
5
- }
@@ -1,15 +0,0 @@
1
- import { extend } from "@inglorious/utils/data-structures/objects.js"
2
-
3
- import { clampToBounds } from "../bounds.js"
4
-
5
- export function enableClampToBounds() {
6
- return (type) =>
7
- extend(type, {
8
- "game:update"(instance, event, options) {
9
- type["game:update"]?.(instance, event, options)
10
-
11
- const { instances } = options
12
- clampToBounds(instance, instances.game.bounds)
13
- },
14
- })
15
- }
@@ -1,48 +0,0 @@
1
- import modernMove from "@inglorious/engine/movement/dynamic/modern.js"
2
- import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
4
-
5
- const DEFAULT_PARAMS = {
6
- maxAcceleration: 500,
7
- }
8
- const X = 0
9
- const Z = 2
10
-
11
- export function enableModernControls(params) {
12
- params = extend(DEFAULT_PARAMS, params)
13
-
14
- return (type) =>
15
- extend(type, {
16
- "game:update"(instance, event, options) {
17
- type["game:update"]?.(instance, event, options)
18
-
19
- const maxAcceleration =
20
- instance.maxAcceleration ?? params.maxAcceleration
21
-
22
- const { input0 } = options.instances
23
- instance.acceleration = zero()
24
-
25
- if (input0.left) {
26
- instance.acceleration[X] = -maxAcceleration
27
- }
28
- if (input0.right) {
29
- instance.acceleration[X] = maxAcceleration
30
- }
31
- if (input0.down) {
32
- instance.acceleration[Z] = -maxAcceleration
33
- }
34
- if (input0.up) {
35
- instance.acceleration[Z] = maxAcceleration
36
- }
37
-
38
- if (input0.leftRight != null) {
39
- instance.acceleration[X] += input0.leftRight * maxAcceleration
40
- }
41
- if (input0.upDown != null) {
42
- instance.acceleration[Z] += -input0.upDown * maxAcceleration
43
- }
44
-
45
- merge(instance, modernMove(instance, options))
46
- },
47
- })
48
- }
@@ -1,47 +0,0 @@
1
- import face from "@inglorious/engine/ai/movement/dynamic/face.js"
2
- import tankMove from "@inglorious/engine/movement/dynamic/tank.js"
3
- import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
4
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
5
- import { pi } from "@inglorious/utils/math/trigonometry.js"
6
-
7
- const FULL_CIRCLE = 2
8
- const DEFAULT_PARAMS = {
9
- maxAngularSpeed: FULL_CIRCLE * pi(),
10
- maxSpeed: 250,
11
- }
12
- const X = 0
13
- const Z = 2
14
-
15
- export function enableShooterControls(params) {
16
- params = extend(DEFAULT_PARAMS, params)
17
-
18
- return (type) =>
19
- extend(type, {
20
- "game:update"(instance, event, options) {
21
- instance.maxAngularSpeed =
22
- instance.maxAngularSpeed ?? params.maxAngularSpeed
23
- instance.maxAcceleration =
24
- instance.maxAcceleration ?? params.maxAcceleration
25
- instance.maxSpeed = instance.maxSpeed ?? params.maxSpeed
26
-
27
- const { input0, mouse } = options.instances
28
- instance.acceleration = zero()
29
-
30
- if (input0.left) {
31
- instance.acceleration[Z] = -instance.maxAcceleration
32
- }
33
- if (input0.down) {
34
- instance.acceleration[X] = -instance.maxAcceleration
35
- }
36
- if (input0.right) {
37
- instance.acceleration[Z] = instance.maxAcceleration
38
- }
39
- if (input0.up) {
40
- instance.acceleration[X] = instance.maxAcceleration
41
- }
42
-
43
- merge(instance, face(instance, mouse, options))
44
- merge(instance, tankMove(instance, options))
45
- },
46
- })
47
- }
@@ -1,55 +0,0 @@
1
- import tankMove from "@inglorious/engine/movement/dynamic/tank.js"
2
- import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
4
-
5
- const DEFAULT_PARAMS = {
6
- maxAngularSpeed: 10,
7
- maxAcceleration: 500,
8
- maxSpeed: 250,
9
- }
10
- const X = 0
11
- const Z = 2
12
-
13
- export function enableTankControls(params) {
14
- params = extend(DEFAULT_PARAMS, params)
15
-
16
- return (type) =>
17
- extend(type, {
18
- "game:update"(instance, event, options) {
19
- instance.maxAngularSpeed =
20
- instance.maxAngularSpeed ?? params.maxAngularSpeed
21
- instance.maxAcceleration =
22
- instance.maxAcceleration ?? params.maxAcceleration
23
- instance.maxSpeed = instance.maxSpeed ?? params.maxSpeed
24
-
25
- instance.acceleration = zero()
26
-
27
- const { input0 } = options.instances
28
- if (input0.left) {
29
- instance.orientation += 0.1
30
- }
31
- if (input0.down) {
32
- instance.acceleration[X] = -instance.maxAcceleration
33
- }
34
- if (input0.right) {
35
- instance.orientation -= 0.1
36
- }
37
- if (input0.up) {
38
- instance.acceleration[X] = instance.maxAcceleration
39
- }
40
-
41
- if (input0.leftRight != null) {
42
- instance.orientation +=
43
- -input0.leftRight * instance.maxAngularSpeed * options.dt
44
- }
45
- if (input0.upDown != null) {
46
- instance.acceleration[X] += -input0.upDown * instance.maxAcceleration
47
- }
48
- if (input0.strafe != null) {
49
- instance.acceleration[Z] += input0.strafe * instance.maxAcceleration
50
- }
51
-
52
- merge(instance, tankMove(instance, options))
53
- },
54
- })
55
- }
@@ -1,49 +0,0 @@
1
- import modernMove from "@inglorious/engine/movement/kinematic/modern.js"
2
- import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
3
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
4
-
5
- const DEFAULT_PARAMS = {
6
- onState: "default",
7
- movementStrategy: "kinematic",
8
- maxSpeed: 250,
9
- }
10
- const X = 0
11
- const Z = 2
12
-
13
- export function enableModernControls(params) {
14
- params = extend(DEFAULT_PARAMS, params)
15
-
16
- return (type) =>
17
- extend(type, {
18
- "game:update"(instance, event, options) {
19
- type["game:update"]?.(instance, event, options)
20
-
21
- const maxSpeed = instance.maxSpeed ?? params.maxSpeed
22
-
23
- const { input0 } = options.instances
24
- instance.velocity = zero()
25
-
26
- if (input0.left) {
27
- instance.velocity[X] = -maxSpeed
28
- }
29
- if (input0.down) {
30
- instance.velocity[Z] = -maxSpeed
31
- }
32
- if (input0.right) {
33
- instance.velocity[X] = maxSpeed
34
- }
35
- if (input0.up) {
36
- instance.velocity[Z] = maxSpeed
37
- }
38
-
39
- if (input0.leftRight != null) {
40
- instance.velocity[X] += input0.leftRight * maxSpeed
41
- }
42
- if (input0.upDown != null) {
43
- instance.velocity[Z] += -input0.upDown * maxSpeed
44
- }
45
-
46
- merge(instance, modernMove(instance, options))
47
- },
48
- })
49
- }
@@ -1,45 +0,0 @@
1
- import face from "@inglorious/engine/ai/movement/kinematic/face.js"
2
- import tankMove from "@inglorious/engine/movement/kinematic/tank.js"
3
- import { extend, merge } from "@inglorious/utils/data-structures/objects.js"
4
- import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
5
- import { pi } from "@inglorious/utils/math/trigonometry.js"
6
-
7
- const FULL_CIRCLE = 2
8
- const DEFAULT_PARAMS = {
9
- maxAngularSpeed: FULL_CIRCLE * pi(),
10
- maxSpeed: 250,
11
- }
12
- const X = 0
13
- const Z = 2
14
-
15
- export function enableShooterControls(params) {
16
- params = extend(DEFAULT_PARAMS, params)
17
-
18
- return (type) =>
19
- extend(type, {
20
- "game:update"(instance, event, options) {
21
- instance.maxAngularSpeed =
22
- instance.maxAngularSpeed ?? params.maxAngularSpeed
23
- instance.maxSpeed = instance.maxSpeed ?? params.maxSpeed
24
-
25
- const { input0, mouse } = options.instances
26
- instance.velocity = zero()
27
-
28
- if (input0.left) {
29
- instance.velocity[Z] = -instance.maxSpeed
30
- }
31
- if (input0.down) {
32
- instance.velocity[X] = -instance.maxSpeed
33
- }
34
- if (input0.right) {
35
- instance.velocity[Z] = instance.maxSpeed
36
- }
37
- if (input0.up) {
38
- instance.velocity[X] = instance.maxSpeed
39
- }
40
-
41
- merge(instance, face(instance, mouse, options))
42
- merge(instance, tankMove(instance, options))
43
- },
44
- })
45
- }