From c4e6bb42e83acdb97a2d7473bca7c44b52615c29 Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" Date: Mon, 23 Nov 2026 08:40:01 +0000 Subject: [PATCH] New purple 2x ship; doubles points Co-authored-by: DanielGeek --- 89-OpenCode-Projects/03-asteroids/AGENTS.md | 7 ++--- 89-OpenCode-Projects/03-asteroids/README.md | 5 +++- 89-OpenCode-Projects/03-asteroids/game.js | 30 ++++++++++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/89-OpenCode-Projects/03-asteroids/AGENTS.md b/89-OpenCode-Projects/03-asteroids/AGENTS.md index a2f9b51..08aa062 100644 --- a/89-OpenCode-Projects/03-asteroids/AGENTS.md +++ b/89-OpenCode-Projects/03-asteroids/AGENTS.md @@ -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: ` 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: ` 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. @@ -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). diff --git a/89-OpenCode-Projects/03-asteroids/README.md b/89-OpenCode-Projects/03-asteroids/README.md index 1c50406..5117ac3 100644 --- a/89-OpenCode-Projects/03-asteroids/README.md +++ b/89-OpenCode-Projects/03-asteroids/README.md @@ -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) @@ -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 diff --git a/89-OpenCode-Projects/03-asteroids/game.js b/89-OpenCode-Projects/03-asteroids/game.js index f259099..459376c 100644 --- a/89-OpenCode-Projects/03-asteroids/game.js +++ b/89-OpenCode-Projects/03-asteroids/game.js @@ -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', @@ -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'; @@ -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; @@ -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; @@ -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)]; @@ -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); @@ -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());