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: add example projects with template browser in new project dialog

esengine69424b026737
diff --git a/.gitignore b/.gitignore
index 3d1c2884b..73cfbec05 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,6 +57,10 @@ compile_commands.json
# Astro
.astro/
+# Examples
+desktop/public/examples/
+examples/tools/
+
# OS files
.DS_Store
Thumbs.db
diff --git a/build-tools/cli.js b/build-tools/cli.js
index 28bf1fac8..540371407 100644
--- a/build-tools/cli.js
+++ b/build-tools/cli.js
@@ -14,6 +14,7 @@ import { syncToDesktop } from './tasks/sync.js';
import { startWatch } from './tasks/watch.js';
import { BuildManifest } from './manifest.js';
import { handleBuildError } from './utils/errorHelp.js';
+import { zipExamples } from './tasks/examples.js';
program
.name('esengine-build')
@@ -76,6 +77,7 @@ program
if (options.sync) {
await syncToDesktop();
+ await zipExamples(config.paths.root);
}
if (manifest) {
@@ -190,4 +192,14 @@ async function cleanAll() {
await cleanSdk();
}
+program
+ .command('zip-examples')
+ .description('Pack example projects into zip files for editor')
+ .action(async () => {
+ logger.header('Zip Examples');
+ const startTime = Date.now();
+ await zipExamples(config.paths.root);
+ logger.printTime(Date.now() - startTime);
+ });
+
program.parse();
diff --git a/build-tools/tasks/examples.js b/build-tools/tasks/examples.js
new file mode 100644
index 000000000..8aa870f00
--- /dev/null
+++ b/build-tools/tasks/examples.js
@@ -0,0 +1,53 @@
+/**
+ * @file examples.js
+ * @brief Pack example projects into zip files for editor
+ */
+
+import { execSync } from 'child_process';
+import { existsSync, mkdirSync } from 'fs';
+import path from 'path';
+import * as logger from '../utils/logger.js';
+
+const EXAMPLES = [
+ { name: 'space-shooter', dir: 'examples/space-shooter' },
+];
+
+const OUTPUT_DIR = 'desktop/public/examples';
+
+export async function zipExamples(rootDir) {
+ logger.step('Packing example projects...');
+
+ const outDir = path.join(rootDir, OUTPUT_DIR);
+ if (!existsSync(outDir)) {
+ mkdirSync(outDir, { recursive: true });
+ }
+
+ for (const example of EXAMPLES) {
+ const srcDir = path.join(rootDir, example.dir);
+ const zipPath = path.join(outDir, `${example.name}.zip`);
+
+ if (!existsSync(srcDir)) {
+ logger.warn(`Example not found: ${srcDir}`);
+ continue;
+ }
+
+ const excludes = [
+ '-x', '*.DS_Store',
+ '-x', '*node_modules/*',
+ '-x', '*dist/*',
+ '-x', '*.esengine/cache/*',
+ '-x', '*tools/*',
+ '-x', '*__pycache__/*',
+ ];
+
+ try {
+ execSync(
+ `cd "${srcDir}" && zip -r "${path.resolve(zipPath)}" . ${excludes.join(' ')}`,
+ { stdio: 'pipe' }
+ );
+ logger.success(`${example.name}.zip`);
+ } catch (err) {
+ logger.error(`Failed to zip ${example.name}: ${err.message}`);
+ }
+ }
+}
diff --git a/desktop/src-tauri/Cargo.lock b/desktop/src-tauri/Cargo.lock
index c3c29e078..87f7c3b73 100644
--- a/desktop/src-tauri/Cargo.lock
+++ b/desktop/src-tauri/Cargo.lock
@@ -8,6 +8,17 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
+[[package]]
+name = "aes"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
+dependencies = [
+ "cfg-if",
+ "cipher",
+ "cpufeatures",
+]
+
[[package]]
name = "aho-corasick"
version = "1.1.4"
@@ -190,6 +201,25 @@ dependencies = [
"serde",
]
+[[package]]
+name = "bzip2"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
+dependencies = [
+ "bzip2-sys",
+]
+
+[[package]]
+name = "bzip2-sys"
+version = "0.1.13+1.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
+dependencies = [
+ "cc",
+ "pkg-config",
+]
+
[[package]]
name = "cairo-rs"
version = "0.18.5"
@@ -264,6 +294,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29"
dependencies = [
"find-msvc-tools",
+ "jobserver",
+ "libc",
"shlex",
]
@@ -318,6 +350,16 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901"
+[[package]]
+name = "cipher"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
+dependencies = [
+ "crypto-common",
+ "inout",
+]
+
[[package]]
name = "combine"
version = "4.6.7"
@@ -328,6 +370,12 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "constant_time_eq"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
+
[[package]]
name = "convert_case"
version = "0.4.0"
@@ -393,6 +441,21 @@ dependencies = [
"libc",
]
+[[package]]
+name = "crc"
+version = "3.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d"
+dependencies = [
+ "crc-catalog",
+]
+
+[[package]]
+name = "crc-catalog"
+version = "2.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
+
[[package]]
name = "crc32fast"
version = "1.5.0"
@@ -499,6 +562,12 @@ dependencies = [
"syn 2.0.114",
]
+[[package]]
+name = "deflate64"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26bf8fc351c5ed29b5c2f0cbbac1b209b74f60ecd62e675a998df72c49af5204"
+
[[package]]
name = "deranged"
version = "0.5.5"
@@ -541,6 +610,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
+ "subtle",
]
[[package]]
@@ -725,6 +795,7 @@ dependencies = [
"tiny_http",
"tokio",
"urlencoding",
+ "zip 2.4.2",
]
[[package]]
@@ -1068,9 +1139,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"r-efi",
"wasip2",
+ "wasm-bindgen",
]
[[package]]
@@ -1251,6 +1324,15 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+[[package]]
+name = "hmac"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
+dependencies = [
+ "digest",
+]
+
[[package]]
name = "html5ever"
version = "0.29.1"
@@ -1568,6 +1650,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "inout"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
+dependencies = [
+ "generic-array",
+]
+
[[package]]
name = "ipnet"
version = "2.11.0"
@@ -1654,6 +1745,16 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
+[[package]]
+name = "jobserver"
+version = "0.1.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
+dependencies = [
+ "getrandom 0.3.4",
+ "libc",
+]
+
[[package]]
name = "js-sys"
version = "0.3.85"
@@ -1813,6 +1914,27 @@ version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
+[[package]]
+name = "lzma-rs"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e"
+dependencies = [
+ "byteorder",
+ "crc",
+]
+
+[[package]]
+name = "lzma-sys"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
+dependencies = [
+ "cc",
+ "libc",
+ "pkg-config",
+]
+
[[package]]
name = "mac"
version = "0.1.1"
@@ -2372,6 +2494,16 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
+[[package]]
+name = "pbkdf2"
+version = "0.12.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
+dependencies = [
+ "digest",
+ "hmac",
+]
+
[[package]]
name = "percent-encoding"
version = "2.3.2"
@@ -3305,6 +3437,17 @@ dependencies = [
"stable_deref_trait",
]
+[[package]]
+name = "sha1"
+version = "0.10.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
+dependencies = [
+ "cfg-if",
+ "cpufeatures",
+ "digest",
+]
+
[[package]]
name = "sha2"
version = "0.10.9"
@@ -3864,7 +4007,7 @@ dependencies = [
"tokio",
"url",
"windows-sys 0.60.2",
- "zip",
+ "zip 4.6.1",
]
[[package]]
@@ -5242,6 +5385,15 @@ dependencies = [
"rustix",
]
+[[package]]
+name = "xz2"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
+dependencies = [
+ "lzma-sys",
+]
+
[[package]]
name = "yoke"
version = "0.8.1"
@@ -5311,6 +5463,20 @@ name = "zeroize"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
+dependencies = [
+ "zeroize_derive",
+]
+
+[[package]]
+name = "zeroize_derive"
+version = "1.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.114",
+]
[[package]]
name = "zerotrie"
@@ -5345,6 +5511,36 @@ dependencies = [
"syn 2.0.114",
]
+[[package]]
+name = "zip"
+version = "2.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50"
+dependencies = [
+ "aes",
+ "arbitrary",
+ "bzip2",
+ "constant_time_eq",
+ "crc32fast",
+ "crossbeam-utils",
+ "deflate64",
+ "displaydoc",
+ "flate2",
+ "getrandom 0.3.4",
+ "hmac",
+ "indexmap 2.13.0",
+ "lzma-rs",
+ "memchr",
+ "pbkdf2",
+ "sha1",
+ "thiserror 2.0.18",
+ "time",
+ "xz2",
+ "zeroize",
+ "zopfli",
+ "zstd",
+]
+
[[package]]
name = "zip"
version = "4.6.1"
@@ -5362,3 +5558,43 @@ name = "zmij"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ff05f8caa9038894637571ae6b9e29466c1f4f829d26c9b28f869a29cbe3445"
+
+[[package]]
+name = "zopfli"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
+dependencies = [
+ "bumpalo",
+ "crc32fast",
+ "log",
+ "simd-adler32",
+]
+
+[[package]]
+name = "zstd"
+version = "0.13.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
+dependencies = [
+ "zstd-safe",
+]
+
+[[package]]
+name = "zstd-safe"
+version = "7.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
+dependencies = [
+ "zstd-sys",
+]
+
+[[package]]
+name = "zstd-sys"
+version = "2.0.16+zstd.1.5.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748"
+dependencies = [
+ "cc",
+ "pkg-config",
+]
diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml
index 88e648b2e..cc19cc581 100644
--- a/desktop/src-tauri/Cargo.toml
+++ b/desktop/src-tauri/Cargo.toml
@@ -25,6 +25,7 @@ tokio = { version = "1", features = ["process", "io-util", "macros"] }
tiny_http = "0.12"
open = "5"
urlencoding = "2"
+zip = "2"
[profile.release]
panic = "abort"
diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs
index cf0b411dc..f5e7c75e4 100644
--- a/desktop/src-tauri/src/lib.rs
+++ b/desktop/src-tauri/src/lib.rs
@@ -4,6 +4,7 @@ mod embedded_assets;
mod preview_server;
use preview_server::PreviewServer;
+use std::io::Read as _;
use std::path::PathBuf;
use std::process::Stdio;
use std::sync::Mutex;
@@ -77,6 +78,42 @@ fn open_preview_in_browser(port: u16) -> Result<(), String> {
open::that(&url).map_err(|e| e.to_string())
}
+#[tauri::command]
+fn unzip_to_directory(zip_bytes: Vec<u8>, target_dir: String) -> Result<(), String> {
+ let target = PathBuf::from(&target_dir);
+ if target.exists() {
+ return Err("Target directory already exists".to_string());
+ }
+ std::fs::create_dir_all(&target).map_err(|e| e.to_string())?;
+
+ let cursor = std::io::Cursor::new(zip_bytes);
+ let mut archive = zip::ZipArchive::new(cursor).map_err(|e| e.to_string())?;
+
+ for i in 0..archive.len() {
+ let mut file = archive.by_index(i).map_err(|e| e.to_string())?;
+ let name = file.name().to_string();
+
+ if name.starts_with("__MACOSX") || name.ends_with(".DS_Store") {
+ continue;
+ }
+
+ let out_path = target.join(&name);
+
+ if file.is_dir() {
+ std::fs::create_dir_all(&out_path).map_err(|e| e.to_string())?;
+ } else {
+ if let Some(parent) = out_path.parent() {
+ std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
+ }
+ let mut buf = Vec::new();
+ file.read_to_end(&mut buf).map_err(|e| e.to_string())?;
+ std::fs::write(&out_path, &buf).map_err(|e| e.to_string())?;
+ }
+ }
+
+ Ok(())
+}
+
#[tauri::command]
fn open_folder(path: String) -> Result<(), String> {
open::that(&path).map_err(|e| e.to_string())
@@ -192,6 +229,7 @@ pub fn run() {
notify_preview_reload,
open_preview_in_browser,
open_folder,
+ unzip_to_directory,
execute_command,
get_embedded_asset,
])
diff --git a/editor/src/launcher/NewProjectDialog.ts b/editor/src/launcher/NewProjectDialog.ts
index cae8f768f..6b8b98209 100644
--- a/editor/src/launcher/NewProjectDialog.ts
+++ b/editor/src/launcher/NewProjectDialog.ts
@@ -1,11 +1,11 @@
/**
* @file NewProjectDialog.ts
- * @brief New project creation dialog
+ * @brief New project creation dialog with Templates and Examples tabs
*/
-import type { ProjectTemplate } from '../types/ProjectTypes';
-import { PROJECT_TEMPLATES } from '../types/ProjectTypes';
-import { createProject, selectProjectLocation } from './ProjectService';
+import type { ProjectTemplate, ExampleProjectInfo } from '../types/ProjectTypes';
+import { PROJECT_TEMPLATES, EXAMPLE_PROJECTS } from '../types/ProjectTypes';
+import { createProject, createFromExample, selectProjectLocation } from './ProjectService';
// =============================================================================
// Types
@@ -16,6 +16,8 @@ export interface NewProjectDialogOptions {
onProjectCreated: (projectPath: string) => void;
}
+type DialogTab = 'templates' | 'examples';
+
// =============================================================================
// NewProjectDialog
// =============================================================================
@@ -24,6 +26,8 @@ export class NewProjectDialog {
private overlay_: HTMLElement;
private options_: NewProjectDialogOptions;
private selectedTemplate_: ProjectTemplate = 'empty';
+ private selectedExample_: ExampleProjectInfo | null = EXAMPLE_PROJECTS[0] ?? null;
+ private activeTab_: DialogTab = 'templates';
private projectLocation_: string = '';
constructor(options: NewProjectDialogOptions) {
@@ -42,18 +46,6 @@ export class NewProjectDialog {
}
private render(): void {
- const templatesHtml = PROJECT_TEMPLATES.map(
- (t) => `
- <label class="es-dialog-template ${t.id === this.selectedTemplate_ ? 'selected' : ''} ${!t.enabled ? 'disabled' : ''}">
- <input type="radio" name="template" value="${t.id}"
- ${t.id === this.selectedTemplate_ ? 'checked' : ''}
- ${!t.enabled ? 'disabled' : ''}>
- <span class="es-dialog-template-name">${t.name}</span>
- <span class="es-dialog-template-desc">${t.description}${!t.enabled ? ' (coming soon)' : ''}</span>
- </label>
- `
- ).join('');
-
this.overlay_.innerHTML = `
<div class="es-dialog">
<div class="es-dialog-header">
@@ -61,6 +53,12 @@ export class NewProjectDialog {
<button class="es-dialog-close" data-action="close">×</button>
</div>
<div class="es-dialog-body">
+ <div class="es-dialog-tabs">
+ <button class="es-dialog-tab ${this.activeTab_ === 'templates' ? 'active' : ''}"
+ data-tab="templates">Templates</button>
+ <button class="es-dialog-tab ${this.activeTab_ === 'examples' ? 'active' : ''}"
+ data-tab="examples">Examples</button>
+ </div>
<div class="es-dialog-field">
<label class="es-dialog-label">Project Name</label>
<input type="text" class="es-dialog-input" id="project-name"
@@ -74,12 +72,7 @@ export class NewProjectDialog {
<button class="es-dialog-browse" data-action="browse">...</button>
</div>
</div>
- <div class="es-dialog-field">
- <label class="es-dialog-label">Template</label>
- <div class="es-dialog-templates">
- ${templatesHtml}
- </div>
- </div>
+ ${this.renderTabContent()}
</div>
<div class="es-dialog-footer">
<button class="es-dialog-btn" data-action="cancel">Cancel</button>
@@ -89,37 +82,85 @@ export class NewProjectDialog {
`;
}
- private setupEvents(): void {
- // Close button
- this.overlay_.querySelector('[data-action="close"]')?.addEventListener('click', () => {
- this.options_.onClose();
- });
+ private renderTabContent(): string {
+ if (this.activeTab_ === 'templates') {
+ return this.renderTemplatesTab();
+ }
+ return this.renderExamplesTab();
+ }
- // Cancel button
- this.overlay_.querySelector('[data-action="cancel"]')?.addEventListener('click', () => {
- this.options_.onClose();
- });
+ private renderTemplatesTab(): string {
+ const items = PROJECT_TEMPLATES.map(
+ (t) => `
+ <label class="es-dialog-template ${t.id === this.selectedTemplate_ ? 'selected' : ''} ${!t.enabled ? 'disabled' : ''}">
+ <input type="radio" name="template" value="${t.id}"
+ ${t.id === this.selectedTemplate_ ? 'checked' : ''}
+ ${!t.enabled ? 'disabled' : ''}>
+ <span class="es-dialog-template-name">${t.name}</span>
+ <span class="es-dialog-template-desc">${t.description}${!t.enabled ? ' (coming soon)' : ''}</span>
+ </label>
+ `
+ ).join('');
- // Browse button
- this.overlay_.querySelector('[data-action="browse"]')?.addEventListener('click', () => {
- this.handleBrowse();
- });
+ return `
+ <div class="es-dialog-field">
+ <label class="es-dialog-label">Template</label>
+ <div class="es-dialog-templates">${items}</div>
+ </div>
+ `;
+ }
+
+ private renderExamplesTab(): string {
+ if (EXAMPLE_PROJECTS.length === 0) {
+ return `<div class="es-dialog-field"><span class="es-dialog-empty">No examples available</span></div>`;
+ }
+
+ const items = EXAMPLE_PROJECTS.map(
+ (ex) => `
+ <label class="es-dialog-template ${this.selectedExample_?.id === ex.id ? 'selected' : ''}">
+ <input type="radio" name="example" value="${ex.id}" ${this.selectedExample_?.id === ex.id ? 'checked' : ''}>
+ <span class="es-dialog-template-name">${ex.name}</span>
+ <span class="es-dialog-template-desc">${ex.description}</span>
+ </label>
+ `
+ ).join('');
+
+ return `
+ <div class="es-dialog-field">
+ <label class="es-dialog-label">Example</label>
+ <div class="es-dialog-templates">${items}</div>
+ </div>
+ `;
+ }
+
+ private setupEvents(): void {
+ this.overlay_.addEventListener('click', (e) => {
+ const target = e.target as HTMLElement;
+ const action = target.dataset.action ?? target.closest('[data-action]')?.getAttribute('data-action');
+ const tab = target.dataset.tab;
- // Create button
- this.overlay_.querySelector('[data-action="create"]')?.addEventListener('click', () => {
- this.handleCreate();
+ if (action === 'close' || action === 'cancel') {
+ this.options_.onClose();
+ } else if (action === 'browse') {
+ this.handleBrowse();
+ } else if (action === 'create') {
+ this.handleCreate();
+ } else if (tab) {
+ this.switchTab(tab as DialogTab);
+ }
});
- // Template selection
- this.overlay_.querySelectorAll('input[name="template"]').forEach((input) => {
- input.addEventListener('change', (e) => {
- const target = e.target as HTMLInputElement;
+ this.overlay_.addEventListener('change', (e) => {
+ const target = e.target as HTMLInputElement;
+ if (target.name === 'template') {
this.selectedTemplate_ = target.value as ProjectTemplate;
- this.updateTemplateSelection();
- });
+ this.updateSelection();
+ } else if (target.name === 'example') {
+ this.selectedExample_ = EXAMPLE_PROJECTS.find(ex => ex.id === target.value) ?? null;
+ this.updateSelection();
+ }
});
- // Escape key to close
const keyHandler = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
this.options_.onClose();
@@ -129,7 +170,23 @@ export class NewProjectDialog {
document.addEventListener('keydown', keyHandler);
}
- private updateTemplateSelection(): void {
+ private switchTab(tab: DialogTab): void {
+ this.activeTab_ = tab;
+
+ const locationInput = this.overlay_.querySelector('#project-location') as HTMLInputElement;
+ const nameInput = this.overlay_.querySelector('#project-name') as HTMLInputElement;
+ const savedLocation = locationInput?.value ?? '';
+ const savedName = nameInput?.value ?? 'MyGame';
+
+ this.render();
+
+ const newNameInput = this.overlay_.querySelector('#project-name') as HTMLInputElement;
+ const newLocationInput = this.overlay_.querySelector('#project-location') as HTMLInputElement;
+ if (newNameInput) newNameInput.value = savedName;
+ if (newLocationInput && savedLocation) newLocationInput.value = savedLocation;
+ }
+
+ private updateSelection(): void {
this.overlay_.querySelectorAll('.es-dialog-template').forEach((el) => {
const input = el.querySelector('input') as HTMLInputElement;
el.classList.toggle('selected', input.checked);
@@ -162,7 +219,6 @@ export class NewProjectDialog {
return;
}
- // Validate project name
if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
alert('Project name can only contain letters, numbers, underscores, and hyphens');
nameInput?.focus();
@@ -175,11 +231,20 @@ export class NewProjectDialog {
createBtn.textContent = 'Creating...';
}
- const result = await createProject({
- name,
- location: this.projectLocation_,
- template: this.selectedTemplate_,
- });
+ let result;
+ if (this.activeTab_ === 'examples' && this.selectedExample_) {
+ result = await createFromExample({
+ name,
+ location: this.projectLocation_,
+ example: this.selectedExample_,
+ });
+ } else {
+ result = await createProject({
+ name,
+ location: this.projectLocation_,
+ template: this.selectedTemplate_,
+ });
+ }
if (result.success && result.data) {
this.options_.onProjectCreated(result.data);
diff --git a/editor/src/launcher/ProjectLauncher.ts b/editor/src/launcher/ProjectLauncher.ts
index 09e273d4c..5dcf7b654 100644
--- a/editor/src/launcher/ProjectLauncher.ts
+++ b/editor/src/launcher/ProjectLauncher.ts
@@ -4,7 +4,7 @@
*/
import type { RecentProject } from '../types/ProjectTypes';
-import { ENGINE_VERSION, SDK_VERSION } from '../types/ProjectTypes';
+import { ENGINE_VERSION } from '../types/ProjectTypes';
import {
getRecentProjects,
removeRecentProject,
@@ -77,7 +77,7 @@ export class ProjectLauncher {
</div>
<div class="es-launcher-footer">
- <span>Editor v${ENGINE_VERSION} | SDK v${SDK_VERSION}</span>
+ <span>v${ENGINE_VERSION}</span>
</div>
</div>
`;
diff --git a/editor/src/launcher/ProjectService.ts b/editor/src/launcher/ProjectService.ts
index 6218b2d71..d38638fdf 100644
--- a/editor/src/launcher/ProjectService.ts
+++ b/editor/src/launcher/ProjectService.ts
@@ -7,6 +7,7 @@ import type {
ProjectConfig,
RecentProject,
ProjectTemplate,
+ ExampleProjectInfo,
} from '../types/ProjectTypes';
import { ENGINE_VERSION } from '../types/ProjectTypes';
import { DEFAULT_DESIGN_WIDTH, DEFAULT_DESIGN_HEIGHT, DEFAULT_PIXELS_PER_UNIT } from 'esengine';
@@ -178,6 +179,80 @@ export async function createProject(
return { success: true, data: projectFilePath };
}
+// =============================================================================
+// Create from Example
+// =============================================================================
+
+export interface CreateFromExampleOptions {
+ name: string;
+ location: string;
+ example: ExampleProjectInfo;
+}
+
+export async function createFromExample(
+ options: CreateFromExampleOptions
+): Promise<ProjectServiceResult<string>> {
+ const fs = getNativeFS();
+ const invoke = getEditorContext().invoke;
+ if (!fs || !invoke) {
+ return { success: false, error: 'Native file system not available' };
+ }
+
+ const { name, location, example } = options;
+ const projectDir = getProjectDir(location, name);
+
+ if (await fs.exists(projectDir)) {
+ return { success: false, error: 'Project directory already exists' };
+ }
+
+ try {
+ const response = await fetch(`/${example.zipFile}`);
+ if (!response.ok) {
+ return { success: false, error: `Failed to fetch example: ${response.statusText}` };
+ }
+
+ const arrayBuffer = await response.arrayBuffer();
+ const zipBytes = Array.from(new Uint8Array(arrayBuffer));
+
+ await invoke('unzip_to_directory', {
+ zipBytes,
+ targetDir: projectDir,
+ });
+
+ // Update project config with user's name and current engine version
+ const projectFilePath = joinPath(projectDir, 'project.esproject');
+ const configContent = await fs.readFile(projectFilePath);
+ if (configContent) {
+ try {
+ const config = JSON.parse(configContent) as ProjectConfig;
+ config.name = name;
+ config.engine = ENGINE_VERSION;
+ const now = new Date().toISOString();
+ config.created = now;
+ config.modified = now;
+ await fs.writeFile(projectFilePath, JSON.stringify(config, null, 2));
+ } catch { /* keep original config if parse fails */ }
+ }
+
+ // Export SDK and editor types
+ const sdkService = new SdkExportService();
+ await sdkService.exportToProject(projectDir);
+
+ const editorExportService = new EditorExportService();
+ await editorExportService.exportToProject(projectDir);
+
+ addRecentProject({
+ name,
+ path: projectFilePath,
+ lastOpened: new Date().toISOString(),
+ });
+
+ return { success: true, data: projectFilePath };
+ } catch (err) {
+ return { success: false, error: String(err) };
+ }
+}
+
export async function openProjectDialog(): Promise<ProjectServiceResult<string>> {
const fs = getNativeFS();
if (!fs) {
diff --git a/editor/src/styles/dialogs.css b/editor/src/styles/dialogs.css
index 1d86688f8..50c744e42 100644
--- a/editor/src/styles/dialogs.css
+++ b/editor/src/styles/dialogs.css
@@ -330,6 +330,41 @@
background: var(--es-bg-hover);
}
+.es-dialog-tabs {
+ display: flex;
+ gap: 0;
+ margin-bottom: 16px;
+ border-bottom: 1px solid var(--es-border);
+}
+
+.es-dialog-tab {
+ padding: 8px 20px;
+ background: none;
+ border: none;
+ border-bottom: 2px solid transparent;
+ color: var(--es-text-secondary);
+ font-size: 14px;
+ cursor: pointer;
+ transition: all 0.15s;
+}
+
+.es-dialog-tab:hover {
+ color: var(--es-text-primary);
+}
+
+.es-dialog-tab.active {
+ color: var(--es-accent-gold);
+ border-bottom-color: var(--es-accent-gold);
+}
+
+.es-dialog-empty {
+ display: block;
+ color: var(--es-text-secondary);
+ font-size: 13px;
+ padding: 20px 0;
+ text-align: center;
+}
+
.es-dialog-templates {
display: flex;
flex-direction: column;
diff --git a/editor/src/types/ProjectTypes.ts b/editor/src/types/ProjectTypes.ts
index a4a507e12..17094ec56 100644
--- a/editor/src/types/ProjectTypes.ts
+++ b/editor/src/types/ProjectTypes.ts
@@ -79,11 +79,34 @@ export const PROJECT_TEMPLATES: ProjectTemplateInfo[] = [
},
];
+// =============================================================================
+// Example Projects
+// =============================================================================
+
+export interface ExampleProjectInfo {
+ id: string;
+ name: string;
+ description: string;
+ zipFile: string;
+}
+
+export const EXAMPLE_PROJECTS: ExampleProjectInfo[] = [
+ {
+ id: 'space-shooter',
+ name: 'Space Shooter',
+ description: 'A vertical scrolling shoot\'em up with enemies, bullets, explosions and HUD',
+ zipFile: 'examples/space-shooter.zip',
+ },
+];
+
// =============================================================================
// Constants
// =============================================================================
export const PROJECT_FILE_EXTENSION = '.esproject';
export const SCENE_FILE_EXTENSION = '.esscene';
-export const ENGINE_VERSION = '0.1.0';
-export const SDK_VERSION = '0.4.0';
+declare const __ENGINE_VERSION__: string;
+declare const __SDK_VERSION__: string;
+
+export const ENGINE_VERSION: string = typeof __ENGINE_VERSION__ !== 'undefined' ? __ENGINE_VERSION__ : '0.0.0';
+export const SDK_VERSION: string = typeof __SDK_VERSION__ !== 'undefined' ? __SDK_VERSION__ : '0.0.0';
diff --git a/examples/space-shooter/.esengine/settings.json b/examples/space-shooter/.esengine/settings.json
new file mode 100644
index 000000000..49baf3816
--- /dev/null
+++ b/examples/space-shooter/.esengine/settings.json
@@ -0,0 +1,3 @@
+{
+ "lastOpenedScene": "assets/scenes/main.esscene"
+}
diff --git a/examples/space-shooter/.gitignore b/examples/space-shooter/.gitignore
new file mode 100644
index 000000000..359472ac2
--- /dev/null
+++ b/examples/space-shooter/.gitignore
@@ -0,0 +1,7 @@
+node_modules/
+dist/
+.vscode/
+.idea/
+.DS_Store
+Thumbs.db
+.esengine/cache/
diff --git a/examples/space-shooter/assets/prefabs/EnemyA.esprefab.meta b/examples/space-shooter/assets/prefabs/EnemyA.esprefab.meta
new file mode 100644
index 000000000..b04c38a61
--- /dev/null
+++ b/examples/space-shooter/assets/prefabs/EnemyA.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "32ce19e9-a172-4c3b-b984-0abe846318d9",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/prefabs/EnemyB.esprefab.meta b/examples/space-shooter/assets/prefabs/EnemyB.esprefab.meta
new file mode 100644
index 000000000..0e9dcd9e7
--- /dev/null
+++ b/examples/space-shooter/assets/prefabs/EnemyB.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "7fd4ff1c-73db-456a-94c5-6a01fc798d44",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/prefabs/EnemyBullet.esprefab.meta b/examples/space-shooter/assets/prefabs/EnemyBullet.esprefab.meta
new file mode 100644
index 000000000..0fcc5ea12
--- /dev/null
+++ b/examples/space-shooter/assets/prefabs/EnemyBullet.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "0646ae9b-8fc5-4962-b2a8-c63b786af407",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/prefabs/Explosion.esprefab.meta b/examples/space-shooter/assets/prefabs/Explosion.esprefab.meta
new file mode 100644
index 000000000..0289aafea
--- /dev/null
+++ b/examples/space-shooter/assets/prefabs/Explosion.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "050e931e-47f7-4dce-8955-db800468c399",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/prefabs/PlayerBullet.esprefab.meta b/examples/space-shooter/assets/prefabs/PlayerBullet.esprefab.meta
new file mode 100644
index 000000000..c961dca4e
--- /dev/null
+++ b/examples/space-shooter/assets/prefabs/PlayerBullet.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "d9a8fcb9-2320-4751-8a8e-33a3d05adc5a",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/prefabs/Star.esprefab.meta b/examples/space-shooter/assets/prefabs/Star.esprefab.meta
new file mode 100644
index 000000000..0f715d0a9
--- /dev/null
+++ b/examples/space-shooter/assets/prefabs/Star.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "dba300e8-3d8c-40f1-8dba-4f7897969ff7",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/scenes/main.esscene b/examples/space-shooter/assets/scenes/main.esscene
new file mode 100644
index 000000000..70a7123ef
--- /dev/null
+++ b/examples/space-shooter/assets/scenes/main.esscene
@@ -0,0 +1,165 @@
+{
+ "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": 540, "isActive": true, "priority": 0 } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 1,
+ "name": "Background",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": -1 } } },
+ { "type": "Sprite", "data": { "texture": "78c53bf7-88b8-481d-805c-a443c2d06076", "size": { "x": 600, "y": 1080 }, "layer": -1 } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 2,
+ "name": "Player",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": -420, "z": 0 } } },
+ { "type": "Sprite", "data": { "texture": "92f1ab5f-28f4-4b95-bb82-7182fdb33494", "size": { "x": 64, "y": 64 } } },
+ { "type": "Player", "data": { "speed": 400 } },
+ { "type": "Health", "data": { "value": 3, "maxValue": 3 } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 10,
+ "name": "HUD",
+ "parent": null,
+ "children": [11, 12, 13, 14, 15],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "Canvas", "data": { "designResolution": { "x": 600, "y": 1080 } } },
+ { "type": "UIRect", "data": {
+ "anchorMin": { "x": 0.5, "y": 0.5 },
+ "anchorMax": { "x": 0.5, "y": 0.5 },
+ "size": { "x": 600, "y": 1080 },
+ "pivot": { "x": 0.5, "y": 0.5 }
+ }}
+ ],
+ "visible": true
+ },
+ {
+ "id": 11,
+ "name": "ScoreText",
+ "parent": 10,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "UIRect", "data": {
+ "anchorMin": { "x": 0, "y": 1 },
+ "anchorMax": { "x": 0, "y": 1 },
+ "offsetMin": { "x": 20, "y": -40 },
+ "size": { "x": 200, "y": 40 },
+ "pivot": { "x": 0, "y": 1 }
+ }},
+ { "type": "Text", "data": {
+ "content": "SCORE: 0",
+ "fontSize": 28,
+ "color": { "r": 0, "g": 0.86, "b": 1, "a": 1 },
+ "align": 0,
+ "verticalAlign": 0
+ }},
+ { "type": "ScoreDisplay", "data": {} }
+ ],
+ "visible": true
+ },
+ {
+ "id": 12,
+ "name": "Heart1",
+ "parent": 10,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 216, "y": 520, "z": 0 } } },
+ { "type": "UIRect", "data": {
+ "anchorMin": { "x": 1, "y": 1 },
+ "anchorMax": { "x": 1, "y": 1 },
+ "offsetMin": { "x": -84, "y": -20 },
+ "size": { "x": 24, "y": 24 },
+ "pivot": { "x": 1, "y": 1 }
+ }},
+ { "type": "Image", "data": { "texture": "5b21b6a6-dffa-4256-872a-36f4e4549408", "color": { "r": 1, "g": 1, "b": 1, "a": 1 } } },
+ { "type": "HealthHeart", "data": {} }
+ ],
+ "visible": true
+ },
+ {
+ "id": 13,
+ "name": "Heart2",
+ "parent": 10,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 248, "y": 520, "z": 0 } } },
+ { "type": "UIRect", "data": {
+ "anchorMin": { "x": 1, "y": 1 },
+ "anchorMax": { "x": 1, "y": 1 },
+ "offsetMin": { "x": -52, "y": -20 },
+ "size": { "x": 24, "y": 24 },
+ "pivot": { "x": 1, "y": 1 }
+ }},
+ { "type": "Image", "data": { "texture": "5b21b6a6-dffa-4256-872a-36f4e4549408", "color": { "r": 1, "g": 1, "b": 1, "a": 1 } } },
+ { "type": "HealthHeart", "data": {} }
+ ],
+ "visible": true
+ },
+ {
+ "id": 14,
+ "name": "Heart3",
+ "parent": 10,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 280, "y": 520, "z": 0 } } },
+ { "type": "UIRect", "data": {
+ "anchorMin": { "x": 1, "y": 1 },
+ "anchorMax": { "x": 1, "y": 1 },
+ "offsetMin": { "x": -20, "y": -20 },
+ "size": { "x": 24, "y": 24 },
+ "pivot": { "x": 1, "y": 1 }
+ }},
+ { "type": "Image", "data": { "texture": "5b21b6a6-dffa-4256-872a-36f4e4549408", "color": { "r": 1, "g": 1, "b": 1, "a": 1 } } },
+ { "type": "HealthHeart", "data": {} }
+ ],
+ "visible": true
+ },
+ {
+ "id": 15,
+ "name": "GameOverText",
+ "parent": 10,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "UIRect", "data": {
+ "anchorMin": { "x": 0.5, "y": 0.5 },
+ "anchorMax": { "x": 0.5, "y": 0.5 },
+ "offsetMin": { "x": 0, "y": 0 },
+ "size": { "x": 400, "y": 120 },
+ "pivot": { "x": 0.5, "y": 0.5 }
+ }},
+ { "type": "Text", "data": {
+ "content": "",
+ "fontSize": 36,
+ "color": { "r": 1, "g": 0.24, "b": 0.24, "a": 1 },
+ "align": 1,
+ "verticalAlign": 1
+ }},
+ { "type": "GameOverScreen", "data": {} }
+ ],
+ "visible": true
+ }
+ ]
+}
diff --git a/examples/space-shooter/assets/scenes/main.esscene.meta b/examples/space-shooter/assets/scenes/main.esscene.meta
new file mode 100644
index 000000000..7975df58b
--- /dev/null
+++ b/examples/space-shooter/assets/scenes/main.esscene.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "8615ad9d-a4f9-4f97-902f-fbecc698e2be",
+ "version": "2.0",
+ "type": "scene",
+ "importer": {
+ "autoMigrate": true
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/background.png b/examples/space-shooter/assets/textures/background.png
new file mode 100644
index 000000000..f468f83ce
Binary files /dev/null and b/examples/space-shooter/assets/textures/background.png differ
diff --git a/examples/space-shooter/assets/textures/background.png.meta b/examples/space-shooter/assets/textures/background.png.meta
new file mode 100644
index 000000000..d48bddce5
--- /dev/null
+++ b/examples/space-shooter/assets/textures/background.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "78c53bf7-88b8-481d-805c-a443c2d06076",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/bullet-enemy.png b/examples/space-shooter/assets/textures/bullet-enemy.png
new file mode 100644
index 000000000..993e082a3
Binary files /dev/null and b/examples/space-shooter/assets/textures/bullet-enemy.png differ
diff --git a/examples/space-shooter/assets/textures/bullet-enemy.png.meta b/examples/space-shooter/assets/textures/bullet-enemy.png.meta
new file mode 100644
index 000000000..5fb5f8a08
--- /dev/null
+++ b/examples/space-shooter/assets/textures/bullet-enemy.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "97a221a6-85bd-49e7-9af5-2880960fecda",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/bullet-player.png b/examples/space-shooter/assets/textures/bullet-player.png
new file mode 100644
index 000000000..c931613b9
Binary files /dev/null and b/examples/space-shooter/assets/textures/bullet-player.png differ
diff --git a/examples/space-shooter/assets/textures/bullet-player.png.meta b/examples/space-shooter/assets/textures/bullet-player.png.meta
new file mode 100644
index 000000000..ac28f6c47
--- /dev/null
+++ b/examples/space-shooter/assets/textures/bullet-player.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "c643c566-1859-460a-8029-4568951787f8",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/enemy-a.png b/examples/space-shooter/assets/textures/enemy-a.png
new file mode 100644
index 000000000..37c576426
Binary files /dev/null and b/examples/space-shooter/assets/textures/enemy-a.png differ
diff --git a/examples/space-shooter/assets/textures/enemy-a.png.meta b/examples/space-shooter/assets/textures/enemy-a.png.meta
new file mode 100644
index 000000000..c653a2469
--- /dev/null
+++ b/examples/space-shooter/assets/textures/enemy-a.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "25e60610-c126-48bf-9b14-85c4699dc912",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/enemy-b.png b/examples/space-shooter/assets/textures/enemy-b.png
new file mode 100644
index 000000000..0c2b9b32f
Binary files /dev/null and b/examples/space-shooter/assets/textures/enemy-b.png differ
diff --git a/examples/space-shooter/assets/textures/enemy-b.png.meta b/examples/space-shooter/assets/textures/enemy-b.png.meta
new file mode 100644
index 000000000..0c4494aa3
--- /dev/null
+++ b/examples/space-shooter/assets/textures/enemy-b.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "d429cf7d-d52c-42eb-823e-9b775b6249b6",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/explosion.png b/examples/space-shooter/assets/textures/explosion.png
new file mode 100644
index 000000000..960964004
Binary files /dev/null and b/examples/space-shooter/assets/textures/explosion.png differ
diff --git a/examples/space-shooter/assets/textures/explosion.png.meta b/examples/space-shooter/assets/textures/explosion.png.meta
new file mode 100644
index 000000000..d227e7e9e
--- /dev/null
+++ b/examples/space-shooter/assets/textures/explosion.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "4e16b7e8-3ba1-455b-ab3c-1cfbf5a97e0c",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/heart.png b/examples/space-shooter/assets/textures/heart.png
new file mode 100644
index 000000000..2066e09d7
Binary files /dev/null and b/examples/space-shooter/assets/textures/heart.png differ
diff --git a/examples/space-shooter/assets/textures/heart.png.meta b/examples/space-shooter/assets/textures/heart.png.meta
new file mode 100644
index 000000000..e1de6f9b5
--- /dev/null
+++ b/examples/space-shooter/assets/textures/heart.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "5b21b6a6-dffa-4256-872a-36f4e4549408",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/player.png b/examples/space-shooter/assets/textures/player.png
new file mode 100644
index 000000000..31118d46a
Binary files /dev/null and b/examples/space-shooter/assets/textures/player.png differ
diff --git a/examples/space-shooter/assets/textures/player.png.meta b/examples/space-shooter/assets/textures/player.png.meta
new file mode 100644
index 000000000..c1d1b5823
--- /dev/null
+++ b/examples/space-shooter/assets/textures/player.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "92f1ab5f-28f4-4b95-bb82-7182fdb33494",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/assets/textures/star.png b/examples/space-shooter/assets/textures/star.png
new file mode 100644
index 000000000..d4f590653
Binary files /dev/null and b/examples/space-shooter/assets/textures/star.png differ
diff --git a/examples/space-shooter/assets/textures/star.png.meta b/examples/space-shooter/assets/textures/star.png.meta
new file mode 100644
index 000000000..c8c62397b
--- /dev/null
+++ b/examples/space-shooter/assets/textures/star.png.meta
@@ -0,0 +1,17 @@
+{
+ "uuid": "8f56c884-0439-47f1-86d9-05839abfa6e0",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/space-shooter/project.esproject b/examples/space-shooter/project.esproject
new file mode 100644
index 000000000..0dfb09eab
--- /dev/null
+++ b/examples/space-shooter/project.esproject
@@ -0,0 +1,10 @@
+{
+ "name": "Space Shooter",
+ "version": "0.1.0",
+ "engine": "0.1.0",
+ "defaultScene": "assets/scenes/main.esscene",
+ "created": "2026-02-26T00:00:00.000Z",
+ "modified": "2026-02-26T00:00:00.000Z",
+ "spineVersion": "none",
+ "designResolution": { "width": 600, "height": 1080 }
+}
diff --git a/examples/space-shooter/src/components.ts b/examples/space-shooter/src/components.ts
new file mode 100644
index 000000000..401c5241d
--- /dev/null
+++ b/examples/space-shooter/src/components.ts
@@ -0,0 +1,35 @@
+import { defineComponent, defineTag } from 'esengine';
+
+export const Player = defineComponent('Player', {
+ speed: 400,
+});
+
+export const Enemy = defineComponent('Enemy', {
+ speed: 150,
+ type: 'A',
+ shootTimer: 2,
+ phase: 0,
+});
+
+export const Bullet = defineComponent('Bullet', {
+ speed: 600,
+ fromPlayer: true,
+});
+
+export const Star = defineComponent('Star', {
+ speed: 30,
+ layer: 0,
+});
+
+export const Explosion = defineComponent('Explosion', {
+ timer: 0.3,
+});
+
+export const Health = defineComponent('Health', {
+ value: 3,
+ maxValue: 3,
+});
+
+export const ScoreDisplay = defineTag('ScoreDisplay');
+export const HealthHeart = defineTag('HealthHeart');
+export const GameOverScreen = defineTag('GameOverScreen');
diff --git a/examples/space-shooter/src/main.ts b/examples/space-shooter/src/main.ts
new file mode 100644
index 000000000..0fdb6b758
--- /dev/null
+++ b/examples/space-shooter/src/main.ts
@@ -0,0 +1,22 @@
+import { addStartupSystem, addSystemToSchedule, Schedule } from 'esengine';
+
+import './components';
+import { setupSystem } from './systems/setup';
+import { playerMoveSystem, playerShootSystem } from './systems/player';
+import { enemySpawnSystem, enemyAISystem } from './systems/enemy';
+import { collisionSystem } from './systems/collision';
+import { bulletMoveSystem, explosionSystem, starScrollSystem, boundarySystem } from './systems/effects';
+import { hudSystem, gameOverSystem } from './systems/hud';
+
+addStartupSystem(setupSystem);
+addSystemToSchedule(Schedule.Update, playerMoveSystem);
+addSystemToSchedule(Schedule.Update, playerShootSystem);
+addSystemToSchedule(Schedule.Update, enemySpawnSystem);
+addSystemToSchedule(Schedule.Update, enemyAISystem);
+addSystemToSchedule(Schedule.Update, bulletMoveSystem);
+addSystemToSchedule(Schedule.Update, collisionSystem);
+addSystemToSchedule(Schedule.Update, explosionSystem);
+addSystemToSchedule(Schedule.Update, starScrollSystem);
+addSystemToSchedule(Schedule.Update, boundarySystem);
+addSystemToSchedule(Schedule.Update, hudSystem);
+addSystemToSchedule(Schedule.Update, gameOverSystem);
diff --git a/examples/space-shooter/src/resources.ts b/examples/space-shooter/src/resources.ts
new file mode 100644
index 000000000..7940712ef
--- /dev/null
+++ b/examples/space-shooter/src/resources.ts
@@ -0,0 +1,65 @@
+import { defineResource, type PrefabOverride } from 'esengine';
+
+export const HALF_HEIGHT = 540;
+export const HALF_WIDTH = 300;
+export const PLAYER_START_Y = -420;
+export const SPAWN_Y = HALF_HEIGHT + 60;
+export const DESTROY_Y = -(HALF_HEIGHT + 60);
+
+export const PLAYER_SIZE = 64;
+export const ENEMY_A_SIZE = 48;
+export const ENEMY_B_SIZE = 56;
+export const BULLET_PLAYER_W = 8;
+export const BULLET_PLAYER_H = 24;
+export const BULLET_ENEMY_W = 8;
+export const BULLET_ENEMY_H = 20;
+export const EXPLOSION_SIZE = 64;
+export const STAR_SIZE = 4;
+
+export const SHOOT_COOLDOWN = 0.15;
+export const ENEMY_SPAWN_INTERVAL_BASE = 1.2;
+export const ENEMY_SPAWN_INTERVAL_MIN = 0.3;
+export const DIFFICULTY_RAMP_RATE = 0.02;
+
+export const PREFAB_ENEMY_A = 'assets/prefabs/EnemyA.esprefab';
+export const PREFAB_ENEMY_B = 'assets/prefabs/EnemyB.esprefab';
+export const PREFAB_PLAYER_BULLET = 'assets/prefabs/PlayerBullet.esprefab';
+export const PREFAB_ENEMY_BULLET = 'assets/prefabs/EnemyBullet.esprefab';
+export const PREFAB_EXPLOSION = 'assets/prefabs/Explosion.esprefab';
+export const PREFAB_STAR = 'assets/prefabs/Star.esprefab';
+
+export function positionOverride(x: number, y: number): PrefabOverride {
+ return {
+ prefabEntityId: 0,
+ type: 'property',
+ componentType: 'Transform',
+ propertyName: 'position',
+ value: { x, y, z: 0 },
+ };
+}
+
+export function propOverride(componentType: string, propertyName: string, value: unknown): PrefabOverride {
+ return {
+ prefabEntityId: 0,
+ type: 'property',
+ componentType,
+ propertyName,
+ value,
+ };
+}
+
+export interface GameStateData {
+ score: number;
+ gameOver: boolean;
+ spawnTimer: number;
+ difficulty: number;
+ shootCooldown: number;
+}
+
+export const GameState = defineResource<GameStateData>({
+ score: 0,
+ gameOver: false,
+ spawnTimer: 0,
+ difficulty: 1,
+ shootCooldown: 0,
+}, 'GameState');
diff --git a/examples/space-shooter/src/systems/collision.ts b/examples/space-shooter/src/systems/collision.ts
new file mode 100644
index 000000000..911d454be
--- /dev/null
+++ b/examples/space-shooter/src/systems/collision.ts
@@ -0,0 +1,94 @@
+import {
+ defineSystem, Query, Mut, ResMut, Res, Commands,
+ Transform, Prefabs, type Entity,
+} from 'esengine';
+import { Bullet, Enemy, Player, Health } from '../components';
+import {
+ GameState, PREFAB_EXPLOSION, positionOverride,
+ ENEMY_A_SIZE, ENEMY_B_SIZE, PLAYER_SIZE,
+ BULLET_PLAYER_W, BULLET_PLAYER_H,
+ BULLET_ENEMY_W, BULLET_ENEMY_H,
+} from '../resources';
+
+function aabb(
+ ax: number, ay: number, aw: number, ah: number,
+ bx: number, by: number, bw: number, bh: number,
+): boolean {
+ return Math.abs(ax - bx) < (aw + bw) / 2
+ && Math.abs(ay - by) < (ah + bh) / 2;
+}
+
+export const collisionSystem = defineSystem(
+ [
+ Commands(),
+ ResMut(GameState),
+ Res(Prefabs),
+ Query(Transform, Bullet),
+ Query(Transform, Enemy),
+ Query(Transform, Mut(Health), Player),
+ ],
+ (cmds, stateMut, prefabServer, bulletQuery, enemyQuery, playerQuery) => {
+ const state = stateMut.get();
+ if (state.gameOver) return;
+
+ const destroyed = new Set<Entity>();
+
+ for (const [bulletEntity, bulletTf, bullet] of bulletQuery) {
+ if (!bullet.fromPlayer) continue;
+ if (destroyed.has(bulletEntity)) continue;
+
+ for (const [enemyEntity, enemyTf, enemy] of enemyQuery) {
+ if (destroyed.has(enemyEntity)) continue;
+
+ const enemySize = enemy.type === 'B' ? ENEMY_B_SIZE : ENEMY_A_SIZE;
+
+ if (aabb(
+ bulletTf.position.x, bulletTf.position.y,
+ BULLET_PLAYER_W, BULLET_PLAYER_H,
+ enemyTf.position.x, enemyTf.position.y,
+ enemySize, enemySize,
+ )) {
+ cmds.despawn(bulletEntity);
+ cmds.despawn(enemyEntity);
+ destroyed.add(bulletEntity);
+ destroyed.add(enemyEntity);
+
+ state.score += enemy.type === 'B' ? 20 : 10;
+
+ prefabServer.instantiate(PREFAB_EXPLOSION, {
+ overrides: [
+ positionOverride(enemyTf.position.x, enemyTf.position.y),
+ ],
+ });
+ break;
+ }
+ }
+ }
+
+ for (const [bulletEntity, bulletTf, bullet] of bulletQuery) {
+ if (bullet.fromPlayer) continue;
+ if (destroyed.has(bulletEntity)) continue;
+
+ for (const [_playerEntity, playerTf, health] of playerQuery) {
+ if (aabb(
+ bulletTf.position.x, bulletTf.position.y,
+ BULLET_ENEMY_W, BULLET_ENEMY_H,
+ playerTf.position.x, playerTf.position.y,
+ PLAYER_SIZE * 0.6, PLAYER_SIZE * 0.6,
+ )) {
+ cmds.despawn(bulletEntity);
+ destroyed.add(bulletEntity);
+ health.value -= 1;
+
+ prefabServer.instantiate(PREFAB_EXPLOSION, {
+ overrides: [
+ positionOverride(playerTf.position.x, playerTf.position.y),
+ ],
+ });
+ break;
+ }
+ }
+ }
+ },
+ { name: 'CollisionSystem' }
+);
diff --git a/examples/space-shooter/src/systems/effects.ts b/examples/space-shooter/src/systems/effects.ts
new file mode 100644
index 000000000..bbe85cbfd
--- /dev/null
+++ b/examples/space-shooter/src/systems/effects.ts
@@ -0,0 +1,74 @@
+import {
+ defineSystem, Query, Mut, Res, Commands,
+ Transform, Time,
+} from 'esengine';
+import { Explosion, Star, Bullet, Enemy } from '../components';
+import { HALF_HEIGHT, HALF_WIDTH, DESTROY_Y, SPAWN_Y } from '../resources';
+
+export const bulletMoveSystem = defineSystem(
+ [Res(Time), Query(Mut(Transform), Bullet)],
+ (time, query) => {
+ const dt = time.delta;
+
+ for (const [_entity, transform, bullet] of query) {
+ const dir = bullet.fromPlayer ? 1 : -1;
+ transform.position.y += bullet.speed * dt * dir;
+ }
+ },
+ { name: 'BulletMoveSystem' }
+);
+
+export const explosionSystem = defineSystem(
+ [Res(Time), Commands(), Query(Mut(Transform), Mut(Explosion))],
+ (time, cmds, query) => {
+ const dt = time.delta;
+
+ for (const [entity, transform, explosion] of query) {
+ explosion.timer -= dt;
+
+ const progress = 1 - explosion.timer / 0.3;
+ const scale = 0.5 + progress * 1.0;
+ transform.scale = { x: scale, y: scale, z: 1 };
+
+ if (explosion.timer <= 0) {
+ cmds.despawn(entity);
+ }
+ }
+ },
+ { name: 'ExplosionSystem' }
+);
+
+export const starScrollSystem = defineSystem(
+ [Res(Time), Query(Mut(Transform), Star)],
+ (time, query) => {
+ const dt = time.delta;
+
+ for (const [_entity, transform, star] of query) {
+ transform.position.y -= star.speed * dt;
+
+ if (transform.position.y < -HALF_HEIGHT - 10) {
+ transform.position.y = HALF_HEIGHT + 10;
+ transform.position.x = (Math.random() - 0.5) * HALF_WIDTH * 2;
+ }
+ }
+ },
+ { name: 'StarScrollSystem' }
+);
+
+export const boundarySystem = defineSystem(
+ [Commands(), Query(Transform, Bullet), Query(Transform, Enemy)],
+ (cmds, bulletQuery, enemyQuery) => {
+ for (const [entity, transform] of bulletQuery) {
+ if (transform.position.y > SPAWN_Y || transform.position.y < DESTROY_Y) {
+ cmds.despawn(entity);
+ }
+ }
+
+ for (const [entity, transform] of enemyQuery) {
+ if (transform.position.y < DESTROY_Y) {
+ cmds.despawn(entity);
+ }
+ }
+ },
+ { name: 'BoundarySystem' }
+);
diff --git a/examples/space-shooter/src/systems/enemy.ts b/examples/space-shooter/src/systems/enemy.ts
new file mode 100644
index 000000000..2983b8048
--- /dev/null
+++ b/examples/space-shooter/src/systems/enemy.ts
@@ -0,0 +1,85 @@
+import {
+ defineSystem, Query, Mut, Res, ResMut,
+ Transform, Time, Prefabs,
+} from 'esengine';
+import { Enemy } from '../components';
+import {
+ GameState, HALF_WIDTH, SPAWN_Y,
+ ENEMY_SPAWN_INTERVAL_BASE, ENEMY_SPAWN_INTERVAL_MIN, DIFFICULTY_RAMP_RATE,
+ PREFAB_ENEMY_A, PREFAB_ENEMY_B, PREFAB_ENEMY_BULLET,
+ positionOverride, propOverride,
+} from '../resources';
+
+export const enemySpawnSystem = defineSystem(
+ [Res(Time), ResMut(GameState), Res(Prefabs)],
+ (time, stateMut, prefabServer) => {
+ const state = stateMut.get();
+ if (state.gameOver) return;
+
+ state.difficulty += DIFFICULTY_RAMP_RATE * time.delta;
+ state.spawnTimer -= time.delta;
+
+ if (state.spawnTimer > 0) return;
+
+ const interval = Math.max(
+ ENEMY_SPAWN_INTERVAL_MIN,
+ ENEMY_SPAWN_INTERVAL_BASE / state.difficulty
+ );
+ state.spawnTimer = interval;
+
+ const spawnX = (Math.random() - 0.5) * (HALF_WIDTH * 2 - 60);
+ const isTypeB = Math.random() < 0.35;
+
+ if (isTypeB) {
+ prefabServer.instantiate(PREFAB_ENEMY_B, {
+ overrides: [
+ positionOverride(spawnX, SPAWN_Y),
+ propOverride('Enemy', 'speed', 100 + state.difficulty * 10),
+ propOverride('Enemy', 'shootTimer', 2 + Math.random() * 2),
+ propOverride('Enemy', 'phase', Math.random() * Math.PI * 2),
+ ],
+ });
+ } else {
+ prefabServer.instantiate(PREFAB_ENEMY_A, {
+ overrides: [
+ positionOverride(spawnX, SPAWN_Y),
+ propOverride('Enemy', 'speed', 120 + state.difficulty * 15),
+ propOverride('Enemy', 'shootTimer', 1.5 + Math.random() * 2),
+ ],
+ });
+ }
+ },
+ { name: 'EnemySpawnSystem' }
+);
+
+export const enemyAISystem = defineSystem(
+ [Res(Time), Res(GameState), Res(Prefabs), Query(Mut(Transform), Mut(Enemy))],
+ (time, state, prefabServer, query) => {
+ if (state.gameOver) return;
+ const dt = time.delta;
+
+ for (const [_entity, transform, enemy] of query) {
+ transform.position.y -= enemy.speed * dt;
+
+ if (enemy.type === 'B') {
+ enemy.phase += dt * 3;
+ transform.position.x += Math.sin(enemy.phase) * 120 * dt;
+ transform.position.x = Math.max(
+ -HALF_WIDTH + 30,
+ Math.min(HALF_WIDTH - 30, transform.position.x)
+ );
+ }
+
+ enemy.shootTimer -= dt;
+ if (enemy.shootTimer <= 0) {
+ enemy.shootTimer = 2 + Math.random() * 2;
+ prefabServer.instantiate(PREFAB_ENEMY_BULLET, {
+ overrides: [
+ positionOverride(transform.position.x, transform.position.y - 30),
+ ],
+ });
+ }
+ }
+ },
+ { name: 'EnemyAISystem' }
+);
diff --git a/examples/space-shooter/src/systems/hud.ts b/examples/space-shooter/src/systems/hud.ts
new file mode 100644
index 000000000..64cfd9047
--- /dev/null
+++ b/examples/space-shooter/src/systems/hud.ts
@@ -0,0 +1,79 @@
+import {
+ defineSystem, Query, Mut, Res, ResMut, Commands,
+ Input, Text, Image, Transform,
+} from 'esengine';
+import { Player, Health, ScoreDisplay, HealthHeart, GameOverScreen, Enemy, Bullet, Explosion } from '../components';
+import { GameState, PLAYER_START_Y } from '../resources';
+
+export const hudSystem = defineSystem(
+ [Res(GameState), Query(Mut(Text), ScoreDisplay), Query(Health, Player), Query(Mut(Image), HealthHeart)],
+ (state, scoreQuery, playerQuery, heartQuery) => {
+ for (const [_entity, text] of scoreQuery) {
+ text.content = `SCORE: ${state.score}`;
+ }
+
+ for (const [_entity, health] of playerQuery) {
+ let heartIndex = 0;
+ for (const [_hEntity, image] of heartQuery) {
+ image.color = heartIndex < health.value
+ ? { r: 1, g: 1, b: 1, a: 1 }
+ : { r: 0.3, g: 0.3, b: 0.3, a: 0.4 };
+ heartIndex++;
+ }
+ }
+ },
+ { name: 'HUDSystem' }
+);
+
+export const gameOverSystem = defineSystem(
+ [
+ Res(Input), ResMut(GameState), Commands(),
+ Query(Mut(Transform), Mut(Health), Player),
+ Query(Mut(Text), GameOverScreen),
+ Query(Enemy),
+ Query(Bullet),
+ Query(Explosion),
+ ],
+ (input, stateMut, cmds, playerQuery, gameOverQuery, enemyQuery, bulletQuery, explosionQuery) => {
+ const state = stateMut.get();
+
+ for (const [_entity, _transform, health] of playerQuery) {
+ if (health.value <= 0 && !state.gameOver) {
+ state.gameOver = true;
+
+ for (const [_goEntity, text] of gameOverQuery) {
+ text.content = `GAME OVER\nSCORE: ${state.score}\nPress R to restart`;
+ }
+ }
+ }
+
+ if (state.gameOver && input.isKeyPressed('KeyR')) {
+ state.score = 0;
+ state.gameOver = false;
+ state.spawnTimer = 0;
+ state.difficulty = 1;
+ state.shootCooldown = 0;
+
+ for (const [_entity, transform, health] of playerQuery) {
+ health.value = health.maxValue;
+ transform.position.x = 0;
+ transform.position.y = PLAYER_START_Y;
+ }
+
+ for (const [_goEntity, text] of gameOverQuery) {
+ text.content = '';
+ }
+
+ for (const [entity] of enemyQuery) {
+ cmds.despawn(entity);
+ }
+ for (const [entity] of bulletQuery) {
+ cmds.despawn(entity);
+ }
+ for (const [entity] of explosionQuery) {
+ cmds.despawn(entity);
+ }
+ }
+ },
+ { name: 'GameOverSystem' }
+);
diff --git a/examples/space-shooter/src/systems/player.ts b/examples/space-shooter/src/systems/player.ts
new file mode 100644
index 000000000..fc20c3662
--- /dev/null
+++ b/examples/space-shooter/src/systems/player.ts
@@ -0,0 +1,66 @@
+import {
+ defineSystem, Query, Mut, Res, ResMut,
+ Transform, Input, Time, Prefabs,
+} from 'esengine';
+import { Player } from '../components';
+import {
+ GameState, HALF_WIDTH, PLAYER_SIZE, SHOOT_COOLDOWN,
+ PREFAB_PLAYER_BULLET, positionOverride,
+} from '../resources';
+
+export const playerMoveSystem = defineSystem(
+ [Res(Input), Res(Time), Res(GameState), Query(Mut(Transform), Player)],
+ (input, time, state, query) => {
+ if (state.gameOver) return;
+ const dt = time.delta;
+
+ for (const [_entity, transform, player] of query) {
+ let dx = 0;
+ let dy = 0;
+
+ if (input.isKeyDown('ArrowLeft') || input.isKeyDown('KeyA')) dx -= 1;
+ if (input.isKeyDown('ArrowRight') || input.isKeyDown('KeyD')) dx += 1;
+ if (input.isKeyDown('ArrowUp') || input.isKeyDown('KeyW')) dy += 1;
+ if (input.isKeyDown('ArrowDown') || input.isKeyDown('KeyS')) dy -= 1;
+
+ if (dx !== 0 && dy !== 0) {
+ const inv = 1 / Math.SQRT2;
+ dx *= inv;
+ dy *= inv;
+ }
+
+ transform.position.x += dx * player.speed * dt;
+ transform.position.y += dy * player.speed * dt;
+
+ const bound = HALF_WIDTH - PLAYER_SIZE / 2;
+ transform.position.x = Math.max(-bound, Math.min(bound, transform.position.x));
+ transform.position.y = Math.max(-500, Math.min(-300, transform.position.y));
+ }
+ },
+ { name: 'PlayerMoveSystem' }
+);
+
+export const playerShootSystem = defineSystem(
+ [Res(Input), Res(Time), ResMut(GameState), Res(Prefabs), Query(Transform, Player)],
+ (input, time, stateMut, prefabServer, query) => {
+ const state = stateMut.get();
+ if (state.gameOver) return;
+
+ state.shootCooldown -= time.delta;
+
+ if (input.isKeyDown('Space') && state.shootCooldown <= 0) {
+ for (const [_entity, transform] of query) {
+ prefabServer.instantiate(PREFAB_PLAYER_BULLET, {
+ overrides: [
+ positionOverride(
+ transform.position.x,
+ transform.position.y + PLAYER_SIZE / 2 + 4,
+ ),
+ ],
+ });
+ }
+ state.shootCooldown = SHOOT_COOLDOWN;
+ }
+ },
+ { name: 'PlayerShootSystem' }
+);
diff --git a/examples/space-shooter/src/systems/setup.ts b/examples/space-shooter/src/systems/setup.ts
new file mode 100644
index 000000000..e666014cc
--- /dev/null
+++ b/examples/space-shooter/src/systems/setup.ts
@@ -0,0 +1,38 @@
+import {
+ defineSystem, Commands, Res, Prefabs,
+} from 'esengine';
+import {
+ GameState, HALF_WIDTH, HALF_HEIGHT,
+ PREFAB_STAR, positionOverride, propOverride,
+} from '../resources';
+
+const INITIAL_STAR_COUNT = 40;
+
+export const setupSystem = defineSystem(
+ [Commands(), Res(Prefabs)],
+ (cmds, prefabServer) => {
+ cmds.insertResource(GameState, {
+ score: 0,
+ gameOver: false,
+ spawnTimer: 0,
+ difficulty: 1,
+ shootCooldown: 0,
+ });
+
+ for (let i = 0; i < INITIAL_STAR_COUNT; i++) {
+ const layer = i % 3;
+ const speed = 20 + layer * 30;
+ prefabServer.instantiate(PREFAB_STAR, {
+ overrides: [
+ positionOverride(
+ (Math.random() - 0.5) * HALF_WIDTH * 2,
+ (Math.random() - 0.5) * HALF_HEIGHT * 2,
+ ),
+ propOverride('Star', 'speed', speed),
+ propOverride('Sprite', 'color', { r: 1, g: 1, b: 1, a: 0.3 + layer * 0.3 }),
+ ],
+ });
+ }
+ },
+ { name: 'SetupSystem' }
+);
diff --git a/examples/space-shooter/tsconfig.json b/examples/space-shooter/tsconfig.json
new file mode 100644
index 000000000..0a8528b29
--- /dev/null
+++ b/examples/space-shooter/tsconfig.json
@@ -0,0 +1,22 @@
+{
+ "compilerOptions": {
+ "target": "ES2020",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "strict": true,
+ "esModuleInterop": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true,
+ "declaration": false,
+ "outDir": "./dist",
+ "rootDir": ".",
+ "baseUrl": ".",
+ "paths": {
+ "esengine": ["./.esengine/sdk/index.d.ts"],
+ "esengine/wasm": ["./.esengine/sdk/wasm.d.ts"],
+ "@esengine/editor": ["./.esengine/editor/index.d.ts"]
+ }
+ },
+ "include": ["src/**/*"],
+ "exclude": ["node_modules"]
+}