nova64 0.2.5 → 0.2.6
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/README.md +25 -8
- package/bin/nova64.js +165 -0
- package/dist/assets/console-CY_kygm3.js +14 -0
- package/dist/assets/console-CY_kygm3.js.map +1 -0
- package/dist/assets/main-l0sNRNKZ.js.map +1 -0
- package/dist/assets/sky/studio/nx.png +0 -0
- package/dist/assets/sky/studio/ny.png +0 -0
- package/dist/assets/sky/studio/nz.png +0 -0
- package/dist/assets/sky/studio/px.png +0 -0
- package/dist/assets/sky/studio/py.png +0 -0
- package/dist/assets/sky/studio/pz.png +0 -0
- package/dist/assets/vanilla-Dcuy32gi.js +2 -0
- package/dist/assets/vanilla-Dcuy32gi.js.map +1 -0
- package/dist/console.html +899 -0
- package/dist/docs/BENCHMARK.md +77 -0
- package/dist/docs/CHEATSHEET.md +255 -0
- package/dist/docs/EFFECTS_API_GUIDE.md +577 -0
- package/dist/docs/EFFECTS_QUICK_REFERENCE.md +331 -0
- package/dist/docs/FONT_CHARACTER_REFERENCE.md +219 -0
- package/dist/docs/FREE_GLB_ASSETS.md +330 -0
- package/dist/docs/FULLSCREEN_BUTTON_FEATURE.md +296 -0
- package/dist/docs/GAMEPAD_SUPPORT.md +348 -0
- package/dist/docs/GAME_IMPROVEMENTS.md +278 -0
- package/dist/docs/GAME_QUALITY_STATUS.md +300 -0
- package/dist/docs/MIGRATION_GUIDE.md +553 -0
- package/dist/docs/NOVA64_3D_API.md +356 -0
- package/dist/docs/NOVA64_API_REFERENCE.md +1406 -0
- package/dist/docs/NOVA64_UI_API.md +503 -0
- package/dist/docs/UI_SYSTEM_SUMMARY.md +445 -0
- package/dist/docs/VOXEL_ENGINE_GUIDE.md +662 -0
- package/dist/docs/VOXEL_QUICK_REFERENCE.md +386 -0
- package/dist/docs/api-3d.html +750 -0
- package/dist/docs/api-effects.html +385 -0
- package/dist/docs/api-improvements.md +121 -0
- package/dist/docs/api-skybox.html +407 -0
- package/dist/docs/api-sprites.html +321 -0
- package/dist/docs/api-voxel.html +337 -0
- package/dist/docs/api.html +543 -0
- package/dist/docs/assets.html +306 -0
- package/dist/docs/audio.html +340 -0
- package/dist/docs/blogs.html +286 -0
- package/dist/docs/collision.html +316 -0
- package/dist/docs/console.html +247 -0
- package/dist/docs/editor.html +297 -0
- package/dist/docs/font.html +247 -0
- package/dist/docs/framebuffer.html +247 -0
- package/dist/docs/fullscreen-button.html +297 -0
- package/dist/docs/gpu-systems.html +247 -0
- package/dist/docs/index.html +580 -0
- package/dist/docs/input.html +491 -0
- package/dist/docs/physics.html +311 -0
- package/dist/docs/screens.html +311 -0
- package/dist/docs/storage.html +311 -0
- package/dist/docs/textinput.html +332 -0
- package/dist/docs/ui.html +488 -0
- package/dist/examples/3d-advanced/code.js +695 -0
- package/dist/examples/adventure-comic-3d/code.js +342 -0
- package/dist/examples/audio-lab/code.js +150 -0
- package/dist/examples/boids-flocking/code.js +270 -0
- package/dist/examples/crystal-cathedral-3d/code.js +706 -0
- package/dist/examples/cyberpunk-city-3d/code.js +1383 -0
- package/dist/examples/demoscene/README.md +192 -0
- package/dist/examples/demoscene/code.js +1081 -0
- package/dist/examples/demoscene/meta.json +21 -0
- package/dist/examples/dungeon-crawler-3d/code.js +1117 -0
- package/dist/examples/f-zero-nova-3d/code.js +865 -0
- package/dist/examples/f-zero-nova-3d/code_old.js +1555 -0
- package/dist/examples/fps-demo-3d/code.js +744 -0
- package/dist/examples/game-of-life-3d/code.js +338 -0
- package/dist/examples/generative-art/code.js +632 -0
- package/dist/examples/hello-3d/code.js +325 -0
- package/dist/examples/hello-skybox/code.js +183 -0
- package/dist/examples/hello-world/code.js +19 -0
- package/dist/examples/input-showcase/code.js +109 -0
- package/dist/examples/instancing-demo/code.js +315 -0
- package/dist/examples/minecraft-demo/code.js +387 -0
- package/dist/examples/model-viewer-3d/code.js +114 -0
- package/dist/examples/mystical-realm-3d/code.js +1203 -0
- package/dist/examples/nature-explorer-3d/code.js +1318 -0
- package/dist/examples/particles-demo/code.js +522 -0
- package/dist/examples/pbr-showcase/code.js +140 -0
- package/dist/examples/physics-demo-3d/code.js +948 -0
- package/dist/examples/screen-demo/code.js +267 -0
- package/dist/examples/shooter-demo-3d/code.js +1286 -0
- package/dist/examples/space-combat-3d/IMPLEMENTATION_SUMMARY.md +109 -0
- package/dist/examples/space-combat-3d/README.md +135 -0
- package/dist/examples/space-combat-3d/code.js +1332 -0
- package/dist/examples/space-harrier-3d/code.js +923 -0
- package/dist/examples/star-fox-nova-3d/code.js +1116 -0
- package/dist/examples/star-fox-nova-3d/code_backup.js +410 -0
- package/dist/examples/star-fox-nova-3d/code_broken.js +1821 -0
- package/dist/examples/storage-quest/code.js +209 -0
- package/dist/examples/strider-demo-3d/IMPROVEMENT_OPTIONS.md +285 -0
- package/dist/examples/strider-demo-3d/cache-test.html +132 -0
- package/dist/examples/strider-demo-3d/code-fixed.js +582 -0
- package/dist/examples/strider-demo-3d/code-old.js +1537 -0
- package/dist/examples/strider-demo-3d/code.js +1462 -0
- package/dist/examples/strider-demo-3d/code.js.bak2 +1169 -0
- package/dist/examples/strider-demo-3d/fix-game.sh +53 -0
- package/dist/examples/super-plumber-64/README.md +128 -0
- package/dist/examples/super-plumber-64/code.js +1185 -0
- package/dist/examples/super-plumber-64/index.html +88 -0
- package/dist/examples/test-2d-overlay/code.js +32 -0
- package/dist/examples/test-font/code.js +51 -0
- package/dist/examples/test-minimal/code.js +21 -0
- package/dist/examples/ui-demo/code.js +306 -0
- package/dist/examples/wing-commander-space/README.md +180 -0
- package/dist/examples/wing-commander-space/code.js +1285 -0
- package/dist/examples/wizardry-3d/CHANGELOG.md +366 -0
- package/dist/examples/wizardry-3d/code.js +3928 -0
- package/dist/index.html +666 -0
- package/dist/os9-shell/assets/index-DIHfrTaW.css +1 -0
- package/dist/os9-shell/assets/index-KchE_ngx.js +483 -0
- package/dist/os9-shell/assets/index-KchE_ngx.js.map +1 -0
- package/dist/os9-shell/index.html +23 -0
- package/dist/os9-shell/nova-icon.svg +12 -0
- package/index.html +6 -1
- package/package.json +37 -32
- package/public/assets/sky/studio/nx.png +0 -0
- package/public/assets/sky/studio/ny.png +0 -0
- package/public/assets/sky/studio/nz.png +0 -0
- package/public/assets/sky/studio/px.png +0 -0
- package/public/assets/sky/studio/py.png +0 -0
- package/public/assets/sky/studio/pz.png +0 -0
- package/public/os9-shell/assets/index-KchE_ngx.js +483 -0
- package/public/os9-shell/assets/index-KchE_ngx.js.map +1 -0
- package/public/os9-shell/index.html +10 -1
- package/runtime/api-2d.js +301 -21
- package/runtime/api-3d/pbr.js +45 -1
- package/runtime/api-3d.js +1 -0
- package/runtime/api-effects.js +90 -3
- package/runtime/api-gameutils.js +476 -0
- package/runtime/api-generative.js +610 -0
- package/runtime/api-skybox.js +54 -0
- package/runtime/api-voxel.js +139 -28
- package/runtime/gpu-threejs.js +13 -9
- package/runtime/ui.js +2 -2
- package/src/main.js +20 -0
- package/public/os9-shell/assets/index-B1Uvacma.js +0 -32825
- package/public/os9-shell/assets/index-B1Uvacma.js.map +0 -1
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// SIMPLE STAR FOX NOVA 64 - Stable and Working
|
|
2
|
+
// Like Deserted Space quality, no crashes
|
|
3
|
+
|
|
4
|
+
let gameData = {
|
|
5
|
+
arwing: null,
|
|
6
|
+
enemies: [],
|
|
7
|
+
projectiles: [],
|
|
8
|
+
particles: [],
|
|
9
|
+
stars: [],
|
|
10
|
+
score: 0,
|
|
11
|
+
health: 100,
|
|
12
|
+
waveNumber: 1,
|
|
13
|
+
time: 0,
|
|
14
|
+
camera: { shake: 0 },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
let gameSettings = {
|
|
18
|
+
graphics: {
|
|
19
|
+
enableParticles: true,
|
|
20
|
+
starDensity: 200,
|
|
21
|
+
},
|
|
22
|
+
physics: {
|
|
23
|
+
acceleration: 15,
|
|
24
|
+
maxSpeed: 25,
|
|
25
|
+
friction: 0.88,
|
|
26
|
+
},
|
|
27
|
+
gameplay: {
|
|
28
|
+
difficulty: 1.0,
|
|
29
|
+
enemySpawnRate: 2.0,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Game state management
|
|
34
|
+
let gameState = {
|
|
35
|
+
currentScreen: 'start',
|
|
36
|
+
transition: false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export async function init() {
|
|
40
|
+
console.log('🚀 STAR FOX NOVA 64 - Simple and Stable');
|
|
41
|
+
|
|
42
|
+
// Clear everything
|
|
43
|
+
cls();
|
|
44
|
+
|
|
45
|
+
// Simple, effective 3D setup
|
|
46
|
+
setCameraPosition(0, 5, 15);
|
|
47
|
+
setCameraTarget(0, 0, 0);
|
|
48
|
+
setCameraFOV(75);
|
|
49
|
+
|
|
50
|
+
// Clean lighting
|
|
51
|
+
setLightDirection(0, -1, -0.5);
|
|
52
|
+
setLightColor(0xffffff);
|
|
53
|
+
setAmbientLight(0x404040);
|
|
54
|
+
|
|
55
|
+
// Create starfield
|
|
56
|
+
createStarfield();
|
|
57
|
+
|
|
58
|
+
return initScreens({
|
|
59
|
+
start: createStartScreen(),
|
|
60
|
+
game: createGameScreen(),
|
|
61
|
+
pause: createPauseScreen(),
|
|
62
|
+
gameOver: createGameOverScreen(),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function createStarfield() {
|
|
67
|
+
console.log('🌌 Creating stable starfield...');
|
|
68
|
+
|
|
69
|
+
gameData.stars = [];
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < 200; i++) {
|
|
72
|
+
const star = createCube(0.5, 0xffffff, [
|
|
73
|
+
(Math.random() - 0.5) * 200,
|
|
74
|
+
(Math.random() - 0.5) * 100,
|
|
75
|
+
-100 - Math.random() * 300,
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
gameData.stars.push({
|
|
79
|
+
mesh: star,
|
|
80
|
+
speed: 20 + Math.random() * 30,
|
|
81
|
+
x: (Math.random() - 0.5) * 200,
|
|
82
|
+
y: (Math.random() - 0.5) * 100,
|
|
83
|
+
z: -100 - Math.random() * 300,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log('✅ Starfield created with', gameData.stars.length, 'stars');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function updateStarfield(dt) {
|
|
91
|
+
for (let star of gameData.stars) {
|
|
92
|
+
star.z += star.speed * dt;
|
|
93
|
+
setPosition(star.mesh, star.x, star.y, star.z);
|
|
94
|
+
|
|
95
|
+
if (star.z > 30) {
|
|
96
|
+
star.z = -300 - Math.random() * 100;
|
|
97
|
+
star.x = (Math.random() - 0.5) * 200;
|
|
98
|
+
star.y = (Math.random() - 0.5) * 100;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Screen creation functions
|
|
104
|
+
function createStartScreen() {
|
|
105
|
+
return {
|
|
106
|
+
enter() {
|
|
107
|
+
console.log('Start screen entered');
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
update(dt) {
|
|
111
|
+
updateStarfield(dt);
|
|
112
|
+
|
|
113
|
+
if (isKeyPressed('space') || isKeyPressed('enter')) {
|
|
114
|
+
switchScreen('game');
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
draw() {
|
|
119
|
+
// Title text
|
|
120
|
+
color(0xffffff);
|
|
121
|
+
text('STAR FOX NOVA 64', 100, 100, 32);
|
|
122
|
+
text('PRESS SPACE TO START', 120, 200, 16);
|
|
123
|
+
text('WASD: Move | SPACE: Fire', 120, 250, 12);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function createGameScreen() {
|
|
129
|
+
return {
|
|
130
|
+
enter() {
|
|
131
|
+
console.log('🎮 Starting game...');
|
|
132
|
+
resetGame();
|
|
133
|
+
createArwing();
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
update(dt) {
|
|
137
|
+
gameData.time += dt;
|
|
138
|
+
|
|
139
|
+
updateStarfield(dt);
|
|
140
|
+
updateArwing(dt);
|
|
141
|
+
updateEnemies(dt);
|
|
142
|
+
updateProjectiles(dt);
|
|
143
|
+
updateParticles(dt);
|
|
144
|
+
|
|
145
|
+
spawnEnemies(dt);
|
|
146
|
+
|
|
147
|
+
if (gameData.health <= 0) {
|
|
148
|
+
switchScreen('gameOver');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (isKeyPressed('escape')) {
|
|
152
|
+
switchScreen('pause');
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
draw() {
|
|
157
|
+
drawHUD();
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function createPauseScreen() {
|
|
163
|
+
return {
|
|
164
|
+
enter() {},
|
|
165
|
+
update(dt) {
|
|
166
|
+
if (isKeyPressed('escape') || isKeyPressed('space')) {
|
|
167
|
+
switchScreen('game');
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
draw() {
|
|
171
|
+
color(0xffffff);
|
|
172
|
+
text('PAUSED', 200, 150, 32);
|
|
173
|
+
text('PRESS ESC TO RESUME', 150, 200, 16);
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function createGameOverScreen() {
|
|
179
|
+
return {
|
|
180
|
+
enter() {},
|
|
181
|
+
update(dt) {
|
|
182
|
+
updateStarfield(dt);
|
|
183
|
+
|
|
184
|
+
if (isKeyPressed('space') || isKeyPressed('enter')) {
|
|
185
|
+
switchScreen('start');
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
draw() {
|
|
189
|
+
color(0xff4444);
|
|
190
|
+
text('GAME OVER', 150, 150, 32);
|
|
191
|
+
color(0xffffff);
|
|
192
|
+
text('Score: ' + gameData.score, 180, 200, 16);
|
|
193
|
+
text('PRESS SPACE TO RESTART', 130, 250, 16);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function resetGame() {
|
|
199
|
+
gameData.enemies = [];
|
|
200
|
+
gameData.projectiles = [];
|
|
201
|
+
gameData.particles = [];
|
|
202
|
+
gameData.score = 0;
|
|
203
|
+
gameData.health = 100;
|
|
204
|
+
gameData.waveNumber = 1;
|
|
205
|
+
gameData.time = 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function createArwing() {
|
|
209
|
+
const arwing = createCube(2, 0x0099ff, [0, 0, 0]);
|
|
210
|
+
setScale(arwing, 3, 1.5, 4);
|
|
211
|
+
|
|
212
|
+
gameData.arwing = {
|
|
213
|
+
mesh: arwing,
|
|
214
|
+
position: { x: 0, y: 0, z: 0 },
|
|
215
|
+
velocity: { x: 0, y: 0, z: 0 },
|
|
216
|
+
speed: 30,
|
|
217
|
+
lastShot: 0,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function updateArwing(dt) {
|
|
222
|
+
if (!gameData.arwing) return;
|
|
223
|
+
|
|
224
|
+
const arwing = gameData.arwing;
|
|
225
|
+
const speed = 50;
|
|
226
|
+
|
|
227
|
+
// Movement
|
|
228
|
+
if (isKeyDown('a') || isKeyDown('arrowleft')) {
|
|
229
|
+
arwing.position.x -= speed * dt;
|
|
230
|
+
}
|
|
231
|
+
if (isKeyDown('d') || isKeyDown('arrowright')) {
|
|
232
|
+
arwing.position.x += speed * dt;
|
|
233
|
+
}
|
|
234
|
+
if (isKeyDown('w') || isKeyDown('arrowup')) {
|
|
235
|
+
arwing.position.y += speed * dt;
|
|
236
|
+
}
|
|
237
|
+
if (isKeyDown('s') || isKeyDown('arrowdown')) {
|
|
238
|
+
arwing.position.y -= speed * dt;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Boundaries
|
|
242
|
+
arwing.position.x = Math.max(-40, Math.min(40, arwing.position.x));
|
|
243
|
+
arwing.position.y = Math.max(-20, Math.min(20, arwing.position.y));
|
|
244
|
+
|
|
245
|
+
// Update mesh position
|
|
246
|
+
setPosition(arwing.mesh, arwing.position.x, arwing.position.y, arwing.position.z);
|
|
247
|
+
|
|
248
|
+
// Shooting
|
|
249
|
+
if (isKeyDown('space') && gameData.time - arwing.lastShot > 0.1) {
|
|
250
|
+
fireProjectile();
|
|
251
|
+
arwing.lastShot = gameData.time;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function fireProjectile() {
|
|
256
|
+
const arwing = gameData.arwing;
|
|
257
|
+
const projectile = createCube(0.5, 0xffff00, [
|
|
258
|
+
arwing.position.x,
|
|
259
|
+
arwing.position.y,
|
|
260
|
+
arwing.position.z + 2,
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
gameData.projectiles.push({
|
|
264
|
+
mesh: projectile,
|
|
265
|
+
position: {
|
|
266
|
+
x: arwing.position.x,
|
|
267
|
+
y: arwing.position.y,
|
|
268
|
+
z: arwing.position.z + 2,
|
|
269
|
+
},
|
|
270
|
+
velocity: { x: 0, y: 0, z: 100 },
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function updateProjectiles(dt) {
|
|
275
|
+
for (let i = gameData.projectiles.length - 1; i >= 0; i--) {
|
|
276
|
+
const proj = gameData.projectiles[i];
|
|
277
|
+
|
|
278
|
+
proj.position.z += proj.velocity.z * dt;
|
|
279
|
+
setPosition(proj.mesh, proj.position.x, proj.position.y, proj.position.z);
|
|
280
|
+
|
|
281
|
+
if (proj.position.z > 100) {
|
|
282
|
+
destroyMesh(proj.mesh);
|
|
283
|
+
gameData.projectiles.splice(i, 1);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function spawnEnemies(dt) {
|
|
289
|
+
if (Math.random() < gameSettings.gameplay.enemySpawnRate * dt) {
|
|
290
|
+
spawnEnemy();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function spawnEnemy() {
|
|
295
|
+
const x = (Math.random() - 0.5) * 80;
|
|
296
|
+
const y = (Math.random() - 0.5) * 40;
|
|
297
|
+
const z = 100 + Math.random() * 50;
|
|
298
|
+
|
|
299
|
+
const enemy = createCube(1.5, 0xff3030, [x, y, z]);
|
|
300
|
+
setScale(enemy, 2, 1, 3);
|
|
301
|
+
|
|
302
|
+
gameData.enemies.push({
|
|
303
|
+
mesh: enemy,
|
|
304
|
+
position: { x, y, z },
|
|
305
|
+
velocity: { x: 0, y: 0, z: -30 },
|
|
306
|
+
health: 1,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function updateEnemies(dt) {
|
|
311
|
+
for (let i = gameData.enemies.length - 1; i >= 0; i--) {
|
|
312
|
+
const enemy = gameData.enemies[i];
|
|
313
|
+
|
|
314
|
+
enemy.position.z += enemy.velocity.z * dt;
|
|
315
|
+
setPosition(enemy.mesh, enemy.position.x, enemy.position.y, enemy.position.z);
|
|
316
|
+
|
|
317
|
+
if (enemy.position.z < -30 || enemy.health <= 0) {
|
|
318
|
+
if (enemy.position.z < -30) {
|
|
319
|
+
gameData.health -= 10;
|
|
320
|
+
}
|
|
321
|
+
destroyMesh(enemy.mesh);
|
|
322
|
+
gameData.enemies.splice(i, 1);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Check collisions
|
|
327
|
+
checkCollisions();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function checkCollisions() {
|
|
331
|
+
for (let i = gameData.projectiles.length - 1; i >= 0; i--) {
|
|
332
|
+
const proj = gameData.projectiles[i];
|
|
333
|
+
|
|
334
|
+
for (let j = gameData.enemies.length - 1; j >= 0; j--) {
|
|
335
|
+
const enemy = gameData.enemies[j];
|
|
336
|
+
|
|
337
|
+
const dx = proj.position.x - enemy.position.x;
|
|
338
|
+
const dy = proj.position.y - enemy.position.y;
|
|
339
|
+
const dz = proj.position.z - enemy.position.z;
|
|
340
|
+
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
341
|
+
|
|
342
|
+
if (distance < 4) {
|
|
343
|
+
// Hit!
|
|
344
|
+
createExplosion(enemy.position.x, enemy.position.y, enemy.position.z);
|
|
345
|
+
|
|
346
|
+
destroyMesh(proj.mesh);
|
|
347
|
+
gameData.projectiles.splice(i, 1);
|
|
348
|
+
|
|
349
|
+
destroyMesh(enemy.mesh);
|
|
350
|
+
gameData.enemies.splice(j, 1);
|
|
351
|
+
|
|
352
|
+
gameData.score += 100;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function createExplosion(x, y, z) {
|
|
360
|
+
for (let i = 0; i < 8; i++) {
|
|
361
|
+
const particle = createCube(0.5, 0xff6600, [x, y, z]);
|
|
362
|
+
|
|
363
|
+
gameData.particles.push({
|
|
364
|
+
mesh: particle,
|
|
365
|
+
position: { x, y, z },
|
|
366
|
+
velocity: {
|
|
367
|
+
x: (Math.random() - 0.5) * 40,
|
|
368
|
+
y: (Math.random() - 0.5) * 40,
|
|
369
|
+
z: (Math.random() - 0.5) * 40,
|
|
370
|
+
},
|
|
371
|
+
life: 1.0,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function updateParticles(dt) {
|
|
377
|
+
for (let i = gameData.particles.length - 1; i >= 0; i--) {
|
|
378
|
+
const p = gameData.particles[i];
|
|
379
|
+
|
|
380
|
+
p.position.x += p.velocity.x * dt;
|
|
381
|
+
p.position.y += p.velocity.y * dt;
|
|
382
|
+
p.position.z += p.velocity.z * dt;
|
|
383
|
+
|
|
384
|
+
setPosition(p.mesh, p.position.x, p.position.y, p.position.z);
|
|
385
|
+
|
|
386
|
+
p.life -= dt;
|
|
387
|
+
if (p.life <= 0) {
|
|
388
|
+
destroyMesh(p.mesh);
|
|
389
|
+
gameData.particles.splice(i, 1);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function drawHUD() {
|
|
395
|
+
color(0xffffff);
|
|
396
|
+
text('Health: ' + gameData.health, 10, 10, 16);
|
|
397
|
+
text('Score: ' + gameData.score, 10, 30, 16);
|
|
398
|
+
text('Wave: ' + gameData.waveNumber, 10, 50, 16);
|
|
399
|
+
|
|
400
|
+
color(0x00ff00);
|
|
401
|
+
text('Enemies: ' + gameData.enemies.length, 10, 400, 12);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function update(dt) {
|
|
405
|
+
// This will be handled by the screen manager
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export function draw() {
|
|
409
|
+
// This will be handled by the screen manager
|
|
410
|
+
}
|