@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
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Canvas, Meta, Source } from '@storybook/blocks'
|
|
2
|
-
import * as Kinematic from './kinematic.stories'
|
|
3
|
-
|
|
4
|
-
import align from './align?raw'
|
|
5
|
-
import arrive from './arrive?raw'
|
|
6
|
-
import flee from './flee?raw'
|
|
7
|
-
import seek from './seek?raw'
|
|
8
|
-
import wander from './wander?raw'
|
|
9
|
-
import wanderAsSeek from './wander-as-seek?raw'
|
|
10
|
-
|
|
11
|
-
<Meta of={Kinematic} />
|
|
12
|
-
|
|
13
|
-
# Kinematic Movement
|
|
14
|
-
|
|
15
|
-
The algorithms described here make an NPC instance move by changing its velocity. The movement is a little snappy but it does the trick for simple games.
|
|
16
|
-
|
|
17
|
-
Every algorithm returns some parameters, such as velocity, position, and orientation, which can be merged to the instance.
|
|
18
|
-
|
|
19
|
-
Most examples here make use of user [input](/?path=/docs/games-input--docs), so check those out if you haven't already.
|
|
20
|
-
|
|
21
|
-
## Seek
|
|
22
|
-
|
|
23
|
-
The seek algorithm makes the instance chase a target. Speed is constant and it makes the character flick around the target once reached.
|
|
24
|
-
|
|
25
|
-
<Source dark code={seek} />
|
|
26
|
-
|
|
27
|
-
<Canvas of={Kinematic.Seek} />
|
|
28
|
-
|
|
29
|
-
## Flee
|
|
30
|
-
|
|
31
|
-
The flee algorithm is the exact opposite of seek: the instance will run away from the target.
|
|
32
|
-
|
|
33
|
-
<Source dark code={flee} />
|
|
34
|
-
|
|
35
|
-
<Canvas of={Kinematic.Flee} />
|
|
36
|
-
|
|
37
|
-
## Arrive
|
|
38
|
-
|
|
39
|
-
The arrive algorithm is a more refined version of seek: the instance will slow down as it approaches the target.
|
|
40
|
-
|
|
41
|
-
<Source dark code={arrive} />
|
|
42
|
-
|
|
43
|
-
<Canvas of={Kinematic.Arrive} />
|
|
44
|
-
|
|
45
|
-
## Align
|
|
46
|
-
|
|
47
|
-
The align algorithm makes the instance rotate to match the target's orientation.
|
|
48
|
-
|
|
49
|
-
<Source dark code={align} />
|
|
50
|
-
|
|
51
|
-
<Canvas of={Kinematic.Align} />
|
|
52
|
-
|
|
53
|
-
## Wander
|
|
54
|
-
|
|
55
|
-
The wander algorithm makes the instance move around randomly. It does so by changing its orientation by a small random amount at each frame.
|
|
56
|
-
|
|
57
|
-
<Source dark code={wander} />
|
|
58
|
-
|
|
59
|
-
<Canvas of={Kinematic.Wander} />
|
|
60
|
-
|
|
61
|
-
## Wander as Seek
|
|
62
|
-
|
|
63
|
-
This is a simpler version of the wander algorithm that does not require trigonometry. It just seeks a random point in the scene, and once it's reached, it seeks another one.
|
|
64
|
-
|
|
65
|
-
<Source dark code={wanderAsSeek} />
|
|
66
|
-
|
|
67
|
-
<Canvas of={Kinematic.WanderAsSeek} />
|
|
@@ -1,42 +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 face from "./face.js"
|
|
6
|
-
import flee from "./flee.js"
|
|
7
|
-
import seek from "./seek.js"
|
|
8
|
-
import wander from "./wander.js"
|
|
9
|
-
import wanderAsSeek from "./wander-as-seek.js"
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
title: "Engine/AI/Movement/Kinematic",
|
|
13
|
-
component: UiChooser,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const Seek = {
|
|
17
|
-
args: { config: seek },
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const Flee = {
|
|
21
|
-
args: { config: flee },
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const Arrive = {
|
|
25
|
-
args: { config: arrive },
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const Align = {
|
|
29
|
-
args: { config: align },
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const Face = {
|
|
33
|
-
args: { config: face },
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const Wander = {
|
|
37
|
-
args: { config: wander },
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const WanderAsSeek = {
|
|
41
|
-
args: { config: wanderAsSeek },
|
|
42
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import seek from "@inglorious/engine/ai/movement/kinematic/seek.js"
|
|
2
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
3
|
-
import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
|
|
4
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
types: {
|
|
8
|
-
mouse: [enableMouse()],
|
|
9
|
-
|
|
10
|
-
character: [
|
|
11
|
-
enableCharacter(),
|
|
12
|
-
{
|
|
13
|
-
"game:update"(instance, event, { dt, instances }) {
|
|
14
|
-
const target = instances.mouse
|
|
15
|
-
|
|
16
|
-
merge(instance, seek(instance, target, { dt }))
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
instances: {
|
|
23
|
-
mouse: {
|
|
24
|
-
type: "mouse",
|
|
25
|
-
position: [400, 0, 300],
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
character: {
|
|
29
|
-
type: "character",
|
|
30
|
-
maxSpeed: 250,
|
|
31
|
-
position: [400, 0, 300],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import wanderAsSeek, {
|
|
2
|
-
DEFAULT_WANDER_RADIUS,
|
|
3
|
-
} from "@inglorious/engine/ai/movement/kinematic/wander-as-seek.js"
|
|
4
|
-
import { flip } from "@inglorious/game/bounds.js"
|
|
5
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
6
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
7
|
-
import { pi } from "@inglorious/utils/math/trigonometry.js"
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
types: {
|
|
11
|
-
character: [
|
|
12
|
-
enableCharacter(),
|
|
13
|
-
{
|
|
14
|
-
"game:update"(instance, event, { dt, instances }) {
|
|
15
|
-
const { fields } = instances.parameters.groups.wanderAsSeek
|
|
16
|
-
|
|
17
|
-
merge(
|
|
18
|
-
instance,
|
|
19
|
-
wanderAsSeek(instance, {
|
|
20
|
-
dt,
|
|
21
|
-
wanderRadius: fields.wanderRadius.value,
|
|
22
|
-
}),
|
|
23
|
-
)
|
|
24
|
-
flip(instance, instances.game.bounds)
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
|
|
29
|
-
form: {
|
|
30
|
-
"field:change"(instance, event) {
|
|
31
|
-
const { id, value } = event.payload
|
|
32
|
-
instance.groups.wanderAsSeek.fields[id].value = value
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
instances: {
|
|
38
|
-
character: {
|
|
39
|
-
type: "character",
|
|
40
|
-
maxSpeed: 250,
|
|
41
|
-
maxAngularSpeed: pi() / 4,
|
|
42
|
-
position: [400, 0, 300],
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
parameters: {
|
|
46
|
-
type: "form",
|
|
47
|
-
position: [800 - 352, 0, 600],
|
|
48
|
-
groups: {
|
|
49
|
-
wanderAsSeek: {
|
|
50
|
-
title: "Wander As Seek",
|
|
51
|
-
fields: {
|
|
52
|
-
wanderRadius: {
|
|
53
|
-
label: "Wander Radius",
|
|
54
|
-
inputType: "number",
|
|
55
|
-
defaultValue: DEFAULT_WANDER_RADIUS,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import wander from "@inglorious/engine/ai/movement/kinematic/wander.js"
|
|
2
|
-
import { flip } from "@inglorious/game/bounds.js"
|
|
3
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
4
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
5
|
-
import { pi } from "@inglorious/utils/math/trigonometry.js"
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
types: {
|
|
9
|
-
character: [
|
|
10
|
-
enableCharacter(),
|
|
11
|
-
{
|
|
12
|
-
"game:update"(instance, event, { dt, instances }) {
|
|
13
|
-
merge(instance, wander(instance, { dt }))
|
|
14
|
-
flip(instance, instances.game.bounds)
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
instances: {
|
|
21
|
-
character: {
|
|
22
|
-
type: "character",
|
|
23
|
-
maxSpeed: 250,
|
|
24
|
-
maxAngularSpeed: pi() / 4,
|
|
25
|
-
position: [400, 0, 300],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
}
|
package/src/docs/bounds.js
DELETED
package/src/docs/code-reuse.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { bounce } from "@inglorious/game/bounds.js"
|
|
2
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
3
|
-
import { enableFps } from "@inglorious/game/decorators/fps.js"
|
|
4
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
5
|
-
import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
|
|
6
|
-
import { pi } from "@inglorious/utils/math/trigonometry.js"
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
types: {
|
|
10
|
-
character: [
|
|
11
|
-
enableCharacter(),
|
|
12
|
-
{
|
|
13
|
-
"game:update"(instance, event, options) {
|
|
14
|
-
merge(instance, bounce(instance, options))
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
|
|
19
|
-
fps: [enableFps()],
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
instances: {
|
|
23
|
-
character: {
|
|
24
|
-
type: "character",
|
|
25
|
-
maxSpeed: 250,
|
|
26
|
-
orientation: pi() / 6,
|
|
27
|
-
position: zero(),
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
fps: {
|
|
31
|
-
type: "fps",
|
|
32
|
-
position: [0, 0, 600],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { collidesWith } from "@inglorious/engine/collision/detection.js"
|
|
2
|
-
import { bounce } from "@inglorious/game/bounds.js"
|
|
3
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
4
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
5
|
-
import { mod } from "@inglorious/utils/math/numbers.js"
|
|
6
|
-
import { pi } from "@inglorious/utils/math/trigonometry.js"
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
types: {
|
|
10
|
-
character: [
|
|
11
|
-
enableCharacter(),
|
|
12
|
-
{
|
|
13
|
-
"game:update"(instance, event, options) {
|
|
14
|
-
const characters = Object.values(options.instances).filter(
|
|
15
|
-
({ type }) => type === "character",
|
|
16
|
-
)
|
|
17
|
-
const target = characters.find(({ id }) => id !== instance.id)
|
|
18
|
-
|
|
19
|
-
if (collidesWith(instance, target)) {
|
|
20
|
-
instance.orientation += pi()
|
|
21
|
-
instance.orientation = mod(instance.orientation, 2 * pi())
|
|
22
|
-
}
|
|
23
|
-
merge(instance, bounce(instance, options))
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
instances: {
|
|
30
|
-
left: {
|
|
31
|
-
type: "character",
|
|
32
|
-
position: [200, 0, 300],
|
|
33
|
-
orientation: 0,
|
|
34
|
-
maxSpeed: 250,
|
|
35
|
-
collisions: {
|
|
36
|
-
hitbox: {
|
|
37
|
-
shape: "circle",
|
|
38
|
-
offset: [-6, 0, -6],
|
|
39
|
-
radius: 12,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
right: {
|
|
45
|
-
type: "character",
|
|
46
|
-
position: [600, 0, 300],
|
|
47
|
-
orientation: pi(),
|
|
48
|
-
maxSpeed: 250,
|
|
49
|
-
collisions: {
|
|
50
|
-
hitbox: {
|
|
51
|
-
shape: "circle",
|
|
52
|
-
offset: [-6, 0, -6],
|
|
53
|
-
radius: 12,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Canvas, Meta, Source } from '@storybook/blocks'
|
|
2
|
-
import * as Collision from './collision.stories'
|
|
3
|
-
|
|
4
|
-
import circles from './circles?raw'
|
|
5
|
-
import platform from './platform?raw'
|
|
6
|
-
|
|
7
|
-
<Meta of={Collision} />
|
|
8
|
-
|
|
9
|
-
# Collision Detection
|
|
10
|
-
|
|
11
|
-
Examples on how to use the built-in collision detection functions.
|
|
12
|
-
|
|
13
|
-
## Circles
|
|
14
|
-
|
|
15
|
-
Two shapes with a circular hitbox bounce against each other when colliding.
|
|
16
|
-
|
|
17
|
-
<Source dark code={circles} />
|
|
18
|
-
|
|
19
|
-
<Canvas of={Collision.Circles} />
|
|
20
|
-
|
|
21
|
-
## Platform
|
|
22
|
-
|
|
23
|
-
A character is able to jump on top of a platform and keep its `y` position.
|
|
24
|
-
|
|
25
|
-
<Source dark code={platform} />
|
|
26
|
-
|
|
27
|
-
<Canvas of={Collision.Platform} />
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import UiChooser from "@inglorious/docs/ui-chooser.jsx"
|
|
2
|
-
|
|
3
|
-
import circles from "./circles.js"
|
|
4
|
-
import platform from "./platform.js"
|
|
5
|
-
import tilemap from "./tilemap.js"
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: "Engine/Collision Detection",
|
|
9
|
-
component: UiChooser,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Circles = {
|
|
13
|
-
args: { config: circles },
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const Platform = {
|
|
17
|
-
args: { config: platform },
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const Tilemap = {
|
|
21
|
-
args: { config: tilemap },
|
|
22
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
2
|
-
import { enableClampToBounds } from "@inglorious/game/decorators/clamp-to-bounds.js"
|
|
3
|
-
import { enableModernControls } from "@inglorious/game/decorators/controls/kinematic/modern.js"
|
|
4
|
-
import {
|
|
5
|
-
createControls,
|
|
6
|
-
enableControls,
|
|
7
|
-
} from "@inglorious/game/decorators/input/controls.js"
|
|
8
|
-
import { enableJump } from "@inglorious/game/decorators/jump.js"
|
|
9
|
-
import { enablePlatform } from "@inglorious/game/decorators/platform.js"
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
types: {
|
|
13
|
-
...enableControls(),
|
|
14
|
-
|
|
15
|
-
platform: [enablePlatform()],
|
|
16
|
-
|
|
17
|
-
character: [
|
|
18
|
-
enableCharacter(),
|
|
19
|
-
enableModernControls(),
|
|
20
|
-
enableClampToBounds(),
|
|
21
|
-
enableJump(),
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
instances: {
|
|
26
|
-
...createControls("input0", {
|
|
27
|
-
ArrowLeft: "left",
|
|
28
|
-
ArrowRight: "right",
|
|
29
|
-
Space: "jump",
|
|
30
|
-
KeyA: "left",
|
|
31
|
-
KeyD: "right",
|
|
32
|
-
Btn0: "jump",
|
|
33
|
-
Btn14: "left",
|
|
34
|
-
Btn15: "right",
|
|
35
|
-
Axis0: "leftRight",
|
|
36
|
-
}),
|
|
37
|
-
|
|
38
|
-
ground: {
|
|
39
|
-
type: "platform",
|
|
40
|
-
position: [0, 50, 0],
|
|
41
|
-
size: [800, 50, 0],
|
|
42
|
-
backgroundColor: "green",
|
|
43
|
-
collisions: {
|
|
44
|
-
platform: {
|
|
45
|
-
shape: "platform",
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
platform: {
|
|
51
|
-
type: "platform",
|
|
52
|
-
position: [600, 100, 0],
|
|
53
|
-
size: [80, 20, 0],
|
|
54
|
-
backgroundColor: "grey",
|
|
55
|
-
collisions: {
|
|
56
|
-
platform: {
|
|
57
|
-
shape: "platform",
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
character: {
|
|
63
|
-
type: "character",
|
|
64
|
-
layer: 1,
|
|
65
|
-
position: [200, 62, 0],
|
|
66
|
-
collisions: {
|
|
67
|
-
platform: {
|
|
68
|
-
// shape: "rectangle",
|
|
69
|
-
// size: [24, 24, 24],
|
|
70
|
-
shape: "circle",
|
|
71
|
-
radius: 12,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { findCollisions } from "@inglorious/engine/collision/detection.js"
|
|
2
|
-
import { enableCollisionsDebug } from "@inglorious/game/decorators/debug/collisions.js"
|
|
3
|
-
import { enableSprite } from "@inglorious/game/decorators/image/sprite.js"
|
|
4
|
-
import { enableTilemap } from "@inglorious/game/decorators/image/tilemap.js"
|
|
5
|
-
import {
|
|
6
|
-
createControls,
|
|
7
|
-
enableControls,
|
|
8
|
-
} from "@inglorious/game/decorators/input/controls.js"
|
|
9
|
-
import { Sprite } from "@inglorious/game/sprite.js"
|
|
10
|
-
import { extend } from "@inglorious/utils/data-structures/objects.js"
|
|
11
|
-
import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
|
|
12
|
-
|
|
13
|
-
const X = 0
|
|
14
|
-
const Z = 2
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
types: {
|
|
18
|
-
...enableControls(),
|
|
19
|
-
|
|
20
|
-
tilemap: [enableTilemap(), enableCollisionsDebug()],
|
|
21
|
-
|
|
22
|
-
player: [
|
|
23
|
-
enableSprite(),
|
|
24
|
-
enableCollisionsDebug(),
|
|
25
|
-
// enableModernControls(),
|
|
26
|
-
(type) =>
|
|
27
|
-
extend(type, {
|
|
28
|
-
"game:update"(instance, event, options) {
|
|
29
|
-
type["game:update"]?.(instance, event, options)
|
|
30
|
-
|
|
31
|
-
const { maxSpeed } = instance
|
|
32
|
-
const { dungeon } = options.instances
|
|
33
|
-
|
|
34
|
-
const spriteState = Sprite.move2(instance)
|
|
35
|
-
Sprite.play(spriteState, instance, options)
|
|
36
|
-
|
|
37
|
-
const { input0 } = options.instances
|
|
38
|
-
instance.velocity = zero()
|
|
39
|
-
|
|
40
|
-
if (input0.left) {
|
|
41
|
-
instance.velocity[X] = -maxSpeed
|
|
42
|
-
}
|
|
43
|
-
if (input0.right) {
|
|
44
|
-
instance.velocity[X] = maxSpeed
|
|
45
|
-
}
|
|
46
|
-
if (input0.leftRight != null) {
|
|
47
|
-
instance.velocity[X] += input0.leftRight * maxSpeed
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const oldX = instance.position[X]
|
|
51
|
-
instance.position[X] += instance.velocity[X] * options.dt
|
|
52
|
-
if (findCollisions(dungeon, instance)) {
|
|
53
|
-
instance.position[X] = oldX
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (input0.down) {
|
|
57
|
-
instance.velocity[Z] = -maxSpeed
|
|
58
|
-
}
|
|
59
|
-
if (input0.up) {
|
|
60
|
-
instance.velocity[Z] = maxSpeed
|
|
61
|
-
}
|
|
62
|
-
if (input0.upDown != null) {
|
|
63
|
-
instance.velocity[Z] += -input0.upDown * maxSpeed
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const oldZ = instance.position[Z]
|
|
67
|
-
instance.position[Z] += instance.velocity[Z] * options.dt
|
|
68
|
-
if (findCollisions(dungeon, instance)) {
|
|
69
|
-
instance.position[Z] = oldZ
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
instances: {
|
|
77
|
-
game: {
|
|
78
|
-
pixelated: true,
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
...createControls("input0", {
|
|
82
|
-
ArrowLeft: "left",
|
|
83
|
-
ArrowRight: "right",
|
|
84
|
-
ArrowDown: "down",
|
|
85
|
-
ArrowUp: "up",
|
|
86
|
-
}),
|
|
87
|
-
|
|
88
|
-
dungeon: {
|
|
89
|
-
type: "tilemap",
|
|
90
|
-
position: [400 - (16 * 6 * 3) / 2, 0, 300 - (16 * 5 * 3) / 2],
|
|
91
|
-
tilemap: {
|
|
92
|
-
image: {
|
|
93
|
-
id: "dungeon",
|
|
94
|
-
src: "/tilemaps/dungeon.png",
|
|
95
|
-
imageSize: [160, 160],
|
|
96
|
-
tileSize: [16, 16],
|
|
97
|
-
columns: 6,
|
|
98
|
-
scale: 3,
|
|
99
|
-
},
|
|
100
|
-
layers: [
|
|
101
|
-
{
|
|
102
|
-
tiles: [
|
|
103
|
-
// first row
|
|
104
|
-
0, 1, 2, 3, 4, 5,
|
|
105
|
-
// second row
|
|
106
|
-
10, 11, 12, 13, 14, 15,
|
|
107
|
-
// third row
|
|
108
|
-
20, 21, 22, 23, 24, 25,
|
|
109
|
-
// fourth row
|
|
110
|
-
30, 31, 32, 33, 34, 35,
|
|
111
|
-
// fifth row
|
|
112
|
-
40, 41, 42, 43, 44, 45,
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
tiles: [
|
|
117
|
-
// first row
|
|
118
|
-
-1, -1, -1, -1, -1, -1,
|
|
119
|
-
// second row
|
|
120
|
-
-1, -1, 83, -1, -1, -1,
|
|
121
|
-
// third row
|
|
122
|
-
-1, -1, -1, 97, -1, -1,
|
|
123
|
-
// fourth row
|
|
124
|
-
-1, -1, -1, -1, -1, -1,
|
|
125
|
-
// fifth row
|
|
126
|
-
-1, -1, 66, 67, -1, -1,
|
|
127
|
-
],
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
},
|
|
131
|
-
collisions: {
|
|
132
|
-
hitbox: {
|
|
133
|
-
shape: "hitmask",
|
|
134
|
-
tileSize: [48, 48],
|
|
135
|
-
columns: 6,
|
|
136
|
-
heights: [
|
|
137
|
-
// first row
|
|
138
|
-
2, 2, 2, 2, 2, 2,
|
|
139
|
-
// second row
|
|
140
|
-
2, 0, 1, 0, 0, 2,
|
|
141
|
-
// third row
|
|
142
|
-
2, 0, 0, 1, 0, 2,
|
|
143
|
-
// fourth row
|
|
144
|
-
2, 0, 0, 0, 0, 2,
|
|
145
|
-
// fifth row
|
|
146
|
-
2, 2, 2, 2, 2, 2,
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
player: {
|
|
153
|
-
type: "player",
|
|
154
|
-
position: [400 - 16 * 3, 1, 300 - 16],
|
|
155
|
-
maxSpeed: 250,
|
|
156
|
-
sprite: {
|
|
157
|
-
image: {
|
|
158
|
-
id: "dungeon_character",
|
|
159
|
-
src: "/sprites/dungeon_character.png",
|
|
160
|
-
imageSize: [112, 64],
|
|
161
|
-
tileSize: [16, 16],
|
|
162
|
-
scale: 3,
|
|
163
|
-
},
|
|
164
|
-
speed: 0.2,
|
|
165
|
-
frames: {
|
|
166
|
-
right: [17],
|
|
167
|
-
left: [0x80000000 + 17],
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
collisions: {
|
|
171
|
-
hitbox: {
|
|
172
|
-
shape: "rectangle",
|
|
173
|
-
size: [48, 0, 48],
|
|
174
|
-
offset: [-48 / 2, 0, -48 / 2],
|
|
175
|
-
// size: [24, 0, 24],
|
|
176
|
-
// offset: [-8, 0, -8],
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
}
|
package/src/docs/empty.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {}
|