-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
54 lines (31 loc) · 1.46 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {Schedule} from "directed";
import {createWorld, World, createActions} from "koota";
import {AnimateColors, AnimateSpheres, SyncPositionToThree} from "./systems";
import {IsSphere, Position} from "./traits";
// =================================================================================================================
// create our world
export const world = createWorld();
// create a default schedule (we can control what data it passes into systems)
export const schedule = new Schedule<{ world: World, delta: number }>();
// import all ecs systems and build the schedule
schedule.add(AnimateSpheres);
schedule.add(SyncPositionToThree, {after: AnimateSpheres});
schedule.add(AnimateColors, {after: AnimateSpheres});
schedule.build();
// =================================================================================================================
// an example actions store to be used from within React.
// Creating action stores is optional – we can execute the code directly –
// but it can help us with organization.
export const exampleActions = createActions((world: World) => ({
spawnSphere: () => {
world.spawn(IsSphere, Position({
x: Math.random() * 70 - 35,
y: Math.random() * 15,
z: Math.random() * 70 - 35
}))
},
removeSphere: () => {
world.queryFirst(IsSphere)?.destroy();
},
}))
// =================================================================================================================