@inglorious/engine 0.1.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 (256) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +72 -0
  3. package/package.json +76 -0
  4. package/src/docs/ai/movement/dynamic/align.js +131 -0
  5. package/src/docs/ai/movement/dynamic/arrive.js +88 -0
  6. package/src/docs/ai/movement/dynamic/dynamic.mdx +99 -0
  7. package/src/docs/ai/movement/dynamic/dynamic.stories.js +58 -0
  8. package/src/docs/ai/movement/dynamic/evade.js +72 -0
  9. package/src/docs/ai/movement/dynamic/face.js +90 -0
  10. package/src/docs/ai/movement/dynamic/flee.js +38 -0
  11. package/src/docs/ai/movement/dynamic/look-where-youre-going.js +114 -0
  12. package/src/docs/ai/movement/dynamic/match-velocity.js +92 -0
  13. package/src/docs/ai/movement/dynamic/pursue.js +72 -0
  14. package/src/docs/ai/movement/dynamic/seek.js +37 -0
  15. package/src/docs/ai/movement/dynamic/wander.js +71 -0
  16. package/src/docs/ai/movement/kinematic/align.js +122 -0
  17. package/src/docs/ai/movement/kinematic/arrive.js +78 -0
  18. package/src/docs/ai/movement/kinematic/face.js +82 -0
  19. package/src/docs/ai/movement/kinematic/flee.js +36 -0
  20. package/src/docs/ai/movement/kinematic/kinematic.mdx +67 -0
  21. package/src/docs/ai/movement/kinematic/kinematic.stories.js +42 -0
  22. package/src/docs/ai/movement/kinematic/seek.js +34 -0
  23. package/src/docs/ai/movement/kinematic/wander-as-seek.js +62 -0
  24. package/src/docs/ai/movement/kinematic/wander.js +28 -0
  25. package/src/docs/bounds.js +7 -0
  26. package/src/docs/code-reuse.js +35 -0
  27. package/src/docs/collision/circles.js +58 -0
  28. package/src/docs/collision/collision.mdx +27 -0
  29. package/src/docs/collision/collision.stories.js +22 -0
  30. package/src/docs/collision/platform.js +76 -0
  31. package/src/docs/collision/tilemap.js +181 -0
  32. package/src/docs/empty.js +1 -0
  33. package/src/docs/engine.mdx +81 -0
  34. package/src/docs/engine.stories.js +37 -0
  35. package/src/docs/event-handlers.js +68 -0
  36. package/src/docs/framerate.js +37 -0
  37. package/src/docs/game.jsx +15 -0
  38. package/src/docs/image/image.js +19 -0
  39. package/src/docs/image/image.stories.js +22 -0
  40. package/src/docs/image/sprite.js +39 -0
  41. package/src/docs/image/tilemap.js +84 -0
  42. package/src/docs/input/controls.js +67 -0
  43. package/src/docs/input/gamepad.js +67 -0
  44. package/src/docs/input/input.mdx +55 -0
  45. package/src/docs/input/input.stories.js +27 -0
  46. package/src/docs/input/keyboard.js +58 -0
  47. package/src/docs/input/mouse.js +32 -0
  48. package/src/docs/instances.js +49 -0
  49. package/src/docs/player/dynamic/double-jump.js +90 -0
  50. package/src/docs/player/dynamic/dynamic.stories.js +32 -0
  51. package/src/docs/player/dynamic/jump.js +83 -0
  52. package/src/docs/player/dynamic/modern-controls.js +57 -0
  53. package/src/docs/player/dynamic/shooter-controls.js +51 -0
  54. package/src/docs/player/dynamic/tank-controls.js +44 -0
  55. package/src/docs/player/kinematic/double-jump.js +90 -0
  56. package/src/docs/player/kinematic/jump.js +82 -0
  57. package/src/docs/player/kinematic/kinematic.stories.js +32 -0
  58. package/src/docs/player/kinematic/modern-controls.js +56 -0
  59. package/src/docs/player/kinematic/shooter-controls.js +48 -0
  60. package/src/docs/player/kinematic/tank-controls.js +42 -0
  61. package/src/docs/quick-start/first-game.js +49 -0
  62. package/src/docs/quick-start/hello-world.js +1 -0
  63. package/src/docs/quick-start.mdx +127 -0
  64. package/src/docs/quick-start.stories.js +17 -0
  65. package/src/docs/recipes/add-and-remove.js +71 -0
  66. package/src/docs/recipes/add-instance.js +42 -0
  67. package/src/docs/recipes/decision-tree.js +169 -0
  68. package/src/docs/recipes/random-instances.js +25 -0
  69. package/src/docs/recipes/recipes.mdx +81 -0
  70. package/src/docs/recipes/recipes.stories.js +37 -0
  71. package/src/docs/recipes/remove-instance.js +52 -0
  72. package/src/docs/recipes/states.js +64 -0
  73. package/src/docs/ui/button.js +28 -0
  74. package/src/docs/ui/form.stories.js +55 -0
  75. package/src/docs/ui-chooser.jsx +6 -0
  76. package/src/docs/utils/data-structures/object.mdx +47 -0
  77. package/src/docs/utils/data-structures/objects.mdx +30 -0
  78. package/src/docs/utils/functions/functions.mdx +34 -0
  79. package/src/docs/utils/math/geometry/circle.mdx +55 -0
  80. package/src/docs/utils/math/geometry/point.mdx +38 -0
  81. package/src/docs/utils/math/geometry/rectangle.mdx +24 -0
  82. package/src/docs/utils/math/geometry/segment.mdx +55 -0
  83. package/src/docs/utils/math/geometry/triangle.mdx +22 -0
  84. package/src/docs/utils/math/linear-algebra/2d.mdx +22 -0
  85. package/src/docs/utils/math/linear-algebra/quaternion.mdx +21 -0
  86. package/src/docs/utils/math/linear-algebra/quaternions.mdx +22 -0
  87. package/src/docs/utils/math/linear-algebra/vector.mdx +177 -0
  88. package/src/docs/utils/math/linear-algebra/vectors.mdx +58 -0
  89. package/src/docs/utils/math/numbers.mdx +76 -0
  90. package/src/docs/utils/math/random.mdx +35 -0
  91. package/src/docs/utils/math/statistics.mdx +38 -0
  92. package/src/docs/utils/math/trigonometry.mdx +85 -0
  93. package/src/docs/utils/physics/friction.mdx +20 -0
  94. package/src/docs/utils/physics/gravity.mdx +28 -0
  95. package/src/engine/ai/movement/dynamic/align.js +63 -0
  96. package/src/engine/ai/movement/dynamic/arrive.js +43 -0
  97. package/src/engine/ai/movement/dynamic/evade.js +38 -0
  98. package/src/engine/ai/movement/dynamic/face.js +20 -0
  99. package/src/engine/ai/movement/dynamic/flee.js +45 -0
  100. package/src/engine/ai/movement/dynamic/look-where-youre-going.js +17 -0
  101. package/src/engine/ai/movement/dynamic/match-velocity.js +50 -0
  102. package/src/engine/ai/movement/dynamic/pursue.js +38 -0
  103. package/src/engine/ai/movement/dynamic/seek.js +44 -0
  104. package/src/engine/ai/movement/dynamic/wander.js +32 -0
  105. package/src/engine/ai/movement/kinematic/align.js +37 -0
  106. package/src/engine/ai/movement/kinematic/arrive.js +42 -0
  107. package/src/engine/ai/movement/kinematic/face.js +20 -0
  108. package/src/engine/ai/movement/kinematic/flee.js +26 -0
  109. package/src/engine/ai/movement/kinematic/seek.js +26 -0
  110. package/src/engine/ai/movement/kinematic/seek.test.js +42 -0
  111. package/src/engine/ai/movement/kinematic/wander-as-seek.js +31 -0
  112. package/src/engine/ai/movement/kinematic/wander.js +27 -0
  113. package/src/engine/collision/detection.js +115 -0
  114. package/src/engine/loop/animation-frame.js +26 -0
  115. package/src/engine/loop/elapsed.js +23 -0
  116. package/src/engine/loop/fixed.js +28 -0
  117. package/src/engine/loop/flash.js +14 -0
  118. package/src/engine/loop/lag.js +27 -0
  119. package/src/engine/loop.js +15 -0
  120. package/src/engine/movement/dynamic/modern.js +24 -0
  121. package/src/engine/movement/dynamic/tank.js +43 -0
  122. package/src/engine/movement/kinematic/modern.js +16 -0
  123. package/src/engine/movement/kinematic/modern.test.js +27 -0
  124. package/src/engine/movement/kinematic/tank.js +27 -0
  125. package/src/engine/store.js +174 -0
  126. package/src/engine/store.test.js +256 -0
  127. package/src/engine.js +74 -0
  128. package/src/game/animation.js +26 -0
  129. package/src/game/bounds.js +66 -0
  130. package/src/game/decorators/character.js +5 -0
  131. package/src/game/decorators/clamp-to-bounds.js +15 -0
  132. package/src/game/decorators/collisions.js +24 -0
  133. package/src/game/decorators/controls/dynamic/modern.js +48 -0
  134. package/src/game/decorators/controls/dynamic/shooter.js +47 -0
  135. package/src/game/decorators/controls/dynamic/tank.js +55 -0
  136. package/src/game/decorators/controls/kinematic/modern.js +49 -0
  137. package/src/game/decorators/controls/kinematic/shooter.js +45 -0
  138. package/src/game/decorators/controls/kinematic/tank.js +52 -0
  139. package/src/game/decorators/debug/collisions.js +32 -0
  140. package/src/game/decorators/double-jump.js +70 -0
  141. package/src/game/decorators/fps.js +30 -0
  142. package/src/game/decorators/fsm.js +27 -0
  143. package/src/game/decorators/fsm.test.js +56 -0
  144. package/src/game/decorators/game.js +11 -0
  145. package/src/game/decorators/image/image.js +5 -0
  146. package/src/game/decorators/image/sprite.js +5 -0
  147. package/src/game/decorators/image/tilemap.js +5 -0
  148. package/src/game/decorators/input/controls.js +27 -0
  149. package/src/game/decorators/input/gamepad.js +74 -0
  150. package/src/game/decorators/input/input.js +41 -0
  151. package/src/game/decorators/input/keyboard.js +49 -0
  152. package/src/game/decorators/input/mouse.js +65 -0
  153. package/src/game/decorators/jump.js +72 -0
  154. package/src/game/decorators/platform.js +5 -0
  155. package/src/game/decorators/ui/button.js +21 -0
  156. package/src/game/sprite.js +119 -0
  157. package/src/main.js +5 -0
  158. package/src/ui/canvas/absolute-position.js +17 -0
  159. package/src/ui/canvas/character.js +35 -0
  160. package/src/ui/canvas/form/button.js +25 -0
  161. package/src/ui/canvas/fps.js +18 -0
  162. package/src/ui/canvas/image/hitmask.js +37 -0
  163. package/src/ui/canvas/image/image.js +37 -0
  164. package/src/ui/canvas/image/sprite.js +49 -0
  165. package/src/ui/canvas/image/tilemap.js +64 -0
  166. package/src/ui/canvas/mouse.js +37 -0
  167. package/src/ui/canvas/shapes/circle.js +31 -0
  168. package/src/ui/canvas/shapes/rectangle.js +31 -0
  169. package/src/ui/canvas.js +81 -0
  170. package/src/ui/react/game/character/character.module.scss +17 -0
  171. package/src/ui/react/game/character/index.jsx +30 -0
  172. package/src/ui/react/game/cursor/cursor.module.scss +47 -0
  173. package/src/ui/react/game/cursor/index.jsx +20 -0
  174. package/src/ui/react/game/form/fields/field/field.module.scss +5 -0
  175. package/src/ui/react/game/form/fields/field/index.jsx +56 -0
  176. package/src/ui/react/game/form/fields/fields.module.scss +48 -0
  177. package/src/ui/react/game/form/fields/index.jsx +12 -0
  178. package/src/ui/react/game/form/form.module.scss +18 -0
  179. package/src/ui/react/game/form/index.jsx +22 -0
  180. package/src/ui/react/game/fps/index.jsx +16 -0
  181. package/src/ui/react/game/game.jsx +71 -0
  182. package/src/ui/react/game/index.jsx +29 -0
  183. package/src/ui/react/game/platform/index.jsx +30 -0
  184. package/src/ui/react/game/platform/platform.module.scss +7 -0
  185. package/src/ui/react/game/scene/index.jsx +25 -0
  186. package/src/ui/react/game/scene/scene.module.scss +9 -0
  187. package/src/ui/react/game/sprite/index.jsx +58 -0
  188. package/src/ui/react/game/sprite/sprite.module.css +3 -0
  189. package/src/ui/react/game/stats/index.jsx +22 -0
  190. package/src/ui/react/hocs/with-absolute-position/index.jsx +20 -0
  191. package/src/ui/react/hocs/with-absolute-position/with-absolute-position.module.scss +5 -0
  192. package/src/ui/react/index.jsx +9 -0
  193. package/src/utils/algorithms/decision-tree.js +24 -0
  194. package/src/utils/algorithms/decision-tree.test.js +102 -0
  195. package/src/utils/algorithms/path-finding.js +155 -0
  196. package/src/utils/algorithms/path-finding.test.js +151 -0
  197. package/src/utils/algorithms/types.d.ts +28 -0
  198. package/src/utils/data-structures/array.js +83 -0
  199. package/src/utils/data-structures/array.test.js +173 -0
  200. package/src/utils/data-structures/board.js +159 -0
  201. package/src/utils/data-structures/board.test.js +242 -0
  202. package/src/utils/data-structures/boolean.js +9 -0
  203. package/src/utils/data-structures/heap.js +164 -0
  204. package/src/utils/data-structures/heap.test.js +103 -0
  205. package/src/utils/data-structures/object.js +102 -0
  206. package/src/utils/data-structures/object.test.js +121 -0
  207. package/src/utils/data-structures/objects.js +48 -0
  208. package/src/utils/data-structures/objects.test.js +99 -0
  209. package/src/utils/data-structures/tree.js +36 -0
  210. package/src/utils/data-structures/tree.test.js +33 -0
  211. package/src/utils/data-structures/types.d.ts +4 -0
  212. package/src/utils/functions/functions.js +19 -0
  213. package/src/utils/functions/functions.test.js +23 -0
  214. package/src/utils/math/geometry/circle.js +117 -0
  215. package/src/utils/math/geometry/circle.test.js +97 -0
  216. package/src/utils/math/geometry/hitmask.js +39 -0
  217. package/src/utils/math/geometry/hitmask.test.js +84 -0
  218. package/src/utils/math/geometry/line.js +35 -0
  219. package/src/utils/math/geometry/line.test.js +49 -0
  220. package/src/utils/math/geometry/platform.js +42 -0
  221. package/src/utils/math/geometry/platform.test.js +133 -0
  222. package/src/utils/math/geometry/point.js +71 -0
  223. package/src/utils/math/geometry/point.test.js +81 -0
  224. package/src/utils/math/geometry/rectangle.js +45 -0
  225. package/src/utils/math/geometry/rectangle.test.js +42 -0
  226. package/src/utils/math/geometry/segment.js +80 -0
  227. package/src/utils/math/geometry/segment.test.js +183 -0
  228. package/src/utils/math/geometry/triangle.js +15 -0
  229. package/src/utils/math/geometry/triangle.test.js +11 -0
  230. package/src/utils/math/geometry/types.d.ts +23 -0
  231. package/src/utils/math/linear-algebra/2d.js +28 -0
  232. package/src/utils/math/linear-algebra/2d.test.js +17 -0
  233. package/src/utils/math/linear-algebra/quaternion.js +22 -0
  234. package/src/utils/math/linear-algebra/quaternion.test.js +25 -0
  235. package/src/utils/math/linear-algebra/quaternions.js +20 -0
  236. package/src/utils/math/linear-algebra/quaternions.test.js +29 -0
  237. package/src/utils/math/linear-algebra/types.d.ts +4 -0
  238. package/src/utils/math/linear-algebra/vector.js +302 -0
  239. package/src/utils/math/linear-algebra/vector.test.js +257 -0
  240. package/src/utils/math/linear-algebra/vectors.js +122 -0
  241. package/src/utils/math/linear-algebra/vectors.test.js +65 -0
  242. package/src/utils/math/numbers.js +90 -0
  243. package/src/utils/math/numbers.test.js +137 -0
  244. package/src/utils/math/rng.js +44 -0
  245. package/src/utils/math/rng.test.js +39 -0
  246. package/src/utils/math/statistics.js +43 -0
  247. package/src/utils/math/statistics.test.js +47 -0
  248. package/src/utils/math/trigonometry.js +89 -0
  249. package/src/utils/math/trigonometry.test.js +52 -0
  250. package/src/utils/physics/acceleration.js +63 -0
  251. package/src/utils/physics/friction.js +30 -0
  252. package/src/utils/physics/friction.test.js +44 -0
  253. package/src/utils/physics/gravity.js +71 -0
  254. package/src/utils/physics/gravity.test.js +80 -0
  255. package/src/utils/physics/jump.js +41 -0
  256. package/src/utils/physics/velocity.js +38 -0
