Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions 89-OpenCode-Projects/03-asteroids/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

- Input: `keys`/`justPressed` maps plus `pressed(code)` for edge detection; arrow keys rotate and thrust, `Space` fires and also restarts after game over.
- Utils: `wrap` (toroidal space — entities wrap at the edges), `dist`, `rand`, `randInt`.
- Classes: `Bullet` (fixed speed, ttl), `Asteroid` (sizes 1–3 driven by the `RADII`/`SPEEDS`/`POINTS` tables; splitting produces two of the next smaller size; each instance carries its own `points` and `rgb`), `ShootingStar` (`Asteroid` subclass: fixed fast speed, despawn ttl, never splits, golden comet tail), `Ship` (thrust, drag, respawn invincibility, shoot cooldown, velocity, shield and triple-shot timers), `PowerUp` (base pickup: hexagon outline, kind icon, despawn-ttl bar; subclasses set `rgb`, `apply` the effect and `drawIcon`), `VelocityPowerUp` (cyan, doubles thrust), `ShieldPowerUp` (green, grants collision protection), `TripleShotPowerUp` (magenta, three parallel bullets), `Particle` (explosion sparks, optional color).
- Ship skins: the `SKINS` table (name, stroke, optional fill, flame color, `rear` flame anchor, hull as closed subpaths with the nose on +x) defines 5 silhouettes; `traceHull` traces any hull on the canvas without stroking or filling. `KeyS` cycles skins in any state via `cycleSkin`, persists the pick in `localStorage` (`asteroids-skin`), and shows a fading `SKIN: <NAME>` toast under the level HUD (`skinLabelTimer`). `Ship.draw` and `drawLifeIcon` (hull at half scale) both render the active skin; the thruster flame uses the skin's color except while Velocity is active (cyan), and a dim `S: CHANGE SKIN` hint at the bottom-left of the canvas keeps the key discoverable in every state.
- Classes: `Bullet` (fixed speed, ttl), `Asteroid` (sizes 1–3 driven by the `RADII`/`SPEEDS`/`POINTS` tables; splitting produces two of the next smaller size; each instance carries its own `points` and `rgb`), `ShootingStar` (`Asteroid` subclass: fixed fast speed, despawn ttl, never splits, golden comet tail), `Ship` (thrust, drag, respawn invincibility, shoot cooldown, velocity, shield and triple-shot timers, skin-scaled collision radius), `PowerUp` (base pickup: hexagon outline, kind icon, despawn-ttl bar; subclasses set `rgb`, `apply` the effect and `drawIcon`), `VelocityPowerUp` (cyan, doubles thrust), `ShieldPowerUp` (green, grants collision protection), `TripleShotPowerUp` (magenta, three parallel bullets), `Particle` (explosion sparks, optional color).
- Ship skins: the `SKINS` table (name, stroke, optional fill, flame color, `rear` flame anchor, hull as closed subpaths with the nose on +x, optional `scale` and `scoreMultiplier`) defines 6 silhouettes; `traceHull` traces any hull on the canvas without stroking or filling. `KeyS` cycles skins in any state via `cycleSkin`, persists the pick in `localStorage` (`asteroids-skin`), and shows a fading `SKIN: <NAME>` toast under the level HUD (`skinLabelTimer`). `Ship.draw` and `drawLifeIcon` (hull at half scale) both render the active skin; the thruster flame uses the skin's color except while Velocity is active (cyan), and a dim `S: CHANGE SKIN` hint at the bottom-left of the canvas keeps the key discoverable in every state. A skin's `scale` (default 1) multiplies the `Ship.draw` transform (stroke width compensated so it stays ~1.5px), the `Ship.radius` getter (hitbox) and the `tryShoot` nose offset; life icons stay at half of the base hull for every skin.
- Amethyst skin: purple 2× ship (`scale: 2`) drawn at twice the CLASSIC size with a matching double hitbox and nose, whose `scoreMultiplier: 2` doubles every point scored while it is the active skin (asteroid and shooting-star points alike; shield vaporization still scores nothing).
- Game state lives in module-level variables (`ship`, `bullets`, `asteroids`, `particles`, `powerups`, `score`, `lives`, `level`) with a `state` machine: `'playing' | 'dead' | 'gameover'`.
- `update(dt)` and `draw()` run from a `requestAnimationFrame` loop with delta time clamped to 0.05s.
- `spawnAsteroids` keeps a 130px safe distance from the canvas center so asteroids never spawn on the ship.
Expand All @@ -29,4 +30,4 @@

