create-exo-app 0.19.1 → 0.20.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 +10 -8
- package/dist/scaffold.js +21 -19
- package/package.json +1 -1
- package/templates/audio-reactive/package.json +1 -2
- package/templates/audio-reactive/src/scenes/AudioReactiveScene.ts +5 -2
- package/templates/game-starter/src/scenes/GameOverScene.ts +5 -1
- package/templates/platformer/README.md +11 -1
- package/templates/platformer/package.json +1 -2
- package/templates/platformer/src/objects/Player.ts +22 -11
- package/templates/platformer/src/scenes/PlatformerScene.ts +53 -54
- package/templates/top-down/README.md +27 -10
- package/templates/top-down/package.json +1 -4
- package/templates/top-down/public/assets/town-square.tmj +110 -49
- package/templates/top-down/src/actor.ts +159 -0
- package/templates/top-down/src/level.ts +29 -31
- package/templates/top-down/src/main.ts +6 -5
- package/templates/top-down/src/scenes/ProceduralMapScene.ts +70 -45
- package/templates/top-down/src/scenes/TiledMapScene.ts +8 -20
- package/templates/top-down/src/scenes/TopDownScene.ts +304 -130
- package/templates/ui-app/README.md +2 -0
- package/templates/ui-app/src/scenes/SettingsScene.ts +6 -1
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TILE_TRANSFORM_IDENTITY, TileLayer, TileMap, TileSet } from '@codexo/exojs
|
|
1
|
+
import { Texture, TextureRegion } from '@codexo/exojs';
|
|
2
|
+
import { ObjectKind, ObjectLayer, TILE_TRANSFORM_IDENTITY, TileLayer, TileMap, type TileMapObject, TileSet } from '@codexo/exojs/tilemap';
|
|
3
3
|
|
|
4
|
-
import { COLUMNS,
|
|
4
|
+
import { cellAt, COLUMNS, DOOR_TILE, findMarker, FLOOR_TILE, ROWS, TILE, WALL_TILE } from '../level';
|
|
5
5
|
import { TopDownScene } from './TopDownScene';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
const
|
|
9
|
-
|
|
7
|
+
/** A collision shape covering one whole tile, as Tiled stores a tile's collision. */
|
|
8
|
+
const wholeTile: TileMapObject = {
|
|
9
|
+
id: 1,
|
|
10
|
+
name: '',
|
|
11
|
+
type: '',
|
|
12
|
+
kind: ObjectKind.Rectangle,
|
|
13
|
+
x: 0,
|
|
14
|
+
y: 0,
|
|
15
|
+
width: TILE,
|
|
16
|
+
height: TILE,
|
|
17
|
+
rotation: 0,
|
|
18
|
+
visible: true,
|
|
19
|
+
properties: {},
|
|
20
|
+
};
|
|
10
21
|
|
|
11
22
|
/**
|
|
12
|
-
* The level built in code
|
|
13
|
-
*
|
|
23
|
+
* The level built in code from `src/level.ts`: the same layers, tile
|
|
24
|
+
* definitions and spawn object `town-square.tmj` carries, so the rest of the
|
|
25
|
+
* scene cannot tell the two apart.
|
|
14
26
|
*
|
|
15
27
|
* This is the right shape when the level is generated - procedural dungeons,
|
|
16
28
|
* puzzle boards, anything whose layout is decided at runtime. When a designer
|
|
17
29
|
* edits the level instead, see `TiledMapScene`.
|
|
18
30
|
*/
|
|
19
31
|
export class ProceduralMapScene extends TopDownScene {
|
|
20
|
-
protected override async loadMap(): Promise<
|
|
21
|
-
// Awaited
|
|
22
|
-
|
|
23
|
-
// got yet.
|
|
24
|
-
await this.loader.load(Asset.type('texture', 'map-pack.png'));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected override buildMap(): Container {
|
|
28
|
-
const texture = this.loader.get('map-pack.png');
|
|
32
|
+
protected override async loadMap(): Promise<TileMap> {
|
|
33
|
+
// Awaited so the texture has real dimensions: `TileSet` needs a region.
|
|
34
|
+
const texture = await this.assets.load(new Texture('map-pack.png'));
|
|
29
35
|
const tileset = new TileSet({
|
|
30
36
|
name: 'map-pack',
|
|
31
37
|
texture: new TextureRegion(texture, { x: 0, y: 0, width: texture.width, height: texture.height }),
|
|
@@ -35,40 +41,59 @@ export class ProceduralMapScene extends TopDownScene {
|
|
|
35
41
|
columns: 17,
|
|
36
42
|
});
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
tileHeight: TILE,
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
tileset.setDefinitions([
|
|
45
|
+
{ localTileId: WALL_TILE, collision: [wholeTile] },
|
|
46
|
+
{ localTileId: DOOR_TILE, collision: [wholeTile], properties: { door: true } },
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const layer = (id: number, name: string): TileLayer =>
|
|
50
|
+
new TileLayer({ id, name, width: COLUMNS, height: ROWS, tileWidth: TILE, tileHeight: TILE, tilesets: [tileset] });
|
|
51
|
+
const ground = layer(1, 'Ground');
|
|
52
|
+
const walls = layer(2, 'Walls');
|
|
47
53
|
|
|
48
54
|
for (let row = 0; row < ROWS; row++) {
|
|
49
55
|
for (let column = 0; column < COLUMNS; column++) {
|
|
50
|
-
ground.setTileAt(column, row, {
|
|
51
|
-
tileset,
|
|
52
|
-
localTileId: isWall(column, row) ? WALL_TILE : FLOOR_TILE,
|
|
53
|
-
transform: TILE_TRANSFORM_IDENTITY,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
56
|
+
ground.setTileAt(column, row, { tileset, localTileId: FLOOR_TILE, transform: TILE_TRANSFORM_IDENTITY });
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
name: 'town-square',
|
|
60
|
-
width: COLUMNS,
|
|
61
|
-
height: ROWS,
|
|
62
|
-
tileWidth: TILE,
|
|
63
|
-
tileHeight: TILE,
|
|
64
|
-
tilesets: [tileset],
|
|
65
|
-
layers: [ground],
|
|
66
|
-
});
|
|
58
|
+
const cell = cellAt(column, row);
|
|
67
59
|
|
|
68
|
-
|
|
60
|
+
if (cell === '#' || cell === 'D') {
|
|
61
|
+
walls.setTileAt(column, row, { tileset, localTileId: cell === '#' ? WALL_TILE : DOOR_TILE, transform: TILE_TRANSFORM_IDENTITY });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
69
65
|
|
|
70
|
-
|
|
66
|
+
const spawn = findMarker('S');
|
|
71
67
|
|
|
72
|
-
|
|
68
|
+
// Built here rather than by the loader, so the scene owns it.
|
|
69
|
+
return this.track(
|
|
70
|
+
new TileMap({
|
|
71
|
+
name: 'town-square',
|
|
72
|
+
width: COLUMNS,
|
|
73
|
+
height: ROWS,
|
|
74
|
+
tileWidth: TILE,
|
|
75
|
+
tileHeight: TILE,
|
|
76
|
+
tilesets: [tileset],
|
|
77
|
+
layers: [ground, walls],
|
|
78
|
+
objectLayers: [
|
|
79
|
+
new ObjectLayer({
|
|
80
|
+
id: 3,
|
|
81
|
+
name: 'Markers',
|
|
82
|
+
objects: [
|
|
83
|
+
{
|
|
84
|
+
...wholeTile,
|
|
85
|
+
name: 'spawn',
|
|
86
|
+
type: 'spawn',
|
|
87
|
+
kind: ObjectKind.Point,
|
|
88
|
+
x: (spawn.column + 0.5) * TILE,
|
|
89
|
+
y: (spawn.row + 0.5) * TILE,
|
|
90
|
+
width: 0,
|
|
91
|
+
height: 0,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
}),
|
|
95
|
+
],
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
73
98
|
}
|
|
74
99
|
}
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TileMapNode } from '@codexo/exojs-tiled';
|
|
3
|
-
import type { TileMap } from '@codexo/exojs-tilemap';
|
|
1
|
+
import type { TileMap } from '@codexo/exojs/tilemap';
|
|
4
2
|
|
|
5
3
|
import { TopDownScene } from './TopDownScene';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
|
-
* The
|
|
9
|
-
* in code.
|
|
6
|
+
* The level loaded from `public/assets/town-square.tmj`, edited in Tiled.
|
|
10
7
|
*
|
|
11
|
-
* `
|
|
12
|
-
*
|
|
8
|
+
* `{ type: 'tileMap', source: url }` parses the Tiled source and converts it to the
|
|
9
|
+
* runtime `TileMap`, tileset collision shapes and tile properties included.
|
|
13
10
|
* The tileset image is resolved relative to the map file, so both live in
|
|
14
|
-
* `public/assets/`.
|
|
11
|
+
* `public/assets/`. The map belongs to this scene's loader and is released
|
|
12
|
+
* with the scene.
|
|
15
13
|
*
|
|
16
14
|
* `tiledExtension` has to be registered on the Application for this asset type
|
|
17
15
|
* to exist - see `main.ts`.
|
|
18
16
|
*/
|
|
19
17
|
export class TiledMapScene extends TopDownScene {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
protected override async loadMap(): Promise<void> {
|
|
23
|
-
this._map = await this.loader.load(Asset.type('tileMap', 'town-square.tmj'));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
protected override buildMap(): Container {
|
|
27
|
-
const container = new Container();
|
|
28
|
-
|
|
29
|
-
container.addChild(new TileMapNode(this._map));
|
|
30
|
-
|
|
31
|
-
return container;
|
|
18
|
+
protected override async loadMap(): Promise<TileMap> {
|
|
19
|
+
return await this.loader.load({ type: 'tileMap', source: 'town-square.tmj' });
|
|
32
20
|
}
|
|
33
21
|
}
|