nova64 0.2.4 → 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.
Files changed (140) hide show
  1. package/README.md +25 -8
  2. package/bin/nova64.js +165 -0
  3. package/dist/assets/console-CY_kygm3.js +14 -0
  4. package/dist/assets/console-CY_kygm3.js.map +1 -0
  5. package/dist/assets/main-l0sNRNKZ.js.map +1 -0
  6. package/dist/assets/sky/studio/nx.png +0 -0
  7. package/dist/assets/sky/studio/ny.png +0 -0
  8. package/dist/assets/sky/studio/nz.png +0 -0
  9. package/dist/assets/sky/studio/px.png +0 -0
  10. package/dist/assets/sky/studio/py.png +0 -0
  11. package/dist/assets/sky/studio/pz.png +0 -0
  12. package/dist/assets/vanilla-Dcuy32gi.js +2 -0
  13. package/dist/assets/vanilla-Dcuy32gi.js.map +1 -0
  14. package/dist/console.html +899 -0
  15. package/dist/docs/BENCHMARK.md +77 -0
  16. package/dist/docs/CHEATSHEET.md +255 -0
  17. package/dist/docs/EFFECTS_API_GUIDE.md +577 -0
  18. package/dist/docs/EFFECTS_QUICK_REFERENCE.md +331 -0
  19. package/dist/docs/FONT_CHARACTER_REFERENCE.md +219 -0
  20. package/dist/docs/FREE_GLB_ASSETS.md +330 -0
  21. package/dist/docs/FULLSCREEN_BUTTON_FEATURE.md +296 -0
  22. package/dist/docs/GAMEPAD_SUPPORT.md +348 -0
  23. package/dist/docs/GAME_IMPROVEMENTS.md +278 -0
  24. package/dist/docs/GAME_QUALITY_STATUS.md +300 -0
  25. package/dist/docs/MIGRATION_GUIDE.md +553 -0
  26. package/dist/docs/NOVA64_3D_API.md +356 -0
  27. package/dist/docs/NOVA64_API_REFERENCE.md +1406 -0
  28. package/dist/docs/NOVA64_UI_API.md +503 -0
  29. package/dist/docs/UI_SYSTEM_SUMMARY.md +445 -0
  30. package/dist/docs/VOXEL_ENGINE_GUIDE.md +662 -0
  31. package/dist/docs/VOXEL_QUICK_REFERENCE.md +386 -0
  32. package/dist/docs/api-3d.html +750 -0
  33. package/dist/docs/api-effects.html +385 -0
  34. package/dist/docs/api-improvements.md +121 -0
  35. package/dist/docs/api-skybox.html +407 -0
  36. package/dist/docs/api-sprites.html +321 -0
  37. package/dist/docs/api-voxel.html +337 -0
  38. package/dist/docs/api.html +543 -0
  39. package/dist/docs/assets.html +306 -0
  40. package/dist/docs/audio.html +340 -0
  41. package/dist/docs/blogs.html +286 -0
  42. package/dist/docs/collision.html +316 -0
  43. package/dist/docs/console.html +247 -0
  44. package/dist/docs/editor.html +297 -0
  45. package/dist/docs/font.html +247 -0
  46. package/dist/docs/framebuffer.html +247 -0
  47. package/dist/docs/fullscreen-button.html +297 -0
  48. package/dist/docs/gpu-systems.html +247 -0
  49. package/dist/docs/index.html +580 -0
  50. package/dist/docs/input.html +491 -0
  51. package/dist/docs/physics.html +311 -0
  52. package/dist/docs/screens.html +311 -0
  53. package/dist/docs/storage.html +311 -0
  54. package/dist/docs/textinput.html +332 -0
  55. package/dist/docs/ui.html +488 -0
  56. package/dist/examples/3d-advanced/code.js +695 -0
  57. package/dist/examples/adventure-comic-3d/code.js +342 -0
  58. package/dist/examples/audio-lab/code.js +150 -0
  59. package/dist/examples/boids-flocking/code.js +270 -0
  60. package/dist/examples/crystal-cathedral-3d/code.js +706 -0
  61. package/dist/examples/cyberpunk-city-3d/code.js +1383 -0
  62. package/dist/examples/demoscene/README.md +192 -0
  63. package/dist/examples/demoscene/code.js +1081 -0
  64. package/dist/examples/demoscene/meta.json +21 -0
  65. package/dist/examples/dungeon-crawler-3d/code.js +1117 -0
  66. package/dist/examples/f-zero-nova-3d/code.js +865 -0
  67. package/dist/examples/f-zero-nova-3d/code_old.js +1555 -0
  68. package/dist/examples/fps-demo-3d/code.js +744 -0
  69. package/dist/examples/game-of-life-3d/code.js +338 -0
  70. package/dist/examples/generative-art/code.js +632 -0
  71. package/dist/examples/hello-3d/code.js +325 -0
  72. package/dist/examples/hello-skybox/code.js +183 -0
  73. package/dist/examples/hello-world/code.js +19 -0
  74. package/dist/examples/input-showcase/code.js +109 -0
  75. package/dist/examples/instancing-demo/code.js +315 -0
  76. package/dist/examples/minecraft-demo/code.js +387 -0
  77. package/dist/examples/model-viewer-3d/code.js +114 -0
  78. package/dist/examples/mystical-realm-3d/code.js +1203 -0
  79. package/dist/examples/nature-explorer-3d/code.js +1318 -0
  80. package/dist/examples/particles-demo/code.js +522 -0
  81. package/dist/examples/pbr-showcase/code.js +140 -0
  82. package/dist/examples/physics-demo-3d/code.js +948 -0
  83. package/dist/examples/screen-demo/code.js +267 -0
  84. package/dist/examples/shooter-demo-3d/code.js +1286 -0
  85. package/dist/examples/space-combat-3d/IMPLEMENTATION_SUMMARY.md +109 -0
  86. package/dist/examples/space-combat-3d/README.md +135 -0
  87. package/dist/examples/space-combat-3d/code.js +1332 -0
  88. package/dist/examples/space-harrier-3d/code.js +923 -0
  89. package/dist/examples/star-fox-nova-3d/code.js +1116 -0
  90. package/dist/examples/star-fox-nova-3d/code_backup.js +410 -0
  91. package/dist/examples/star-fox-nova-3d/code_broken.js +1821 -0
  92. package/dist/examples/storage-quest/code.js +209 -0
  93. package/dist/examples/strider-demo-3d/IMPROVEMENT_OPTIONS.md +285 -0
  94. package/dist/examples/strider-demo-3d/cache-test.html +132 -0
  95. package/dist/examples/strider-demo-3d/code-fixed.js +582 -0
  96. package/dist/examples/strider-demo-3d/code-old.js +1537 -0
  97. package/dist/examples/strider-demo-3d/code.js +1462 -0
  98. package/dist/examples/strider-demo-3d/code.js.bak2 +1169 -0
  99. package/dist/examples/strider-demo-3d/fix-game.sh +53 -0
  100. package/dist/examples/super-plumber-64/README.md +128 -0
  101. package/dist/examples/super-plumber-64/code.js +1185 -0
  102. package/dist/examples/super-plumber-64/index.html +88 -0
  103. package/dist/examples/test-2d-overlay/code.js +32 -0
  104. package/dist/examples/test-font/code.js +51 -0
  105. package/dist/examples/test-minimal/code.js +21 -0
  106. package/dist/examples/ui-demo/code.js +306 -0
  107. package/dist/examples/wing-commander-space/README.md +180 -0
  108. package/dist/examples/wing-commander-space/code.js +1285 -0
  109. package/dist/examples/wizardry-3d/CHANGELOG.md +366 -0
  110. package/dist/examples/wizardry-3d/code.js +3928 -0
  111. package/dist/index.html +666 -0
  112. package/dist/os9-shell/assets/index-DIHfrTaW.css +1 -0
  113. package/dist/os9-shell/assets/index-KchE_ngx.js +483 -0
  114. package/dist/os9-shell/assets/index-KchE_ngx.js.map +1 -0
  115. package/dist/os9-shell/index.html +23 -0
  116. package/dist/os9-shell/nova-icon.svg +12 -0
  117. package/index.html +6 -1
  118. package/package.json +37 -32
  119. package/public/assets/sky/studio/nx.png +0 -0
  120. package/public/assets/sky/studio/ny.png +0 -0
  121. package/public/assets/sky/studio/nz.png +0 -0
  122. package/public/assets/sky/studio/px.png +0 -0
  123. package/public/assets/sky/studio/py.png +0 -0
  124. package/public/assets/sky/studio/pz.png +0 -0
  125. package/public/os9-shell/assets/index-KchE_ngx.js +483 -0
  126. package/public/os9-shell/assets/index-KchE_ngx.js.map +1 -0
  127. package/public/os9-shell/index.html +10 -1
  128. package/runtime/api-2d.js +301 -21
  129. package/runtime/api-3d/pbr.js +45 -1
  130. package/runtime/api-3d.js +1 -0
  131. package/runtime/api-effects.js +90 -3
  132. package/runtime/api-gameutils.js +476 -0
  133. package/runtime/api-generative.js +610 -0
  134. package/runtime/api-skybox.js +54 -0
  135. package/runtime/api-voxel.js +139 -28
  136. package/runtime/gpu-threejs.js +13 -9
  137. package/runtime/ui.js +2 -2
  138. package/src/main.js +24 -1
  139. package/public/os9-shell/assets/index-B1Uvacma.js +0 -32825
  140. package/public/os9-shell/assets/index-B1Uvacma.js.map +0 -1
