@inglorious/engine 0.1.0 → 0.1.1
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.
- package/package.json +11 -12
- package/src/docs/ai/movement/dynamic/align.js +0 -131
- package/src/docs/ai/movement/dynamic/arrive.js +0 -88
- package/src/docs/ai/movement/dynamic/dynamic.mdx +0 -99
- package/src/docs/ai/movement/dynamic/dynamic.stories.js +0 -58
- package/src/docs/ai/movement/dynamic/evade.js +0 -72
- package/src/docs/ai/movement/dynamic/face.js +0 -90
- package/src/docs/ai/movement/dynamic/flee.js +0 -38
- package/src/docs/ai/movement/dynamic/look-where-youre-going.js +0 -114
- package/src/docs/ai/movement/dynamic/match-velocity.js +0 -92
- package/src/docs/ai/movement/dynamic/pursue.js +0 -72
- package/src/docs/ai/movement/dynamic/seek.js +0 -37
- package/src/docs/ai/movement/dynamic/wander.js +0 -71
- package/src/docs/ai/movement/kinematic/align.js +0 -122
- package/src/docs/ai/movement/kinematic/arrive.js +0 -78
- package/src/docs/ai/movement/kinematic/face.js +0 -82
- package/src/docs/ai/movement/kinematic/flee.js +0 -36
- package/src/docs/ai/movement/kinematic/kinematic.mdx +0 -67
- package/src/docs/ai/movement/kinematic/kinematic.stories.js +0 -42
- package/src/docs/ai/movement/kinematic/seek.js +0 -34
- package/src/docs/ai/movement/kinematic/wander-as-seek.js +0 -62
- package/src/docs/ai/movement/kinematic/wander.js +0 -28
- package/src/docs/bounds.js +0 -7
- package/src/docs/code-reuse.js +0 -35
- package/src/docs/collision/circles.js +0 -58
- package/src/docs/collision/collision.mdx +0 -27
- package/src/docs/collision/collision.stories.js +0 -22
- package/src/docs/collision/platform.js +0 -76
- package/src/docs/collision/tilemap.js +0 -181
- package/src/docs/empty.js +0 -1
- package/src/docs/engine.mdx +0 -81
- package/src/docs/engine.stories.js +0 -37
- package/src/docs/event-handlers.js +0 -68
- package/src/docs/framerate.js +0 -37
- package/src/docs/game.jsx +0 -15
- package/src/docs/image/image.js +0 -19
- package/src/docs/image/image.stories.js +0 -22
- package/src/docs/image/sprite.js +0 -39
- package/src/docs/image/tilemap.js +0 -84
- package/src/docs/input/controls.js +0 -67
- package/src/docs/input/gamepad.js +0 -67
- package/src/docs/input/input.mdx +0 -55
- package/src/docs/input/input.stories.js +0 -27
- package/src/docs/input/keyboard.js +0 -58
- package/src/docs/input/mouse.js +0 -32
- package/src/docs/instances.js +0 -49
- package/src/docs/player/dynamic/double-jump.js +0 -90
- package/src/docs/player/dynamic/dynamic.stories.js +0 -32
- package/src/docs/player/dynamic/jump.js +0 -83
- package/src/docs/player/dynamic/modern-controls.js +0 -57
- package/src/docs/player/dynamic/shooter-controls.js +0 -51
- package/src/docs/player/dynamic/tank-controls.js +0 -44
- package/src/docs/player/kinematic/double-jump.js +0 -90
- package/src/docs/player/kinematic/jump.js +0 -82
- package/src/docs/player/kinematic/kinematic.stories.js +0 -32
- package/src/docs/player/kinematic/modern-controls.js +0 -56
- package/src/docs/player/kinematic/shooter-controls.js +0 -48
- package/src/docs/player/kinematic/tank-controls.js +0 -42
- package/src/docs/quick-start/first-game.js +0 -49
- package/src/docs/quick-start/hello-world.js +0 -1
- package/src/docs/quick-start.mdx +0 -127
- package/src/docs/quick-start.stories.js +0 -17
- package/src/docs/recipes/add-and-remove.js +0 -71
- package/src/docs/recipes/add-instance.js +0 -42
- package/src/docs/recipes/decision-tree.js +0 -169
- package/src/docs/recipes/random-instances.js +0 -25
- package/src/docs/recipes/recipes.mdx +0 -81
- package/src/docs/recipes/recipes.stories.js +0 -37
- package/src/docs/recipes/remove-instance.js +0 -52
- package/src/docs/recipes/states.js +0 -64
- package/src/docs/ui/button.js +0 -28
- package/src/docs/ui/form.stories.js +0 -55
- package/src/docs/ui-chooser.jsx +0 -6
- package/src/docs/utils/data-structures/object.mdx +0 -47
- package/src/docs/utils/data-structures/objects.mdx +0 -30
- package/src/docs/utils/functions/functions.mdx +0 -34
- package/src/docs/utils/math/geometry/circle.mdx +0 -55
- package/src/docs/utils/math/geometry/point.mdx +0 -38
- package/src/docs/utils/math/geometry/rectangle.mdx +0 -24
- package/src/docs/utils/math/geometry/segment.mdx +0 -55
- package/src/docs/utils/math/geometry/triangle.mdx +0 -22
- package/src/docs/utils/math/linear-algebra/2d.mdx +0 -22
- package/src/docs/utils/math/linear-algebra/quaternion.mdx +0 -21
- package/src/docs/utils/math/linear-algebra/quaternions.mdx +0 -22
- package/src/docs/utils/math/linear-algebra/vector.mdx +0 -177
- package/src/docs/utils/math/linear-algebra/vectors.mdx +0 -58
- package/src/docs/utils/math/numbers.mdx +0 -76
- package/src/docs/utils/math/random.mdx +0 -35
- package/src/docs/utils/math/statistics.mdx +0 -38
- package/src/docs/utils/math/trigonometry.mdx +0 -85
- package/src/docs/utils/physics/friction.mdx +0 -20
- package/src/docs/utils/physics/gravity.mdx +0 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,16 +29,6 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
|
34
|
-
"format": "prettier --write '**/*.{js,jsx}'",
|
|
35
|
-
"test:watch": "vitest",
|
|
36
|
-
"test": "vitest run",
|
|
37
|
-
"start": "serve",
|
|
38
|
-
"storybook": "storybook dev -p 6006",
|
|
39
|
-
"build-storybook": "storybook build",
|
|
40
|
-
"prepare": "husky"
|
|
41
|
-
},
|
|
42
32
|
"dependencies": {
|
|
43
33
|
"immer": "^10.1.1",
|
|
44
34
|
"react": "^19.0.0",
|
|
@@ -72,5 +62,14 @@
|
|
|
72
62
|
"storybook": "^8.6.12",
|
|
73
63
|
"vite": "^4.4.5",
|
|
74
64
|
"vitest": "^0.34.3"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
|
68
|
+
"format": "prettier --write '**/*.{js,jsx}'",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"start": "serve",
|
|
72
|
+
"storybook": "storybook dev -p 6006",
|
|
73
|
+
"build-storybook": "storybook build"
|
|
75
74
|
}
|
|
76
|
-
}
|
|
75
|
+
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import align, {
|
|
2
|
-
DEFAULT_SLOW_RADIUS,
|
|
3
|
-
DEFAULT_TARGET_RADIUS,
|
|
4
|
-
DEFAULT_TIME_TO_TARGET,
|
|
5
|
-
} from "@inglorious/engine/ai/movement/dynamic/align.js"
|
|
6
|
-
import { clampToBounds } from "@inglorious/game/bounds.js"
|
|
7
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
8
|
-
import {
|
|
9
|
-
createControls,
|
|
10
|
-
enableControls,
|
|
11
|
-
} from "@inglorious/game/decorators/input/controls.js"
|
|
12
|
-
import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
|
|
13
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
14
|
-
import { clamp } from "@inglorious/utils/math/numbers.js"
|
|
15
|
-
import { pi } from "@inglorious/utils/math/trigonometry.js"
|
|
16
|
-
|
|
17
|
-
export default {
|
|
18
|
-
types: {
|
|
19
|
-
mouse: [
|
|
20
|
-
enableMouse(),
|
|
21
|
-
{
|
|
22
|
-
"field:change"(instance, event) {
|
|
23
|
-
const { id, value } = event.payload
|
|
24
|
-
if (id === "targetOrientation") {
|
|
25
|
-
instance.orientation = -value * pi()
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
"game:update"(instance, event, options) {
|
|
30
|
-
const { input0 } = options.instances
|
|
31
|
-
|
|
32
|
-
if (input0.left || input0.up) {
|
|
33
|
-
instance.orientation += 0.1
|
|
34
|
-
} else if (input0.right || input0.down) {
|
|
35
|
-
instance.orientation -= 0.1
|
|
36
|
-
}
|
|
37
|
-
instance.orientation = clamp(instance.orientation, -pi(), pi())
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
|
|
42
|
-
...enableControls(),
|
|
43
|
-
|
|
44
|
-
character: [
|
|
45
|
-
enableCharacter(),
|
|
46
|
-
{
|
|
47
|
-
"game:update"(instance, event, { dt, instances }) {
|
|
48
|
-
const target = instances.mouse
|
|
49
|
-
const { fields } = instances.parameters.groups.align
|
|
50
|
-
|
|
51
|
-
merge(
|
|
52
|
-
instance,
|
|
53
|
-
align(instance, target, {
|
|
54
|
-
dt,
|
|
55
|
-
targetRadius: fields.targetRadius.value,
|
|
56
|
-
slowRadius: fields.slowRadius.value,
|
|
57
|
-
timeToTarget: fields.timeToTarget.value,
|
|
58
|
-
}),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
clampToBounds(instance, instances.game.bounds)
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
|
|
66
|
-
form: {
|
|
67
|
-
"field:change"(instance, event) {
|
|
68
|
-
const { id, value } = event.payload
|
|
69
|
-
instance.groups.align.fields[id].value = value
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
instances: {
|
|
75
|
-
mouse: {
|
|
76
|
-
type: "mouse",
|
|
77
|
-
position: [400, 0, 300],
|
|
78
|
-
orientation: 0,
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
...createControls("input0", {
|
|
82
|
-
ArrowLeft: "left",
|
|
83
|
-
ArrowRight: "right",
|
|
84
|
-
ArrowDown: "down",
|
|
85
|
-
ArrowUp: "up",
|
|
86
|
-
}),
|
|
87
|
-
|
|
88
|
-
character: {
|
|
89
|
-
type: "character",
|
|
90
|
-
maxAngularSpeed: pi() / 4,
|
|
91
|
-
maxAngularAcceleration: 10,
|
|
92
|
-
position: [400, 0, 300],
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
parameters: {
|
|
96
|
-
type: "form",
|
|
97
|
-
position: [800 - 328, 0, 600],
|
|
98
|
-
groups: {
|
|
99
|
-
align: {
|
|
100
|
-
title: "Dynamic Align",
|
|
101
|
-
fields: {
|
|
102
|
-
targetRadius: {
|
|
103
|
-
label: "Target Radius",
|
|
104
|
-
inputType: "number",
|
|
105
|
-
defaultValue: DEFAULT_TARGET_RADIUS,
|
|
106
|
-
},
|
|
107
|
-
slowRadius: {
|
|
108
|
-
label: "Slow Radius",
|
|
109
|
-
inputType: "number",
|
|
110
|
-
defaultValue: DEFAULT_SLOW_RADIUS,
|
|
111
|
-
},
|
|
112
|
-
timeToTarget: {
|
|
113
|
-
label: "Time To Target",
|
|
114
|
-
inputType: "number",
|
|
115
|
-
step: 0.1,
|
|
116
|
-
defaultValue: DEFAULT_TIME_TO_TARGET,
|
|
117
|
-
},
|
|
118
|
-
targetOrientation: {
|
|
119
|
-
label: "Target Orientation",
|
|
120
|
-
inputType: "number",
|
|
121
|
-
step: 0.25,
|
|
122
|
-
min: -1,
|
|
123
|
-
max: 1,
|
|
124
|
-
defaultValue: 0,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import arrive, {
|
|
2
|
-
DEFAULT_SLOW_RADIUS,
|
|
3
|
-
DEFAULT_TARGET_RADIUS,
|
|
4
|
-
DEFAULT_TIME_TO_TARGET,
|
|
5
|
-
} from "@inglorious/engine/ai/movement/dynamic/arrive.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
|
-
|
|
11
|
-
export default {
|
|
12
|
-
types: {
|
|
13
|
-
mouse: [enableMouse()],
|
|
14
|
-
|
|
15
|
-
character: [
|
|
16
|
-
enableCharacter(),
|
|
17
|
-
{
|
|
18
|
-
"game:update"(instance, event, { dt, instances }) {
|
|
19
|
-
const target = instances.mouse
|
|
20
|
-
const { fields } = instances.parameters.groups.arrive
|
|
21
|
-
|
|
22
|
-
merge(
|
|
23
|
-
instance,
|
|
24
|
-
arrive(instance, target, {
|
|
25
|
-
dt,
|
|
26
|
-
targetRadius: fields.targetRadius.value,
|
|
27
|
-
slowRadius: fields.slowRadius.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.arrive.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
|
-
maxAcceleration: 1000,
|
|
54
|
-
maxSpeed: 250,
|
|
55
|
-
position: [400, 0, 300],
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
parameters: {
|
|
59
|
-
type: "form",
|
|
60
|
-
position: [800 - 328, 0, 600],
|
|
61
|
-
groups: {
|
|
62
|
-
arrive: {
|
|
63
|
-
title: "Dynamic Arrive",
|
|
64
|
-
fields: {
|
|
65
|
-
targetRadius: {
|
|
66
|
-
label: "Target Radius",
|
|
67
|
-
inputType: "number",
|
|
68
|
-
step: 0.1,
|
|
69
|
-
defaultValue: DEFAULT_TARGET_RADIUS,
|
|
70
|
-
},
|
|
71
|
-
slowRadius: {
|
|
72
|
-
label: "Slow Radius",
|
|
73
|
-
inputType: "number",
|
|
74
|
-
step: 0.1,
|
|
75
|
-
defaultValue: DEFAULT_SLOW_RADIUS,
|
|
76
|
-
},
|
|
77
|
-
timeToTarget: {
|
|
78
|
-
label: "Time To Target",
|
|
79
|
-
inputType: "number",
|
|
80
|
-
step: 0.1,
|
|
81
|
-
defaultValue: DEFAULT_TIME_TO_TARGET,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
}
|
|
@@ -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
|
-
}
|