create-exo-app 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/index.js +122 -0
- package/package.json +32 -0
- package/templates/audio-reactive/index.html +15 -0
- package/templates/audio-reactive/package.json +17 -0
- package/templates/audio-reactive/public/assets/.gitkeep +0 -0
- package/templates/audio-reactive/src/main.ts +14 -0
- package/templates/audio-reactive/src/scenes/AudioReactiveScene.ts +84 -0
- package/templates/audio-reactive/tsconfig.json +12 -0
- package/templates/audio-reactive/vite.config.ts +5 -0
- package/templates/game-starter/index.html +15 -0
- package/templates/game-starter/package.json +17 -0
- package/templates/game-starter/public/assets/.gitkeep +0 -0
- package/templates/game-starter/src/main.ts +14 -0
- package/templates/game-starter/src/objects/Player.ts +12 -0
- package/templates/game-starter/src/scenes/GameOverScene.ts +33 -0
- package/templates/game-starter/src/scenes/GameScene.ts +65 -0
- package/templates/game-starter/tsconfig.json +12 -0
- package/templates/game-starter/vite.config.ts +5 -0
- package/templates/minimal/index.html +15 -0
- package/templates/minimal/package.json +17 -0
- package/templates/minimal/public/assets/.gitkeep +0 -0
- package/templates/minimal/src/main.ts +16 -0
- package/templates/minimal/src/scenes/MainScene.ts +27 -0
- package/templates/minimal/tsconfig.json +12 -0
- package/templates/minimal/vite.config.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codexo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# create-exo-app
|
|
2
|
+
|
|
3
|
+
Official starter for [ExoJS](https://github.com/Exoridus/ExoJS).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm create exo-app@latest my-game
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or pick a template:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm create exo-app@latest my-game -- --template minimal
|
|
15
|
+
npm create exo-app@latest my-game -- --template game-starter
|
|
16
|
+
npm create exo-app@latest my-game -- --template audio-reactive
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd my-game
|
|
23
|
+
npm install
|
|
24
|
+
npm run dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Templates
|
|
28
|
+
|
|
29
|
+
| Template | Description |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `minimal` | Smallest TypeScript ExoJS app — one `Scene`, one rotating box |
|
|
32
|
+
| `game-starter` | Keyboard-controlled player, `GameScene` + `GameOverScene`, score HUD |
|
|
33
|
+
| `audio-reactive` | `AudioAnalyser`-driven frequency bar visualiser; click-to-start gesture |
|
|
34
|
+
|
|
35
|
+
## CLI options
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
create-exo-app <project-name> [--template <name>] [--force]
|
|
39
|
+
|
|
40
|
+
--template minimal | game-starter | audio-reactive (default: minimal)
|
|
41
|
+
--force overwrite an existing non-empty directory
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
When run interactively (TTY) without `--template`, the CLI prompts for a template choice.
|
|
45
|
+
In non-TTY / CI environments it defaults to `minimal` automatically.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
7
|
+
const TEMPLATES = ['minimal', 'game-starter', 'audio-reactive'];
|
|
8
|
+
const TEMPLATE_DESCRIPTIONS = {
|
|
9
|
+
'minimal': 'smallest TypeScript ExoJS app with one Scene and one visible object',
|
|
10
|
+
'game-starter': 'keyboard-controlled game loop starter with Scene structure',
|
|
11
|
+
'audio-reactive': 'AudioAnalyser-driven shapes and animations',
|
|
12
|
+
};
|
|
13
|
+
function isInteractive() {
|
|
14
|
+
return process.stdin.isTTY === true;
|
|
15
|
+
}
|
|
16
|
+
function prompt(question) {
|
|
17
|
+
return new Promise(resolve => {
|
|
18
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
19
|
+
rl.question(question, answer => {
|
|
20
|
+
rl.close();
|
|
21
|
+
resolve(answer.trim());
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function promptProjectName() {
|
|
26
|
+
const answer = await prompt('Project name: ');
|
|
27
|
+
if (!answer) {
|
|
28
|
+
console.error('Error: project name cannot be empty.');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
return answer;
|
|
32
|
+
}
|
|
33
|
+
async function promptTemplate() {
|
|
34
|
+
console.log('\nWhich template?');
|
|
35
|
+
for (let i = 0; i < TEMPLATES.length; i++) {
|
|
36
|
+
const t = TEMPLATES[i];
|
|
37
|
+
const marker = i === 0 ? '❯' : ' ';
|
|
38
|
+
console.log(` ${marker} ${(i + 1).toString()}) ${t.padEnd(16)} — ${TEMPLATE_DESCRIPTIONS[t]}`);
|
|
39
|
+
}
|
|
40
|
+
const answer = await prompt('\nEnter number or name [1]: ');
|
|
41
|
+
if (!answer || answer === '1')
|
|
42
|
+
return 'minimal';
|
|
43
|
+
const num = parseInt(answer, 10);
|
|
44
|
+
if (!Number.isNaN(num) && num >= 1 && num <= TEMPLATES.length) {
|
|
45
|
+
return TEMPLATES[num - 1];
|
|
46
|
+
}
|
|
47
|
+
const matched = TEMPLATES.find(t => t === answer);
|
|
48
|
+
if (matched)
|
|
49
|
+
return matched;
|
|
50
|
+
console.error(`Unknown template: "${answer}". Using "minimal".`);
|
|
51
|
+
return 'minimal';
|
|
52
|
+
}
|
|
53
|
+
async function main() {
|
|
54
|
+
const args = process.argv.slice(2);
|
|
55
|
+
let projectName = '';
|
|
56
|
+
let templateArg = null;
|
|
57
|
+
let force = false;
|
|
58
|
+
for (let i = 0; i < args.length; i++) {
|
|
59
|
+
const arg = args[i];
|
|
60
|
+
if (arg === '--template' || arg === '-t') {
|
|
61
|
+
templateArg = args[++i] ?? null;
|
|
62
|
+
}
|
|
63
|
+
else if (arg === '--force' || arg === '-f') {
|
|
64
|
+
force = true;
|
|
65
|
+
}
|
|
66
|
+
else if (!arg.startsWith('-')) {
|
|
67
|
+
projectName = arg;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!projectName) {
|
|
71
|
+
if (!isInteractive()) {
|
|
72
|
+
console.error('Error: project name is required in non-interactive mode.');
|
|
73
|
+
console.error('Usage: create-exo-app <project-name> [--template minimal|game-starter|audio-reactive]');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
projectName = await promptProjectName();
|
|
77
|
+
}
|
|
78
|
+
let template;
|
|
79
|
+
if (templateArg !== null) {
|
|
80
|
+
if (!TEMPLATES.includes(templateArg)) {
|
|
81
|
+
console.error(`Error: unknown template "${templateArg}".`);
|
|
82
|
+
console.error(`Valid templates: ${TEMPLATES.join(', ')}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
template = templateArg;
|
|
86
|
+
}
|
|
87
|
+
else if (isInteractive()) {
|
|
88
|
+
template = await promptTemplate();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
template = 'minimal';
|
|
92
|
+
}
|
|
93
|
+
const destDir = resolve(process.cwd(), projectName);
|
|
94
|
+
if (existsSync(destDir)) {
|
|
95
|
+
const entries = readdirSync(destDir);
|
|
96
|
+
if (entries.length > 0 && !force) {
|
|
97
|
+
console.error(`Error: directory "${projectName}" already exists and is not empty.`);
|
|
98
|
+
console.error('Use --force to overwrite.');
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Locate templates relative to dist/index.js (one level up)
|
|
103
|
+
const templateDir = join(__dirname, '..', 'templates', template);
|
|
104
|
+
mkdirSync(destDir, { recursive: true });
|
|
105
|
+
cpSync(templateDir, destDir, { recursive: true });
|
|
106
|
+
// Set package name to the project directory's basename
|
|
107
|
+
const pkgPath = join(destDir, 'package.json');
|
|
108
|
+
const pkgContent = readFileSync(pkgPath, 'utf-8');
|
|
109
|
+
const pkgJson = JSON.parse(pkgContent);
|
|
110
|
+
pkgJson['name'] = basename(projectName);
|
|
111
|
+
writeFileSync(pkgPath, JSON.stringify(pkgJson, null, 2) + '\n');
|
|
112
|
+
console.log(`\nDone.\n`);
|
|
113
|
+
console.log(`Next steps:`);
|
|
114
|
+
console.log(` cd ${projectName}`);
|
|
115
|
+
console.log(` npm install`);
|
|
116
|
+
console.log(` npm run dev`);
|
|
117
|
+
console.log('');
|
|
118
|
+
}
|
|
119
|
+
main().catch((err) => {
|
|
120
|
+
console.error('Error:', err instanceof Error ? err.message : String(err));
|
|
121
|
+
process.exit(1);
|
|
122
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-exo-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official starter for ExoJS — scaffold a new app with npm create exo-app",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-exo-app": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/",
|
|
12
|
+
"templates/"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/Exoridus/ExoJS",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Exoridus/ExoJS.git"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^25.6.0",
|
|
24
|
+
"tsx": "^4.21.0",
|
|
25
|
+
"typescript": "^6.0.3"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc && node --input-type=module --eval \"import{readFileSync,writeFileSync}from'node:fs';const f='dist/index.js';writeFileSync(f,'#!/usr/bin/env node\\n'+readFileSync(f,'utf-8'));\"",
|
|
29
|
+
"dev": "tsc --watch",
|
|
30
|
+
"start": "tsx src/index.ts"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>ExoJS Audio Reactive</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
body { background: #000; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<script type="module" src="/src/main.ts"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "exo-audio-reactive",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "tsc && vite build",
|
|
8
|
+
"preview": "vite preview"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@codexo/exojs": "^0.12.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.8.0",
|
|
15
|
+
"vite": "^6.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Application, Color } from '@codexo/exojs';
|
|
2
|
+
import { AudioReactiveScene } from './scenes/AudioReactiveScene';
|
|
3
|
+
|
|
4
|
+
const app = new Application({
|
|
5
|
+
canvas: {
|
|
6
|
+
width: 800,
|
|
7
|
+
height: 600,
|
|
8
|
+
},
|
|
9
|
+
clearColor: new Color(8, 8, 16),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
document.body.append(app.canvas);
|
|
13
|
+
|
|
14
|
+
app.start(new AudioReactiveScene());
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AudioAnalyser, Color, getAudioContext, Graphics, Scene, Text } from '@codexo/exojs';
|
|
2
|
+
import type { RenderingContext } from '@codexo/exojs';
|
|
3
|
+
|
|
4
|
+
const BAR_COUNT = 32;
|
|
5
|
+
|
|
6
|
+
export class AudioReactiveScene extends Scene {
|
|
7
|
+
private _analyser!: AudioAnalyser;
|
|
8
|
+
private _bars!: Graphics;
|
|
9
|
+
private _prompt!: Text;
|
|
10
|
+
private _started = false;
|
|
11
|
+
|
|
12
|
+
public override init(): void {
|
|
13
|
+
const { width, height } = this.app!.canvas;
|
|
14
|
+
|
|
15
|
+
this._prompt = new Text('Click to start', {
|
|
16
|
+
align: 'center',
|
|
17
|
+
fillColor: Color.white,
|
|
18
|
+
fontSize: 28,
|
|
19
|
+
});
|
|
20
|
+
this._prompt.setAnchor(0.5);
|
|
21
|
+
this._prompt.setPosition(width / 2, height / 2);
|
|
22
|
+
|
|
23
|
+
this._bars = new Graphics();
|
|
24
|
+
this._analyser = new AudioAnalyser({ fftSize: 512, smoothingTimeConstant: 0.75 });
|
|
25
|
+
|
|
26
|
+
this.addChild(this._prompt);
|
|
27
|
+
this.addChild(this._bars);
|
|
28
|
+
|
|
29
|
+
const onTap = (): void => {
|
|
30
|
+
if (this._started) return;
|
|
31
|
+
this._started = true;
|
|
32
|
+
this._prompt.visible = false;
|
|
33
|
+
|
|
34
|
+
// Use the shared audio context — the pointer gesture unlocks it.
|
|
35
|
+
const ctx = getAudioContext();
|
|
36
|
+
|
|
37
|
+
// Sawtooth oscillator as an always-on audio source for the analyser.
|
|
38
|
+
// Frequency sweeps slowly to produce a varied spectrum.
|
|
39
|
+
const osc = ctx.createOscillator();
|
|
40
|
+
const gain = ctx.createGain();
|
|
41
|
+
gain.gain.value = 0.1;
|
|
42
|
+
osc.type = 'sawtooth';
|
|
43
|
+
osc.frequency.setValueAtTime(60, ctx.currentTime);
|
|
44
|
+
osc.frequency.linearRampToValueAtTime(880, ctx.currentTime + 6);
|
|
45
|
+
osc.frequency.linearRampToValueAtTime(60, ctx.currentTime + 12);
|
|
46
|
+
osc.connect(gain);
|
|
47
|
+
gain.connect(ctx.destination);
|
|
48
|
+
osc.start();
|
|
49
|
+
|
|
50
|
+
// AudioAnalyser accepts any AudioNode as source
|
|
51
|
+
this._analyser.source = osc;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
this.app!.input.onPointerTap.add(onTap);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public override draw(context: RenderingContext): void {
|
|
58
|
+
const { width, height } = this.app!.canvas;
|
|
59
|
+
context.backend.clear(new Color(8, 8, 16));
|
|
60
|
+
|
|
61
|
+
if (this._started) {
|
|
62
|
+
const spectrum = this._analyser.getSpectrum();
|
|
63
|
+
const barWidth = width / BAR_COUNT;
|
|
64
|
+
const maxHeight = height * 0.75;
|
|
65
|
+
|
|
66
|
+
this._bars.clear();
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < BAR_COUNT; i++) {
|
|
69
|
+
const binIndex = Math.floor((i / BAR_COUNT) * spectrum.length * 0.5);
|
|
70
|
+
const value = (spectrum[binIndex] ?? 0) / 255;
|
|
71
|
+
const barHeight = Math.max(2, value * maxHeight);
|
|
72
|
+
const t = i / (BAR_COUNT - 1);
|
|
73
|
+
// Gradient from cyan (low freq) to magenta (high freq)
|
|
74
|
+
const r = Math.floor(t * 220);
|
|
75
|
+
const g = Math.floor((1 - Math.abs(t - 0.5) * 2) * 160 + 60);
|
|
76
|
+
const b = Math.floor((1 - t) * 220 + 35);
|
|
77
|
+
this._bars.fillColor = new Color(r, g, b);
|
|
78
|
+
this._bars.drawRectangle(i * barWidth + 1, height - barHeight, barWidth - 2, barHeight);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
context.render(this.root);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>ExoJS Game Starter</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
body { background: #000; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<script type="module" src="/src/main.ts"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "exo-game",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "tsc && vite build",
|
|
8
|
+
"preview": "vite preview"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@codexo/exojs": "^0.12.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.8.0",
|
|
15
|
+
"vite": "^6.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Application, Color } from '@codexo/exojs';
|
|
2
|
+
import { GameScene } from './scenes/GameScene';
|
|
3
|
+
|
|
4
|
+
const app = new Application({
|
|
5
|
+
canvas: {
|
|
6
|
+
width: 800,
|
|
7
|
+
height: 600,
|
|
8
|
+
},
|
|
9
|
+
clearColor: new Color(18, 28, 48),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
document.body.append(app.canvas);
|
|
13
|
+
|
|
14
|
+
app.start(new GameScene());
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Color, Graphics } from '@codexo/exojs';
|
|
2
|
+
|
|
3
|
+
export class Player extends Graphics {
|
|
4
|
+
public readonly speed = 280;
|
|
5
|
+
|
|
6
|
+
public constructor() {
|
|
7
|
+
super();
|
|
8
|
+
// Circle drawn at local origin so the node position is the visual center
|
|
9
|
+
this.fillColor = Color.tomato;
|
|
10
|
+
this.drawCircle(0, 0, 20);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Color, Keyboard, Scene, Text } from '@codexo/exojs';
|
|
2
|
+
import type { RenderingContext } from '@codexo/exojs';
|
|
3
|
+
import { GameScene } from './GameScene';
|
|
4
|
+
|
|
5
|
+
export class GameOverScene extends Scene {
|
|
6
|
+
private _label!: Text;
|
|
7
|
+
|
|
8
|
+
public constructor(private readonly _score: number) {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public override init(): void {
|
|
13
|
+
const { width, height } = this.app!.canvas;
|
|
14
|
+
|
|
15
|
+
this._label = new Text(
|
|
16
|
+
`Game Over\nScore: ${this._score}\n\nPress Space to restart`,
|
|
17
|
+
{ align: 'center', fillColor: Color.white, fontSize: 26 },
|
|
18
|
+
);
|
|
19
|
+
this._label.setAnchor(0.5);
|
|
20
|
+
this._label.setPosition(width / 2, height / 2);
|
|
21
|
+
|
|
22
|
+
this.addChild(this._label);
|
|
23
|
+
|
|
24
|
+
this.inputs.onTrigger(Keyboard.Space, () => {
|
|
25
|
+
void this.app!.scene.setScene(new GameScene());
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override draw(context: RenderingContext): void {
|
|
30
|
+
context.backend.clear(new Color(48, 10, 10));
|
|
31
|
+
context.render(this.root);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Color, Keyboard, Scene, Text } from '@codexo/exojs';
|
|
2
|
+
import type { RenderingContext, Time } from '@codexo/exojs';
|
|
3
|
+
import { Player } from '../objects/Player';
|
|
4
|
+
import { GameOverScene } from './GameOverScene';
|
|
5
|
+
|
|
6
|
+
export class GameScene extends Scene {
|
|
7
|
+
private _player!: Player;
|
|
8
|
+
private _scoreText!: Text;
|
|
9
|
+
private _elapsed = 0;
|
|
10
|
+
private _move = { up: 0, down: 0, left: 0, right: 0 };
|
|
11
|
+
|
|
12
|
+
public override init(): void {
|
|
13
|
+
const { width, height } = this.app!.canvas;
|
|
14
|
+
|
|
15
|
+
this._player = new Player();
|
|
16
|
+
this._player.setPosition(width / 2, height / 2);
|
|
17
|
+
|
|
18
|
+
this._scoreText = new Text('Score: 0', { fillColor: Color.white, fontSize: 18 });
|
|
19
|
+
this._scoreText.setPosition(16, 16);
|
|
20
|
+
|
|
21
|
+
this.addChild(this._player);
|
|
22
|
+
this.addChild(this._scoreText);
|
|
23
|
+
|
|
24
|
+
// WASD + arrow keys
|
|
25
|
+
this.inputs.onActive(Keyboard.W, () => { this._move.up = 1; });
|
|
26
|
+
this.inputs.onStop(Keyboard.W, () => { this._move.up = 0; });
|
|
27
|
+
this.inputs.onActive(Keyboard.S, () => { this._move.down = 1; });
|
|
28
|
+
this.inputs.onStop(Keyboard.S, () => { this._move.down = 0; });
|
|
29
|
+
this.inputs.onActive(Keyboard.A, () => { this._move.left = 1; });
|
|
30
|
+
this.inputs.onStop(Keyboard.A, () => { this._move.left = 0; });
|
|
31
|
+
this.inputs.onActive(Keyboard.D, () => { this._move.right = 1; });
|
|
32
|
+
this.inputs.onStop(Keyboard.D, () => { this._move.right = 0; });
|
|
33
|
+
this.inputs.onActive(Keyboard.Up, () => { this._move.up = 1; });
|
|
34
|
+
this.inputs.onStop(Keyboard.Up, () => { this._move.up = 0; });
|
|
35
|
+
this.inputs.onActive(Keyboard.Down, () => { this._move.down = 1; });
|
|
36
|
+
this.inputs.onStop(Keyboard.Down, () => { this._move.down = 0; });
|
|
37
|
+
this.inputs.onActive(Keyboard.Left, () => { this._move.left = 1; });
|
|
38
|
+
this.inputs.onStop(Keyboard.Left, () => { this._move.left = 0; });
|
|
39
|
+
this.inputs.onActive(Keyboard.Right, () => { this._move.right = 1; });
|
|
40
|
+
this.inputs.onStop(Keyboard.Right, () => { this._move.right = 0; });
|
|
41
|
+
|
|
42
|
+
this.inputs.onTrigger(Keyboard.Escape, () => {
|
|
43
|
+
void this.app!.scene.setScene(new GameOverScene(Math.floor(this._elapsed)));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public override update(delta: Time): void {
|
|
48
|
+
const dx = this._move.right - this._move.left;
|
|
49
|
+
const dy = this._move.down - this._move.up;
|
|
50
|
+
|
|
51
|
+
if (dx !== 0 || dy !== 0) {
|
|
52
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
53
|
+
const speed = this._player.speed * delta.seconds;
|
|
54
|
+
this._player.move((dx / len) * speed, (dy / len) * speed);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this._elapsed += delta.seconds;
|
|
58
|
+
this._scoreText.text = `Score: ${Math.floor(this._elapsed)}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public override draw(context: RenderingContext): void {
|
|
62
|
+
context.backend.clear();
|
|
63
|
+
context.render(this.root);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>ExoJS App</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
body { background: #000; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<script type="module" src="/src/main.ts"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "exo-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "tsc && vite build",
|
|
8
|
+
"preview": "vite preview"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@codexo/exojs": "^0.12.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.8.0",
|
|
15
|
+
"vite": "^6.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// #region guide:minimal-main
|
|
2
|
+
import { Application, Color } from '@codexo/exojs';
|
|
3
|
+
import { MainScene } from './scenes/MainScene';
|
|
4
|
+
|
|
5
|
+
const app = new Application({
|
|
6
|
+
canvas: {
|
|
7
|
+
width: 800,
|
|
8
|
+
height: 600,
|
|
9
|
+
},
|
|
10
|
+
clearColor: Color.cornflowerBlue,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
document.body.append(app.canvas);
|
|
14
|
+
|
|
15
|
+
app.start(new MainScene());
|
|
16
|
+
// #endregion guide:minimal-main
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// #region guide:minimal-scene
|
|
2
|
+
import { Color, Graphics, Scene } from '@codexo/exojs';
|
|
3
|
+
import type { RenderingContext, Time } from '@codexo/exojs';
|
|
4
|
+
|
|
5
|
+
export class MainScene extends Scene {
|
|
6
|
+
private readonly _box = new Graphics();
|
|
7
|
+
|
|
8
|
+
public constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this._box.fillColor = Color.white;
|
|
12
|
+
this._box.drawRectangle(-40, -40, 80, 80);
|
|
13
|
+
this._box.setPosition(400, 300);
|
|
14
|
+
|
|
15
|
+
this.addChild(this._box);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public override update(delta: Time): void {
|
|
19
|
+
this._box.rotate(delta.seconds * 90);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public override draw(context: RenderingContext): void {
|
|
23
|
+
context.backend.clear();
|
|
24
|
+
context.render(this.root);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// #endregion guide:minimal-scene
|