@@ -0,0 +1,923 @@
1
+ // ⭐ SPACE HARRIER NOVA 64 - Exceptional 2.5D/3D Rail Shooter ⭐
2
+
3
+ let gameState = 'start';
4
+ let gameTime = 0;
5
+ let inputLockoutCD;
6
+ let weaponCD;
7
+
8
+ // Colors
9
+ const PALETTE = {
10
+ sky: 0xaa22ff,
11
+ ground1: 0x22cc55,
12
+ ground2: 0x118833,
13
+ playerBody: 0xff3333,
14
+ playerHead: 0xffccaa,
15
+ gun: 0xcccccc,
16
+ bullet: 0xffff00,
17
+ enemy: 0xaa22ff,
18
+ enemyEye: 0x00ff00,
19
+ enemyShot: 0xff00ff,
20
+ treeTrunk: 0x8b4513,
21
+ treeLeaves: 0x11aa55,
22
+ pillar: 0xffaa00,
23
+ explosion: 0xff5500,
24
+ };
25
+
26
+ let game = {
27
+ player: {
28
+ x: 0,
29
+ y: 0,
30
+ z: -5,
31
+ health: 100,
32
+ meshes: {},
33
+ animPhase: 0,
34
+ bobPhase: 0,
35
+ },
36
+ speed: 45,
37
+ distance: 0,
38
+ score: 0,
39
+ lives: 3,
40
+ wave: 0,
41
+ waveTimer: 0,
42
+ waveEnemiesLeft: 0,
43
+ waveClear: false,
44
+ waveClearTimer: 0,
45
+ powerup: null, // active power-up type
46
+ powerupTimer: 0,
47
+ powerupPickups: [], // on-screen power-up meshes
48
+ shake: null,
49
+ killStreak: 0,
50
+ streakTimer: 0,
51
+ glitchTimer: 0,
52
+
53
+ gridPlanes: [],
54
+ scenery: [],
55
+ enemies: [],
56
+ bullets: [],
57
+ enemyBullets: [],
58
+ particles: [],
59
+ enemySpawnTimer: 0,
60
+ };
61
+
62
+ export async function init() {
63
+ console.log('🚀 SPACE HARRIER NOVA 64 - Loading...');
64
+
65
+ setCameraPosition(0, 5, 12);
66
+ setCameraTarget(0, 3, -50);
67
+ setCameraFOV(70);
68
+
69
+ // Vibrant alien sky and effects
70
+ setAmbientLight(0xffffff, 1.0);
71
+ setLightDirection(-0.5, -1, -0.5);
72
+ setLightColor(0xfff0dd);
73
+ setFog(PALETTE.sky, 30, 150);
74
+
75
+ // Retro presentation with modern shader touch
76
+ if (typeof enablePixelation === 'function') enablePixelation(1);
77
+ if (typeof enableDithering === 'function') enableDithering(true);
78
+ enableBloom(1.0, 0.5, 0.3); // Alien sky & bullet glow
79
+ enableFXAA();
80
+ enableVignette(1.0, 0.95);
81
+
82
+ createCheckeredFloor();
83
+ createPlayer();
84
+
85
+ // Hide player meshes on start screen to prevent 3D artifacts/bloom trails
86
+ setPlayerVisible(false);
87
+
88
+ for (let i = 0; i < 40; i++) {
89
+ spawnScenery(true);
90
+ }
91
+
92
+ inputLockoutCD = createCooldown(0.6);
93
+ inputLockoutCD.timer = 0.6; // start locked out
94
+ weaponCD = createCooldown(0.12);
95
+ game.shake = createShake({ decay: 5 });
96
+
97
+ initStartScreen();
98
+ }
99
+
100
+ function createCheckeredFloor() {
101
+ const cols = 22;
102
+ const rows = 35;
103
+ const size = 5;
104
+ const startX = -(cols * size) / 2;
105
+ const startZ = 20;
106
+
107
+ for (let r = 0; r < rows; r++) {
108
+ for (let c = 0; c < cols; c++) {
109
+ const isAlt = (r + c) % 2 === 0;
110
+ const color = isAlt ? PALETTE.ground1 : PALETTE.ground2;
111
+ const x = startX + c * size + size / 2;
112
+ const z = startZ - r * size - size / 2;
113
+ const y = -2;
114
+
115
+ const plane = createPlane(size, size, color, [x, y, z]);
116
+ rotateMesh(plane, -Math.PI / 2, 0, 0);
117
+
118
+ game.gridPlanes.push({
119
+ mesh: plane,
120
+ x: x,
121
+ y: y,
122
+ z: z,
123
+ size: size,
124
+ });
125
+ }
126
+ }
127
+ }
128
+
129
+ function createPlayer() {
130
+ const p = game.player;
131
+ const bx = p.x,
132
+ by = p.y,
133
+ bz = p.z;
134
+
135
+ p.meshes.body = createCube(1.2, PALETTE.playerBody, [bx, by, bz]);
136
+ setScale(p.meshes.body, 1.0, 1.3, 0.8);
137
+
138
+ p.meshes.head = createSphere(0.6, PALETTE.playerHead, [bx, by + 1.2, bz], 8);
139
+
140
+ p.meshes.hair = createCube(0.7, 0x5a2d0c, [bx, by + 1.5, bz + 0.1]);
141
+ setScale(p.meshes.hair, 1.1, 0.4, 1.1);
142
+
143
+ p.meshes.jetpack = createCube(0.8, 0x888888, [bx, by + 0.2, bz + 0.6]);
144
+ setScale(p.meshes.jetpack, 1.2, 1.5, 0.5);
145
+
146
+ p.meshes.gun = createCube(0.5, PALETTE.gun, [bx + 0.8, by, bz - 1.5]);
147
+ setScale(p.meshes.gun, 0.6, 0.6, 3.5);
148
+
149
+ p.meshes.armL = createCube(0.4, PALETTE.playerBody, [bx - 0.8, by + 0.2, bz]);
150
+ setScale(p.meshes.armL, 0.7, 1.8, 0.7);
151
+
152
+ p.meshes.armR = createCube(0.4, PALETTE.playerBody, [bx + 0.8, by + 0.2, bz]);
153
+ setScale(p.meshes.armR, 0.7, 1.8, 0.7);
154
+
155
+ p.meshes.legL = createCube(0.4, PALETTE.playerBody, [bx - 0.4, by - 1.0, bz]);
156
+ setScale(p.meshes.legL, 0.8, 2.0, 0.8);
157
+
158
+ p.meshes.legR = createCube(0.4, PALETTE.playerBody, [bx + 0.4, by - 1.0, bz]);
159
+ setScale(p.meshes.legR, 0.8, 2.0, 0.8);
160
+
161
+ p.meshes.flameL = createCube(0.3, 0xffaa00, [bx - 0.3, by - 0.6, bz + 0.6]);
162
+ p.meshes.flameR = createCube(0.3, 0xffaa00, [bx + 0.3, by - 0.6, bz + 0.6]);
163
+ }
164
+
165
+ function setPlayerVisible(visible) {
166
+ Object.values(game.player.meshes).forEach(m => setMeshVisible(m, visible));
167
+ }
168
+
169
+ function spawnScenery(randomZ = false) {
170
+ const isLeft = Math.random() > 0.5;
171
+ const x = (isLeft ? -1 : 1) * (15 + Math.random() * 25);
172
+ const z = randomZ ? 10 - Math.random() * 120 : -120;
173
+ const y = -2;
174
+
175
+ const type = Math.random() > 0.5 ? 'tree' : 'pillar';
176
+ let parts = [];
177
+
178
+ if (type === 'tree') {
179
+ const height = 3 + Math.random() * 6;
180
+ const trunk = createCube(1, PALETTE.treeTrunk, [x, y + height / 2, z]);
181
+ setScale(trunk, 1, height, 1);
182
+
183
+ // Exceptional foliage look
184
+ const top = createSphere(2.5 + Math.random(), PALETTE.treeLeaves, [x, y + height + 1, z], 6);
185
+ parts.push({ mesh: trunk, oy: y + height / 2 });
186
+ parts.push({ mesh: top, oy: y + height + 1 });
187
+ } else {
188
+ // Exceptional floating glowing rings/pillars
189
+ const pHeight = 6 + Math.random() * 8;
190
+ // We try to pass a nice high-end color and maybe emissive
191
+ const pillarOptions = {
192
+ material: 'holographic',
193
+ color: PALETTE.pillar,
194
+ emissive: 0xaa2200,
195
+ opacity: 0.8,
196
+ transparent: true,
197
+ };
198
+ // Use createAdvancedCube for holographic/emissive material support
199
+ const pillar = createAdvancedCube(1, pillarOptions, [x, y + pHeight / 2, z]);
200
+
201
+ setScale(pillar, 2, pHeight, 2);
202
+ parts.push({ mesh: pillar, oy: y + pHeight / 2 });
203
+ }
204
+
205
+ game.scenery.push({
206
+ parts: parts,
207
+ x: x,
208
+ z: z,
209
+ });
210
+ }
211
+
212
+ function spawnEnemy(type) {
213
+ const x = (Math.random() - 0.5) * 40;
214
+ const z = -120;
215
+ const y = 3 + Math.random() * 15;
216
+ type = type || 'normal';
217
+
218
+ let color = PALETTE.enemy;
219
+ let hp = 30;
220
+ let spd = 30 + Math.random() * 30;
221
+ let size = 2.5;
222
+
223
+ if (type === 'fast') {
224
+ color = 0x00ccff;
225
+ hp = 15;
226
+ spd = 60 + Math.random() * 30;
227
+ size = 1.8;
228
+ } else if (type === 'tank') {
229
+ color = 0xff4400;
230
+ hp = 80;
231
+ spd = 20 + Math.random() * 15;
232
+ size = 3.5;
233
+ } else if (type === 'boss') {
234
+ color = 0xff0000;
235
+ hp = 200 + game.wave * 50;
236
+ spd = 15;
237
+ size = 5;
238
+ }
239
+
240
+ const core = createSphere(size, color, [x, y, z], 8);
241
+ const eye = createSphere(size * 0.5, PALETTE.enemyEye, [x, y, z + size * 0.8], 8);
242
+
243
+ const wingL = createCube(size * 0.6, 0x5500aa, [x - size * 1.2, y, z]);
244
+ setScale(wingL, 3, 0.2, 1);
245
+ const wingR = createCube(size * 0.6, 0x5500aa, [x + size * 1.2, y, z]);
246
+ setScale(wingR, 3, 0.2, 1);
247
+
248
+ game.enemies.push({
249
+ parts: [
250
+ { mesh: core, ox: 0, oy: 0, oz: 0 },
251
+ { mesh: eye, ox: 0, oy: 0, oz: size * 0.8 },
252
+ { mesh: wingL, ox: -size * 1.2, oy: 0, oz: 0 },
253
+ { mesh: wingR, ox: size * 1.2, oy: 0, oz: 0 },
254
+ ],
255
+ x: x,
256
+ y: y,
257
+ z: z,
258
+ health: hp,
259
+ maxHealth: hp,
260
+ type: type,
261
+ vx: (Math.random() - 0.5) * 20,
262
+ vy: (Math.random() - 0.5) * 10,
263
+ vz: spd,
264
+ timer: 0,
265
+ });
266
+ }
267
+
268
+ function firePlayerBullet(xOffset) {
269
+ const p = game.player;
270
+ const x = p.x + 0.8 + (xOffset || 0);
271
+ const y = p.y;
272
+ const z = p.z - 2;
273
+
274
+ const bullet = createCube(0.8, PALETTE.bullet, [x, y, z]);
275
+ setScale(bullet, 0.5, 0.5, 6.0);
276
+
277
+ game.bullets.push({
278
+ mesh: bullet,
279
+ x: x,
280
+ y: y,
281
+ z: z,
282
+ vz: -180,
283
+ life: 2.0,
284
+ });
285
+ }
286
+
287
+ function fireEnemyBullet(ex, ey, ez) {
288
+ const bullet = createSphere(1.2, PALETTE.enemyShot, [ex, ey, ez], 6);
289
+
290
+ const p = game.player;
291
+ const dx = p.x - ex,
292
+ dy = p.y - ey,
293
+ dz = p.z - ez;
294
+ const dist = Math.sqrt(dx * dx + dy * dy + dz * dz) || 1;
295
+ const speed = 70 + game.score * 0.001;
296
+
297
+ game.enemyBullets.push({
298
+ mesh: bullet,
299
+ x: ex,
300
+ y: ey,
301
+ z: ez,
302
+ vx: (dx / dist) * speed,
303
+ vy: (dy / dist) * speed,
304
+ vz: (dz / dist) * speed,
305
+ life: 3.0,
306
+ });
307
+ }
308
+
309
+ function createExplosion(x, y, z, color) {
310
+ for (let i = 0; i < 15; i++) {
311
+ const p = createCube(0.8, color, [x, y, z]);
312
+ const speed = 15 + Math.random() * 25;
313
+ const angle1 = Math.random() * Math.PI * 2;
314
+ const angle2 = Math.random() * Math.PI * 2;
315
+
316
+ game.particles.push({
317
+ mesh: p,
318
+ x: x,
319
+ y: y,
320
+ z: z,
321
+ vx: Math.cos(angle1) * Math.sin(angle2) * speed,
322
+ vy: Math.sin(angle1) * speed,
323
+ vz: Math.cos(angle1) * Math.cos(angle2) * speed,
324
+ life: 0.5 + Math.random() * 0.5,
325
+ maxLife: 1.0,
326
+ });
327
+ }
328
+ }
329
+
330
+ export function update(dt) {
331
+ gameTime += dt;
332
+
333
+ if (gameState === 'start' || gameState === 'gameover') {
334
+ updateCooldown(inputLockoutCD, dt);
335
+ updateAllButtons();
336
+ updateGrid(dt * 0.4);
337
+
338
+ // Animate player idly
339
+ updatePlayer(dt, true);
340
+
341
+ if (cooldownReady(inputLockoutCD) && isKeyPressed('Space')) startGame();
342
+ return;
343
+ }
344
+
345
+ game.distance += game.speed * dt;
346
+ game.score += dt * 25;
347
+ game.speed = Math.min(100, 45 + game.wave * 3);
348
+ updateShake(game.shake, dt);
349
+
350
+ // Glitch decay
351
+ if (game.glitchTimer > 0) {
352
+ game.glitchTimer -= dt;
353
+ if (game.glitchTimer <= 0) {
354
+ game.glitchTimer = 0;
355
+ disableGlitch();
356
+ } else {
357
+ setGlitchIntensity(game.glitchTimer * 1.5);
358
+ }
359
+ }
360
+
361
+ // Kill streak timer
362
+ if (game.streakTimer > 0) {
363
+ game.streakTimer -= dt;
364
+ if (game.streakTimer <= 0) game.killStreak = 0;
365
+ }
366
+
367
+ // Power-up timer
368
+ if (game.powerupTimer > 0) {
369
+ game.powerupTimer -= dt;
370
+ if (game.powerupTimer <= 0) game.powerup = null;
371
+ }
372
+
373
+ // Wave management
374
+ if (game.waveClear) {
375
+ game.waveClearTimer -= dt;
376
+ if (game.waveClearTimer <= 0) {
377
+ game.waveClear = false;
378
+ startWave(game.wave + 1);
379
+ }
380
+ } else if (game.waveEnemiesLeft <= 0 && game.enemies.length === 0 && game.wave > 0) {
381
+ game.waveClear = true;
382
+ game.waveClearTimer = 2.0;
383
+ const waveBonus = game.wave * 200;
384
+ game.score += waveBonus;
385
+ sfx('powerup');
386
+ }
387
+
388
+ updatePlayer(dt, false);
389
+ updateGrid(dt);
390
+ updateScenery(dt);
391
+ updateEnemies(dt);
392
+ updateBullets(dt);
393
+ updateEnemyBullets(dt);
394
+ updateParticles(dt);
395
+ updatePowerupPickups(dt);
396
+ }
397
+
398
+ function startGame() {
399
+ if (gameState === 'playing') return;
400
+ inputLockoutCD.timer = 0.3;
401
+ gameState = 'playing';
402
+ setPlayerVisible(true);
403
+ game.score = 0;
404
+ game.player.health = 100;
405
+ game.speed = 45;
406
+ game.lives = 3;
407
+ game.wave = 0;
408
+ game.powerup = null;
409
+ game.powerupTimer = 0;
410
+ game.killStreak = 0;
411
+ game.streakTimer = 0;
412
+ game.waveClear = false;
413
+
414
+ game.enemies.forEach(e => e.parts.forEach(p => destroyMesh(p.mesh)));
415
+ game.enemyBullets.forEach(b => destroyMesh(b.mesh));
416
+ game.bullets.forEach(b => destroyMesh(b.mesh));
417
+ game.powerupPickups.forEach(p => destroyMesh(p.mesh));
418
+
419
+ game.enemies = [];
420
+ game.enemyBullets = [];
421
+ game.bullets = [];
422
+ game.powerupPickups = [];
423
+ clearButtons();
424
+
425
+ startWave(1);
426
+ }
427
+
428
+ function startWave(num) {
429
+ game.wave = num;
430
+ const baseCount = 4 + num * 2;
431
+ game.waveEnemiesLeft = baseCount;
432
+ game.enemySpawnTimer = 0.5;
433
+ }
434
+
435
+ function spawnPowerup(x, y, z) {
436
+ const types = ['health', 'rapid', 'spread', 'shield'];
437
+ const type = types[Math.floor(Math.random() * types.length)];
438
+ const colors = { health: 0x00ff00, rapid: 0xffff00, spread: 0xff8800, shield: 0x00ccff };
439
+ const mesh = createSphere(1.5, colors[type], [x, y, z], 6);
440
+ game.powerupPickups.push({ mesh, x, y, z, type, timer: 0 });
441
+ }
442
+
443
+ function updatePowerupPickups(dt) {
444
+ const p = game.player;
445
+ for (let i = game.powerupPickups.length - 1; i >= 0; i--) {
446
+ const pu = game.powerupPickups[i];
447
+ pu.z += game.speed * dt * 0.5;
448
+ pu.timer += dt;
449
+ setPosition(pu.mesh, pu.x, pu.y + Math.sin(pu.timer * 4) * 1.5, pu.z);
450
+ setRotation(pu.mesh, 0, pu.timer * 3, 0);
451
+
452
+ // Collect
453
+ if (Math.abs(pu.x - p.x) < 3 && Math.abs(pu.y - p.y) < 3 && Math.abs(pu.z - p.z) < 4) {
454
+ if (pu.type === 'health') {
455
+ p.health = Math.min(100, p.health + 40);
456
+ } else {
457
+ game.powerup = pu.type;
458
+ game.powerupTimer = 8;
459
+ }
460
+ sfx('coin');
461
+ destroyMesh(pu.mesh);
462
+ game.powerupPickups.splice(i, 1);
463
+ continue;
464
+ }
465
+
466
+ if (pu.z > 25) {
467
+ destroyMesh(pu.mesh);
468
+ game.powerupPickups.splice(i, 1);
469
+ }
470
+ }
471
+ }
472
+
473
+ function updatePlayer(dt, isIdle) {
474
+ const p = game.player;
475
+ if (!isIdle && p.health <= 0) {
476
+ createExplosion(p.x, p.y, p.z, PALETTE.playerBody);
477
+ sfx('explosion');
478
+ game.lives--;
479
+ if (game.lives <= 0) {
480
+ gameState = 'gameover';
481
+ initGameOverScreen();
482
+ } else {
483
+ // Respawn with brief invulnerability
484
+ p.health = 100;
485
+ p.x = 0;
486
+ p.y = 0;
487
+ game.powerup = 'shield';
488
+ game.powerupTimer = 3;
489
+ }
490
+ return;
491
+ }
492
+
493
+ let dx = 0;
494
+ let dy = 0;
495
+ if (!isIdle) {
496
+ if (key('ArrowLeft') || key('a')) dx = -1;
497
+ if (key('ArrowRight') || key('d')) dx = 1;
498
+ if (key('ArrowUp') || key('w')) dy = 1;
499
+ if (key('ArrowDown') || key('s')) dy = -1;
500
+ }
501
+
502
+ const moveSpeed = 45;
503
+ p.x += dx * moveSpeed * dt;
504
+ p.y += dy * moveSpeed * dt;
505
+
506
+ if (p.x < -22) p.x = -22;
507
+ if (p.x > 22) p.x = 22;
508
+ if (p.y < 0) p.y = 0;
509
+ if (p.y > 18) p.y = 18;
510
+
511
+ const isGrounded = p.y < 0.5;
512
+ p.animPhase += dt * (isGrounded ? 18 : 6);
513
+ p.bobPhase += dt * moveSpeed * 0.25;
514
+
515
+ const bY = p.y + (isGrounded && dx !== 0 ? Math.abs(Math.sin(p.bobPhase)) * 0.8 : 0);
516
+
517
+ setPosition(p.meshes.body, p.x, bY, p.z);
518
+ setPosition(p.meshes.head, p.x, bY + 1.2, p.z);
519
+ setPosition(p.meshes.hair, p.x, bY + 1.5, p.z + 0.1);
520
+ setPosition(p.meshes.jetpack, p.x, bY + 0.2, p.z + 0.6);
521
+ setPosition(p.meshes.gun, p.x + 0.8, bY - 0.2, p.z - 1.5);
522
+ setPosition(p.meshes.armL, p.x - 0.8, bY + 0.2, p.z);
523
+ setPosition(p.meshes.armR, p.x + 0.8, bY + 0.2, p.z);
524
+
525
+ // Jetpack flames flicker
526
+ setPosition(p.meshes.flameL, p.x - 0.3, bY - 0.6 - Math.random() * 0.3, p.z + 0.6);
527
+ setPosition(p.meshes.flameR, p.x + 0.3, bY - 0.6 - Math.random() * 0.3, p.z + 0.6);
528
+
529
+ if (isGrounded && (dx !== 0 || isIdle)) {
530
+ // idle running in place effectively
531
+ const legSwing = Math.sin(p.animPhase) * 1.5;
532
+ setPosition(p.meshes.legL, p.x - 0.4, bY - 1.0, p.z + legSwing);
533
+ setPosition(p.meshes.legR, p.x + 0.4, bY - 1.0, p.z - legSwing);
534
+ } else {
535
+ setPosition(p.meshes.legL, p.x - 0.4, bY - 1.0, p.z + 0.5);
536
+ setPosition(p.meshes.legR, p.x + 0.4, bY - 1.0, p.z + 0.5);
537
+ }
538
+
539
+ updateCooldown(weaponCD, dt);
540
+ const fireRate = game.powerup === 'rapid' ? 0.04 : 0.12;
541
+ weaponCD.duration = fireRate;
542
+ if (!isIdle && key('Space') && useCooldown(weaponCD)) {
543
+ firePlayerBullet();
544
+ if (game.powerup === 'spread') {
545
+ firePlayerBullet(-8);
546
+ firePlayerBullet(8);
547
+ }
548
+ }
549
+ }
550
+
551
+ function updateGrid(dt) {
552
+ const totalLength = 35 * 5;
553
+ game.gridPlanes.forEach(g => {
554
+ g.z += game.speed * dt;
555
+ if (g.z > 20) {
556
+ g.z -= totalLength;
557
+ }
558
+ setPosition(g.mesh, g.x, g.y, g.z);
559
+ });
560
+ }
561
+
562
+ function updateScenery(dt) {
563
+ game.scenery.forEach(s => {
564
+ s.z += game.speed * dt;
565
+ if (s.z > 20) {
566
+ s.z -= 140 + Math.random() * 60;
567
+ s.x = (Math.random() > 0.5 ? -1 : 1) * (15 + Math.random() * 30);
568
+ }
569
+ s.parts.forEach(p => {
570
+ setPosition(p.mesh, s.x, p.oy, s.z);
571
+ });
572
+ });
573
+ }
574
+
575
+ function updateEnemies(dt) {
576
+ game.enemySpawnTimer -= dt;
577
+ if (game.enemySpawnTimer <= 0 && game.waveEnemiesLeft > 0) {
578
+ game.waveEnemiesLeft--;
579
+ // Enemy type distribution based on wave
580
+ const roll = Math.random();
581
+ if (game.wave >= 3 && game.waveEnemiesLeft === 0 && game.wave % 3 === 0) {
582
+ spawnEnemy('boss');
583
+ } else if (roll < 0.15 && game.wave >= 2) {
584
+ spawnEnemy('fast');
585
+ } else if (roll < 0.25 && game.wave >= 4) {
586
+ spawnEnemy('tank');
587
+ } else {
588
+ spawnEnemy('normal');
589
+ }
590
+ game.enemySpawnTimer = Math.max(0.4, 1.5 - game.wave * 0.08);
591
+ }
592
+
593
+ for (let i = game.enemies.length - 1; i >= 0; i--) {
594
+ const e = game.enemies[i];
595
+ e.timer += dt;
596
+
597
+ e.x += e.vx * dt;
598
+ e.y += e.vy * dt;
599
+ e.z += e.vz * dt;
600
+
601
+ if (e.x < -30 || e.x > 30) e.vx *= -1;
602
+ if (e.y < 2 || e.y > 20) e.vy *= -1;
603
+
604
+ const bob = Math.sin(e.timer * 4) * 2;
605
+
606
+ e.parts.forEach(p => {
607
+ setPosition(p.mesh, e.x + p.ox, e.y + p.oy + bob, e.z + p.oz);
608
+ });
609
+
610
+ if (e.timer > 1.5 && Math.random() < (e.type === 'boss' ? 0.06 : 0.02)) {
611
+ fireEnemyBullet(e.x, e.y + bob, e.z);
612
+ }
613
+
614
+ // Boss fires spread
615
+ if (e.type === 'boss' && e.timer > 2 && Math.random() < 0.01) {
616
+ for (let a = -2; a <= 2; a++) {
617
+ fireEnemyBullet(e.x + a * 3, e.y + bob, e.z);
618
+ }
619
+ }
620
+
621
+ if (e.z > 20) {
622
+ e.parts.forEach(p => destroyMesh(p.mesh));
623
+ game.enemies.splice(i, 1);
624
+ }
625
+ }
626
+ }
627
+
628
+ function updateBullets(dt) {
629
+ for (let i = game.bullets.length - 1; i >= 0; i--) {
630
+ const b = game.bullets[i];
631
+ b.z += b.vz * dt;
632
+ b.life -= dt;
633
+ setPosition(b.mesh, b.x, b.y, b.z);
634
+
635
+ if (b.life <= 0 || b.z < -150) {
636
+ destroyMesh(b.mesh);
637
+ game.bullets.splice(i, 1);
638
+ continue;
639
+ }
640
+
641
+ let hit = false;
642
+ for (let j = game.enemies.length - 1; j >= 0; j--) {
643
+ const e = game.enemies[j];
644
+ if (Math.abs(b.x - e.x) < 3.0 && Math.abs(b.y - e.y) < 3.0 && Math.abs(b.z - e.z) < 4.0) {
645
+ e.health -= 15;
646
+ hit = true;
647
+ sfx('hit');
648
+ if (e.health <= 0) {
649
+ createExplosion(e.x, e.y, e.z, PALETTE.explosion);
650
+ const killPoints =
651
+ e.type === 'boss' ? 3000 : e.type === 'tank' ? 1000 : e.type === 'fast' ? 700 : 500;
652
+ game.score += killPoints;
653
+ game.killStreak++;
654
+ game.streakTimer = 2;
655
+ if (game.killStreak >= 5) {
656
+ game.score += game.killStreak * 100;
657
+ }
658
+ sfx('explosion');
659
+ // 25% chance to drop power-up
660
+ if (Math.random() < 0.25) {
661
+ spawnPowerup(e.x, e.y, e.z);
662
+ }
663
+ e.parts.forEach(p => destroyMesh(p.mesh));
664
+ game.enemies.splice(j, 1);
665
+ }
666
+ break;
667
+ }
668
+ }
669
+
670
+ if (hit) {
671
+ destroyMesh(b.mesh);
672
+ game.bullets.splice(i, 1);
673
+ }
674
+ }
675
+ }
676
+
677
+ function updateEnemyBullets(dt) {
678
+ const p = game.player;
679
+ for (let i = game.enemyBullets.length - 1; i >= 0; i--) {
680
+ const b = game.enemyBullets[i];
681
+ b.x += b.vx * dt;
682
+ b.y += b.vy * dt;
683
+ b.z += b.vz * dt;
684
+ b.life -= dt;
685
+
686
+ setPosition(b.mesh, b.x, b.y, b.z);
687
+
688
+ if (Math.abs(b.x - p.x) < 1.5 && Math.abs(b.y - p.y) < 2.0 && Math.abs(b.z - p.z) < 2.0) {
689
+ if (game.powerup === 'shield') {
690
+ // Shield absorbs hit
691
+ } else {
692
+ p.health -= 25;
693
+ triggerShake(game.shake, 0.4);
694
+ enableGlitch(0.5);
695
+ game.glitchTimer = 0.3;
696
+ sfx('hit');
697
+ }
698
+ createExplosion(p.x, p.y, p.z, PALETTE.playerBody);
699
+ destroyMesh(b.mesh);
700
+ game.enemyBullets.splice(i, 1);
701
+ continue;
702
+ }
703
+
704
+ if (b.life <= 0 || b.z > 20) {
705
+ destroyMesh(b.mesh);
706
+ game.enemyBullets.splice(i, 1);
707
+ }
708
+ }
709
+ }
710
+
711
+ function updateParticles(dt) {
712
+ for (let i = game.particles.length - 1; i >= 0; i--) {
713
+ const p = game.particles[i];
714
+ p.x += p.vx * dt;
715
+ p.y += p.vy * dt;
716
+ p.z += p.vz * dt;
717
+ p.life -= dt;
718
+
719
+ setPosition(p.mesh, p.x, p.y, p.z);
720
+
721
+ const alpha = p.life / p.maxLife;
722
+ setScale(p.mesh, alpha, alpha, alpha);
723
+
724
+ if (p.life <= 0) {
725
+ destroyMesh(p.mesh);
726
+ game.particles.splice(i, 1);
727
+ }
728
+ }
729
+ }
730
+
731
+ function initStartScreen() {
732
+ clearButtons();
733
+ createButton(
734
+ centerX(240),
735
+ 252,
736
+ 240,
737
+ 52,
738
+ '▶ START MISSION',
739
+ () => {
740
+ startGame();
741
+ },
742
+ { normalColor: uiColors.success, hoverColor: rgba8(60, 220, 120, 255) }
743
+ );
744
+ }
745
+
746
+ function drawStartScreen() {
747
+ // Solid opaque base — guaranteed to cover the 3D scene
748
+ cls(rgba8(5, 0, 15, 255));
749
+
750
+ // Rich alien-world gradient layered on top
751
+ drawGradient(0, 0, 640, 360, rgba8(20, 5, 55, 255), rgba8(4, 0, 18, 255), 'v');
752
+
753
+ // Radial spotlight glow behind title
754
+ drawRadialGradient(320, 105, 230, rgba8(200, 60, 255, 48), rgba8(0, 0, 0, 0));
755
+
756
+ // Cosmic starfield noise
757
+ drawNoise(0, 0, 640, 360, 22, Math.floor(gameTime * 6));
758
+
759
+ // Distant planet arc at horizon
760
+ drawRadialGradient(320, 440, 280, rgba8(80, 0, 160, 70), rgba8(0, 0, 0, 0));
761
+
762
+ // Corner starbursts — pulsing
763
+ const sp = Math.sin(gameTime * 2) * 0.5 + 0.5;
764
+ drawStarburst(30, 30, 18, 7, 6, rgba8(255, 140, 0, Math.floor(sp * 210)), true);
765
+ drawStarburst(610, 30, 18, 7, 6, rgba8(255, 140, 0, Math.floor(sp * 210)), true);
766
+ drawStarburst(30, 330, 12, 5, 5, rgba8(180, 0, 255, Math.floor((1 - sp) * 180)), true);
767
+ drawStarburst(610, 330, 12, 5, 5, rgba8(180, 0, 255, Math.floor((1 - sp) * 180)), true);
768
+
769
+ // More scattered star shots across the sky
770
+ drawStarburst(90, 70, 7, 3, 4, rgba8(255, 255, 180, Math.floor(sp * 160)), true);
771
+ drawStarburst(550, 55, 6, 2, 4, rgba8(200, 180, 255, Math.floor((1 - sp) * 150)), true);
772
+ drawStarburst(480, 80, 5, 2, 5, rgba8(255, 200, 100, Math.floor(sp * 130)), true);
773
+
774
+ // Energy wave at the horizon line
775
+ drawWave(0, 185, 640, 6, 0.028, gameTime * 2.2, rgba8(180, 0, 255, 100), 2);
776
+ drawWave(0, 190, 640, 4, 0.042, gameTime * 2.8 + 1.0, rgba8(255, 100, 0, 75), 2);
777
+
778
+ // Main title — SPACE HARRIER with orange/flame glow
779
+ const titleBob = Math.sin(gameTime * 1.8) * 7;
780
+ drawGlowTextCentered(
781
+ 'SPACE',
782
+ 320,
783
+ 44 + titleBob,
784
+ rgba8(255, 160, 0, 255),
785
+ rgba8(160, 50, 0, 170),
786
+ 2
787
+ );
788
+ drawGlowTextCentered(
789
+ 'HARRIER',
790
+ 320,
791
+ 98 + titleBob,
792
+ rgba8(255, 80, 20, 255),
793
+ rgba8(120, 20, 0, 160),
794
+ 2
795
+ );
796
+
797
+ // Subtitle
798
+ const subPulse = Math.sin(gameTime * 3) * 0.25 + 0.75;
799
+ setFont('large');
800
+ setTextAlign('center');
801
+ drawText('NOVA 64 EDITION', 320, 152, rgba8(120, 200, 255, Math.floor(subPulse * 255)), 1);
802
+
803
+ // Tagline
804
+ setFont('normal');
805
+ drawText('THE LEGENDARY RAIL SHOOTER RETURNS', 320, 174, rgba8(200, 150, 255, 200), 1);
806
+
807
+ // Info panel
808
+ const panel = createPanel(centerX(440), 200, 440, 92, {
809
+ bgColor: rgba8(15, 5, 35, 215),
810
+ borderColor: rgba8(180, 60, 255, 255),
811
+ borderWidth: 2,
812
+ shadow: true,
813
+ });
814
+ drawPanel(panel);
815
+
816
+ setFont('small');
817
+ setTextAlign('center');
818
+ drawText('◆ Blast through waves of alien enemies', 320, 218, uiColors.light, 1);
819
+ drawText('◆ Dodge projectiles & collect power-ups', 320, 233, uiColors.light, 1);
820
+ drawText('◆ Retro N64 rail-shooter with 3D visuals', 320, 248, uiColors.light, 1);
821
+
822
+ // Buttons
823
+ drawAllButtons();
824
+
825
+ // Controls hint
826
+ setFont('tiny');
827
+ drawText('WASD / Arrows: Move ◆ Space: Shoot', 320, 318, uiColors.secondary, 1);
828
+
829
+ // Pulsing prompt
830
+ const alpha = Math.floor((Math.sin(gameTime * 5) * 0.5 + 0.5) * 255);
831
+ drawText('◆ PRESS SPACE TO LAUNCH ◆', 320, 334, rgba8(255, 160, 0, alpha), 1);
832
+
833
+ // CRT scanlines
834
+ drawScanlines(45, 2);
835
+ }
836
+
837
+ function initGameOverScreen() {
838
+ setPlayerVisible(false);
839
+ disableGlitch();
840
+ game.glitchTimer = 0;
841
+ clearButtons();
842
+ createButton(
843
+ centerX(220),
844
+ 260,
845
+ 220,
846
+ 50,
847
+ '↻ RETRY',
848
+ () => {
849
+ gameState = 'start';
850
+ inputLockoutCD.timer = 0.6;
851
+ initStartScreen();
852
+ },
853
+ { normalColor: uiColors.danger, hoverColor: rgba8(250, 60, 60, 255) }
854
+ );
855
+ }
856
+
857
+ export function draw() {
858
+ if (gameState === 'start') {
859
+ drawStartScreen();
860
+ return;
861
+ }
862
+
863
+ if (gameState === 'gameover') {
864
+ rect(0, 0, 640, 360, rgba8(100, 0, 0, 150), true);
865
+ setFont('huge');
866
+ setTextAlign('center');
867
+ drawTextShadow('GAME OVER', 320, 120, uiColors.danger, rgba8(0, 0, 0, 255), 4, 1);
868
+
869
+ setFont('normal');
870
+ drawText('SCORE: ' + Math.floor(game.score), 320, 180, uiColors.warning, 1);
871
+ drawAllButtons();
872
+ return;
873
+ }
874
+
875
+ setFont('normal');
876
+ setTextAlign('left');
877
+ drawText('SCORE: ' + Math.floor(game.score), 20, 20, uiColors.warning, 1);
878
+ drawText(`WAVE ${game.wave}`, 20, 40, rgba8(0, 255, 255, 255), 1);
879
+
880
+ // Lives
881
+ for (let i = 0; i < game.lives; i++) {
882
+ rect(170 + i * 18, 22, 12, 12, rgba8(255, 50, 50, 255), true);
883
+ }
884
+
885
+ // Health bar
886
+ rect(420, 20, 200, 20, rgba8(50, 0, 0, 200), true);
887
+ const hpWidth = Math.max(0, game.player.health * 2);
888
+ rect(420, 20, hpWidth, 20, hpWidth > 40 ? uiColors.success : uiColors.danger, true);
889
+ rect(420, 20, 200, 20, uiColors.light, false);
890
+
891
+ // Power-up indicator
892
+ if (game.powerup) {
893
+ const puColors = {
894
+ rapid: rgba8(255, 255, 0, 255),
895
+ spread: rgba8(255, 136, 0, 255),
896
+ shield: rgba8(0, 200, 255, 255),
897
+ };
898
+ drawText(
899
+ `${game.powerup.toUpperCase()} ${Math.ceil(game.powerupTimer)}s`,
900
+ 420,
901
+ 46,
902
+ puColors[game.powerup] || uiColors.light,
903
+ 1
904
+ );
905
+ }
906
+
907
+ // Kill streak
908
+ if (game.killStreak >= 3) {
909
+ setTextAlign('center');
910
+ drawText(`${game.killStreak}x STREAK!`, 320, 60, rgba8(255, 200, 50, 255), 1);
911
+ setTextAlign('left');
912
+ }
913
+
914
+ // Wave clear message
915
+ if (game.waveClear) {
916
+ setTextAlign('center');
917
+ setFont('large');
918
+ drawText(`WAVE ${game.wave} CLEAR!`, 320, 160, rgba8(0, 255, 100, 255), 1);
919
+ setFont('normal');
920
+ drawText(`+${game.wave * 200} BONUS`, 320, 185, rgba8(255, 255, 100, 255), 1);
921
+ setTextAlign('left');
922
+ }
923
+ }