@@ -0,0 +1,38 @@
1
+ import flee from "@inglorious/engine/ai/movement/dynamic/flee.js"
2
+ import { clampToBounds } from "@inglorious/game/bounds.js"
3
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
4
+ import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
5
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
6
+
7
+ export default {
8
+ types: {
9
+ mouse: [enableMouse()],
10
+
11
+ character: [
12
+ enableCharacter(),
13
+ {
14
+ "game:update"(instance, event, { dt, instances }) {
15
+ const target = instances.mouse
16
+
17
+ merge(instance, flee(instance, target, { dt }))
18
+
19
+ clampToBounds(instance, instances.game.bounds)
20
+ },
21
+ },
22
+ ],
23
+ },
24
+
25
+ instances: {
26
+ mouse: {
27
+ type: "mouse",
28
+ position: [400, 0, 300],
29
+ },
30
+
31
+ character: {
32
+ type: "character",
33
+ maxAcceleration: 1000,
34
+ maxSpeed: 250,
35
+ position: [400, 0, 300],
36
+ },
37
+ },
38
+ }
@@ -0,0 +1,114 @@
1
+ import {
2
+ DEFAULT_SLOW_RADIUS,
3
+ DEFAULT_TARGET_RADIUS,
4
+ DEFAULT_TIME_TO_TARGET,
5
+ } from "@inglorious/engine/ai/movement/dynamic/align.js"
6
+ import lookWhereYoureGoing from "@inglorious/engine/ai/movement/dynamic/look-where-youre-going.js"
7
+ import { clampToBounds } from "@inglorious/game/bounds.js"
8
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
9
+ import {
10
+ createControls,
11
+ enableControls,
12
+ } from "@inglorious/game/decorators/input/controls.js"
13
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
14
+ import { sum } from "@inglorious/utils/math/linear-algebra/vectors.js"
15
+ import { pi } from "@inglorious/utils/math/trigonometry.js"
16
+
17
+ export default {
18
+ types: {
19
+ ...enableControls(),
20
+
21
+ character: [
22
+ enableCharacter(),
23
+ {
24
+ "game:update"(instance, event, { dt, instances }) {
25
+ const { fields } = instances.parameters.groups.lookWhereYoureGoing
26
+
27
+ const { input0 } = instances
28
+
29
+ const target = { velocity: [0, 0, 0] }
30
+ if (input0.left) {
31
+ target.velocity[0] = -1
32
+ }
33
+ if (input0.down) {
34
+ target.velocity[2] = -1
35
+ }
36
+ if (input0.right) {
37
+ target.velocity[0] = 1
38
+ }
39
+ if (input0.up) {
40
+ target.velocity[2] = 1
41
+ }
42
+
43
+ merge(instance, {
44
+ velocity: target.velocity,
45
+ position: sum(instance.position, target.velocity),
46
+ })
47
+
48
+ merge(
49
+ instance,
50
+ lookWhereYoureGoing(instance, {
51
+ dt,
52
+ targetRadius: fields.targetRadius.value,
53
+ slowRadius: fields.slowRadius.value,
54
+ timeToTarget: fields.timeToTarget.value,
55
+ }),
56
+ )
57
+
58
+ clampToBounds(instance, instances.game.bounds)
59
+ },
60
+ },
61
+ ],
62
+
63
+ form: {
64
+ "field:change"(instance, event) {
65
+ const { id, value } = event.payload
66
+ instance.groups.lookWhereYoureGoing.fields[id].value = value
67
+ },
68
+ },
69
+ },
70
+
71
+ instances: {
72
+ ...createControls("input0", {
73
+ ArrowLeft: "left",
74
+ ArrowRight: "right",
75
+ ArrowDown: "down",
76
+ ArrowUp: "up",
77
+ }),
78
+
79
+ character: {
80
+ type: "character",
81
+ maxAngularAcceleration: 1000,
82
+ maxAngularSpeed: pi() / 4,
83
+ position: [400, 0, 300],
84
+ },
85
+
86
+ parameters: {
87
+ type: "form",
88
+ position: [800 - 328, 0, 600],
89
+ groups: {
90
+ lookWhereYoureGoing: {
91
+ title: "Look Where You're Going",
92
+ fields: {
93
+ targetRadius: {
94
+ label: "Target Radius",
95
+ inputType: "number",
96
+ defaultValue: DEFAULT_TARGET_RADIUS,
97
+ },
98
+ slowRadius: {
99
+ label: "Slow Radius",
100
+ inputType: "number",
101
+ defaultValue: DEFAULT_SLOW_RADIUS,
102
+ },
103
+ timeToTarget: {
104
+ label: "Time To Target",
105
+ inputType: "number",
106
+ step: 0.1,
107
+ defaultValue: DEFAULT_TIME_TO_TARGET,
108
+ },
109
+ },
110
+ },
111
+ },
112
+ },
113
+ },
114
+ }
@@ -0,0 +1,92 @@
1
+ import matchVelocity, {
2
+ DEFAULT_TIME_TO_TARGET,
3
+ } from "@inglorious/engine/ai/movement/dynamic/match-velocity.js"
4
+ import { clampToBounds } from "@inglorious/game/bounds.js"
5
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
6
+ import {
7
+ createControls,
8
+ enableControls,
9
+ } from "@inglorious/game/decorators/input/controls.js"
10
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
11
+
12
+ export default {
13
+ types: {
14
+ ...enableControls(),
15
+
16
+ character: [
17
+ enableCharacter(),
18
+ {
19
+ "game:update"(instance, event, options) {
20
+ const { parameters, input0, game } = options.instances
21
+ const { fields } = parameters.groups.matchVelocity
22
+ const SPEED = instance.maxSpeed
23
+
24
+ const target = { velocity: [0, 0, 0] }
25
+ if (input0.left) {
26
+ target.velocity[0] = -SPEED
27
+ }
28
+ if (input0.down) {
29
+ target.velocity[2] = -SPEED
30
+ }
31
+ if (input0.right) {
32
+ target.velocity[0] = SPEED
33
+ }
34
+ if (input0.up) {
35
+ target.velocity[2] = SPEED
36
+ }
37
+
38
+ merge(
39
+ instance,
40
+ matchVelocity(instance, target, {
41
+ dt: options.dt,
42
+ timeToTarget: fields.timeToTarget.value,
43
+ }),
44
+ )
45
+
46
+ clampToBounds(instance, game.bounds)
47
+ },
48
+ },
49
+ ],
50
+
51
+ form: {
52
+ "field:change"(instance, event) {
53
+ const { id, value } = event.payload
54
+ instance.groups.matchVelocity.fields[id].value = value
55
+ },
56
+ },
57
+ },
58
+
59
+ instances: {
60
+ ...createControls("input0", {
61
+ ArrowLeft: "left",
62
+ ArrowRight: "right",
63
+ ArrowDown: "down",
64
+ ArrowUp: "up",
65
+ }),
66
+
67
+ character: {
68
+ type: "character",
69
+ maxAcceleration: 1000,
70
+ maxSpeed: 250,
71
+ position: [400, 0, 300],
72
+ },
73
+
74
+ parameters: {
75
+ type: "form",
76
+ position: [800 - 328, 0, 600],
77
+ groups: {
78
+ matchVelocity: {
79
+ title: "Match Velocity",
80
+ fields: {
81
+ timeToTarget: {
82
+ label: "Time To Target",
83
+ inputType: "number",
84
+ step: 0.1,
85
+ defaultValue: DEFAULT_TIME_TO_TARGET,
86
+ },
87
+ },
88
+ },
89
+ },
90
+ },
91
+ },
92
+ }
@@ -0,0 +1,72 @@
1
+ import pursue, {
2
+ DEFAULT_MAX_PREDICTION,
3
+ } from "@inglorious/engine/ai/movement/dynamic/pursue.js"
4
+ import { clampToBounds } from "@inglorious/game/bounds.js"
5
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
6
+ import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
7
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
8
+
9
+ export default {
10
+ types: {
11
+ mouse: [enableMouse()],
12
+
13
+ character: [
14
+ enableCharacter(),
15
+ {
16
+ "game:update"(instance, event, { dt, instances }) {
17
+ const target = instances.mouse
18
+ const { fields } = instances.parameters.groups.pursue
19
+
20
+ merge(
21
+ instance,
22
+ pursue(instance, target, {
23
+ dt,
24
+ maxPrediction: fields.maxPrediction.value,
25
+ }),
26
+ )
27
+
28
+ clampToBounds(instance, instances.game.bounds)
29
+ },
30
+ },
31
+ ],
32
+
33
+ form: {
34
+ "field:change"(instance, event) {
35
+ const { id, value } = event.payload
36
+ instance.groups.pursue.fields[id].value = value
37
+ },
38
+ },
39
+ },
40
+
41
+ instances: {
42
+ mouse: {
43
+ type: "mouse",
44
+ position: [400, 0, 300],
45
+ velocity: [0, 0, 0],
46
+ },
47
+
48
+ character: {
49
+ type: "character",
50
+ maxAcceleration: 1000,
51
+ maxSpeed: 250,
52
+ position: [400, 0, 300],
53
+ },
54
+
55
+ parameters: {
56
+ type: "form",
57
+ position: [800 - 343, 0, 600],
58
+ groups: {
59
+ pursue: {
60
+ title: "Pursue",
61
+ fields: {
62
+ maxPrediction: {
63
+ label: "Max Prediction",
64
+ inputType: "number",
65
+ defaultValue: DEFAULT_MAX_PREDICTION,
66
+ },
67
+ },
68
+ },
69
+ },
70
+ },
71
+ },
72
+ }
@@ -0,0 +1,37 @@
1
+ import seek from "@inglorious/engine/ai/movement/dynamic/seek.js"
2
+ import { clampToBounds } from "@inglorious/game/bounds.js"
3
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
4
+ import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
5
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
6
+
7
+ export default {
8
+ types: {
9
+ mouse: [enableMouse()],
10
+
11
+ character: [
12
+ enableCharacter(),
13
+ {
14
+ "game:update"(instance, event, { dt, instances }) {
15
+ const target = instances.mouse
16
+
17
+ merge(instance, seek(instance, target, { dt }))
18
+ clampToBounds(instance, instances.game.bounds)
19
+ },
20
+ },
21
+ ],
22
+ },
23
+
24
+ instances: {
25
+ mouse: {
26
+ type: "mouse",
27
+ position: [400, 0, 300],
28
+ },
29
+
30
+ character: {
31
+ type: "character",
32
+ maxAcceleration: 1000,
33
+ maxSpeed: 250,
34
+ position: [400, 0, 300],
35
+ },
36
+ },
37
+ }
@@ -0,0 +1,71 @@
1
+ import wander, {
2
+ DEFAULT_WANDER_OFFSET,
3
+ DEFAULT_WANDER_RADIUS,
4
+ } from "@inglorious/engine/ai/movement/dynamic/wander.js"
5
+ import { flip } from "@inglorious/game/bounds.js"
6
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
7
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
8
+ import { pi } from "@inglorious/utils/math/trigonometry.js"
9
+
10
+ export default {
11
+ types: {
12
+ character: [
13
+ enableCharacter(),
14
+ {
15
+ "game:update"(instance, event, { dt, instances }) {
16
+ const { fields } = instances.parameters.groups.wander
17
+
18
+ merge(
19
+ instance,
20
+ wander(instance, {
21
+ dt,
22
+ wanderOffset: fields.wanderOffset.value,
23
+ wanderRadius: fields.wanderRadius.value,
24
+ }),
25
+ )
26
+ flip(instance, instances.game.bounds)
27
+ },
28
+ },
29
+ ],
30
+
31
+ form: {
32
+ "field:change"(instance, event) {
33
+ const { id, value } = event.payload
34
+ instance.groups.wander.fields[id].value = value
35
+ },
36
+ },
37
+ },
38
+
39
+ instances: {
40
+ character: {
41
+ type: "character",
42
+ maxAcceleration: 1000,
43
+ maxSpeed: 250,
44
+ maxAngularSpeed: pi() / 4,
45
+ position: [400, 0, 300],
46
+ },
47
+
48
+ parameters: {
49
+ type: "form",
50
+ position: [800 - 352, 0, 600],
51
+ groups: {
52
+ wander: {
53
+ title: "Dynamic Wander",
54
+ fields: {
55
+ wanderOffset: {
56
+ label: "Wander Offset",
57
+ inputType: "number",
58
+ defaultValue: DEFAULT_WANDER_OFFSET,
59
+ },
60
+ wanderRadius: {
61
+ label: "Wander Radius",
62
+ inputType: "number",
63
+ step: 0.1,
64
+ defaultValue: DEFAULT_WANDER_RADIUS,
65
+ },
66
+ },
67
+ },
68
+ },
69
+ },
70
+ },
71
+ }
@@ -0,0 +1,122 @@
1
+ import align, {
2
+ DEFAULT_TARGET_RADIUS,
3
+ DEFAULT_TIME_TO_TARGET,
4
+ } from "@inglorious/engine/ai/movement/kinematic/align.js"
5
+ import { clampToBounds } from "@inglorious/game/bounds.js"
6
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
7
+ import {
8
+ createControls,
9
+ enableControls,
10
+ } from "@inglorious/game/decorators/input/controls.js"
11
+ import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
12
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
13
+ import { clamp } from "@inglorious/utils/math/numbers.js"
14
+ import { pi } from "@inglorious/utils/math/trigonometry.js"
15
+
16
+ export default {
17
+ types: {
18
+ mouse: [
19
+ enableMouse(),
20
+ {
21
+ "field:change"(instance, event) {
22
+ const { id, value } = event.payload
23
+ if (id === "targetOrientation") {
24
+ instance.orientation = -value * pi()
25
+ }
26
+ },
27
+
28
+ "game:update"(instance, event, options) {
29
+ const { input0 } = options.instances
30
+
31
+ if (input0.left || input0.up) {
32
+ instance.orientation += 0.1
33
+ } else if (input0.right || input0.down) {
34
+ instance.orientation -= 0.1
35
+ }
36
+ instance.orientation = clamp(instance.orientation, -pi(), pi())
37
+ },
38
+ },
39
+ ],
40
+
41
+ ...enableControls(),
42
+
43
+ character: [
44
+ enableCharacter(),
45
+ {
46
+ "game:update"(instance, event, { dt, instances }) {
47
+ const target = instances.mouse
48
+ const { fields } = instances.parameters.groups.align
49
+
50
+ merge(
51
+ instance,
52
+ align(instance, target, {
53
+ dt,
54
+ targetRadius: fields.targetRadius.value,
55
+ timeToTarget: fields.timeToTarget.value,
56
+ }),
57
+ )
58
+
59
+ clampToBounds(instance, instances.game.bounds)
60
+ },
61
+ },
62
+ ],
63
+
64
+ form: {
65
+ "field:change"(instance, event) {
66
+ const { id, value } = event.payload
67
+ instance.groups.align.fields[id].value = value
68
+ },
69
+ },
70
+ },
71
+
72
+ instances: {
73
+ mouse: {
74
+ type: "mouse",
75
+ position: [400, 0, 300],
76
+ orientation: 0,
77
+ },
78
+ ...createControls("input0", {
79
+ ArrowLeft: "left",
80
+ ArrowRight: "right",
81
+ ArrowDown: "down",
82
+ ArrowUp: "up",
83
+ }),
84
+
85
+ character: {
86
+ type: "character",
87
+ maxAngularSpeed: pi() / 4,
88
+ position: [400, 0, 300],
89
+ },
90
+
91
+ parameters: {
92
+ type: "form",
93
+ position: [800 - 328, 0, 600],
94
+ groups: {
95
+ align: {
96
+ title: "Kinematic Align",
97
+ fields: {
98
+ targetRadius: {
99
+ label: "Target Radius",
100
+ inputType: "number",
101
+ defaultValue: DEFAULT_TARGET_RADIUS,
102
+ },
103
+ timeToTarget: {
104
+ label: "Time To Target",
105
+ inputType: "number",
106
+ step: 0.1,
107
+ defaultValue: DEFAULT_TIME_TO_TARGET,
108
+ },
109
+ targetOrientation: {
110
+ label: "Target Orientation",
111
+ inputType: "number",
112
+ step: 0.25,
113
+ min: -1,
114
+ max: 1,
115
+ defaultValue: 0,
116
+ },
117
+ },
118
+ },
119
+ },
120
+ },
121
+ },
122
+ }
@@ -0,0 +1,78 @@
1
+ import arrive, {
2
+ DEFAULT_TARGET_RADIUS,
3
+ DEFAULT_TIME_TO_TARGET,
4
+ } from "@inglorious/engine/ai/movement/kinematic/arrive.js"
5
+ import { clampToBounds } from "@inglorious/game/bounds.js"
6
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
7
+ import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
8
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
9
+
10
+ export default {
11
+ types: {
12
+ mouse: [enableMouse()],
13
+
14
+ character: [
15
+ enableCharacter(),
16
+ {
17
+ "game:update"(instance, event, { dt, instances }) {
18
+ const target = instances.mouse
19
+ const { fields } = instances.parameters.groups.arrive
20
+
21
+ merge(
22
+ instance,
23
+ arrive(instance, target, {
24
+ dt,
25
+ targetRadius: fields.targetRadius.value,
26
+ timeToTarget: fields.timeToTarget.value,
27
+ }),
28
+ )
29
+
30
+ clampToBounds(instance, instances.game.bounds)
31
+ },
32
+ },
33
+ ],
34
+
35
+ form: {
36
+ "field:change"(instance, event) {
37
+ const { id, value } = event.payload
38
+ instance.groups.arrive.fields[id].value = value
39
+ },
40
+ },
41
+ },
42
+
43
+ instances: {
44
+ mouse: {
45
+ type: "mouse",
46
+ position: [400, 0, 300],
47
+ },
48
+
49
+ character: {
50
+ type: "character",
51
+ maxSpeed: 250,
52
+ position: [400, 0, 300],
53
+ },
54
+
55
+ parameters: {
56
+ type: "form",
57
+ position: [800 - 328, 0, 600],
58
+ groups: {
59
+ arrive: {
60
+ title: "Kinematic Arrive",
61
+ fields: {
62
+ targetRadius: {
63
+ label: "Target Radius",
64
+ inputType: "number",
65
+ defaultValue: DEFAULT_TARGET_RADIUS,
66
+ },
67
+ timeToTarget: {
68
+ label: "Time To Target",
69
+ inputType: "number",
70
+ step: 0.1,
71
+ defaultValue: DEFAULT_TIME_TO_TARGET,
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ },
78
+ }
@@ -0,0 +1,82 @@
1
+ import {
2
+ DEFAULT_TARGET_RADIUS,
3
+ DEFAULT_TIME_TO_TARGET,
4
+ } from "@inglorious/engine/ai/movement/kinematic/align.js"
5
+ import face from "@inglorious/engine/ai/movement/kinematic/face.js"
6
+ import { clampToBounds } from "@inglorious/game/bounds.js"
7
+ import { enableCharacter } from "@inglorious/game/decorators/character.js"
8
+ import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
9
+ import { merge } from "@inglorious/utils/data-structures/objects.js"
10
+ import { pi } from "@inglorious/utils/math/trigonometry.js"
11
+
12
+ export default {
13
+ types: {
14
+ mouse: [enableMouse()],
15
+
16
+ character: [
17
+ enableCharacter(),
18
+ {
19
+ "game:update"(instance, event, { dt, instances }) {
20
+ const target = instances.mouse
21
+ const { fields } = instances.parameters.groups.face
22
+
23
+ merge(
24
+ instance,
25
+ face(instance, target, {
26
+ dt,
27
+ targetRadius: fields.targetRadius.value,
28
+ timeToTarget: fields.timeToTarget.value,
29
+ }),
30
+ )
31
+
32
+ clampToBounds(instance, instances.game.bounds)
33
+ },
34
+ },
35
+ ],
36
+
37
+ form: {
38
+ "field:change"(instance, event) {
39
+ const { id, value } = event.payload
40
+ instance.groups.face.fields[id].value = value
41
+ },
42
+ },
43
+ },
44
+
45
+ instances: {
46
+ mouse: {
47
+ type: "mouse",
48
+ position: [400, 0, 300],
49
+ },
50
+
51
+ character: {
52
+ type: "character",
53
+ maxAngularSpeed: pi() / 4,
54
+ maxAngularAcceleration: 1000,
55
+ position: [400, 0, 300],
56
+ },
57
+
58
+ parameters: {
59
+ type: "form",
60
+ position: [800 - 328, 0, 600],
61
+ groups: {
62
+ face: {
63
+ title: "Face",
64
+ fields: {
65
+ targetRadius: {
66
+ label: "Target Radius",
67
+ inputType: "number",
68
+ step: 0.1,
69
+ defaultValue: DEFAULT_TARGET_RADIUS,
70
+ },
71
+ timeToTarget: {
72
+ label: "Time To Target",
73
+ inputType: "number",
74
+ step: 0.1,
75
+ defaultValue: DEFAULT_TIME_TO_TARGET,
76
+ },
77
+ },
78
+ },
79
+ },
80
+ },
81
+ },
82
+ }