## Verification

No automated tests. Open `index.html` in a browser and play: rotate, thrust, and fire; confirm asteroid splitting and scoring (large 20, medium 50, small 100, shooting star 200), edge wrapping, the blinking respawn invincibility, lives, level progression, the game over → restart flow, the power-ups (periodic spawn and asteroid drops pick a random kind; Velocity: cyan flame plus HUD countdown while active, doubled thrust that expires after 5 seconds; Shield: green hexagon with a dome glyph, pulsing green bubble around the ship, collisions with asteroids and shooting stars vaporize them without scoring while it lasts, effect lost on death or level change; Triple shot: three parallel bullets per shot for 5 seconds with a magenta HUD countdown), the shooting star (periodic golden fast asteroid with a comet tail, never splits, kills the ship on contact, bursts into golden particles without scoring when its 8-second lifetime ends), and the skin system (press `S` in any state: hull, flame color, and life icons change with a fading name toast under the level HUD; the pick persists across reloads via `localStorage`).
No automated tests. Open `index.html` in a browser and play: rotate, thrust, and fire; confirm asteroid splitting and scoring (large 20, medium 50, small 100, shooting star 200 — all doubled while the Amethyst skin is active), edge wrapping, the blinking respawn invincibility, lives, level progression, the game over → restart flow, the power-ups (periodic spawn and asteroid drops pick a random kind; Velocity: cyan flame plus HUD countdown while active, doubled thrust that expires after 5 seconds; Shield: green hexagon with a dome glyph, pulsing green bubble around the ship, collisions with asteroids and shooting stars vaporize them without scoring while it lasts, effect lost on death or level change; Triple shot: three parallel bullets per shot for 5 seconds with a magenta HUD countdown), the shooting star (periodic golden fast asteroid with a comet tail, never splits, kills the ship on contact, bursts into golden particles without scoring when its 8-second lifetime ends), and the skin system (press `S` in any state: hull, flame color, and life icons change with a fading name toast under the level HUD; the pick persists across reloads via `localStorage`; the Amethyst skin is purple, drawn at twice the size with a matching double hitbox and nose offset, and doubles all scored points while active).
5 changes: 4 additions & 1 deletion 89-OpenCode-Projects/03-asteroids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Then visit `http://localhost:3000`.
| Small | 100 |
| Shooting star | 200 |

All points are doubled while flying the Amethyst skin.

## Features

