@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/src/docs/engine.mdx
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Canvas, Meta, Source } from '@storybook/blocks'
|
|
2
|
-
import * as Engine from './engine.stories'
|
|
3
|
-
|
|
4
|
-
import bounds from './bounds?raw'
|
|
5
|
-
import codeReuse from './code-reuse?raw'
|
|
6
|
-
import eventHandlers from './event-handlers?raw'
|
|
7
|
-
import framerate from './framerate?raw'
|
|
8
|
-
|
|
9
|
-
<Meta of={Engine} />
|
|
10
|
-
|
|
11
|
-
# Core Concepts
|
|
12
|
-
|
|
13
|
-
This page showcases some of the core concepts and features of the Inglorious Engine. If you are just getting started, we recommend you check out the [Quick Start Guide](/docs/quick-start--docs) first.
|
|
14
|
-
|
|
15
|
-
Inglorious Engine is a headless game engine that takes a configuration file in plain JavaScript and creates a scene. The UI can be implemented in any technology: canvas, HTML, ...here we are using React components.
|
|
16
|
-
|
|
17
|
-
Here are a few examples of what you can do.
|
|
18
|
-
|
|
19
|
-
## Bounds
|
|
20
|
-
|
|
21
|
-
We can customize the game's bounds by passing an array of four numbers: these will hold the upper and lower bounds in pixels.
|
|
22
|
-
|
|
23
|
-
The game is an instance in the game, that we can customize as we please.
|
|
24
|
-
|
|
25
|
-
<Source dark code={bounds} />
|
|
26
|
-
|
|
27
|
-
<Canvas of={Engine.Bounds} />
|
|
28
|
-
|
|
29
|
-
## Event Handlers
|
|
30
|
-
|
|
31
|
-
To animate stuff we write event handlers for events that are triggered by our instances or by the game itself. The `game:update` event, for example, is triggered at every cycle of the game loop.
|
|
32
|
-
|
|
33
|
-
An event handler accepts the following arguments:
|
|
34
|
-
|
|
35
|
-
- The `instance` itself that is handling the event, so we can change its properties to our needs;
|
|
36
|
-
- The triggered `event`, which contains a `payload` that holds whatever we need to accomplish our task;
|
|
37
|
-
- An `options` object that contains the following:
|
|
38
|
-
- The elapsed time `dt`, which can help slow down certain movement algorithms based on the current FPS;
|
|
39
|
-
- The game's current `config` object (here you can find the scene's `bounds`, for example);
|
|
40
|
-
- All `instances` present in the scene; note that they are read-only, so look but don't touch!
|
|
41
|
-
|
|
42
|
-
You might notice the code directly changes properties on the `instance`. While this looks like a direct mutation, the engine uses [Immer](https://immerjs.github.io/immer/) under the hood. This allows you to write simple, mutable-style code while Immer handles the complexity of producing a new, immutable state object for you. It's the best of both worlds: simple code and the safety of immutability.
|
|
43
|
-
|
|
44
|
-
The character shown here updates its velocity and position at every frame, going back and forth like it's patroling the scene!
|
|
45
|
-
|
|
46
|
-
The `fps` type shows FPS debug info on the top left of the scene; its value is updated based on the `dt` time at every `game:update` event.
|
|
47
|
-
|
|
48
|
-
<Source dark code={eventHandlers} />
|
|
49
|
-
|
|
50
|
-
<Canvas of={Engine.EventHandlers} />
|
|
51
|
-
|
|
52
|
-
## Code Reuse
|
|
53
|
-
|
|
54
|
-
Coding is beautiful, but reusing code without reinventing the wheel is even better! This is where the engine's functional approach really shines.
|
|
55
|
-
|
|
56
|
-
Instead of relying on complex class inheritance hierarchies, we use **function composition**. In this example, all the code necessary to draw the character is encapsulated in an `enableCharacter()` decorator.
|
|
57
|
-
|
|
58
|
-
This approach is more flexible and powerful than inheritance. You can mix and match behaviors by simply adding decorators to an array, avoiding problems like the "diamond problem" and creating deeply nested, brittle class structures. You are free to combine `canBeControlledByPlayer`, `canBeHurt`, and `canShoot` decorators on the fly.
|
|
59
|
-
|
|
60
|
-
The event handler for this character is also using a predefined `bounce()` function. There are many predefined functions out there at your disposal, just look through the documentation to find the ones that suit you best.
|
|
61
|
-
|
|
62
|
-
<Source dark code={codeReuse} />
|
|
63
|
-
|
|
64
|
-
<Canvas of={Engine.CodeReuse} />
|
|
65
|
-
|
|
66
|
-
## Fixed Framerate
|
|
67
|
-
|
|
68
|
-
What if you want to provide a more retro feel to your game? You can use a fixed framerate and make your animations more jerky by changing the default loop.
|
|
69
|
-
|
|
70
|
-
<Source dark code={framerate} />
|
|
71
|
-
|
|
72
|
-
<Canvas of={Engine.Framerate} />
|
|
73
|
-
|
|
74
|
-
## What's Next?
|
|
75
|
-
|
|
76
|
-
You've now seen the core features of the engine. Here's where you can go from here:
|
|
77
|
-
|
|
78
|
-
- **Add player controls**: See [Input Handling](/docs/engine-input--docs) for keyboard and mouse.
|
|
79
|
-
- **Detect collisions**: Learn about [Collision Detection](/docs/engine-collision-detection--docs).
|
|
80
|
-
- **Build autonomous characters**: Explore [AI Kinematic Movement](/docs/ai-movement-kinematic--docs) and [AI Dynamic Movement](/docs/ai-movement-dynamic--docs).
|
|
81
|
-
- **See complete examples**: Look at our [Recipes](/docs/engine-recipes--docs) for common game patterns.
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import UiChooser from "@inglorious/docs/ui-chooser.jsx"
|
|
2
|
-
|
|
3
|
-
import bounds from "./bounds.js"
|
|
4
|
-
import codeReuse from "./code-reuse.js"
|
|
5
|
-
import empty from "./empty.js"
|
|
6
|
-
import eventHandlers from "./event-handlers.js"
|
|
7
|
-
import framerate from "./framerate.js"
|
|
8
|
-
import instances from "./instances.js"
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
title: "Engine",
|
|
12
|
-
component: UiChooser,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const Empty = {
|
|
16
|
-
args: { config: empty },
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const Bounds = {
|
|
20
|
-
args: { config: bounds },
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const Instances = {
|
|
24
|
-
args: { config: instances },
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const EventHandlers = {
|
|
28
|
-
args: { config: eventHandlers },
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const CodeReuse = {
|
|
32
|
-
args: { config: codeReuse },
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const Framerate = {
|
|
36
|
-
args: { config: framerate },
|
|
37
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const X = 0
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
types: {
|
|
5
|
-
character: {
|
|
6
|
-
draw(ctx, instance) {
|
|
7
|
-
const {
|
|
8
|
-
size = 24,
|
|
9
|
-
orientation = 0,
|
|
10
|
-
stroke = "black",
|
|
11
|
-
fill = "transparent",
|
|
12
|
-
} = instance
|
|
13
|
-
|
|
14
|
-
const radius = size * 0.5
|
|
15
|
-
|
|
16
|
-
ctx.save()
|
|
17
|
-
ctx.rotate(-orientation)
|
|
18
|
-
ctx.translate(radius - 1, 0)
|
|
19
|
-
|
|
20
|
-
ctx.fillStyle = "black"
|
|
21
|
-
|
|
22
|
-
ctx.beginPath()
|
|
23
|
-
ctx.moveTo(0, 6)
|
|
24
|
-
ctx.lineTo(0, -6)
|
|
25
|
-
ctx.lineTo(6, 0)
|
|
26
|
-
ctx.fill()
|
|
27
|
-
ctx.closePath()
|
|
28
|
-
ctx.restore()
|
|
29
|
-
|
|
30
|
-
ctx.save()
|
|
31
|
-
ctx.lineWidth = 1
|
|
32
|
-
ctx.strokeStyle = stroke
|
|
33
|
-
ctx.fillStyle = fill
|
|
34
|
-
|
|
35
|
-
ctx.beginPath()
|
|
36
|
-
ctx.arc(0, 0, radius, 0, 2 * 3.14)
|
|
37
|
-
ctx.fill()
|
|
38
|
-
ctx.stroke()
|
|
39
|
-
ctx.closePath()
|
|
40
|
-
ctx.restore()
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
"game:update"(instance, event, { dt, instances }) {
|
|
44
|
-
const [left, , right] = instances.game.bounds
|
|
45
|
-
|
|
46
|
-
if (instance.position[X] > right) {
|
|
47
|
-
instance.velocity[X] = -instance.maxSpeed
|
|
48
|
-
instance.orientation = 3.14
|
|
49
|
-
} else if (instance.position[X] < left) {
|
|
50
|
-
instance.velocity[X] = instance.maxSpeed
|
|
51
|
-
instance.orientation = 0
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
instance.position[X] += instance.velocity[X] * dt
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
instances: {
|
|
60
|
-
character: {
|
|
61
|
-
type: "character",
|
|
62
|
-
maxSpeed: 250,
|
|
63
|
-
position: [400, 0, 300],
|
|
64
|
-
velocity: [250, 0, 0],
|
|
65
|
-
orientation: 0,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
}
|
package/src/docs/framerate.js
DELETED
|
@@ -1,37 +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
|
-
loop: { type: "fixed", fps: 10 },
|
|
10
|
-
|
|
11
|
-
types: {
|
|
12
|
-
character: [
|
|
13
|
-
enableCharacter(),
|
|
14
|
-
{
|
|
15
|
-
"game:update"(instance, event, options) {
|
|
16
|
-
merge(instance, bounce(instance, options))
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
|
|
21
|
-
fps: [enableFps()],
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
instances: {
|
|
25
|
-
character: {
|
|
26
|
-
type: "character",
|
|
27
|
-
maxSpeed: 250,
|
|
28
|
-
orientation: pi() / 6,
|
|
29
|
-
position: zero(),
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
fps: {
|
|
33
|
-
type: "fps",
|
|
34
|
-
position: [0, 0, 600],
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}
|
package/src/docs/game.jsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { start } from "@inglorious/ui/canvas"
|
|
2
|
-
import { useRef } from "react"
|
|
3
|
-
import { useEffect } from "react"
|
|
4
|
-
|
|
5
|
-
export default function Game({ config }) {
|
|
6
|
-
const canvas = useRef()
|
|
7
|
-
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (canvas.current) {
|
|
10
|
-
start(config, canvas.current)
|
|
11
|
-
}
|
|
12
|
-
}, [config])
|
|
13
|
-
|
|
14
|
-
return <canvas id="canvas" ref={canvas} />
|
|
15
|
-
}
|
package/src/docs/image/image.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { enableImage } from "@inglorious/game/decorators/image/image"
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
types: {
|
|
5
|
-
image: [enableImage()],
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
instances: {
|
|
9
|
-
logo: {
|
|
10
|
-
type: "image",
|
|
11
|
-
position: [400 - 128 / 2, 0, 300 + 128 / 2],
|
|
12
|
-
image: {
|
|
13
|
-
id: "logo",
|
|
14
|
-
src: "/logo.png",
|
|
15
|
-
imageSize: [128, 128],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import UiChooser from "@inglorious/docs/ui-chooser.jsx"
|
|
2
|
-
|
|
3
|
-
import image from "./image.js"
|
|
4
|
-
import sprite from "./sprite.js"
|
|
5
|
-
import tilemap from "./tilemap.js"
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: "Engine/Image",
|
|
9
|
-
component: UiChooser,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Image = {
|
|
13
|
-
args: { config: image },
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const Tilemap = {
|
|
17
|
-
args: { config: tilemap },
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const Sprite = {
|
|
21
|
-
args: { config: sprite },
|
|
22
|
-
}
|
package/src/docs/image/sprite.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { enableSprite } from "@inglorious/game/decorators/image/sprite.js"
|
|
2
|
-
import { Sprite } from "@inglorious/game/sprite.js"
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
types: {
|
|
6
|
-
cat: [
|
|
7
|
-
enableSprite(),
|
|
8
|
-
{
|
|
9
|
-
"game:update"(instance, event, options) {
|
|
10
|
-
Sprite.play("sleepy", instance, options)
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
instances: {
|
|
17
|
-
game: {
|
|
18
|
-
pixelated: true,
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
neko: {
|
|
22
|
-
type: "cat",
|
|
23
|
-
position: [400, 0, 300],
|
|
24
|
-
sprite: {
|
|
25
|
-
image: {
|
|
26
|
-
id: "neko",
|
|
27
|
-
src: "/sprites/neko.png",
|
|
28
|
-
imageSize: [192, 192],
|
|
29
|
-
tileSize: [32, 32],
|
|
30
|
-
scale: 2,
|
|
31
|
-
},
|
|
32
|
-
speed: 0.2,
|
|
33
|
-
frames: {
|
|
34
|
-
sleepy: [4, 10, 10, 3, 9, 15, 9, 15, 15],
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { enableTilemap } from "@inglorious/game/decorators/image/tilemap"
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
types: {
|
|
5
|
-
tilemap: [enableTilemap()],
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
instances: {
|
|
9
|
-
game: {
|
|
10
|
-
pixelated: true,
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
dungeon: {
|
|
14
|
-
type: "tilemap",
|
|
15
|
-
position: [400 - (16 * 6 * 3) / 2, 0, 300 - (16 * 5 * 3) / 2],
|
|
16
|
-
tilemap: {
|
|
17
|
-
image: {
|
|
18
|
-
id: "dungeon",
|
|
19
|
-
src: "/tilemaps/dungeon.png",
|
|
20
|
-
imageSize: [160, 160],
|
|
21
|
-
tileSize: [16, 16],
|
|
22
|
-
columns: 6,
|
|
23
|
-
scale: 3,
|
|
24
|
-
},
|
|
25
|
-
layers: [
|
|
26
|
-
{
|
|
27
|
-
tiles: [
|
|
28
|
-
// first row
|
|
29
|
-
0, 1, 2, 3, 4, 5,
|
|
30
|
-
// second row
|
|
31
|
-
10, 11, 12, 13, 14, 15,
|
|
32
|
-
// third row
|
|
33
|
-
20, 21, 22, 23, 24, 25,
|
|
34
|
-
// fourth row
|
|
35
|
-
30, 31, 32, 33, 34, 35,
|
|
36
|
-
// fifth row
|
|
37
|
-
40, 41, 42, 43, 44, 45,
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
tiles: [
|
|
42
|
-
// first row
|
|
43
|
-
-1,
|
|
44
|
-
-1,
|
|
45
|
-
-1,
|
|
46
|
-
-1,
|
|
47
|
-
-1,
|
|
48
|
-
-1,
|
|
49
|
-
// second row
|
|
50
|
-
-1,
|
|
51
|
-
91,
|
|
52
|
-
83,
|
|
53
|
-
-1,
|
|
54
|
-
0x80000000 + 91,
|
|
55
|
-
-1,
|
|
56
|
-
// third row
|
|
57
|
-
-1,
|
|
58
|
-
-1,
|
|
59
|
-
-1,
|
|
60
|
-
97,
|
|
61
|
-
-1,
|
|
62
|
-
-1,
|
|
63
|
-
// fourth row
|
|
64
|
-
-1,
|
|
65
|
-
91,
|
|
66
|
-
-1,
|
|
67
|
-
-1,
|
|
68
|
-
0x80000000 + 91,
|
|
69
|
-
-1,
|
|
70
|
-
// fifth row
|
|
71
|
-
// -1, -1, 36, 37, -1, -1,
|
|
72
|
-
-1,
|
|
73
|
-
-1,
|
|
74
|
-
66,
|
|
75
|
-
67,
|
|
76
|
-
-1,
|
|
77
|
-
-1,
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import move from "@inglorious/engine/movement/kinematic/modern.js"
|
|
2
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
3
|
-
import {
|
|
4
|
-
createControls,
|
|
5
|
-
enableControls,
|
|
6
|
-
} from "@inglorious/game/decorators/input/controls.js"
|
|
7
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
8
|
-
import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
|
|
9
|
-
|
|
10
|
-
const X = 0
|
|
11
|
-
const Z = 2
|
|
12
|
-
|
|
13
|
-
export default {
|
|
14
|
-
types: {
|
|
15
|
-
...enableControls(),
|
|
16
|
-
|
|
17
|
-
character: [
|
|
18
|
-
enableCharacter(),
|
|
19
|
-
{
|
|
20
|
-
"game:update"(instance, event, options) {
|
|
21
|
-
const { input0 } = options.instances
|
|
22
|
-
instance.velocity = zero()
|
|
23
|
-
|
|
24
|
-
if (input0.left) {
|
|
25
|
-
instance.velocity[X] = -instance.maxSpeed
|
|
26
|
-
}
|
|
27
|
-
if (input0.down) {
|
|
28
|
-
instance.velocity[Z] = -instance.maxSpeed
|
|
29
|
-
}
|
|
30
|
-
if (input0.right) {
|
|
31
|
-
instance.velocity[X] = instance.maxSpeed
|
|
32
|
-
}
|
|
33
|
-
if (input0.up) {
|
|
34
|
-
instance.velocity[Z] = instance.maxSpeed
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
merge(instance, move(instance, options))
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
instances: {
|
|
44
|
-
...createControls("input0", {
|
|
45
|
-
ArrowUp: "up",
|
|
46
|
-
ArrowDown: "down",
|
|
47
|
-
ArrowLeft: "left",
|
|
48
|
-
ArrowRight: "right",
|
|
49
|
-
KeyW: "up",
|
|
50
|
-
KeyS: "down",
|
|
51
|
-
KeyA: "left",
|
|
52
|
-
KeyD: "right",
|
|
53
|
-
Btn12: "up",
|
|
54
|
-
Btn13: "down",
|
|
55
|
-
Btn14: "left",
|
|
56
|
-
Btn15: "right",
|
|
57
|
-
Axis0: "leftRight",
|
|
58
|
-
Axis1: "upDown",
|
|
59
|
-
}),
|
|
60
|
-
|
|
61
|
-
character: {
|
|
62
|
-
type: "character",
|
|
63
|
-
maxSpeed: 250,
|
|
64
|
-
position: [400, 0, 300],
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import move from "@inglorious/engine/movement/kinematic/modern.js"
|
|
2
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
3
|
-
import {
|
|
4
|
-
createGamepad,
|
|
5
|
-
enableGamepad,
|
|
6
|
-
} from "@inglorious/game/decorators/input/gamepad.js"
|
|
7
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
8
|
-
import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
|
|
9
|
-
|
|
10
|
-
const X = 0
|
|
11
|
-
const Z = 2
|
|
12
|
-
|
|
13
|
-
export default {
|
|
14
|
-
types: {
|
|
15
|
-
gamepad: [enableGamepad()],
|
|
16
|
-
|
|
17
|
-
character: [
|
|
18
|
-
enableCharacter(),
|
|
19
|
-
{
|
|
20
|
-
"game:update"(instance, event, options) {
|
|
21
|
-
const { gamepad0 } = options.instances
|
|
22
|
-
|
|
23
|
-
instance.velocity = zero()
|
|
24
|
-
|
|
25
|
-
if (gamepad0.left) {
|
|
26
|
-
instance.velocity[X] = -instance.maxSpeed
|
|
27
|
-
}
|
|
28
|
-
if (gamepad0.down) {
|
|
29
|
-
instance.velocity[Z] = -instance.maxSpeed
|
|
30
|
-
}
|
|
31
|
-
if (gamepad0.right) {
|
|
32
|
-
instance.velocity[X] = instance.maxSpeed
|
|
33
|
-
}
|
|
34
|
-
if (gamepad0.up) {
|
|
35
|
-
instance.velocity[Z] = instance.maxSpeed
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (gamepad0.leftRight != null) {
|
|
39
|
-
instance.velocity[X] += gamepad0.leftRight * instance.maxSpeed
|
|
40
|
-
}
|
|
41
|
-
if (gamepad0.upDown != null) {
|
|
42
|
-
instance.velocity[Z] += -gamepad0.upDown * instance.maxSpeed
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
merge(instance, move(instance, options))
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
instances: {
|
|
52
|
-
gamepad0: createGamepad("gamepad0", {
|
|
53
|
-
Btn12: "up",
|
|
54
|
-
Btn13: "down",
|
|
55
|
-
Btn14: "left",
|
|
56
|
-
Btn15: "right",
|
|
57
|
-
Axis0: "leftRight",
|
|
58
|
-
Axis1: "upDown",
|
|
59
|
-
}),
|
|
60
|
-
|
|
61
|
-
character: {
|
|
62
|
-
type: "character",
|
|
63
|
-
maxSpeed: 250,
|
|
64
|
-
position: [400, 0, 300],
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
}
|
package/src/docs/input/input.mdx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Canvas, Meta, Source } from '@storybook/blocks'
|
|
2
|
-
import * as Input from './input.stories'
|
|
3
|
-
|
|
4
|
-
import mouse from "./mouse?raw"
|
|
5
|
-
import keyboard from "./keyboard?raw"
|
|
6
|
-
import gamepad from "./gamepad?raw"
|
|
7
|
-
import controls from "./controls?raw"
|
|
8
|
-
|
|
9
|
-
<Meta of={Input} />
|
|
10
|
-
|
|
11
|
-
# Input
|
|
12
|
-
|
|
13
|
-
It's pretty easy to add input controls to your game. Let's have a look.
|
|
14
|
-
|
|
15
|
-
## Mouse
|
|
16
|
-
|
|
17
|
-
If you need mouse support, it's as easy as using the `enableMouse()` decorator. It automatically detects movement and clicks on any instance in the scene.
|
|
18
|
-
|
|
19
|
-
You can get a reference to any instance in the scene by inspecting the `options.instances` property.
|
|
20
|
-
|
|
21
|
-
<Source dark code={mouse} />
|
|
22
|
-
|
|
23
|
-
<Canvas of={Input.Mouse} />
|
|
24
|
-
|
|
25
|
-
## Keyboard
|
|
26
|
-
|
|
27
|
-
Using the keyboard is very similar, but we also need to specify an id for the input and some mapping configuration. This way we can create multiple mappings that can work at the same time!
|
|
28
|
-
|
|
29
|
-
Also, please note how we are using some predefined functions to achieve our goal:
|
|
30
|
-
|
|
31
|
-
- `zero()` returns a vector with the three coordinates set to zero;
|
|
32
|
-
- `move()` calculates orientation, position, and velocity;
|
|
33
|
-
- `merge()` applies those calculations to the instance.
|
|
34
|
-
|
|
35
|
-
<Source dark code={keyboard} />
|
|
36
|
-
|
|
37
|
-
<Canvas of={Input.Keyboard} />
|
|
38
|
-
|
|
39
|
-
## Gamepad
|
|
40
|
-
|
|
41
|
-
If you plug a gamepad, there's a high chance that the engine will recognize it and you will be able to control your character with the D-pad or the left axis.
|
|
42
|
-
|
|
43
|
-
<Source dark code={gamepad} />
|
|
44
|
-
|
|
45
|
-
<Canvas of={Input.Gamepad} />
|
|
46
|
-
|
|
47
|
-
## Controls
|
|
48
|
-
|
|
49
|
-
Want to make both keyboard and gamepad work? Use the `enableControls()` and `createControls()` functions then!
|
|
50
|
-
|
|
51
|
-
You'll probably always want to use these two instead of dealing with keyboards and gamepads separately, but who am I to judge?
|
|
52
|
-
|
|
53
|
-
<Source dark code={controls} />
|
|
54
|
-
|
|
55
|
-
<Canvas of={Input.Controls} />
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import UiChooser from "@inglorious/docs/ui-chooser.jsx"
|
|
2
|
-
|
|
3
|
-
import controls from "./controls.js"
|
|
4
|
-
import gamepad from "./gamepad.js"
|
|
5
|
-
import keyboard from "./keyboard.js"
|
|
6
|
-
import mouse from "./mouse.js"
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
title: "Engine/Input",
|
|
10
|
-
component: UiChooser,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const Mouse = {
|
|
14
|
-
args: { config: mouse },
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const Keyboard = {
|
|
18
|
-
args: { config: keyboard },
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const Gamepad = {
|
|
22
|
-
args: { config: gamepad },
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const Controls = {
|
|
26
|
-
args: { config: controls },
|
|
27
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import move from "@inglorious/engine/movement/kinematic/modern.js"
|
|
2
|
-
import { enableCharacter } from "@inglorious/game/decorators/character.js"
|
|
3
|
-
import {
|
|
4
|
-
createKeyboard,
|
|
5
|
-
enableKeyboard,
|
|
6
|
-
} from "@inglorious/game/decorators/input/keyboard.js"
|
|
7
|
-
import { merge } from "@inglorious/utils/data-structures/objects.js"
|
|
8
|
-
import { zero } from "@inglorious/utils/math/linear-algebra/vector.js"
|
|
9
|
-
|
|
10
|
-
const X = 0
|
|
11
|
-
const Z = 2
|
|
12
|
-
|
|
13
|
-
export default {
|
|
14
|
-
types: {
|
|
15
|
-
keyboard: [enableKeyboard()],
|
|
16
|
-
|
|
17
|
-
character: [
|
|
18
|
-
enableCharacter(),
|
|
19
|
-
{
|
|
20
|
-
"game:update"(instance, event, options) {
|
|
21
|
-
const { keyboard0 } = options.instances
|
|
22
|
-
|
|
23
|
-
instance.velocity = zero()
|
|
24
|
-
|
|
25
|
-
if (keyboard0.left) {
|
|
26
|
-
instance.velocity[X] = -instance.maxSpeed
|
|
27
|
-
}
|
|
28
|
-
if (keyboard0.down) {
|
|
29
|
-
instance.velocity[Z] = -instance.maxSpeed
|
|
30
|
-
}
|
|
31
|
-
if (keyboard0.right) {
|
|
32
|
-
instance.velocity[X] = instance.maxSpeed
|
|
33
|
-
}
|
|
34
|
-
if (keyboard0.up) {
|
|
35
|
-
instance.velocity[Z] = instance.maxSpeed
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
merge(instance, move(instance, options))
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
instances: {
|
|
45
|
-
keyboard0: createKeyboard("keyboard0", {
|
|
46
|
-
ArrowLeft: "left",
|
|
47
|
-
ArrowDown: "down",
|
|
48
|
-
ArrowRight: "right",
|
|
49
|
-
ArrowUp: "up",
|
|
50
|
-
}),
|
|
51
|
-
|
|
52
|
-
character: {
|
|
53
|
-
type: "character",
|
|
54
|
-
maxSpeed: 250,
|
|
55
|
-
position: [400, 0, 300],
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
}
|