@inglorious/engine 7.0.0 → 8.0.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.
- package/README.md +115 -115
- package/package.json +4 -4
- package/src/behaviors/controls/dynamic/modern.js +39 -40
- package/src/behaviors/controls/dynamic/shooter.js +52 -53
- package/src/behaviors/controls/dynamic/tank.js +45 -46
- package/src/behaviors/controls/kinematic/modern.js +39 -40
- package/src/behaviors/controls/kinematic/shooter.js +51 -52
- package/src/behaviors/controls/kinematic/tank.js +44 -45
- package/src/behaviors/debug/collision.js +18 -21
- package/src/behaviors/fsm.js +2 -4
- package/src/behaviors/physics/bouncy.js +13 -14
- package/src/behaviors/physics/clamped.js +21 -22
- package/src/behaviors/physics/jumpable.js +108 -111
- package/src/core/engine.js +6 -5
- package/src/core/middlewares/entity-pool/entity-pool-middleware.js +9 -5
|
@@ -13,53 +13,52 @@ const Z = 2
|
|
|
13
13
|
export function modernVelocity(params) {
|
|
14
14
|
params = extend(DEFAULT_PARAMS, params)
|
|
15
15
|
|
|
16
|
-
return (type) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
]),
|
|
16
|
+
return (type) => ({
|
|
17
|
+
...createMovementEventHandlers([
|
|
18
|
+
"moveLeft",
|
|
19
|
+
"moveRight",
|
|
20
|
+
"moveUp",
|
|
21
|
+
"moveDown",
|
|
22
|
+
"moveLeftRight",
|
|
23
|
+
"moveUpDown",
|
|
24
|
+
]),
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
create(entity, entityId, api) {
|
|
27
|
+
type.create?.(entity, entityId, api)
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
if (entityId !== entity.id) return
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
entity.maxSpeed ??= params.maxSpeed
|
|
32
|
+
entity.movement ??= {}
|
|
33
|
+
},
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
update(entity, dt, api) {
|
|
36
|
+
type.update?.(entity, dt, api)
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const { movement, maxSpeed } = entity
|
|
39
|
+
entity.velocity = zero()
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
if (movement.moveLeft) {
|
|
42
|
+
entity.velocity[X] = -maxSpeed
|
|
43
|
+
}
|
|
44
|
+
if (movement.moveRight) {
|
|
45
|
+
entity.velocity[X] = maxSpeed
|
|
46
|
+
}
|
|
47
|
+
if (movement.moveUp) {
|
|
48
|
+
entity.velocity[Z] = maxSpeed
|
|
49
|
+
}
|
|
50
|
+
if (movement.moveDown) {
|
|
51
|
+
entity.velocity[Z] = -maxSpeed
|
|
52
|
+
}
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
if (movement.moveLeftRight) {
|
|
55
|
+
entity.velocity[X] += movement.moveLeftRight * maxSpeed
|
|
56
|
+
}
|
|
57
|
+
if (movement.moveUpDown) {
|
|
58
|
+
entity.velocity[Z] += -movement.moveUpDown * maxSpeed
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
})
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
export function modernControls(params) {
|
|
@@ -20,65 +20,64 @@ export function shooterControls(params) {
|
|
|
20
20
|
const DEADZONE = 0.1
|
|
21
21
|
const NO_MOVEMENT = 0
|
|
22
22
|
|
|
23
|
-
return (type) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
]),
|
|
23
|
+
return (type) => ({
|
|
24
|
+
...createMovementEventHandlers([
|
|
25
|
+
"moveLeft",
|
|
26
|
+
"moveRight",
|
|
27
|
+
"moveUp",
|
|
28
|
+
"moveDown",
|
|
29
|
+
"move",
|
|
30
|
+
"strafe",
|
|
31
|
+
"turn",
|
|
32
|
+
]),
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
create(entity, entityId, api) {
|
|
35
|
+
type.create?.(entity, entityId, api)
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
if (entityId !== entity.id) return
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
entity.maxSpeed ??= params.maxSpeed
|
|
40
|
+
entity.maxAngularSpeed ??= params.maxAngularSpeed
|
|
41
|
+
entity.movement ??= {}
|
|
42
|
+
},
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
update(entity, dt, api) {
|
|
45
|
+
const mouse = api.getEntity("mouse")
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const { movement, maxSpeed, maxAngularSpeed } = entity
|
|
48
|
+
entity.velocity = zero()
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
if (movement.moveLeft) {
|
|
51
|
+
entity.velocity[Z] = -maxSpeed
|
|
52
|
+
}
|
|
53
|
+
if (movement.moveRight) {
|
|
54
|
+
entity.velocity[Z] = maxSpeed
|
|
55
|
+
}
|
|
56
|
+
if (movement.moveUp) {
|
|
57
|
+
entity.velocity[X] = maxSpeed
|
|
58
|
+
}
|
|
59
|
+
if (movement.moveDown) {
|
|
60
|
+
entity.velocity[X] = -maxSpeed
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
if (movement.strafe) {
|
|
64
|
+
entity.velocity[Z] += movement.strafe * maxSpeed
|
|
65
|
+
}
|
|
66
|
+
if (movement.move) {
|
|
67
|
+
entity.velocity[X] += -movement.move * maxSpeed
|
|
68
|
+
}
|
|
69
|
+
if (movement.turn) {
|
|
70
|
+
entity.orientation += -movement.turn * maxAngularSpeed * dt
|
|
71
|
+
}
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
const isUsingAnalogMovement =
|
|
74
|
+
Math.abs(movement.move ?? NO_MOVEMENT) > DEADZONE ||
|
|
75
|
+
Math.abs(movement.strafe ?? NO_MOVEMENT) > DEADZONE
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
if (!isUsingAnalogMovement) {
|
|
78
|
+
merge(entity, face(entity, mouse, dt))
|
|
79
|
+
}
|
|
80
|
+
merge(entity, tankMove(entity, dt))
|
|
81
|
+
},
|
|
82
|
+
})
|
|
84
83
|
}
|
|
@@ -14,56 +14,55 @@ const Z = 2
|
|
|
14
14
|
export function tankControls(params) {
|
|
15
15
|
params = extend(DEFAULT_PARAMS, params)
|
|
16
16
|
|
|
17
|
-
return (type) =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
]),
|
|
17
|
+
return (type) => ({
|
|
18
|
+
...createMovementEventHandlers([
|
|
19
|
+
"turnLeft",
|
|
20
|
+
"turnRight",
|
|
21
|
+
"moveForward",
|
|
22
|
+
"moveBackward",
|
|
23
|
+
"strafe",
|
|
24
|
+
"move",
|
|
25
|
+
"turn",
|
|
26
|
+
]),
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
create(entity, entityId, api) {
|
|
29
|
+
type.create?.(entity, entityId, api)
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
if (entityId !== entity.id) return
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
entity.maxSpeed ??= params.maxSpeed
|
|
34
|
+
entity.maxAngularSpeed ??= params.maxAngularSpeed
|
|
35
|
+
entity.movement ??= {}
|
|
36
|
+
},
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
update(entity, dt) {
|
|
39
|
+
const { movement, maxSpeed, maxAngularSpeed } = entity
|
|
40
|
+
entity.velocity = zero()
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
if (movement.turnLeft) {
|
|
43
|
+
entity.orientation += maxAngularSpeed * dt
|
|
44
|
+
}
|
|
45
|
+
if (movement.turnRight) {
|
|
46
|
+
entity.orientation -= maxAngularSpeed * dt
|
|
47
|
+
}
|
|
48
|
+
if (movement.moveForward) {
|
|
49
|
+
entity.velocity[X] = maxSpeed
|
|
50
|
+
}
|
|
51
|
+
if (movement.moveBackward) {
|
|
52
|
+
entity.velocity[X] = -maxSpeed
|
|
53
|
+
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
if (movement.strafe) {
|
|
56
|
+
entity.velocity[Z] += movement.strafe * maxSpeed
|
|
57
|
+
}
|
|
58
|
+
if (movement.move) {
|
|
59
|
+
entity.velocity[X] += -movement.move * maxSpeed
|
|
60
|
+
}
|
|
61
|
+
if (movement.turn) {
|
|
62
|
+
entity.orientation += -movement.turn * maxAngularSpeed * dt
|
|
63
|
+
}
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
merge(entity, tankMove(entity, dt))
|
|
66
|
+
},
|
|
67
|
+
})
|
|
69
68
|
}
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import { extend } from "@inglorious/utils/data-structures/objects.js"
|
|
2
|
-
|
|
3
1
|
export function collisionGizmos(params) {
|
|
4
|
-
return (type) =>
|
|
5
|
-
|
|
6
|
-
render(entity, ctx, api)
|
|
7
|
-
type.render(entity, ctx, api)
|
|
2
|
+
return (type) => ({
|
|
3
|
+
render(entity, ctx, api) {
|
|
4
|
+
type.render(entity, ctx, api)
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
const game = api.getEntity("game")
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
if (!game.debug) {
|
|
9
|
+
return
|
|
10
|
+
}
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
if (!params?.shapes) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
ctx.save()
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
Object.values(entity.collisions).forEach((collision) => {
|
|
19
|
+
const render = params.shapes[collision.shape]
|
|
20
|
+
render?.({ ...entity, ...collision, color: "#00FF00" }, ctx, api)
|
|
21
|
+
})
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
ctx.restore()
|
|
24
|
+
},
|
|
25
|
+
})
|
|
29
26
|
}
|
package/src/behaviors/fsm.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { extend } from "@inglorious/utils/data-structures/objects.js"
|
|
2
|
-
|
|
3
1
|
const DEFAULT_STATE = "default"
|
|
4
2
|
|
|
5
3
|
export function fsm(states) {
|
|
@@ -8,7 +6,7 @@ export function fsm(states) {
|
|
|
8
6
|
]
|
|
9
7
|
|
|
10
8
|
return (type) => {
|
|
11
|
-
return
|
|
9
|
+
return {
|
|
12
10
|
create(entity, entityId, api) {
|
|
13
11
|
type.create?.(entity, entityId, api)
|
|
14
12
|
|
|
@@ -30,6 +28,6 @@ export function fsm(states) {
|
|
|
30
28
|
}),
|
|
31
29
|
{},
|
|
32
30
|
),
|
|
33
|
-
}
|
|
31
|
+
}
|
|
34
32
|
}
|
|
35
33
|
}
|
|
@@ -8,21 +8,20 @@ const DEFAULT_PARAMS = {
|
|
|
8
8
|
export function bouncy(params) {
|
|
9
9
|
params = extend(DEFAULT_PARAMS, params)
|
|
10
10
|
|
|
11
|
-
return (type) =>
|
|
12
|
-
|
|
13
|
-
create(entity, entityId, api)
|
|
14
|
-
type.create?.(entity, entityId, api)
|
|
11
|
+
return (type) => ({
|
|
12
|
+
create(entity, entityId, api) {
|
|
13
|
+
type.create?.(entity, entityId, api)
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
if (entityId !== entity.id) return
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
defaults(entity, params)
|
|
18
|
+
},
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
land(entity, entityId) {
|
|
21
|
+
if (entity.id === entityId) {
|
|
22
|
+
entity.vy = jump(entity) * entity.bounciness
|
|
23
|
+
entity.groundObject = undefined
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
28
27
|
}
|
|
@@ -9,30 +9,29 @@ const DEFAULT_PARAMS = {
|
|
|
9
9
|
export function clamped(params) {
|
|
10
10
|
params = extend(DEFAULT_PARAMS, params)
|
|
11
11
|
|
|
12
|
-
return (type) =>
|
|
13
|
-
|
|
14
|
-
create(entity, entityId, api)
|
|
15
|
-
type.create?.(entity, entityId, api)
|
|
12
|
+
return (type) => ({
|
|
13
|
+
create(entity, entityId, api) {
|
|
14
|
+
type.create?.(entity, entityId, api)
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
if (entityId !== entity.id) return
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
entity.collisions ??= {}
|
|
19
|
+
entity.collisions[params.collisionGroup] ??= {}
|
|
20
|
+
entity.collisions[params.collisionGroup].shape ??= "rectangle"
|
|
21
|
+
},
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
update(entity, dt, api) {
|
|
24
|
+
type.update?.(entity, dt, api)
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const game = api.getEntity("game")
|
|
27
|
+
merge(entity, {
|
|
28
|
+
position: clampToBounds(
|
|
29
|
+
entity,
|
|
30
|
+
game.size,
|
|
31
|
+
params.collisionGroup,
|
|
32
|
+
params.depthAxis,
|
|
33
|
+
),
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
})
|
|
38
37
|
}
|