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
feat(editor): a Pixel RPG starter, and the art to walk around in
yhh1d8c5b26ffc6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7d791d12e..2bfa38bc7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -47,6 +47,11 @@ published separately; it ships inside the editor.draws on. Exported because a shipped plugin holds each one up. Plus`extendPlatform`, for a host that can answer what its adapter cannot.+- **A Pixel RPG starter**, the seventh: a 16-pixel overworld with collision in+ the tileset, a four-way animated hero, a camera clamped to the map and snapped+ to whole pixels, and a sign that answers. Its art is drawn for it — nothing to+ license, and every texture imported `nearest`.+- **A plugin can put a button on the editor's activity bar** —`ctx.activityBar.register({ id, title, icon, run })`, with the glyph as theplugin's own inline SVG. The audio mixer uses it, which is how it got back thediff --git a/desktop/templates/pixel-rpg/assets/animations/walk-down.esanim b/desktop/templates/pixel-rpg/assets/animations/walk-down.esanimnew file mode 100644index 000000000..36d951e70--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-down.esanim@@ -0,0 +1,21 @@+{+ "version": "1.3",+ "type": "animation-clip",+ "fps": 8,+ "loop": true,+ "sheet": {+ "texture": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a02",+ "cellWidth": 16,+ "cellHeight": 16,+ "margin": 0,+ "spacing": 0,+ "pageWidth": 48,+ "pageHeight": 64+ },+ "frames": [+ { "cell": 0 },+ { "cell": 1 },+ { "cell": 2 },+ { "cell": 1 }+ ]+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-down.esanim.meta b/desktop/templates/pixel-rpg/assets/animations/walk-down.esanim.metanew file mode 100644index 000000000..8eac6648a--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-down.esanim.meta@@ -0,0 +1,8 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a04",+ "version": "2.0",+ "type": "animation-clip",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-left.esanim b/desktop/templates/pixel-rpg/assets/animations/walk-left.esanimnew file mode 100644index 000000000..3f0e6b017--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-left.esanim@@ -0,0 +1,21 @@+{+ "version": "1.3",+ "type": "animation-clip",+ "fps": 8,+ "loop": true,+ "sheet": {+ "texture": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a02",+ "cellWidth": 16,+ "cellHeight": 16,+ "margin": 0,+ "spacing": 0,+ "pageWidth": 48,+ "pageHeight": 64+ },+ "frames": [+ { "cell": 3 },+ { "cell": 4 },+ { "cell": 5 },+ { "cell": 4 }+ ]+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-left.esanim.meta b/desktop/templates/pixel-rpg/assets/animations/walk-left.esanim.metanew file mode 100644index 000000000..edd2ed28c--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-left.esanim.meta@@ -0,0 +1,8 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a05",+ "version": "2.0",+ "type": "animation-clip",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-right.esanim b/desktop/templates/pixel-rpg/assets/animations/walk-right.esanimnew file mode 100644index 000000000..4ae01b5e3--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-right.esanim@@ -0,0 +1,21 @@+{+ "version": "1.3",+ "type": "animation-clip",+ "fps": 8,+ "loop": true,+ "sheet": {+ "texture": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a02",+ "cellWidth": 16,+ "cellHeight": 16,+ "margin": 0,+ "spacing": 0,+ "pageWidth": 48,+ "pageHeight": 64+ },+ "frames": [+ { "cell": 6 },+ { "cell": 7 },+ { "cell": 8 },+ { "cell": 7 }+ ]+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-right.esanim.meta b/desktop/templates/pixel-rpg/assets/animations/walk-right.esanim.metanew file mode 100644index 000000000..8604757f9--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-right.esanim.meta@@ -0,0 +1,8 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a06",+ "version": "2.0",+ "type": "animation-clip",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-up.esanim b/desktop/templates/pixel-rpg/assets/animations/walk-up.esanimnew file mode 100644index 000000000..048c8e1a8--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-up.esanim@@ -0,0 +1,21 @@+{+ "version": "1.3",+ "type": "animation-clip",+ "fps": 8,+ "loop": true,+ "sheet": {+ "texture": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a02",+ "cellWidth": 16,+ "cellHeight": 16,+ "margin": 0,+ "spacing": 0,+ "pageWidth": 48,+ "pageHeight": 64+ },+ "frames": [+ { "cell": 9 },+ { "cell": 10 },+ { "cell": 11 },+ { "cell": 10 }+ ]+}diff --git a/desktop/templates/pixel-rpg/assets/animations/walk-up.esanim.meta b/desktop/templates/pixel-rpg/assets/animations/walk-up.esanim.metanew file mode 100644index 000000000..a7e226e74--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/animations/walk-up.esanim.meta@@ -0,0 +1,8 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a07",+ "version": "2.0",+ "type": "animation-clip",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/desktop/templates/pixel-rpg/assets/scenes/main.esscene b/desktop/templates/pixel-rpg/assets/scenes/main.esscenenew file mode 100644index 000000000..76b30da1d--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/scenes/main.esscene@@ -0,0 +1,155 @@+{+ "version": "1.0",+ "name": "Main",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 90,+ "isActive": true,+ "priority": 0,+ "pixelPerfect": true+ }+ }+ ],+ "visible": true+ },+ {+ "id": 1,+ "name": "World",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": -256, "y": 192, "z": 0 } } },+ {+ "type": "TilemapLayer",+ "data": {+ "cellSize": { "x": 16, "y": 16 },+ "renderLayer": 0,+ "opacity": 1,+ "visible": true,+ "tilesetAsset": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a03",+ "chunks": "RVNUTQQAAAAAAAAAAAAAAAUAAQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAQAFAAUAAQAFAAUAAQAFAAUAAQAFAAUAAQAFAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEABQAFAAEAAQAFAAEAAQABAAEAAQAFAAEAAQABAAEAAQAFAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAUAAQABAAEAAQABAAEABQABAAEAAQABAAEAAQABAAMABQAFAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAwAFAAUAAQABAAEAAQABAAEAAQAGAAEAAQABAAEAAQADAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAMABQAFAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAwAFAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQADAAUAAQABAAEAAQABAAcABwAHAAcABwAHAAcAAQAIAAMABQAFAAEAAQABAAEABwABAAIAAQACAAEABwABAAEAAwAFAAUAAQABAAEAAQAHAAIAAQACAAEAAgAHAAEAAQADAAUAAQABAAEAAQABAAcAAQACAAEAAgABAAcAAQABAAMAAQAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAQAFAAUABQABAAUABQABAAUABQABAAUABQABAAUABQAFAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAUABQABAAEAAQABAAEABgAEAAQABgAEAAQABgABAAEABQAFAAEAAQABAAEAAQAEAAQABAAEAAQABAAEAAEAAQABAAUAAQABAAEAAQABAAQABAAEAAQABAAEAAQAAQABAAUABQADAAEAAQABAAEABgAEAAQABAAGAAQABgABAAEABQAFAAMAAQABAAEAAQAEAAQABgAEAAQABgAEAAEAAQAFAAUAAwABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEABQADAAMAAwADAAMAAwADAAMAAwABAAEAAQABAAEABQAFAAMAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAFAAUAAwABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAUABQADAAEAAQABAAEAAQABAAEAAQABAAUAAQABAAEAAQAFAAMAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAFAAUAAwABAAEAAQAFAAEAAQABAAEAAQABAAEAAQABAAUABQADAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEABQAFAAAAAAABAAAABQAFAAEAAQABAAEABwACAAEAAgABAAIABwABAAEAAwAFAAUAAQABAAEAAQAHAAEAAgABAAIAAQAHAAEAAQADAAUAAQABAAEAAQABAAcABwAHAAEAAQAHAAcAAQABAAMABQAFAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAwAFAAUAAQABAAEABQABAAEAAQABAAEAAQABAAEAAQADAAUAAQABAAEAAQABAAEAAQABAAEAAQABAAYAAQABAAMAAQAFAAUABQABAAUABQAFAAEABQAFAAUAAQAFAAUAAwAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAMAAQABAAEAAQABAAEAAQAFAAEAAQABAAEAAQABAAUAAwABAAEABgABAAEAAQABAAEAAQABAAEAAQABAAUABQADAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEABQAFAAMAAQABAAEAAQABAAUAAQABAAEAAQABAAEAAQAFAAUAAwABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEABQADAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEABQAFAAMABQAFAAUAAQAFAAUABQABAAUABQAFAAEABQAFAAUAAwAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+ }+ }+ ],+ "visible": true+ },+ {+ "id": 2,+ "name": "Sign",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": -24, "y": -8, "z": 0 } } },+ {+ "type": "Talkable",+ "data": { "line": "The road south leaves the valley. The pond is east." }+ }+ ],+ "visible": true+ },+ {+ "id": 3,+ "name": "Player",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": -8, "y": -72, "z": 1 } } },+ {+ "type": "Sprite",+ "data": {+ "size": { "x": 16, "y": 16 },+ "texture": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a02",+ "layer": 5+ }+ },+ {+ "type": "SpriteAnimator",+ "data": { "clip": "assets/animations/walk-down.esanim" }+ },+ {+ "type": "Facings",+ "data": {+ "down": "assets/animations/walk-down.esanim",+ "left": "assets/animations/walk-left.esanim",+ "right": "assets/animations/walk-right.esanim",+ "up": "assets/animations/walk-up.esanim"+ }+ },+ { "type": "Player", "data": {} },+ { "type": "RigidBody", "data": { "bodyType": 1 } },+ {+ "type": "BoxCollider",+ "data": {+ "halfExtents": { "x": 0.05, "y": 0.035 },+ "offset": { "x": 0, "y": -0.045 },+ "categoryBits": 1,+ "maskBits": 65535+ }+ },+ { "type": "CharacterController", "data": { "maskBits": 65535 } }+ ],+ "visible": true+ },+ {+ "id": 4,+ "name": "Canvas",+ "parent": null,+ "children": [5],+ "components": [+ { "type": "Transform", "data": {} },+ {+ "type": "Canvas",+ "data": {+ "designResolution": { "x": 320, "y": 180 },+ "scaleMode": 2+ }+ },+ { "type": "UINode", "data": {} }+ ],+ "visible": true+ },+ {+ "id": 5,+ "name": "Say",+ "parent": 4,+ "children": [],+ "components": [+ { "type": "Transform", "data": {} },+ {+ "type": "UINode",+ "data": {+ "position": 1,+ "insetLeft": { "value": 16, "unit": 0 },+ "insetRight": { "value": 16, "unit": 0 },+ "insetBottom": { "value": 10, "unit": 0 },+ "height": { "value": 14, "unit": 0 }+ }+ },+ {+ "type": "Text",+ "data": {+ "content": "Arrow keys or WASD to walk.",+ "fontSize": 10,+ "color": { "r": 0.95, "g": 0.95, "b": 0.9, "a": 1 },+ "align": 1,+ "verticalAlign": 1,+ "strokeColor": { "r": 0.05, "g": 0.05, "b": 0.08, "a": 1 },+ "strokeWidth": 2+ }+ },+ { "type": "SayLine", "data": {} }+ ],+ "visible": true+ }+ ]+}diff --git a/desktop/templates/pixel-rpg/assets/scenes/main.esscene.meta b/desktop/templates/pixel-rpg/assets/scenes/main.esscene.metanew file mode 100644index 000000000..9eb3fe6f5--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/scenes/main.esscene.meta@@ -0,0 +1,8 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a08",+ "version": "2.0",+ "type": "scene",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/desktop/templates/pixel-rpg/assets/textures/hero.png b/desktop/templates/pixel-rpg/assets/textures/hero.pngnew file mode 100644index 000000000..0a455a4daBinary files /dev/null and b/desktop/templates/pixel-rpg/assets/textures/hero.png differdiff --git a/desktop/templates/pixel-rpg/assets/textures/hero.png.meta b/desktop/templates/pixel-rpg/assets/textures/hero.png.metanew file mode 100644index 000000000..fc7fcc765--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/textures/hero.png.meta@@ -0,0 +1,17 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a02",+ "version": "2.0",+ "type": "texture",+ "importer": {+ "maxSize": 2048,+ "filterMode": "nearest",+ "wrapMode": "clamp",+ "premultiplyAlpha": false,+ "sliceBorder": {+ "left": 0,+ "right": 0,+ "top": 0,+ "bottom": 0+ }+ }+}diff --git a/desktop/templates/pixel-rpg/assets/textures/tiles.png b/desktop/templates/pixel-rpg/assets/textures/tiles.pngnew file mode 100644index 000000000..621267ea8Binary files /dev/null and b/desktop/templates/pixel-rpg/assets/textures/tiles.png differdiff --git a/desktop/templates/pixel-rpg/assets/textures/tiles.png.meta b/desktop/templates/pixel-rpg/assets/textures/tiles.png.metanew file mode 100644index 000000000..8ccc53afa--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/textures/tiles.png.meta@@ -0,0 +1,17 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a01",+ "version": "2.0",+ "type": "texture",+ "importer": {+ "maxSize": 2048,+ "filterMode": "nearest",+ "wrapMode": "clamp",+ "premultiplyAlpha": false,+ "sliceBorder": {+ "left": 0,+ "right": 0,+ "top": 0,+ "bottom": 0+ }+ }+}diff --git a/desktop/templates/pixel-rpg/assets/tilesets/world.estileset b/desktop/templates/pixel-rpg/assets/tilesets/world.estilesetnew file mode 100644index 000000000..8fe5874ee--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/tilesets/world.estileset@@ -0,0 +1,37 @@+{+ "version": "1",+ "texture": "@uuid:7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a01",+ "tileWidth": 16,+ "tileHeight": 16,+ "columns": 8,+ "margin": 0,+ "spacing": 0,+ "tileCount": 8,+ "tiles": {+ "4": {+ "collision": {+ "type": "box"+ }+ },+ "5": {+ "collision": {+ "type": "box"+ }+ },+ "6": {+ "collision": {+ "type": "box"+ }+ },+ "7": {+ "collision": {+ "type": "box"+ }+ },+ "8": {+ "collision": {+ "type": "box"+ }+ }+ }+}diff --git a/desktop/templates/pixel-rpg/assets/tilesets/world.estileset.meta b/desktop/templates/pixel-rpg/assets/tilesets/world.estileset.metanew file mode 100644index 000000000..507bee69e--- /dev/null+++ b/desktop/templates/pixel-rpg/assets/tilesets/world.estileset.meta@@ -0,0 +1,8 @@+{+ "uuid": "7e1c2a90-11d4-4b8a-9d1a-2c6f0b8e4a03",+ "version": "2.0",+ "type": "tileset",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/desktop/templates/pixel-rpg/project.esproject b/desktop/templates/pixel-rpg/project.esprojectnew file mode 100644index 000000000..036f78f2c--- /dev/null+++ b/desktop/templates/pixel-rpg/project.esproject@@ -0,0 +1,18 @@+{+ "formatVersion": "1",+ "name": "Pixel RPG",+ "description": "A 16-pixel overworld you walk: a tilemap with collision in it, a four-way animated hero, a camera on whole pixels, and a sign that talks back.",+ "tag": "Starter",+ "version": "1.0.0",+ "defaultScene": "assets/scenes/main.esscene",+ "designResolution": {+ "width": 320,+ "height": 180+ },+ "spineVersion": "none",+ "features": {+ "physics": {+ "enabled": true+ }+ }+}diff --git a/desktop/templates/pixel-rpg/src/components.ts b/desktop/templates/pixel-rpg/src/components.tsnew file mode 100644index 000000000..679ae472d--- /dev/null+++ b/desktop/templates/pixel-rpg/src/components.ts@@ -0,0 +1,36 @@+import { defineComponent } from 'esengine';++export const Player = defineComponent('Player', {+ speed: 70,+});++/**+ * The clip that walks each way.+ *+ * Asset FIELDS, not paths in code: a clip nothing in the scene references is+ * one the scene never loads, so the switch would land on nothing at runtime.+ */+export const Facings = defineComponent('Facings', {+ down: '',+ left: '',+ right: '',+ up: '',+}, {+ assetFields: [+ { field: 'down', type: 'anim-clip' },+ { field: 'left', type: 'anim-clip' },+ { field: 'right', type: 'anim-clip' },+ { field: 'up', type: 'anim-clip' },+ ],+});++/** Something with a line to say when you stand next to it and press Space. */+export const Talkable = defineComponent('Talkable', {+ line: '',+ range: 24,+});++/** The one label the world talks through. */+export const SayLine = defineComponent('SayLine', {+ idle: 'Arrow keys or WASD to walk.',+});diff --git a/desktop/templates/pixel-rpg/src/main.ts b/desktop/templates/pixel-rpg/src/main.tsnew file mode 100644index 000000000..3d1b3139d--- /dev/null+++ b/desktop/templates/pixel-rpg/src/main.ts@@ -0,0 +1,11 @@+import { addSystemToSchedule, Schedule } from 'esengine';++import './components';+import { moveSystem } from './systems/move';+import { followSystem } from './systems/follow';+import { talkSystem } from './systems/talk';++addSystemToSchedule(Schedule.Update, moveSystem);+addSystemToSchedule(Schedule.Update, talkSystem);+// After the hero has moved, or the camera trails a frame behind them.+addSystemToSchedule(Schedule.PostUpdate, followSystem);diff --git a/desktop/templates/pixel-rpg/src/systems/follow.ts b/desktop/templates/pixel-rpg/src/systems/follow.tsnew file mode 100644index 000000000..be899a392--- /dev/null+++ b/desktop/templates/pixel-rpg/src/systems/follow.ts@@ -0,0 +1,36 @@+import { defineSystem, Query, Mut, Res, Transform, Camera, UICameraInfo } from 'esengine';+import { Player } from '../components';++// The world the tilemap covers, in world units: 32×24 cells of 16, with the+// layer's origin at its top-left corner (see the World entity's Transform).+const MAP = { left: -256, right: 256, bottom: -192, top: 192 };++/** Keep `v` inside [min, max]; centred when the span is smaller than the view. */+function clamp(v: number, min: number, max: number): number {+ return min > max ? (min + max) / 2 : Math.min(Math.max(v, min), max);+}++/**+ * The camera sits ON the hero, stopped at the edges of the map and snapped to+ * whole pixels. A pixel-art camera that eases (as a smooth-scrolling one should)+ * lands between pixels, and every sprite in the frame shimmers as it crosses the+ * sampling grid.+ */+export const followSystem = defineSystem(+ [Query(Mut(Transform), Camera), Query(Transform, Player), Res(UICameraInfo)],+ (cameras, players, view) => {+ const target = [...players][0];+ if (!target) return;+ const [, to] = target;+ // The visible half-extent, from the camera the frame was drawn with —+ // so the clamp is right at any window size rather than at one.+ const halfW = view.valid ? (view.worldRight - view.worldLeft) / 2 : 0;+ const halfH = view.valid ? (view.worldTop - view.worldBottom) / 2 : 0;++ for (const [, camera] of cameras) {+ camera.position.x = Math.round(clamp(to.position.x, MAP.left + halfW, MAP.right - halfW));+ camera.position.y = Math.round(clamp(to.position.y, MAP.bottom + halfH, MAP.top - halfH));+ }+ },+ { name: 'FollowSystem' },+);diff --git a/desktop/templates/pixel-rpg/src/systems/move.ts b/desktop/templates/pixel-rpg/src/systems/move.tsnew file mode 100644index 000000000..6f090e810--- /dev/null+++ b/desktop/templates/pixel-rpg/src/systems/move.ts@@ -0,0 +1,48 @@+import {+ defineSystem, Query, Mut, Res, Input, GetWorld,+ CharacterController, SpriteAnimator,+} from 'esengine';+import { Facings, Player } from '../components';++export const moveSystem = defineSystem(+ [Query(Mut(CharacterController), SpriteAnimator, Facings, Player), Res(Input), GetWorld()],+ (players, input, world) => {+ let x = 0;+ let y = 0;+ if (input.isKeyDown('ArrowLeft') || input.isKeyDown('KeyA')) x -= 1;+ if (input.isKeyDown('ArrowRight') || input.isKeyDown('KeyD')) x += 1;+ if (input.isKeyDown('ArrowDown') || input.isKeyDown('KeyS')) y -= 1;+ if (input.isKeyDown('ArrowUp') || input.isKeyDown('KeyW')) y += 1;+ // Normalised, or a diagonal would be ~1.4× faster than a straight line.+ const length = Math.hypot(x, y);+ const moving = length !== 0;++ for (const [entity, cc, animator, facings, player] of players) {+ cc.velocity.x = moving ? (x / length) * player.speed : 0;+ cc.velocity.y = moving ? (y / length) * player.speed : 0;++ // The way you face is a clip the scene chose, so new art is a new+ // asset rather than an edit here.+ const facing = moving+ ? (Math.abs(x) > Math.abs(y)+ ? (x < 0 ? facings.left : facings.right)+ : (y < 0 ? facings.down : facings.up))+ : animator.clip;+ const changed = animator.clip !== facing;++ // Written only when it CHANGES: the animator advances its own timer+ // on this component, and a system rewriting the whole thing every+ // frame puts that timer back — the cycle stands still.+ if (changed || animator.playing !== moving) {+ world.insert(entity, SpriteAnimator, {+ ...animator,+ clip: facing,+ playing: moving,+ currentFrame: changed ? 0 : animator.currentFrame,+ frameTimer: changed ? 0 : animator.frameTimer,+ });+ }+ }+ },+ { name: 'MoveSystem' },+);diff --git a/desktop/templates/pixel-rpg/src/systems/talk.ts b/desktop/templates/pixel-rpg/src/systems/talk.tsnew file mode 100644index 000000000..edef8d7d1--- /dev/null+++ b/desktop/templates/pixel-rpg/src/systems/talk.ts@@ -0,0 +1,36 @@+import { defineSystem, Query, Mut, Res, Input, Transform, Text } from 'esengine';+import { Player, SayLine, Talkable } from '../components';++/** The nearest thing in range with something to say, or null. */+function nearest(+ at: { x: number; y: number },+ talkers: Iterable<[unknown, { position: { x: number; y: number } }, { line: string; range: number }]>,+): string | null {+ let best: string | null = null;+ let bestDistance = Infinity;+ for (const [, transform, talkable] of talkers) {+ const d = Math.hypot(transform.position.x - at.x, transform.position.y - at.y);+ if (d <= talkable.range && d < bestDistance) {+ bestDistance = d;+ best = talkable.line;+ }+ }+ return best;+}++export const talkSystem = defineSystem(+ [Query(Transform, Player), Query(Transform, Talkable), Query(SayLine, Mut(Text)), Res(Input)],+ (players, talkers, labels, input) => {+ const player = [...players][0];+ if (!player) return;+ const line = nearest(player[1].position, talkers);++ for (const [, say, text] of labels) {+ const wanted = line === null+ ? say.idle+ : (input.isKeyDown('Space') ? line : 'Space to read.');+ if (text.content !== wanted) text.content = wanted;+ }+ },+ { name: 'TalkSystem' },+);diff --git a/desktop/templates/pixel-rpg/tsconfig.json b/desktop/templates/pixel-rpg/tsconfig.jsonnew file mode 100644index 000000000..1f11ff310--- /dev/null+++ b/desktop/templates/pixel-rpg/tsconfig.json@@ -0,0 +1,20 @@+{+ "compilerOptions": {+ "target": "ES2020",+ "module": "ESNext",+ "moduleResolution": "bundler",+ "strict": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "declaration": false,+ "outDir": "./dist",+ "rootDir": ".",+ "paths": {+ "esengine": ["./.esengine/sdk/index.d.ts"],+ "esengine/wasm": ["./.esengine/sdk/wasm.d.ts"]+ }+ },+ "include": ["src/**/*"],+ "exclude": ["node_modules"]+}