Asteroids-2026/js/scenes/BootScene.js

94 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// BootScene runs once at startup to generate all shared textures, then hands
// off to MenuScene. Textures live in Phaser's global TextureManager so every
// subsequent scene can use them without re-creating them.
export default class BootScene extends Phaser.Scene {
constructor() {
super({ key: 'BootScene' });
}
create() {
this._createTextures();
this.scene.start('MenuScene');
}
// ─── Texture Generation ───────────────────────────────────────────────────
_createTextures() {
// Player ship 64×32, nose points right (angle 0)
let g = this.make.graphics({ add: false });
g.lineStyle(2, 0x00ff44, 1);
g.strokeTriangle(56, 16, 12, 4, 12, 28);
g.generateTexture('player', 64, 32);
g.destroy();
// Player ship with thruster flame
g = this.make.graphics({ add: false });
g.lineStyle(2, 0x00ff44, 1);
g.strokeTriangle(56, 16, 12, 4, 12, 28);
g.lineStyle(2, 0xff6600, 1);
g.strokeTriangle(12, 11, 12, 21, 0, 16);
g.generateTexture('player_thrust', 64, 32);
g.destroy();
// Large asteroid 120×120, radius 50, 12-sided
g = this.make.graphics({ add: false });
g.lineStyle(2, 0xcccccc, 1);
g.strokePoints(this._asteroidPoints(60, 60, 50, 12,
[1.0, 0.82, 1.08, 0.88, 1.0, 0.78, 1.1, 0.9, 0.94, 1.0, 0.84, 1.06]
), true);
g.generateTexture('asteroid_large', 120, 120);
g.destroy();
// Medium asteroid 64×64, radius 26, 10-sided
g = this.make.graphics({ add: false });
g.lineStyle(2, 0xcccccc, 1);
g.strokePoints(this._asteroidPoints(32, 32, 26, 10,
[1.0, 0.78, 1.1, 0.88, 1.0, 0.82, 1.0, 0.92, 1.06, 0.80]
), true);
g.generateTexture('asteroid_medium', 64, 64);
g.destroy();
// Small asteroid 32×32, radius 12, 8-sided
g = this.make.graphics({ add: false });
g.lineStyle(2, 0xcccccc, 1);
g.strokePoints(this._asteroidPoints(16, 16, 12, 8,
[1.0, 0.78, 1.12, 0.84, 1.0, 0.9, 0.80, 1.04]
), true);
g.generateTexture('asteroid_small', 32, 32);
g.destroy();
// Alien saucer 64×48
g = this.make.graphics({ add: false });
g.lineStyle(2, 0x00ffff, 1);
g.strokeEllipse(32, 30, 52, 20);
g.strokeEllipse(32, 22, 30, 18);
g.generateTexture('alien', 64, 48);
g.destroy();
// Player bullet 8×8 yellow circle
g = this.make.graphics({ add: false });
g.fillStyle(0xffff00, 1);
g.fillCircle(4, 4, 4);
g.generateTexture('bullet', 8, 8);
g.destroy();
// Alien bullet 8×8 red circle
g = this.make.graphics({ add: false });
g.fillStyle(0xff4444, 1);
g.fillCircle(4, 4, 4);
g.generateTexture('alien_bullet', 8, 8);
g.destroy();
}
_asteroidPoints(cx, cy, radius, numPoints, offsets) {
return offsets.map((scale, i) => {
const angle = (i / numPoints) * Math.PI * 2;
return {
x: cx + Math.cos(angle) * radius * scale,
y: cy + Math.sin(angle) * radius * scale
};
});
}
}