@inglorious/engine 0.1.0 → 0.2.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 (292) hide show
  1. package/README.md +39 -36
  2. package/package.json +20 -33
  3. package/src/engine/ai/movement/dynamic/align.js +63 -63
  4. package/src/engine/ai/movement/dynamic/arrive.js +42 -43
  5. package/src/engine/ai/movement/dynamic/evade.js +38 -38
  6. package/src/engine/ai/movement/dynamic/face.js +19 -20
  7. package/src/engine/ai/movement/dynamic/flee.js +45 -45
  8. package/src/engine/ai/movement/dynamic/look-where-youre-going.js +16 -17
  9. package/src/engine/ai/movement/dynamic/match-velocity.js +51 -50
  10. package/src/engine/ai/movement/dynamic/pursue.js +38 -38
  11. package/src/engine/ai/movement/dynamic/seek.js +44 -44
  12. package/src/engine/ai/movement/dynamic/wander.js +31 -32
  13. package/src/engine/ai/movement/kinematic/align.js +37 -37
  14. package/src/engine/ai/movement/kinematic/arrive.js +42 -42
  15. package/src/engine/ai/movement/kinematic/face.js +19 -20
  16. package/src/engine/ai/movement/kinematic/flee.js +26 -26
  17. package/src/engine/ai/movement/kinematic/seek.js +26 -26
  18. package/src/engine/ai/movement/kinematic/seek.test.js +42 -42
  19. package/src/engine/ai/movement/kinematic/wander-as-seek.js +31 -31
  20. package/src/engine/ai/movement/kinematic/wander.js +27 -27
  21. package/src/engine/animation/sprite.js +101 -0
  22. package/src/engine/animation/ticker.js +38 -0
  23. package/src/engine/behaviors/camera.js +68 -0
  24. package/src/engine/behaviors/controls/dynamic/modern.js +76 -0
  25. package/src/engine/behaviors/controls/dynamic/shooter.js +84 -0
  26. package/src/engine/behaviors/controls/dynamic/tank.js +69 -0
  27. package/src/engine/behaviors/controls/event-handlers.js +17 -0
  28. package/src/engine/behaviors/controls/kinematic/modern.js +76 -0
  29. package/src/engine/behaviors/controls/kinematic/shooter.js +82 -0
  30. package/src/engine/behaviors/controls/kinematic/tank.js +67 -0
  31. package/src/engine/behaviors/debug/collision.js +35 -0
  32. package/src/engine/behaviors/fps.js +29 -0
  33. package/src/engine/behaviors/fsm.js +33 -0
  34. package/src/{game/decorators → engine/behaviors}/fsm.test.js +49 -56
  35. package/src/engine/behaviors/game.js +15 -0
  36. package/src/engine/behaviors/input/controls.js +37 -0
  37. package/src/engine/behaviors/input/gamepad.js +114 -0
  38. package/src/engine/behaviors/input/input.js +48 -0
  39. package/src/engine/behaviors/input/keyboard.js +64 -0
  40. package/src/engine/behaviors/input/mouse.js +91 -0
  41. package/src/engine/behaviors/physics/bouncy.js +25 -0
  42. package/src/engine/behaviors/physics/clamped.js +36 -0
  43. package/src/{game/decorators/collisions.js → engine/behaviors/physics/collidable.js} +20 -24
  44. package/src/engine/behaviors/physics/jumpable.js +145 -0
  45. package/src/engine/behaviors/ui/button.js +17 -0
  46. package/src/engine/collision/detection.js +110 -115
  47. package/src/engine/core/api.js +34 -0
  48. package/src/engine/core/dev-tools.js +135 -0
  49. package/src/engine/core/engine.js +119 -0
  50. package/src/engine/core/loop.js +15 -0
  51. package/src/engine/{loop → core/loops}/animation-frame.js +25 -26
  52. package/src/engine/{loop → core/loops}/elapsed.js +22 -23
  53. package/src/engine/{loop → core/loops}/fixed.js +27 -28
  54. package/src/engine/{loop → core/loops}/flash.js +13 -14
  55. package/src/engine/{loop → core/loops}/lag.js +26 -27
  56. package/src/engine/core/select.js +26 -0
  57. package/src/engine/core/store.js +178 -0
  58. package/src/engine/core/store.test.js +110 -0
  59. package/src/engine/movement/dynamic/modern.js +21 -24
  60. package/src/engine/movement/dynamic/tank.js +43 -43
  61. package/src/engine/movement/kinematic/modern.js +16 -16
  62. package/src/engine/movement/kinematic/modern.test.js +27 -27
  63. package/src/engine/movement/kinematic/tank.js +27 -27
  64. package/src/engine/physics/bounds.js +138 -0
  65. package/src/engine/physics/position.js +43 -0
  66. package/src/engine/physics/position.test.js +80 -0
  67. package/src/engine/systems/sprite-animation.js +27 -0
  68. package/src/main.js +10 -5
  69. package/src/renderers/canvas/absolute-position.js +18 -0
  70. package/src/renderers/canvas/camera.js +13 -0
  71. package/src/renderers/canvas/canvas-renderer.js +68 -0
  72. package/src/{ui → renderers}/canvas/character.js +38 -35
  73. package/src/{ui → renderers}/canvas/form/button.js +25 -25
  74. package/src/{ui → renderers}/canvas/fps.js +18 -18
  75. package/src/renderers/canvas/image/hitmask.js +51 -0
  76. package/src/{ui → renderers}/canvas/image/image.js +34 -37
  77. package/src/{ui → renderers}/canvas/image/sprite.js +49 -49
  78. package/src/{ui → renderers}/canvas/image/tilemap.js +66 -64
  79. package/src/{ui → renderers}/canvas/mouse.js +37 -37
  80. package/src/renderers/canvas/rendering-system.js +79 -0
  81. package/src/{ui → renderers}/canvas/shapes/circle.js +29 -31
  82. package/src/{ui → renderers}/canvas/shapes/rectangle.js +27 -31
  83. package/src/renderers/react/game/character/index.jsx +20 -0
  84. package/src/{ui → renderers}/react/game/cursor/index.jsx +20 -20
  85. package/src/{ui → renderers}/react/game/form/fields/field/index.jsx +56 -56
  86. package/src/{ui → renderers}/react/game/form/fields/index.jsx +12 -12
  87. package/src/{ui → renderers}/react/game/form/index.jsx +22 -22
  88. package/src/{ui → renderers}/react/game/fps/index.jsx +16 -16
  89. package/src/{ui → renderers}/react/game/game.jsx +72 -71
  90. package/src/{ui → renderers}/react/game/index.jsx +29 -29
  91. package/src/{ui → renderers}/react/game/platform/index.jsx +30 -30
  92. package/src/{ui → renderers}/react/game/scene/index.jsx +27 -25
  93. package/src/{ui → renderers}/react/game/sprite/index.jsx +60 -58
  94. package/src/{ui → renderers}/react/game/stats/index.jsx +22 -22
  95. package/src/{ui → renderers}/react/hocs/with-absolute-position/index.jsx +20 -20
  96. package/src/{ui → renderers}/react/index.jsx +9 -9
  97. package/src/utils/algorithms/decision-tree.js +24 -24
  98. package/src/utils/algorithms/decision-tree.test.js +153 -102
  99. package/src/utils/algorithms/path-finding.js +155 -155
  100. package/src/utils/algorithms/path-finding.test.js +151 -151
  101. package/src/utils/data-structures/array.js +83 -83
  102. package/src/utils/data-structures/array.test.js +173 -173
  103. package/src/utils/data-structures/board.js +159 -159
  104. package/src/utils/data-structures/board.test.js +242 -242
  105. package/src/utils/data-structures/boolean.js +9 -9
  106. package/src/utils/data-structures/heap.js +164 -164
  107. package/src/utils/data-structures/heap.test.js +103 -103
  108. package/src/utils/data-structures/object.js +138 -102
  109. package/src/utils/data-structures/object.test.js +218 -121
  110. package/src/utils/data-structures/objects.js +66 -48
  111. package/src/utils/data-structures/objects.test.js +99 -99
  112. package/src/utils/data-structures/tree.js +36 -36
  113. package/src/utils/data-structures/tree.test.js +33 -33
  114. package/src/utils/functions/functions.js +19 -19
  115. package/src/utils/functions/functions.test.js +23 -23
  116. package/src/utils/math/geometry/circle.js +70 -117
  117. package/src/utils/math/geometry/circle.test.js +97 -97
  118. package/src/utils/math/geometry/hitmask.js +70 -39
  119. package/src/utils/math/geometry/hitmask.test.js +155 -84
  120. package/src/utils/math/geometry/line.js +35 -35
  121. package/src/utils/math/geometry/line.test.js +49 -49
  122. package/src/utils/math/geometry/point.js +78 -71
  123. package/src/utils/math/geometry/point.test.js +81 -81
  124. package/src/utils/math/geometry/rectangle.js +76 -45
  125. package/src/utils/math/geometry/rectangle.test.js +42 -42
  126. package/src/utils/math/geometry/segment.js +80 -80
  127. package/src/utils/math/geometry/segment.test.js +183 -183
  128. package/src/utils/math/geometry/triangle.js +15 -15
  129. package/src/utils/math/geometry/triangle.test.js +11 -11
  130. package/src/utils/math/linear-algebra/2d.js +28 -28
  131. package/src/utils/math/linear-algebra/2d.test.js +17 -17
  132. package/src/utils/math/linear-algebra/quaternion.js +22 -22
  133. package/src/utils/math/linear-algebra/quaternion.test.js +25 -25
  134. package/src/utils/math/linear-algebra/quaternions.js +20 -20
  135. package/src/utils/math/linear-algebra/quaternions.test.js +29 -29
  136. package/src/utils/math/linear-algebra/vector.js +327 -302
  137. package/src/utils/math/linear-algebra/vector.test.js +265 -257
  138. package/src/utils/math/linear-algebra/vectors.js +122 -122
  139. package/src/utils/math/linear-algebra/vectors.test.js +65 -65
  140. package/src/utils/math/linear-interpolation.js +9 -0
  141. package/src/utils/math/numbers.js +90 -90
  142. package/src/utils/math/numbers.test.js +137 -137
  143. package/src/utils/math/rng.js +44 -44
  144. package/src/utils/math/rng.test.js +39 -39
  145. package/src/utils/math/statistics.js +43 -43
  146. package/src/utils/math/statistics.test.js +47 -47
  147. package/src/utils/math/trigonometry.js +89 -89
  148. package/src/utils/math/trigonometry.test.js +52 -52
  149. package/src/utils/physics/acceleration.js +61 -63
  150. package/src/utils/physics/friction.js +28 -30
  151. package/src/utils/physics/friction.test.js +42 -44
  152. package/src/utils/physics/gravity.js +69 -71
  153. package/src/utils/physics/gravity.test.js +77 -80
  154. package/src/utils/physics/jump.js +31 -41
  155. package/src/utils/physics/velocity.js +36 -38
  156. package/src/docs/ai/movement/dynamic/align.js +0 -131
  157. package/src/docs/ai/movement/dynamic/arrive.js +0 -88
  158. package/src/docs/ai/movement/dynamic/dynamic.mdx +0 -99
  159. package/src/docs/ai/movement/dynamic/dynamic.stories.js +0 -58
  160. package/src/docs/ai/movement/dynamic/evade.js +0 -72
  161. package/src/docs/ai/movement/dynamic/face.js +0 -90
  162. package/src/docs/ai/movement/dynamic/flee.js +0 -38
  163. package/src/docs/ai/movement/dynamic/look-where-youre-going.js +0 -114
  164. package/src/docs/ai/movement/dynamic/match-velocity.js +0 -92
  165. package/src/docs/ai/movement/dynamic/pursue.js +0 -72
  166. package/src/docs/ai/movement/dynamic/seek.js +0 -37
  167. package/src/docs/ai/movement/dynamic/wander.js +0 -71
  168. package/src/docs/ai/movement/kinematic/align.js +0 -122
  169. package/src/docs/ai/movement/kinematic/arrive.js +0 -78
  170. package/src/docs/ai/movement/kinematic/face.js +0 -82
  171. package/src/docs/ai/movement/kinematic/flee.js +0 -36
  172. package/src/docs/ai/movement/kinematic/kinematic.mdx +0 -67
  173. package/src/docs/ai/movement/kinematic/kinematic.stories.js +0 -42
  174. package/src/docs/ai/movement/kinematic/seek.js +0 -34
  175. package/src/docs/ai/movement/kinematic/wander-as-seek.js +0 -62
  176. package/src/docs/ai/movement/kinematic/wander.js +0 -28
  177. package/src/docs/bounds.js +0 -7
  178. package/src/docs/code-reuse.js +0 -35
  179. package/src/docs/collision/circles.js +0 -58
  180. package/src/docs/collision/collision.mdx +0 -27
  181. package/src/docs/collision/collision.stories.js +0 -22
  182. package/src/docs/collision/platform.js +0 -76
  183. package/src/docs/collision/tilemap.js +0 -181
  184. package/src/docs/empty.js +0 -1
  185. package/src/docs/engine.mdx +0 -81
  186. package/src/docs/engine.stories.js +0 -37
  187. package/src/docs/event-handlers.js +0 -68
  188. package/src/docs/framerate.js +0 -37
  189. package/src/docs/game.jsx +0 -15
  190. package/src/docs/image/image.js +0 -19
  191. package/src/docs/image/image.stories.js +0 -22
  192. package/src/docs/image/sprite.js +0 -39
  193. package/src/docs/image/tilemap.js +0 -84
  194. package/src/docs/input/controls.js +0 -67
  195. package/src/docs/input/gamepad.js +0 -67
  196. package/src/docs/input/input.mdx +0 -55
  197. package/src/docs/input/input.stories.js +0 -27
  198. package/src/docs/input/keyboard.js +0 -58
  199. package/src/docs/input/mouse.js +0 -32
  200. package/src/docs/instances.js +0 -49
  201. package/src/docs/player/dynamic/double-jump.js +0 -90
  202. package/src/docs/player/dynamic/dynamic.stories.js +0 -32
  203. package/src/docs/player/dynamic/jump.js +0 -83
  204. package/src/docs/player/dynamic/modern-controls.js +0 -57
  205. package/src/docs/player/dynamic/shooter-controls.js +0 -51
  206. package/src/docs/player/dynamic/tank-controls.js +0 -44
  207. package/src/docs/player/kinematic/double-jump.js +0 -90
  208. package/src/docs/player/kinematic/jump.js +0 -82
  209. package/src/docs/player/kinematic/kinematic.stories.js +0 -32
  210. package/src/docs/player/kinematic/modern-controls.js +0 -56
  211. package/src/docs/player/kinematic/shooter-controls.js +0 -48
  212. package/src/docs/player/kinematic/tank-controls.js +0 -42
  213. package/src/docs/quick-start/first-game.js +0 -49
  214. package/src/docs/quick-start/hello-world.js +0 -1
  215. package/src/docs/quick-start.mdx +0 -127
  216. package/src/docs/quick-start.stories.js +0 -17
  217. package/src/docs/recipes/add-and-remove.js +0 -71
  218. package/src/docs/recipes/add-instance.js +0 -42
  219. package/src/docs/recipes/decision-tree.js +0 -169
  220. package/src/docs/recipes/random-instances.js +0 -25
  221. package/src/docs/recipes/recipes.mdx +0 -81
  222. package/src/docs/recipes/recipes.stories.js +0 -37
  223. package/src/docs/recipes/remove-instance.js +0 -52
  224. package/src/docs/recipes/states.js +0 -64
  225. package/src/docs/ui/button.js +0 -28
  226. package/src/docs/ui/form.stories.js +0 -55
  227. package/src/docs/ui-chooser.jsx +0 -6
  228. package/src/docs/utils/data-structures/object.mdx +0 -47
  229. package/src/docs/utils/data-structures/objects.mdx +0 -30
  230. package/src/docs/utils/functions/functions.mdx +0 -34
  231. package/src/docs/utils/math/geometry/circle.mdx +0 -55
  232. package/src/docs/utils/math/geometry/point.mdx +0 -38
  233. package/src/docs/utils/math/geometry/rectangle.mdx +0 -24
  234. package/src/docs/utils/math/geometry/segment.mdx +0 -55
  235. package/src/docs/utils/math/geometry/triangle.mdx +0 -22
  236. package/src/docs/utils/math/linear-algebra/2d.mdx +0 -22
  237. package/src/docs/utils/math/linear-algebra/quaternion.mdx +0 -21
  238. package/src/docs/utils/math/linear-algebra/quaternions.mdx +0 -22
  239. package/src/docs/utils/math/linear-algebra/vector.mdx +0 -177
  240. package/src/docs/utils/math/linear-algebra/vectors.mdx +0 -58
  241. package/src/docs/utils/math/numbers.mdx +0 -76
  242. package/src/docs/utils/math/random.mdx +0 -35
  243. package/src/docs/utils/math/statistics.mdx +0 -38
  244. package/src/docs/utils/math/trigonometry.mdx +0 -85
  245. package/src/docs/utils/physics/friction.mdx +0 -20
  246. package/src/docs/utils/physics/gravity.mdx +0 -28
  247. package/src/engine/loop.js +0 -15
  248. package/src/engine/store.js +0 -174
  249. package/src/engine/store.test.js +0 -256
  250. package/src/engine.js +0 -74
  251. package/src/game/animation.js +0 -26
  252. package/src/game/bounds.js +0 -66
  253. package/src/game/decorators/character.js +0 -5
  254. package/src/game/decorators/clamp-to-bounds.js +0 -15
  255. package/src/game/decorators/controls/dynamic/modern.js +0 -48
  256. package/src/game/decorators/controls/dynamic/shooter.js +0 -47
  257. package/src/game/decorators/controls/dynamic/tank.js +0 -55
  258. package/src/game/decorators/controls/kinematic/modern.js +0 -49
  259. package/src/game/decorators/controls/kinematic/shooter.js +0 -45
  260. package/src/game/decorators/controls/kinematic/tank.js +0 -52
  261. package/src/game/decorators/debug/collisions.js +0 -32
  262. package/src/game/decorators/double-jump.js +0 -70
  263. package/src/game/decorators/fps.js +0 -30
  264. package/src/game/decorators/fsm.js +0 -27
  265. package/src/game/decorators/game.js +0 -11
  266. package/src/game/decorators/image/image.js +0 -5
  267. package/src/game/decorators/image/sprite.js +0 -5
  268. package/src/game/decorators/image/tilemap.js +0 -5
  269. package/src/game/decorators/input/controls.js +0 -27
  270. package/src/game/decorators/input/gamepad.js +0 -74
  271. package/src/game/decorators/input/input.js +0 -41
  272. package/src/game/decorators/input/keyboard.js +0 -49
  273. package/src/game/decorators/input/mouse.js +0 -65
  274. package/src/game/decorators/jump.js +0 -72
  275. package/src/game/decorators/platform.js +0 -5
  276. package/src/game/decorators/ui/button.js +0 -21
  277. package/src/game/sprite.js +0 -119
  278. package/src/ui/canvas/absolute-position.js +0 -17
  279. package/src/ui/canvas/image/hitmask.js +0 -37
  280. package/src/ui/canvas.js +0 -81
  281. package/src/ui/react/game/character/index.jsx +0 -30
  282. package/src/utils/math/geometry/platform.js +0 -42
  283. package/src/utils/math/geometry/platform.test.js +0 -133
  284. /package/src/{ui → renderers}/react/game/character/character.module.scss +0 -0
  285. /package/src/{ui → renderers}/react/game/cursor/cursor.module.scss +0 -0
  286. /package/src/{ui → renderers}/react/game/form/fields/field/field.module.scss +0 -0
  287. /package/src/{ui → renderers}/react/game/form/fields/fields.module.scss +0 -0
  288. /package/src/{ui → renderers}/react/game/form/form.module.scss +0 -0
  289. /package/src/{ui → renderers}/react/game/platform/platform.module.scss +0 -0
  290. /package/src/{ui → renderers}/react/game/scene/scene.module.scss +0 -0
  291. /package/src/{ui → renderers}/react/game/sprite/sprite.module.css +0 -0
  292. /package/src/{ui → renderers}/react/hocs/with-absolute-position/with-absolute-position.module.scss +0 -0
