A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
test(gameplay): the level is played from cold boot to victory, on its own facts
esengine0f4833539dae
diff --git a/examples/third-person-3d/assets/scenes/main.esscene b/examples/third-person-3d/assets/scenes/main.essceneindex 2a0a32181..1c29c4231 100644--- a/examples/third-person-3d/assets/scenes/main.esscene+++ b/examples/third-person-3d/assets/scenes/main.esscene@@ -1593,7 +1593,7 @@{"type": "Reachable","data": {- "radius": 110,+ "radius": 190,"prompt": "take the core"}}@@ -1831,7 +1831,8 @@{"type": "Checkpoint","data": {- "armZ": 200+ "armZ": 200,+ "id": "start"}}]@@ -1856,7 +1857,8 @@{"type": "Checkpoint","data": {- "armZ": -740+ "armZ": -740,+ "id": "shelf"}}]@@ -1881,7 +1883,8 @@{"type": "Checkpoint","data": {- "armZ": -1120+ "armZ": -1120,+ "id": "gap"}}]@@ -1906,7 +1909,8 @@{"type": "Checkpoint","data": {- "armZ": -1820+ "armZ": -1820,+ "id": "bridge"}}]@@ -1931,7 +1935,8 @@{"type": "Checkpoint","data": {- "armZ": -2850+ "armZ": -2850,+ "id": "plaza"}}]@@ -4857,4 +4862,4 @@]}]-}\ No newline at end of file+}diff --git a/examples/third-person-3d/playthrough.json b/examples/third-person-3d/playthrough.jsonindex 2c91c5763..e2f48f8d0 100644--- a/examples/third-person-3d/playthrough.json+++ b/examples/third-person-3d/playthrough.json@@ -1,20 +1,57 @@{- "name": "third-person \u2014 the facts a run states about itself",+ "name": "third-person \u2014 cold boot to victory, on the game's own facts",+ "diagnose": [+ "Player",+ "CoreA",+ "CoreB",+ "CoreC",+ "Gate"+ ],"legs": [{"area": "main","until": {"phase": "playing","health": 100,- "dead": false+ "coresCollected": 0,+ "gateOpen": false},"timeout": 300},{"area": "main","keys": [- "KeyD"+ "KeyW"+ ],+ "until": {+ "checkpoint": "shelf"+ },+ "timeout": 900+ },+ {+ "area": "main",+ "keys": [+ "KeyW"],+ "until": {+ "checkpoint": "bridge"+ },+ "timeout": 1200+ },+ {+ "area": "main",+ "keys": [+ "KeyW"+ ],+ "until": {+ "health": {+ "atMost": 99+ }+ },+ "timeout": 900+ },+ {+ "area": "main","until": {"dead": true,"health": 0@@ -46,6 +83,104 @@"paused": false},"timeout": 600+ },+ {+ "area": "main",+ "keys": [+ "KeyW"+ ],+ "tap": "KeyE",+ "until": {+ "coresCollected": 1,+ "gateOpen": false+ },+ "timeout": 2000+ },+ {+ "area": "main",+ "keys": [+ "KeyD"+ ],+ "hold": 85+ },+ {+ "area": "main",+ "keys": [+ "KeyW"+ ],+ "tap": "KeyE",+ "until": {+ "coresCollected": 2,+ "gateOpen": false+ },+ "timeout": 90+ },+ {+ "area": "main",+ "keys": [+ "KeyA"+ ],+ "hold": 85+ },+ {+ "area": "main",+ "keys": [+ "KeyW"+ ],+ "tap": "KeyE",+ "hold": 24+ },+ {+ "area": "main",+ "expect": {+ "gateOpen": false,+ "phase": "playing",+ "coresCollected": 2+ }+ },+ {+ "area": "main",+ "keys": [+ "KeyS"+ ],+ "hold": 40+ },+ {+ "area": "main",+ "keys": [+ "KeyA"+ ],+ "hold": 75+ },+ {+ "area": "main",+ "keys": [+ "KeyS"+ ],+ "tap": "KeyE",+ "until": {+ "coresCollected": 3+ },+ "timeout": 110+ },+ {+ "area": "main",+ "keys": [+ "KeyD"+ ],+ "hold": 75+ },+ {+ "area": "main",+ "keys": [+ "KeyW"+ ],+ "tap": "KeyE",+ "until": {+ "phase": "won",+ "gateOpen": true+ },+ "timeout": 140}]}diff --git a/examples/third-person-3d/src/components.ts b/examples/third-person-3d/src/components.tsindex 70112be48..72be35c85 100644--- a/examples/third-person-3d/src/components.ts+++ b/examples/third-person-3d/src/components.ts@@ -33,6 +33,9 @@ export const Checkpoint = defineComponent('Checkpoint', {/** Z the runner must reach for this to become the one it returns to. */armZ: 0,reached: false,+ /** What this place is called, for anything outside the game that has to name+ * it. A stable id and not an entity: re-serialising a scene renumbers one. */+ id: '',});export const HealthMeter = defineTag('HealthMeter');diff --git a/examples/third-person-3d/src/resources.ts b/examples/third-person-3d/src/resources.tsindex da2a0d8cd..477cc2f36 100644--- a/examples/third-person-3d/src/resources.ts+++ b/examples/third-person-3d/src/resources.ts@@ -20,6 +20,8 @@ export interface RunData {elapsed: number;/** Where the next death returns the runner to. */respawn: { x: number; y: number; z: number };+ /** Which checkpoint that is, by name. Empty until one is armed. */+ checkpoint: string;/** What the runner may press E on this frame, and what that would do. */prompt: string;/** Set by input, consumed by the lifecycle: one edge per press. */@@ -33,6 +35,7 @@ export const Run = defineResource<RunData>({cores: 0,elapsed: 0,respawn: { ...SPAWN },+ checkpoint: '',prompt: '',restartPressed: false,pausePressed: false,diff --git a/examples/third-person-3d/src/systems/hud.ts b/examples/third-person-3d/src/systems/hud.tsindex 78221e352..4e2dc6e82 100644--- a/examples/third-person-3d/src/systems/hud.ts+++ b/examples/third-person-3d/src/systems/hud.ts@@ -2,7 +2,7 @@ import {defineSystem, Res, ResMut, Query, Mut,Text, UIVisual, Health, Playthrough, type PlaythroughData,} from 'esengine';-import { Runner, HealthMeter, ObjectiveText, PromptText, OverlayText } from '../components';+import { Runner, Gate, HealthMeter, ObjectiveText, PromptText, OverlayText } from '../components';import { Run, MAX_HEALTH, CORES_NEEDED, type RunData } from '../resources';const clock = (seconds: number): string => {@@ -67,22 +67,24 @@ export const openingSystem = defineSystem(* judged on, published by the game that owns them.*/export const factsSystem = defineSystem(- [Res(Run), Query(Health, Runner), ResMut(Playthrough)],- (run: RunData, runners, factsMut) => {+ [Res(Run), Query(Health, Runner), Query(Gate), ResMut(Playthrough)],+ (run: RunData, runners, gates, factsMut) => {let health = 0;for (const [, hp] of runners) health = hp.current;+ let gateOpen = false;+ for (const [, gate] of gates) gateOpen = gateOpen || gate.open;const out = factsMut.get() as PlaythroughData;+ // `phase` is the authority on what the run IS; nothing here restates it+ // as a second flag. `dead` and `paused` are the two a route stops on.out.facts = {phase: run.phase,health,dead: run.phase === 'dead',paused: run.phase === 'paused',- victory: run.phase === 'won',- cores: run.cores,- coresNeeded: CORES_NEEDED,- gateOpen: run.cores >= CORES_NEEDED,- checkpointZ: run.respawn.z,- elapsed: Math.round(run.elapsed),+ checkpoint: run.checkpoint,+ coresCollected: run.cores,+ coresRequired: CORES_NEEDED,+ gateOpen,};},{ name: 'PlaythroughFactsSystem' },diff --git a/examples/third-person-3d/src/systems/lifecycle.ts b/examples/third-person-3d/src/systems/lifecycle.tsindex 9a6597795..4fba1f556 100644--- a/examples/third-person-3d/src/systems/lifecycle.ts+++ b/examples/third-person-3d/src/systems/lifecycle.ts@@ -53,6 +53,7 @@ export const lifecycleSystem = defineSystem(run.cores = 0;run.elapsed = 0;run.respawn = { ...SPAWN };+ run.checkpoint = '';for (const [, core, mesh] of cores) { core.taken = false; mesh.enabled = true; }for (const [, gate, mesh] of gates) { gate.open = false; mesh.enabled = true; }for (const [, point] of checkpoints) point.reached = false;diff --git a/examples/third-person-3d/src/systems/run.ts b/examples/third-person-3d/src/systems/run.tsindex 3b992d5e9..33dbd5ae6 100644--- a/examples/third-person-3d/src/systems/run.ts+++ b/examples/third-person-3d/src/systems/run.ts@@ -57,6 +57,7 @@ export const progressSystem = defineSystem(if (point.reached || z > point.armZ) continue;point.reached = true;run.respawn = { x: at.position.x, y: at.position.y, z: at.position.z };+ run.checkpoint = point.id;}}},