Skip to content

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.

feat(game): the Spire, and the thing waiting at the top of it

esengine805314d6a81c
diff --git a/examples/celestial-heights/assets/ai/vesper.esbt b/examples/celestial-heights/assets/ai/vesper.esbt
new file mode 100644
index 000000000..a7d7e5a9e
--- /dev/null
+++ b/examples/celestial-heights/assets/ai/vesper.esbt
@@ -0,0 +1,61 @@
+{
+ "root": {
+ "type": "selector",
+ "id": "n0",
+ "x": 60,
+ "y": 240,
+ "children": [
+ {
+ "type": "sequence",
+ "id": "n1",
+ "x": 300,
+ "y": 40,
+ "children": [
+ { "type": "condition", "id": "n2", "name": "isCharging", "x": 560, "y": 0 },
+ { "type": "action", "id": "n3", "name": "charge", "x": 560, "y": 80 }
+ ]
+ },
+ {
+ "type": "sequence",
+ "id": "n4",
+ "x": 300,
+ "y": 140,
+ "children": [
+ { "type": "condition", "id": "n5", "name": "canSummon", "x": 560, "y": 100 },
+ { "type": "action", "id": "n6", "name": "summon", "x": 560, "y": 180 }
+ ]
+ },
+ {
+ "type": "sequence",
+ "id": "n7",
+ "x": 300,
+ "y": 240,
+ "children": [
+ { "type": "condition", "id": "n8", "name": "canCharge", "x": 560, "y": 200 },
+ { "type": "action", "id": "n9", "name": "charge", "x": 560, "y": 280 }
+ ]
+ },
+ {
+ "type": "sequence",
+ "id": "n10",
+ "x": 300,
+ "y": 340,
+ "children": [
+ { "type": "condition", "id": "n11", "name": "inStrikeRange", "x": 560, "y": 300 },
+ { "type": "action", "id": "n12", "name": "strike", "x": 560, "y": 380 }
+ ]
+ },
+ {
+ "type": "sequence",
+ "id": "n13",
+ "x": 300,
+ "y": 440,
+ "children": [
+ { "type": "condition", "id": "n14", "name": "seesPlayer", "x": 560, "y": 400 },
+ { "type": "action", "id": "n15", "name": "chase", "x": 560, "y": 480 }
+ ]
+ },
+ { "type": "action", "id": "n16", "name": "hover", "x": 300, "y": 540 }
+ ]
+ }
+}
diff --git a/examples/celestial-heights/assets/ai/vesper.esbt.meta b/examples/celestial-heights/assets/ai/vesper.esbt.meta
new file mode 100644
index 000000000..b2ecd6ab5
--- /dev/null
+++ b/examples/celestial-heights/assets/ai/vesper.esbt.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "94c0a1cf-e395-4ec7-9b19-751223a8fb33",
+ "version": "1.0",
+ "type": "behaviortree",
+ "importer": {
+ "autoMigrate": true
+ }
+}
diff --git a/examples/celestial-heights/assets/i18n/en.eslocale b/examples/celestial-heights/assets/i18n/en.eslocale
index cce5175de..b9a72d643 100644
--- a/examples/celestial-heights/assets/i18n/en.eslocale
+++ b/examples/celestial-heights/assets/i18n/en.eslocale
@@ -12,6 +12,9 @@
"item.ember": "Ember",
"achievement.first-blood": "Unlocked — First Blood",
"achievement.collector": "Unlocked — Collector",
- "achievement.wayfarer": "Unlocked — Wayfarer"
+ "achievement.wayfarer": "Unlocked — Wayfarer",
+ "area.spire": "Spire of Vesper",
+ "boss.vesper": "Vesper of the Waning Moon",
+ "achievement.spire-cleared": "Unlocked — Starfall"
}
}
diff --git a/examples/celestial-heights/assets/i18n/zh-CN.eslocale b/examples/celestial-heights/assets/i18n/zh-CN.eslocale
index 2acfa75a6..05f4dfb23 100644
--- a/examples/celestial-heights/assets/i18n/zh-CN.eslocale
+++ b/examples/celestial-heights/assets/i18n/zh-CN.eslocale
@@ -12,6 +12,9 @@
"item.ember": "余烬",
"achievement.first-blood": "达成——初战告捷",
"achievement.collector": "达成——采集者",
- "achievement.wayfarer": "达成——远行者"
+ "achievement.wayfarer": "达成——远行者",
+ "area.spire": "暮星塔顶",
+ "boss.vesper": "暮星 · 维斯珀",
+ "achievement.spire-cleared": "达成——星陨"
}
}
diff --git a/examples/celestial-heights/assets/prefabs/wisp.esprefab b/examples/celestial-heights/assets/prefabs/wisp.esprefab
new file mode 100644
index 000000000..5c31c4056
--- /dev/null
+++ b/examples/celestial-heights/assets/prefabs/wisp.esprefab
@@ -0,0 +1,192 @@
+{
+ "version": "2",
+ "name": "Wisp",
+ "rootEntityId": "0",
+ "entities": [
+ {
+ "prefabEntityId": "0",
+ "name": "Wisp_called",
+ "parent": null,
+ "children": [
+ "1",
+ "2"
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 64,
+ "y": 96
+ },
+ "color": {
+ "r": 0.412,
+ "g": 0.812,
+ "b": 0.902,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Enemy",
+ "data": {}
+ },
+ {
+ "type": "Facing",
+ "data": {
+ "x": -1,
+ "y": 0
+ }
+ },
+ {
+ "type": "Health",
+ "data": {
+ "current": 45,
+ "max": 45,
+ "invulnerability": 0.2,
+ "invulnerable": 0
+ }
+ },
+ {
+ "type": "MeleeAttack",
+ "data": {
+ "damage": 10,
+ "reach": 76,
+ "arcDegrees": 160,
+ "cooldown": 1.2,
+ "cooldownLeft": 0,
+ "pending": false,
+ "hits": 2
+ }
+ },
+ {
+ "type": "Perceiver",
+ "data": {
+ "range": 520,
+ "fovDegrees": 360
+ }
+ },
+ {
+ "type": "NavAgent",
+ "data": {
+ "speed": 165,
+ "arriveRadius": 48,
+ "repathInterval": 0.4
+ }
+ },
+ {
+ "type": "BehaviorTreeAgent",
+ "data": {
+ "bt": "assets/ai/wisp.esbt"
+ }
+ },
+ {
+ "type": "RigidBody",
+ "data": {
+ "bodyType": 1
+ }
+ },
+ {
+ "type": "CircleCollider",
+ "data": {
+ "radius": 0.26,
+ "offset": {
+ "x": 0,
+ "y": -0.3
+ },
+ "categoryBits": 4,
+ "maskBits": 1
+ }
+ }
+ ]
+ },
+ {
+ "prefabEntityId": "1",
+ "name": "HealthBar_Back",
+ "parent": "0",
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 66,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 76,
+ "y": 12
+ },
+ "color": {
+ "r": 0.078,
+ "g": 0.067,
+ "b": 0.125,
+ "a": 1
+ },
+ "layer": 3
+ }
+ }
+ ]
+ },
+ {
+ "prefabEntityId": "2",
+ "name": "HealthBar_Fill",
+ "parent": "0",
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 66,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 72,
+ "y": 8
+ },
+ "color": {
+ "r": 0.906,
+ "g": 0.353,
+ "b": 0.412,
+ "a": 1
+ },
+ "layer": 3
+ }
+ },
+ {
+ "type": "HealthBarFill",
+ "data": {
+ "width": 72
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/examples/celestial-heights/assets/prefabs/wisp.esprefab.meta b/examples/celestial-heights/assets/prefabs/wisp.esprefab.meta
new file mode 100644
index 000000000..162300b8a
--- /dev/null
+++ b/examples/celestial-heights/assets/prefabs/wisp.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "62f588a9-0052-437f-8338-e1a1219f9dcb",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
diff --git a/examples/celestial-heights/assets/scenes/hud.esscene b/examples/celestial-heights/assets/scenes/hud.esscene
index 4b61d0fb6..ed4f8b897 100644
--- a/examples/celestial-heights/assets/scenes/hud.esscene
+++ b/examples/celestial-heights/assets/scenes/hud.esscene
@@ -10,7 +10,8 @@
"children": [
51,
60,
- 70
+ 70,
+ 80
],
"visible": true,
"components": [
@@ -523,6 +524,200 @@
}
}
]
+ },
+ {
+ "id": 80,
+ "name": "BossPanel",
+ "parent": 50,
+ "children": [
+ 81,
+ 82
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "display": 1,
+ "insetLeft": {
+ "value": 560,
+ "unit": 0
+ },
+ "insetRight": {
+ "value": 560,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 36,
+ "unit": 0
+ },
+ "height": {
+ "value": 70,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "FlexContainer",
+ "data": {
+ "direction": 1,
+ "justifyContent": 0,
+ "alignItems": 0,
+ "gap": {
+ "x": 0,
+ "y": 8
+ }
+ }
+ },
+ {
+ "type": "BossPanel",
+ "data": {}
+ }
+ ]
+ },
+ {
+ "id": 81,
+ "name": "BossName",
+ "parent": 80,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 30,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "Text",
+ "data": {
+ "content": "",
+ "i18nKey": "boss.vesper",
+ "fontSize": 28,
+ "bold": true,
+ "color": {
+ "r": 0.925,
+ "g": 0.906,
+ "b": 0.98,
+ "a": 1
+ },
+ "align": 1,
+ "verticalAlign": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 82,
+ "name": "BossTrack",
+ "parent": 80,
+ "children": [
+ 83
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 24,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 1,
+ "color": {
+ "r": 0.078,
+ "g": 0.067,
+ "b": 0.125,
+ "a": 0.85
+ },
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 83,
+ "name": "BossFill",
+ "parent": 82,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "insetLeft": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetRight": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetBottom": {
+ "value": 0,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 5,
+ "fillMethod": 0,
+ "fillOrigin": 0,
+ "fillAmount": 1,
+ "color": {
+ "r": 0.729,
+ "g": 0.616,
+ "b": 0.949,
+ "a": 1
+ },
+ "enabled": true
+ }
+ },
+ {
+ "type": "BossMeter",
+ "data": {}
+ }
+ ]
}
]
}
diff --git a/examples/celestial-heights/assets/scenes/main.esscene b/examples/celestial-heights/assets/scenes/main.esscene
index fa04ee322..748117599 100644
--- a/examples/celestial-heights/assets/scenes/main.esscene
+++ b/examples/celestial-heights/assets/scenes/main.esscene
@@ -629,7 +629,7 @@
"position": {
"x": 0,
"y": 66,
- "z": 0
+ "z": 1
}
}
},
@@ -817,7 +817,7 @@
"position": {
"x": 0,
"y": 66,
- "z": 0
+ "z": 1
}
}
},
@@ -1005,7 +1005,7 @@
"position": {
"x": 0,
"y": 66,
- "z": 0
+ "z": 1
}
}
},
diff --git a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
index 95d1a048c..41c3b0608 100644
--- a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
+++ b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
@@ -129,7 +129,7 @@
{
"type": "Gate",
"data": {
- "toScene": "main",
+ "toScene": "spire",
"radius": 90
}
}
@@ -545,7 +545,7 @@
"position": {
"x": 0,
"y": 66,
- "z": 0
+ "z": 1
}
}
},
@@ -733,7 +733,7 @@
"position": {
"x": 0,
"y": 66,
- "z": 0
+ "z": 1
}
}
},
@@ -775,6 +775,49 @@
}
}
]
+ },
+ {
+ "id": 41,
+ "name": "Gate_back",
+ "parent": null,
+ "children": [],
+ "folder": "Environment",
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -960,
+ "y": -32,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 72,
+ "y": 132
+ },
+ "color": {
+ "r": 0.545,
+ "g": 0.902,
+ "b": 0.918,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Gate",
+ "data": {
+ "toScene": "main",
+ "radius": 90
+ }
+ }
+ ]
}
]
}
diff --git a/examples/celestial-heights/assets/scenes/spire.esscene b/examples/celestial-heights/assets/scenes/spire.esscene
new file mode 100644
index 000000000..eb634d938
--- /dev/null
+++ b/examples/celestial-heights/assets/scenes/spire.esscene
@@ -0,0 +1,635 @@
+{
+ "version": "1.0",
+ "name": "spire",
+ "folders": [
+ "Environment",
+ "Actors"
+ ],
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -1248,
+ "y": 32,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 540,
+ "isActive": true,
+ "priority": 0
+ }
+ },
+ {
+ "type": "FollowTarget",
+ "data": {
+ "target": -1,
+ "offsetX": 0,
+ "offsetY": 0,
+ "deadzone": 40,
+ "damping": 0.18
+ }
+ },
+ {
+ "type": "CameraBounds",
+ "data": {
+ "minX": -1536,
+ "minY": -1024,
+ "maxX": 1536,
+ "maxY": 1024
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Terrain",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "folder": "Environment",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -1536,
+ "y": 1024,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "TilemapLayer",
+ "data": {
+ "cellSize": {
+ "x": 64,
+ "y": 64
+ },
+ "renderLayer": 0,
+ "opacity": 1,
+ "visible": true,
+ "tilesetAsset": "@uuid:cf5ed115-8369-48af-bbd1-163efd25c1aa",
+ "collidableTileIds": [
+ 4,
+ 5,
+ 6
+ ],
+ "chunks": "RVNUTQYAAAAAAAAAAAAAAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAEAAQAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAQAAAAAAAAAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAgACAAIAAgAEAAQAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYAAgACAAYABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAwADAAMAAgACAAIAAgACAAIAAgACAAIAAgACAAMAAwADAAMAAwACAAIAAgACAAIAAgACAAIAAgACAAMAAwADAAMAAwADAAIAAgACAAIAAgACAAIAAgACAAMAAwADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAMAAwADAAMAAwADAAMAAwACAAIAAgACAAIAAgACAAIAAwADAAMAAwADAAMAAwADAAIAAAAAAAAABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAGAAIAAgACAAIAAgACAAIAAgACAAQAAgACAAIAAgACAAYABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAYAAgACAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAYABgACAAIABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgADAAMAAwACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAMAAwADAAMAAwACAAIAAgACAAIAAgACAAIAAgACAAYAAwADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAIABgADAAMAAwADAAMAAwADAAIAAgACAAIAAgACAAIAAgAGAAMAAwADAAMAAwADAAMAAwACAAIAAgACAAIAAgACAAYAAwADAAMAAwADAAMAAwADAAIAAgACAAIAAgACAAIABgAAAAAAAQAAAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAgACAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgACAAIABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAQABAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAAQAAAAEAAAACAAIAAgACAAIAAgACAAIAAwADAAMAAwADAAMAAwADAAIAAgACAAIAAgACAAIAAgADAAMAAwADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAIAAwADAAMAAwADAAMAAwACAAIAAgACAAIAAgACAAIAAgACAAMAAwADAAMAAwADAAIAAgACAAIAAgACAAIAAgACAAIAAgADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgADAAMAAwACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIABAAEAAIAAgACAAIAAgACAAIAAgACAAYAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAIAAAABAAAAAwADAAMAAwADAAMAAwADAAIAAgACAAIAAgACAAIABgADAAMAAwADAAMAAwADAAMAAgACAAIAAgACAAIAAgAGAAMAAwADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAYAAwADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAIABgADAAMAAwADAAMAAgACAAIAAgACAAIAAgACAAIAAgAGAAMAAwADAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAYAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgACAAIAAgACAAIAAgACAAIAAgACAAIABgAGAAIAAgAGAAIAAgACAAIAAgACAAIAAgACAAIAAgAGAAYAAgACAAYABgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIABgAGAAIAAgACAAIAAgACAAIAAgAEAAIAAgACAAIAAgAGAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgA"
+ }
+ }
+ ]
+ },
+ {
+ "id": 90,
+ "name": "Area",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Area",
+ "data": {
+ "nameKey": "area.spire"
+ }
+ }
+ ]
+ },
+ {
+ "id": 40,
+ "name": "Gate",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "folder": "Environment",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -1440,
+ "y": 32,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 72,
+ "y": 132
+ },
+ "color": {
+ "r": 0.545,
+ "g": 0.902,
+ "b": 0.918,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Gate",
+ "data": {
+ "toScene": "moonlit-gallery",
+ "radius": 90
+ }
+ }
+ ]
+ },
+ {
+ "id": 80,
+ "name": "Pickup_shard_7",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "folder": "Environment",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -928,
+ "y": 32,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 44,
+ "y": 44
+ },
+ "color": {
+ "r": 0.545,
+ "g": 0.902,
+ "b": 0.918,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Item",
+ "data": {
+ "kind": "shard"
+ }
+ }
+ ]
+ },
+ {
+ "id": 81,
+ "name": "Pickup_ember_8",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "folder": "Environment",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -224,
+ "y": -544,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 44,
+ "y": 44
+ },
+ "color": {
+ "r": 0.976,
+ "g": 0.706,
+ "b": 0.376,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Item",
+ "data": {
+ "kind": "ember"
+ }
+ }
+ ]
+ },
+ {
+ "id": 45,
+ "name": "SparkEmitter",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "folder": "Environment",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "ParticleEmitter",
+ "data": {
+ "texture": "@uuid:a036a9cb-e792-40bf-8f6f-9a31b65889a7",
+ "shape": 1,
+ "shapeRadius": 10,
+ "rate": 0,
+ "burstCount": 36,
+ "burstInterval": 0,
+ "duration": 0.06,
+ "looping": false,
+ "playOnStart": false,
+ "maxParticles": 96,
+ "lifetimeMin": 0.4,
+ "lifetimeMax": 0.7,
+ "speedMin": 240,
+ "speedMax": 460,
+ "startSizeMin": 30,
+ "startSizeMax": 52,
+ "endSizeMin": 0,
+ "endSizeMax": 6,
+ "startColor": {
+ "r": 1,
+ "g": 0.86,
+ "b": 0.62,
+ "a": 1
+ },
+ "endColor": {
+ "r": 0.98,
+ "g": 0.35,
+ "b": 0.42,
+ "a": 0
+ },
+ "gravity": {
+ "x": 0,
+ "y": -260
+ },
+ "damping": 1.6,
+ "layer": 4,
+ "blendMode": 1,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 20,
+ "name": "Lyra_Player",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "folder": "Actors",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -1248,
+ "y": 32,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 84,
+ "y": 150
+ },
+ "color": {
+ "r": 0.855,
+ "g": 0.788,
+ "b": 0.976,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Player",
+ "data": {
+ "speed": 380
+ }
+ },
+ {
+ "type": "Facing",
+ "data": {
+ "x": 1,
+ "y": 0
+ }
+ },
+ {
+ "type": "Health",
+ "data": {
+ "current": 120,
+ "max": 120,
+ "invulnerability": 0.5,
+ "invulnerable": 0
+ }
+ },
+ {
+ "type": "MeleeAttack",
+ "data": {
+ "damage": 30,
+ "reach": 110,
+ "arcDegrees": 120,
+ "cooldown": 0.4,
+ "cooldownLeft": 0,
+ "pending": false,
+ "hits": 4
+ }
+ },
+ {
+ "type": "PerceptionTarget",
+ "data": {}
+ },
+ {
+ "type": "RigidBody",
+ "data": {
+ "bodyType": 1
+ }
+ },
+ {
+ "type": "CircleCollider",
+ "data": {
+ "radius": 0.3,
+ "offset": {
+ "x": 0,
+ "y": -0.5
+ },
+ "categoryBits": 2,
+ "maskBits": 1
+ }
+ },
+ {
+ "type": "CharacterController",
+ "data": {
+ "up": {
+ "x": 0,
+ "y": 1
+ },
+ "snapLength": 0,
+ "maskBits": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 50,
+ "name": "Vesper",
+ "parent": null,
+ "children": [
+ 500,
+ 501
+ ],
+ "visible": true,
+ "folder": "Actors",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 480,
+ "y": 32,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 132,
+ "y": 196
+ },
+ "color": {
+ "r": 0.729,
+ "g": 0.616,
+ "b": 0.949,
+ "a": 1
+ },
+ "layer": 2
+ }
+ },
+ {
+ "type": "Enemy",
+ "data": {}
+ },
+ {
+ "type": "Boss",
+ "data": {
+ "phase": 0
+ }
+ },
+ {
+ "type": "Facing",
+ "data": {
+ "x": -1,
+ "y": 0
+ }
+ },
+ {
+ "type": "Health",
+ "data": {
+ "current": 480,
+ "max": 480,
+ "invulnerability": 0.12,
+ "invulnerable": 0
+ }
+ },
+ {
+ "type": "MeleeAttack",
+ "data": {
+ "damage": 20,
+ "reach": 150,
+ "arcDegrees": 150,
+ "cooldown": 1.1,
+ "cooldownLeft": 0,
+ "pending": false,
+ "hits": 2
+ }
+ },
+ {
+ "type": "Perceiver",
+ "data": {
+ "range": 1100,
+ "fovDegrees": 360
+ }
+ },
+ {
+ "type": "NavAgent",
+ "data": {
+ "speed": 175,
+ "arriveRadius": 96,
+ "repathInterval": 0.35
+ }
+ },
+ {
+ "type": "BehaviorTreeAgent",
+ "data": {
+ "bt": "assets/ai/vesper.esbt"
+ }
+ },
+ {
+ "type": "Summoner",
+ "data": {
+ "cooldown": 9,
+ "cooldownLeft": 3,
+ "pending": false,
+ "remaining": 3,
+ "count": 2,
+ "prefab": "assets/prefabs/wisp.esprefab"
+ }
+ },
+ {
+ "type": "Charge",
+ "data": {
+ "cooldown": 6,
+ "cooldownLeft": 4,
+ "pending": false,
+ "windup": 0.7,
+ "dashSpeed": 900,
+ "dashTime": 0.55,
+ "state": 0,
+ "timer": 0,
+ "dirX": 0,
+ "dirY": 0
+ }
+ },
+ {
+ "type": "RigidBody",
+ "data": {
+ "bodyType": 1
+ }
+ },
+ {
+ "type": "CircleCollider",
+ "data": {
+ "radius": 0.42,
+ "offset": {
+ "x": 0,
+ "y": -0.5
+ },
+ "categoryBits": 4,
+ "maskBits": 1
+ }
+ },
+ {
+ "type": "CharacterController",
+ "data": {
+ "up": {
+ "x": 0,
+ "y": 1
+ },
+ "snapLength": 0,
+ "maskBits": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 500,
+ "name": "HealthBar_Back",
+ "parent": 50,
+ "children": [],
+ "visible": true,
+ "folder": "Actors",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 112,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 112,
+ "y": 14
+ },
+ "color": {
+ "r": 0.078,
+ "g": 0.067,
+ "b": 0.125,
+ "a": 1
+ },
+ "layer": 3
+ }
+ }
+ ]
+ },
+ {
+ "id": 501,
+ "name": "HealthBar_Fill",
+ "parent": 50,
+ "children": [],
+ "visible": true,
+ "folder": "Actors",
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 112,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 108,
+ "y": 10
+ },
+ "color": {
+ "r": 0.906,
+ "g": 0.353,
+ "b": 0.412,
+ "a": 1
+ },
+ "layer": 3
+ }
+ },
+ {
+ "type": "HealthBarFill",
+ "data": {
+ "width": 108
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/examples/celestial-heights/assets/scenes/spire.esscene.meta b/examples/celestial-heights/assets/scenes/spire.esscene.meta
new file mode 100644
index 000000000..2059895ad
--- /dev/null
+++ b/examples/celestial-heights/assets/scenes/spire.esscene.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "610432c8-7c97-440e-bf24-b3443a816b0b",
+ "version": "2.0",
+ "type": "scene",
+ "importer": {
+ "autoMigrate": true
+ }
+}
diff --git a/examples/celestial-heights/project.esproject b/examples/celestial-heights/project.esproject
index 2ff4040e1..815634b30 100644
--- a/examples/celestial-heights/project.esproject
+++ b/examples/celestial-heights/project.esproject
@@ -40,7 +40,8 @@
"achievements": [
"first-blood",
"collector",
- "wayfarer"
+ "wayfarer",
+ "spire-cleared"
]
}
}
diff --git a/examples/celestial-heights/src/ai/vesper.ts b/examples/celestial-heights/src/ai/vesper.ts
new file mode 100644
index 000000000..e032234f7
--- /dev/null
+++ b/examples/celestial-heights/src/ai/vesper.ts
@@ -0,0 +1,38 @@
+import { registerAction, registerCondition, Perception, Status } from 'esengine';
+import { Boss, Charge, Summoner } from '../components';
+
+// Leaves for assets/ai/vesper.esbt. Vesper reuses the wisps' vocabulary for
+// seeing, closing and striking — a boss is not a second combat system — and
+// adds only what a boss does that a wisp cannot.
+
+registerCondition('canSummon', (ctx) => {
+ if (!ctx.has(Boss) || !ctx.has(Summoner)) return false;
+ const summoner = ctx.get(Summoner);
+ return ctx.get(Boss).phase >= 1 && summoner.remaining > 0 && summoner.cooldownLeft <= 0;
+});
+
+registerAction('summon', (ctx) => {
+ if (!ctx.has(Summoner)) return Status.Failure;
+ ctx.set(Summoner, { ...ctx.get(Summoner), pending: true });
+ return Status.Success;
+});
+
+registerCondition('canCharge', (ctx) => {
+ if (!ctx.has(Boss) || !ctx.has(Charge) || !ctx.has(Perception)) return false;
+ const charge = ctx.get(Charge);
+ // Too close and the wind-up is unreadable — the charge is a way to cover
+ // ground, not a second melee.
+ return ctx.get(Boss).phase >= 2 && charge.cooldownLeft <= 0 && charge.state === 0
+ && ctx.get(Perception).visible && ctx.get(Perception).distance > 260;
+});
+
+registerAction('charge', (ctx) => {
+ if (!ctx.has(Charge)) return Status.Failure;
+ const charge = ctx.get(Charge);
+ if (charge.state !== 0) return Status.Running;
+ ctx.set(Charge, { ...charge, pending: true });
+ return Status.Running;
+});
+
+/** True while a charge is winding up or crossing, so nothing else takes the turn. */
+registerCondition('isCharging', (ctx) => ctx.has(Charge) && ctx.get(Charge).state !== 0);
diff --git a/examples/celestial-heights/src/components.ts b/examples/celestial-heights/src/components.ts
index 680cebd32..9c76fd591 100644
--- a/examples/celestial-heights/src/components.ts
+++ b/examples/celestial-heights/src/components.ts
@@ -12,6 +12,49 @@ export const Player = defineComponent('Player', {
/** Anything the player fights. */
export const Enemy = defineTag('Enemy');
+/**
+ * The one enemy a run ends on. `phase` is written from its health rather than
+ * by whatever last hit it, so the brain, the HUD bar and the arena all read the
+ * same number and a reloaded fight resumes in the phase the health says.
+ */
+export const Boss = defineComponent('Boss', {
+ phase: 0,
+});
+
+/**
+ * Calls help. Like every other attack in this game the brain only sets
+ * `pending`; a system with the prefab server does the spawning, because a
+ * behaviour tree decides and does not reach for engine resources.
+ */
+export const Summoner = defineComponent('Summoner', {
+ prefab: '',
+ /** How many arrive per call. */
+ count: 2,
+ /** Calls left in the fight — help is a phase, not an attrition strategy. */
+ remaining: 3,
+ cooldown: 9,
+ cooldownLeft: 0,
+ pending: false,
+});
+
+/**
+ * A telegraphed charge: wind up in place, then cross the arena. `state` is
+ * 0 idle / 1 winding up / 2 dashing — the wind-up is what makes it dodgeable
+ * rather than an unfair teleport.
+ */
+export const Charge = defineComponent('Charge', {
+ windup: 0.7,
+ dashSpeed: 900,
+ dashTime: 0.55,
+ cooldown: 6,
+ cooldownLeft: 0,
+ pending: false,
+ state: 0,
+ timer: 0,
+ dirX: 0,
+ dirY: 0,
+});
+
/**
* What an area says about itself. Every area scene carries exactly one, which is
* how the shared HUD — a scene of its own, loaded once and never swapped — can
@@ -39,6 +82,12 @@ export const VitalityMeter = defineTag('VitalityMeter');
/** The panel shown while the game is paused. */
export const PauseOverlay = defineTag('PauseOverlay');
+/** The HUD's boss bar: shown only while there is a boss to report on. */
+export const BossPanel = defineTag('BossPanel');
+
+/** The filled part of that bar. */
+export const BossMeter = defineTag('BossMeter');
+
/** The HUD line that announces an unlock, since no local store draws one. */
export const AchievementToast = defineTag('AchievementToast');
diff --git a/examples/celestial-heights/src/main.ts b/examples/celestial-heights/src/main.ts
index 06a55a7e1..f78fdb3f3 100644
--- a/examples/celestial-heights/src/main.ts
+++ b/examples/celestial-heights/src/main.ts
@@ -9,7 +9,10 @@ import { playerMoveSystem, playerAttackSystem } from './systems/player';
import {
meleeResolveSystem, damageSystem, invulnerabilitySystem, deathSystem,
} from './systems/combat';
-import { healthBarSystem, hitFlashSystem, vitalityMeterSystem } from './systems/feedback';
+import {
+ healthBarSystem, hitFlashSystem, vitalityMeterSystem, bossMeterSystem,
+} from './systems/feedback';
+import { bossPhaseSystem, summonSystem, chargeSystem } from './systems/boss';
import {
cameraBindSystem, navFromTerrainSystem, gateSystem, hudSystem, areaLabelSystem,
} from './systems/world';
@@ -24,6 +27,7 @@ import {
import { achievementSystem, achievementToastSystem } from './systems/achievements';
import { hitSparkSystem } from './systems/spark';
import { perceiverFacingSystem } from './ai/wisp';
+import './ai/vesper';
// Perception, nav following, the behaviour-tree tick and scene switching are
// engine plugins, and the runtime already knows every .esscene the package
@@ -44,7 +48,10 @@ addSystemToSchedule(Schedule.PreUpdate, inventoryBuildSystem);
// Everything the pause freezes says so once, as a set with one run condition,
// rather than the same paused check written into eight systems.
addSystemSetToSchedule(Schedule.Update, defineSystemSet('gameplay', {
- systems: [playerMoveSystem, playerAttackSystem, perceiverFacingSystem, gateSystem, pickupSystem],
+ systems: [
+ playerMoveSystem, playerAttackSystem, perceiverFacingSystem, gateSystem, pickupSystem,
+ bossPhaseSystem, summonSystem, chargeSystem,
+ ],
runIf: () => !session.paused,
}));
@@ -66,6 +73,7 @@ addSystemToSchedule(Schedule.Update, inventoryInputSystem);
addSystemToSchedule(Schedule.PostUpdate, pauseOverlaySystem);
addSystemToSchedule(Schedule.PostUpdate, healthBarSystem);
addSystemToSchedule(Schedule.PostUpdate, vitalityMeterSystem);
+addSystemToSchedule(Schedule.PostUpdate, bossMeterSystem);
addSystemToSchedule(Schedule.PostUpdate, hitFlashSystem);
addSystemToSchedule(Schedule.PostUpdate, inventorySyncSystem);
addSystemToSchedule(Schedule.PostUpdate, achievementSystem);
diff --git a/examples/celestial-heights/src/systems/achievements.ts b/examples/celestial-heights/src/systems/achievements.ts
index 4ea2b5832..ac88ea286 100644
--- a/examples/celestial-heights/src/systems/achievements.ts
+++ b/examples/celestial-heights/src/systems/achievements.ts
@@ -1,8 +1,8 @@
import {
defineSystem, Query, Mut, Res, EventReader, Achievements, SceneManager,
- Time, Text, UINode, UIDisplay, Localization,
+ Time, Text, UINode, UIDisplay, Localization, GetWorld,
} from 'esengine';
-import { Item, AchievementToast } from '../components';
+import { Boss, Item, AchievementToast } from '../components';
import { Died } from '../events';
import { session } from '../state';
@@ -14,22 +14,25 @@ import { session } from '../state';
export const FIRST_BLOOD = 'first-blood';
export const COLLECTOR = 'collector';
export const WAYFARER = 'wayfarer';
+export const SPIRE_CLEARED = 'spire-cleared';
/** How many distinct kinds count as having collected. */
const KINDS_FOR_COLLECTOR = 3;
/** Ids in the order they are announced, so a toast names what just happened. */
-const ALL = [FIRST_BLOOD, COLLECTOR, WAYFARER];
+const ALL = [FIRST_BLOOD, COLLECTOR, WAYFARER, SPIRE_CLEARED];
const seen = new Set<string>();
let toast = { id: '', left: 0 };
export const achievementSystem = defineSystem(
- [EventReader(Died), Query(Item), Res(Achievements), Res(SceneManager)],
- (deaths, _items, achievements, scenes) => {
+ [EventReader(Died), Query(Item), Res(Achievements), Res(SceneManager), GetWorld()],
+ (deaths, _items, achievements, scenes, world) => {
for (const death of deaths) {
if (!death.isPlayer) {
void achievements.unlock(FIRST_BLOOD);
- break;
+ // Vesper is despawned with every other enemy, so the death event
+ // is the last frame anything can be asked about her.
+ if (world.has(death.entity, Boss)) void achievements.unlock(SPIRE_CLEARED);
}
}
const kinds = Object.values(session.inventory).filter((n) => n > 0).length;
diff --git a/examples/celestial-heights/src/systems/boss.ts b/examples/celestial-heights/src/systems/boss.ts
new file mode 100644
index 000000000..52d94afdd
--- /dev/null
+++ b/examples/celestial-heights/src/systems/boss.ts
@@ -0,0 +1,126 @@
+import {
+ defineSystem, Query, Mut, Res, GetWorld,
+ Transform, CharacterController, Prefabs, Time, Perception,
+ NavAgent, setNavDestination, stopNavAgent,
+} from 'esengine';
+import type { Entity } from 'esengine';
+import { Boss, Charge, Facing, Health, Summoner } from '../components';
+
+/**
+ * Vesper's phase, read off her health. Deriving it rather than advancing it on
+ * an event means a reloaded fight resumes where the health says it is, and the
+ * brain, the HUD bar and this system never disagree about which fight is on.
+ */
+export const bossPhaseSystem = defineSystem(
+ [Query(Mut(Boss), Health)],
+ (bosses) => {
+ for (const [, boss, health] of bosses) {
+ const fraction = health.max > 0 ? health.current / health.max : 0;
+ boss.phase = fraction <= 0.35 ? 2 : fraction <= 0.7 ? 1 : 0;
+ }
+ },
+ { name: 'BossPhaseSystem' },
+);
+
+/** How far from Vesper the called wisps arrive. */
+const SUMMON_RADIUS = 190;
+
+/**
+ * Turns a pending call into wisps. The prefab is instantiated through the
+ * engine's prefab server, so a called wisp is the same wisp the areas author —
+ * one description, whether it was placed or asked for.
+ */
+export const summonSystem = defineSystem(
+ [Query(Transform, Mut(Summoner)), Res(Prefabs), Res(Time)],
+ (summoners, prefabs, time) => {
+ for (const [, transform, summoner] of summoners) {
+ if (summoner.cooldownLeft > 0) summoner.cooldownLeft -= time.delta;
+ if (!summoner.pending) continue;
+ summoner.pending = false;
+ if (summoner.remaining <= 0 || summoner.cooldownLeft > 0 || !summoner.prefab) continue;
+ summoner.remaining -= 1;
+ summoner.cooldownLeft = summoner.cooldown;
+
+ const origin = { x: transform.position.x, y: transform.position.y };
+ for (let i = 0; i < summoner.count; i++) {
+ const angle = (Math.PI * 2 * i) / summoner.count + Math.PI / 4;
+ void prefabs.instantiate(summoner.prefab, {
+ overrides: [{
+ type: 'property',
+ componentType: 'Transform',
+ propertyName: 'position',
+ value: {
+ x: origin.x + Math.cos(angle) * SUMMON_RADIUS,
+ y: origin.y + Math.sin(angle) * SUMMON_RADIUS * 0.6,
+ z: 0,
+ },
+ }],
+ });
+ }
+ }
+ },
+ { name: 'SummonSystem' },
+);
+
+/**
+ * The charge, in three acts: plant and wind up, cross, recover. Navigation is
+ * stopped for the crossing — the agent walks the Transform and the controller
+ * walks the physics body, and a frame that runs both moves Vesper twice.
+ */
+export const chargeSystem = defineSystem(
+ [
+ Query(Mut(Charge), Mut(CharacterController), Mut(Facing), Transform, Perception),
+ Res(Time), GetWorld(),
+ ],
+ (chargers, time, world) => {
+ for (const [entity, charge, controller, facing, transform, perception] of chargers) {
+ if (charge.cooldownLeft > 0) charge.cooldownLeft -= time.delta;
+
+ if (charge.state === 0) {
+ if (!charge.pending) continue;
+ charge.pending = false;
+ if (charge.cooldownLeft > 0) continue;
+ const dx = perception.targetX - transform.position.x;
+ const dy = perception.targetY - transform.position.y;
+ const length = Math.hypot(dx, dy) || 1;
+ charge.dirX = dx / length;
+ charge.dirY = dy / length;
+ facing.x = charge.dirX;
+ facing.y = charge.dirY;
+ charge.state = 1;
+ charge.timer = charge.windup;
+ stopNavAgent(world, entity as Entity);
+ controller.velocity.x = 0;
+ controller.velocity.y = 0;
+ continue;
+ }
+
+ charge.timer -= time.delta;
+ if (charge.state === 1) {
+ controller.velocity.x = 0;
+ controller.velocity.y = 0;
+ if (charge.timer > 0) continue;
+ charge.state = 2;
+ charge.timer = charge.dashTime;
+ continue;
+ }
+
+ controller.velocity.x = charge.dirX * charge.dashSpeed;
+ controller.velocity.y = charge.dirY * charge.dashSpeed * 0.6;
+ if (charge.timer > 0) continue;
+ charge.state = 0;
+ charge.cooldownLeft = charge.cooldown;
+ controller.velocity.x = 0;
+ controller.velocity.y = 0;
+ // Hand the body back to navigation where it now stands, rather than
+ // leaving it aimed at wherever the chase last pointed it.
+ if (world.has(entity as Entity, NavAgent)) {
+ setNavDestination(world, entity as Entity, {
+ x: transform.position.x,
+ y: transform.position.y,
+ });
+ }
+ }
+ },
+ { name: 'ChargeSystem' },
+);
diff --git a/examples/celestial-heights/src/systems/feedback.ts b/examples/celestial-heights/src/systems/feedback.ts
index c91d04fed..555f1a542 100644
--- a/examples/celestial-heights/src/systems/feedback.ts
+++ b/examples/celestial-heights/src/systems/feedback.ts
@@ -1,7 +1,9 @@
import {
- defineSystem, Query, Mut, Transform, Sprite, Parent, GetWorld, UIVisual,
+ defineSystem, Query, Mut, Transform, Sprite, Parent, GetWorld, UIVisual, UINode, UIDisplay,
} from 'esengine';
-import { Health, HealthBarFill, Player, VitalityMeter } from '../components';
+import {
+ Boss, BossMeter, BossPanel, Health, HealthBarFill, Player, VitalityMeter,
+} from '../components';
/**
* Shrinks a bar towards its left edge. Scaling would take it in from both
@@ -40,6 +42,29 @@ export const vitalityMeterSystem = defineSystem(
{ name: 'VitalityMeterSystem' },
);
+/**
+ * Shows the boss bar while an area has a boss in it, and reports its health.
+ * The bar lives in the shared HUD, so it is the presence of a boss that decides
+ * whether it is on screen — not which scene is loaded.
+ */
+export const bossMeterSystem = defineSystem(
+ [Query(Mut(UIVisual), BossMeter), Query(Mut(UINode), BossPanel), Query(Health, Boss)],
+ (meters, panels, bosses) => {
+ let fraction = -1;
+ for (const [, health] of bosses) {
+ fraction = health.max > 0 ? Math.max(0, health.current / health.max) : 0;
+ break;
+ }
+ const display = fraction < 0 ? UIDisplay.None : UIDisplay.Flex;
+ for (const [, node] of panels) {
+ if (node.display !== display) node.display = display;
+ }
+ if (fraction < 0) return;
+ for (const [, visual] of meters) visual.fillAmount = fraction;
+ },
+ { name: 'BossMeterSystem' },
+);
+
/** Blinks whoever is in invulnerability frames, so a hit is visible at all. */
export const hitFlashSystem = defineSystem(
[Query(Mut(Sprite), Health)],