@@ -1,99 +0,0 @@
1
- import { Canvas, Meta, Source } from '@storybook/blocks'
2
- import * as Dynamic from './dynamic.stories'
3
-
4
- import arrive from './arrive?raw'
5
- import flee from './flee?raw'
6
- import pursue from './pursue?raw'
7
- import evade from './evade?raw'
8
- import seek from './seek?raw'
9
- import wander from './wander?raw'
10
- import lookWhereYoureGoing from './look-where-youre-going?raw'
11
- import face from './face?raw'
12
- import align from './align?raw'
13
- import matchVelocity from './match-velocity?raw'
14
-
15
- <Meta of={Dynamic} />
16
-
17
- # Dynamic Movement
18
-
19
- The algorithms described here make an NPC instance move by applying forces, which in turn affect its acceleration and velocity. The movement is much smoother and more realistic than its [kinematic](/docs/ai-movement-kinematic--docs) counterpart.
20
-
21
- Every algorithm returns a steering object, which contains a linear and an angular acceleration. These can be used to update the instance's velocity and orientation.
22
-
23
- Most examples here make use of user [input](/?path=/docs/games-input--docs), so check those out if you haven't already.
24
-
25
- ## Seek
26
-
27
- The seek algorithm makes the instance chase a target. The movement is much smoother than its kinematic counterpart.
28
-
29
- <Source dark code={seek} />
30
-
31
- <Canvas of={Dynamic.Seek} />
32
-
33
- ## Flee
34
-
35
- The flee algorithm is the exact opposite of seek: the instance will run away from the target.
36
-
37
- <Source dark code={flee} />
38
-
39
- <Canvas of={Dynamic.Flee} />
40
-
41
- ## Arrive
42
-
43
- The arrive algorithm is a more refined version of seek: the instance will slow down as it approaches the target, and the movement is much smoother.
44
-
45
- <Source dark code={arrive} />
46
-
47
- <Canvas of={Dynamic.Arrive} />
48
-
49
- ## Pursue
50
-
51
- The pursue algorithm is an enhanced version of seek. It predicts the future position of a moving target and seeks that position.
52
-
53
- <Source dark code={pursue} />
54
-
55
- <Canvas of={Dynamic.Pursue} />
56
-
57
- ## Evade
58
-
59
- Evade is the opposite of pursue. It predicts the future position of a moving target and flees from it.
60
-
61
- <Source dark code={evade} />
62
-
63
- <Canvas of={Dynamic.Evade} />
64
-
65
- ## Wander
66
-
67
- The wander algorithm makes the instance move around randomly, but in a smooth and realistic way.
68
-
69
- <Source dark code={wander} />
70
-
71
- <Canvas of={Dynamic.Wander} />
72
-
73
- ## Look Where You're Going
74
-
75
- A simple but effective algorithm that aligns the character's orientation with its direction of movement.
76
-
77
- <Source dark code={lookWhereYoureGoing} />
78
-
79
- <Canvas of={Dynamic.LookWhereYoureGoing} />
80
-
81
- ## Align and Face
82
-
83
- The `align` algorithm makes the instance rotate to match the target's orientation, while `face` makes it rotate to look at the target's position. They are smoother versions of their kinematic counterparts.
84
-
85
- <Source dark code={align} />
86
-
87
- <Canvas of={Dynamic.Align} />
88
-
89
- <Source dark code={face} />
90
-
91
- <Canvas of={Dynamic.Face} />
92
-
93
- ## Match Velocity
94
-
95
- This algorithm adjusts the instance's velocity to match the target's velocity. It's a key component for flocking behaviors.
96
-
97
- <Source dark code={matchVelocity} />
98
-
99
- <Canvas of={Dynamic.MatchVelocity} />
@@ -1,58 +0,0 @@
1
- import UiChooser from "@inglorious/docs/ui-chooser.jsx"
2
-
3
- import align from "./align.js"
4
- import arrive from "./arrive.js"
5
- import evade from "./evade.js"
6
- import face from "./face.js"
7
- import flee from "./flee.js"
8
- import lookWhereYoureGoing from "./look-where-youre-going.js"
9
- import matchVelocity from "./match-velocity.js"
10
- import pursue from "./pursue.js"
11
- import seek from "./seek.js"
12
- import wander from "./wander.js"
13
-
14
- export default {
15
- title: "Engine/AI/Movement/Dynamic",
16
- component: UiChooser,
17
- }
18
-
19
- export const Seek = {
20
- args: { config: seek },
21
- }
22
-
23
- export const Flee = {
24
- args: { config: flee },
25
- }
26
-
27
- export const Arrive = {
28
- args: { config: arrive },
29
- }
30
-
31
- export const Pursue = {
32
- args: { config: pursue },
33
- }
34
-
35
- export const Evade = {
36
- args: { config: evade },
37
- }
38
-
39
- export const Wander = {
40
- args: { config: wander },
41
- }
42
-
43
- export const LookWhereYoureGoing = {
44
- name: "Look Where You're Going",
45
- args: { config: lookWhereYoureGoing },
46
- }
47
-
48
- export const Align = {
49
- args: { config: align },
50
- }
51
-
52
- export const Face = {
53
- args: { config: face },
54
- }
55
-
56
- export const MatchVelocity = {
57
- args: { config: matchVelocity },
58
- }
@@ -1,72 +0,0 @@
1
- import evade, {
2
- DEFAULT_MAX_PREDICTION,
3
- } from "@inglorious/engine/ai/movement/dynamic/evade.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.evade
19
-
20
- merge(
21
- instance,
22
- evade(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.evade.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
- evade: {
60
- title: "Evade",
61
- fields: {
62
- maxPrediction: {
63
- label: "Max Prediction",
64
- inputType: "number",
65
- defaultValue: DEFAULT_MAX_PREDICTION,
66
- },
67
- },
68
- },
69
- },
70
- },
71
- },
72
- }
@@ -1,90 +0,0 @@
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 face from "@inglorious/engine/ai/movement/dynamic/face.js"
7
- import { clampToBounds } from "@inglorious/game/bounds.js"
8
- import { enableCharacter } from "@inglorious/game/decorators/character.js"
9
- import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
10
- import { merge } from "@inglorious/utils/data-structures/objects.js"
11
- import { pi } from "@inglorious/utils/math/trigonometry.js"
12
-
13
- export default {
14
- types: {
15
- mouse: [enableMouse()],
16
-
17
- character: [
18
- enableCharacter(),
19
- {
20
- "game:update"(instance, event, { dt, instances }) {
21
- const target = instances.mouse
22
- const { fields } = instances.parameters.groups.face
23
-
24
- merge(
25
- instance,
26
- face(instance, target, {
27
- dt,
28
- targetRadius: fields.targetRadius.value,
29
- slowRadius: fields.slowRadius.value,
30
- timeToTarget: fields.timeToTarget.value,
31
- }),
32
- )
33
-
34
- clampToBounds(instance, instances.game.bounds)
35
- },
36
- },
37
- ],
38
-
39
- form: {
40
- "field:change"(instance, event) {
41
- const { id, value } = event.payload
42
- instance.groups.face.fields[id].value = value
43
- },
44
- },
45
- },
46
-
47
- instances: {
48
- mouse: {
49
- type: "mouse",
50
- position: [400, 0, 300],
51
- },
52
-
53
- character: {
54
- type: "character",
55
- maxAngularSpeed: pi() / 4,
56
- maxAngularAcceleration: 1000,
57
- position: [400, 0, 300],
58
- },
59
-
60
- parameters: {
61
- type: "form",
62
- position: [800 - 328, 0, 600],
63
- groups: {
64
- face: {
65
- title: "Face",
66
- fields: {
67
- targetRadius: {
68
- label: "Target Radius",
69
- inputType: "number",
70
- step: 0.1,
71
- defaultValue: DEFAULT_TARGET_RADIUS,
72
- },
73
- slowRadius: {
74
- label: "Slow Radius",
75
- inputType: "number",
76
- step: 0.1,
77
- defaultValue: DEFAULT_SLOW_RADIUS,
78
- },
79
- timeToTarget: {
80
- label: "Time To Target",
81
- inputType: "number",
82
- step: 0.1,
83
- defaultValue: DEFAULT_TIME_TO_TARGET,
84
- },
85
- },
86
- },
87
- },
88
- },
89
- },
90
- }
@@ -1,38 +0,0 @@
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
- }
@@ -1,114 +0,0 @@
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
- }
@@ -1,92 +0,0 @@
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
- }
@@ -1,72 +0,0 @@
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
- }
@@ -1,37 +0,0 @@
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
- }