- 3 lives with temporary invincibility upon respawning (blinking)
Expand All @@ -48,4 +50,5 @@ Then visit `http://localhost:3000`.
- **Shield power-up**: protects the ship for 6 seconds. While active, a pulsing green bubble vaporizes any asteroid that touches it. Spawns periodically on the field and can drop from destroyed asteroids; collect the green hexagon to activate it
- **Triple shot power-up**: fires three parallel bullets for 5 seconds. Spawns periodically on the field and can drop from destroyed asteroids; collect the magenta hexagon to activate it
- **Shooting star**: fast golden asteroid worth 200 points that never splits. Spawns periodically with a comet tail and bursts into golden particles when its time runs out
- **Ship skins**: press `S` to cycle through 5 hull styles (Classic, Dart, Falcon, Phoenix, Ray), each with its own color scheme and thruster flame. The pick persists between sessions via `localStorage`, the life icons match the active skin, and a persistent on-screen hint plus a brief name toast show which skin is active
- **Ship skins**: press `S` to cycle through 6 hull styles (Classic, Dart, Falcon, Phoenix, Ray, Amethyst), each with its own color scheme and thruster flame. The pick persists between sessions via `localStorage`, the life icons match the active skin, and a persistent on-screen hint plus a brief name toast show which skin is active
- **Amethyst skin**: a purple ship twice the size of the original — bigger target, bigger hitbox — that earns double points for everything it destroys
30 changes: 24 additions & 6 deletions 89-OpenCode-Projects/03-asteroids/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ function spawnPowerUp(x, y) {

// ── Ship skins ───────────────────────────────────────────────────────────────
// Each skin: display name, stroke color, optional fill, thruster flame color,
// hull as closed subpaths (nose points +x), and the x anchor of the flame.
// hull as closed subpaths (nose points +x), the x anchor of the flame, and
// optional scale (drawn size, hitbox and nose offset) and scoreMultiplier.
const SKINS = [
{
name: 'CLASSIC',
Expand Down Expand Up @@ -365,6 +366,19 @@ const SKINS = [
[[14, 0], [6, -7], [-8, -12], [-13, -5], [-9, 0], [-13, 5], [-8, 12], [6, 7]],
],
},
{
// Purple 2x ship: twice the size, double points while flying it
name: 'AMETHYST',
stroke: '#a6f',
fill: 'rgba(170, 102, 255, 0.12)',
flame: 'rgba(170, 102, 255, 0.9)',
rear: -8,
scale: 2,
scoreMultiplier: 2,
hull: [
[[20, 0], [-12, -9], [-7, 0], [-12, 9]],
],
},
];

const SKIN_STORAGE_KEY = 'asteroids-skin';
Expand Down Expand Up @@ -418,7 +432,6 @@ class Ship {
this.angle = -Math.PI / 2;
this.vx = 0;
this.vy = 0;
this.radius = 12;
this.thrusting = false;
this.invincible = 3;
this.shootCooldown = 0;
Expand All @@ -428,6 +441,9 @@ class Ship {
this.dead = false;
}

// Collision radius follows the active skin's scale
get radius() { return 12 * (SKINS[skinIndex].scale || 1); }

update(dt) {
if (this.dead) return;
if (this.invincible > 0) this.invincible -= dt;
Expand Down Expand Up @@ -459,7 +475,7 @@ class Ship {
tryShoot() {
if (this.shootCooldown > 0 || this.dead) return [];
this.shootCooldown = 0.2;
const NOSE = 21;
const NOSE = 21 * (SKINS[skinIndex].scale || 1);
const ox = this.x + Math.cos(this.angle) * NOSE;
const oy = this.y + Math.sin(this.angle) * NOSE;
if (this.tripleTimer <= 0) return [new Bullet(ox, oy, this.angle)];
Expand All @@ -474,13 +490,15 @@ class Ship {
// Blink while invincible after respawn
if (this.invincible > 0 && Math.floor(this.invincible * 8) % 2 === 0) return;

const skin = SKINS[skinIndex];
const skin = SKINS[skinIndex];
const scale = skin.scale || 1;

ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
ctx.scale(scale, scale);
ctx.strokeStyle = skin.stroke;
ctx.lineWidth = 1.5;
ctx.lineWidth = 1.5 / scale; // keeps the stroke at ~1.5px on screen
ctx.lineJoin = 'round';

traceHull(skin.hull);
Expand Down Expand Up @@ -683,7 +701,7 @@ function update(dt) {
if (!a.dead && !b.dead && dist(b, a) < a.radius) {
b.dead = true;
a.dead = true;
score += a.points;
score += a.points * (SKINS[skinIndex].scoreMultiplier || 1);
explode(a.x, a.y, a.size * 5, a.rgb);
if (Math.random() < DROP_CHANCE) spawnPowerUp(a.x, a.y);
newAsteroids.push(...a.split());
Expand Down