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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ All notable changes to this project will be documented in this file.
- The controls card at the start of a sector and the pause panel show the Q key, but only once the run has a main gun. Sectors 1 and 2 are unchanged.
- The game saves your run when you leave the refit bay for the next sector, so closing the tab no longer loses the ship system you just picked. The save appears in the main menu as AUTOSAVE, next to your three slots, and loads and deletes like them. It never overwrites a slot of yours, and it goes away when the run ends or you start a new one.
- Save slots in the main menu and the pause panel name the ship systems the saved run has picked.
- Each main gun now fires its own kind of shot, so you can tell which gun is active at a glance: Lance fires long white-hot needles, Scatter short round pellets, and Seekers small arrowhead darts. They stay in the player's cyan-white, so they never look like enemy fire. The standard gun, the Wingman drone and the helper wing keep the familiar bolt. Hitboxes, damage and speed are unchanged.
- Swapping guns has its own quiet click-and-whir sound instead of the menu confirm chime.
- Fast-kill bonus: beat a boss under its par time and you score 200 points for every second left on the clock, shown as FAST KILL next to the kill. Pausing never costs you any of it.
- The refit bay lists your ship systems next to the upgrades once you have one. Select one to see its three options again, with the current one marked, and pick another: changing here is free, as often as you like, with no wait. Escape, or picking the current one again, keeps it. The next sector flies with your choice, and the autosave and your checkpoints store it.

Expand Down
2 changes: 1 addition & 1 deletion docs/art-direction.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Per-level identity: each level keeps its `accentColor` from the level definition
| --- | --- | --- |
| Player ship | cyan `#5bd8ff` | hero |
| Helper wing | teal `#58f0d8` | ally |
| Player bullets | cyan-white | friendly fire |
| Player bullets | cyan-white; each main gun varies shape, length and brightness (bolt, long lance, round pellet, arrowhead dart), never the palette | friendly fire |
| Scout | red `#ff5d73` | fast flanker |
| Fighter | green `#52f28e` | balanced |
| Bomber | amber `#ffb14b` | heavy ordnance |
Expand Down
2 changes: 1 addition & 1 deletion docs/level-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ shields recharge on every respawn.
Levels 5–10 add payoff without adding player inputs:

- **AEGIS Picket** becomes purchasable after Level 4. Its fixed flank turrets trim chaff with flat-damage bolts while the main gun remains the dominant damage source. Pickets never target bosses.
- **Ship systems** are free one-of-three picks at the refit bay after sectors 2, 5 and 8 (`config/shipSystems.ts`). They change how the ship plays rather than how hard it hits, and are balanced by measurement: each main gun trades single-target damage for one strength and scored inside the standard gun's run-to-run spread in sector 5. Nothing is offered in sectors 1–2, which stay a gentle introduction. A system works without input; the only new input is changing one. Once a slot has a pick the player may change it to another option of that slot: freely at every later refit bay (the picks sit beside the upgrade cards and reopen the pick dialog, which Escape dismisses), the main gun mid-flight on Q or the touch swap key, and support and doctrine from the pause panel's SYSTEMS tab. A gun change in flight costs `GUN_SWAP` (0.5 s of silence, 2 s before the next change, both on the gameplay clock), so swapping mid-fight is a decision and never a free best-of-all-guns; between sectors, at the refit bay, a change is free and has no cooldown. In flight, feedback is a brief name flash over the ship; there is no persistent panel. The current pick is saved with the run.
- **Ship systems** are free one-of-three picks at the refit bay after sectors 2, 5 and 8 (`config/shipSystems.ts`). They change how the ship plays rather than how hard it hits, and are balanced by measurement: each main gun trades single-target damage for one strength and scored inside the standard gun's run-to-run spread in sector 5. Nothing is offered in sectors 1–2, which stay a gentle introduction. A system works without input; the only new input is changing one. Once a slot has a pick the player may change it to another option of that slot: freely at every later refit bay (the picks sit beside the upgrade cards and reopen the pick dialog, which Escape dismisses), the main gun mid-flight on Q or the touch swap key, and support and doctrine from the pause panel's SYSTEMS tab. A gun change in flight costs `GUN_SWAP` (0.5 s of silence, 2 s before the next change, both on the gameplay clock), so swapping mid-fight is a decision and never a free best-of-all-guns; between sectors, at the refit bay, a change is free and has no cooldown. In flight, feedback is a brief name flash over the ship and a short swap sound, and each gun's shots have their own look (the profile's `look`), so the active gun reads from the fire itself; there is no persistent panel. The current pick is saved with the run.
- **Run variation** comes from one seed per run (`systems/runVariation.ts`, `systems/gameplayRandom.ts`). It decides the wave choices, whether each sector is mirrored left to right, and the sky. Two rules keep scores comparable: the sky is looks only, and the only layout change is the mirror, which is as hard by symmetry. Never vary wave order, enemy counts or timing by seed. RETRY keeps the seed; NEW RUN draws a new one. Enemies, asteroids and wormholes each draw from their own seeded stream, so one cannot shift another's choices; how far a run gets through a stream still depends on play. Enemy jitter and pickup drops stay unseeded because they depend on how the fight goes.
- **Marked Aces** are sparse authored variants of existing enemies. Their gilded treatment signals 2× durability, 4× score, and exactly one guaranteed power-up.
- **Boss volleys are telegraphed.** For the last 400 ms before every volley the boss's core swells and its hardpoints flash white. Bosses have no stun or bonus-damage window; fights are paced by the wind-up and each attack's cooldown.
Expand Down
22 changes: 18 additions & 4 deletions src/config/shipSystems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ export function describeShipSystems(systems: ShipSystems): string {
return names.length > 0 ? `SYSTEMS: ${names.join(' · ')}` : '';
}

/**
* How a gun's shots look: a frame of the shared `player-bullet` texture, so every gun's fire batches
* together. Each look says what the gun does (a long piercing lance, short pellets, homing darts) while
* staying in the friendly cyan-white family; the hitbox is the same for all of them.
*/
export type PlayerShotLook = 'bolt' | 'lance' | 'pellet' | 'dart';

/** Main-gun firing patterns. Damage per shot is unchanged; the fire cooldown pays for the pattern. */
export interface MainGunProfile {
look: PlayerShotLook;
/** Multiplies the fire cooldown. */
cooldownScale: number;
/** Shot directions in degrees off straight ahead. */
Expand All @@ -149,19 +157,25 @@ export interface MainGunProfile {
seekDegreesPerSecond: number;
}

const STANDARD_GUN: MainGunProfile = { cooldownScale: 1, spreadDegrees: [0], pierce: false, seekDegreesPerSecond: 0 };
const STANDARD_GUN: MainGunProfile = {
look: 'bolt',
cooldownScale: 1,
spreadDegrees: [0],
pierce: false,
seekDegreesPerSecond: 0,
};

/**
* Tuned by measurement, not only arithmetic: 40 s of sector 5 with autofire and a sweeping ship scored
* 72k-132k with the standard gun over four runs, and each of these landed inside that spread.
*/
const GUN_PROFILES: Record<MainGunId, MainGunProfile> = {
// One target: 0.77x the standard gun. Two in a line: 1.54x. Rewards lining ships up.
lance: { cooldownScale: 1.3, spreadDegrees: [0], pierce: true, seekDegreesPerSecond: 0 },
lance: { look: 'lance', cooldownScale: 1.3, spreadDegrees: [0], pierce: true, seekDegreesPerSecond: 0 },
// All three hit up close: 1.67x. Only the centre shot at range: 0.56x. Rewards flying in.
scatter: { cooldownScale: 1.8, spreadDegrees: [-13, 0, 13], pierce: false, seekDegreesPerSecond: 0 },
scatter: { look: 'pellet', cooldownScale: 1.8, spreadDegrees: [-13, 0, 13], pierce: false, seekDegreesPerSecond: 0 },
// Half the shots of the standard gun, but almost every one connects. Rewards dodging over aiming.
seekers: { cooldownScale: 2, spreadDegrees: [0], pierce: false, seekDegreesPerSecond: 150 },
seekers: { look: 'dart', cooldownScale: 2, spreadDegrees: [0], pierce: false, seekDegreesPerSecond: 150 },
};

export function getMainGunProfile(gun: MainGunId | null): MainGunProfile {
Expand Down
16 changes: 13 additions & 3 deletions src/entities/Bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { despawnEntity, isArcadeSimulationPaused, spawnEntity } from '../utils/e
import { GAME_SCENE_EVENTS } from '../systems/GameplayFlow';
import { ensurePlayerBulletTexture } from '../utils/SpriteFactory';
import { getRuntimeTrailInterval } from '../systems/RuntimePerformanceBudget';
import type { PlayerShotLook } from '../config/shipSystems';

/** Where a seeking shot should steer: the nearest live target, or null to fly straight. */
export type BulletTargetFinder = (x: number, y: number) => { x: number; y: number } | null;
Expand All @@ -27,20 +28,29 @@ export class Bullet extends Phaser.Physics.Arcade.Sprite {
constructor(scene: Phaser.Scene, x: number, y: number) {
ensurePlayerBulletTexture(scene);

super(scene, x, y, 'player-bullet');
super(scene, x, y, 'player-bullet', 'bolt');
scene.add.existing(this);
scene.physics.add.existing(this);

despawnEntity(this);
this.setDepth(4);
this.setBlendMode(Phaser.BlendModes.ADD);
// The texture carries a glow halo; the hitbox stays the original 8x18 bolt.
// The texture carries a glow halo; the hitbox stays the original 8x18 bolt, centred in every look.
(this.body as Phaser.Physics.Arcade.Body | null)?.setSize(8, 18);
}

fire(x: number, y: number, velocityX: number = 0, velocityY?: number, behaviour: BulletBehaviour = {}): void {
fire(
x: number,
y: number,
velocityX: number = 0,
velocityY?: number,
behaviour: BulletBehaviour = {},
look: PlayerShotLook = 'bolt'
): void {
const resolvedVelocityY = velocityY ?? BULLET_SPEED;

// Every look is a same-sized frame of one texture, so this never resizes the body or breaks a batch.
this.setFrame(look);
spawnEntity(this, x, y);
this.lastTrailTime = 0;
this.pierce = behaviour.pierce === true;
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class GameScene extends Phaser.Scene {
gunSwapFeedback: {
swapped: (gun) => {
createShipLabel(this, this.player.x, this.player.y, getShipSystemName(gun), NEON_TEXT.cyan);
audioManager.playSfx('uiConfirm');
audioManager.playSfx('gunSwap');
},
denied: () => audioManager.playSfx('uiClick'),
},
Expand Down
11 changes: 5 additions & 6 deletions src/scenes/gameScene/gameplayFrameBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { BULLET_SPEED } from '@/utils/constants';
import { getActiveSection, getSectionProgress } from '@/config/LevelsConfig';
import type { Boss } from '@/entities/enemies/Boss';
import { audioManager } from '@/systems/AudioManager';
import type { BulletBehaviour, BulletTargetFinder } from '@/entities/Bullet';
import type { BulletTargetFinder } from '@/entities/Bullet';
import type { MainGunId, ShipSystems } from '@/config/shipSystems';
import type { GunSwapOutcome } from '@/systems/ShipSystemsRuntime';
import { fireMainGunVolley, resolveMainGunCooldownMs } from '@/systems/mainGun';
import { fireMainGunVolley, resolveMainGunCooldownMs, type MainGunVolley } from '@/systems/mainGun';
import { GAME_SCENE_EVENTS } from '@/systems/GameplayFlow';
import type { ChainState } from '@/systems/ScoreManager';
import { resolveSectionMusicIntensity } from '@/systems/sectionIdentity';
Expand Down Expand Up @@ -88,9 +88,7 @@ interface GameSceneGameplayFrameDelegate {
hideBossBar(): void;
updateBossHp(hp: number, maxHp: number): void;
};
bulletPool: {
fire(x: number, y: number, velocityX: number, velocityY: number, behaviour?: BulletBehaviour): void;
};
bulletPool: Pick<MainGunVolley, 'fire'>;
/** The nearest live enemy to a point, for seeking shots. */
findBulletTarget: BulletTargetFinder;
effectsManager: {
Expand Down Expand Up @@ -196,7 +194,8 @@ export function createGameSceneGameplayFrameBehavior(
direction: shotDirection,
speed: shotSpeed,
findTarget: delegate.findBulletTarget,
fire: (x, y, velocityX, velocityY, behaviour) => delegate.bulletPool.fire(x, y, velocityX, velocityY, behaviour),
fire: (x, y, velocityX, velocityY, behaviour, look) =>
delegate.bulletPool.fire(x, y, velocityX, velocityY, behaviour, look),
});
delegate.effectsManager.createMuzzleFlash(muzzleFlashOrigin.x, muzzleFlashOrigin.y);
audioManager.playSfx('playerShot');
Expand Down
12 changes: 10 additions & 2 deletions src/systems/BulletPool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Phaser from 'phaser';
import { Bullet, type BulletBehaviour } from '../entities/Bullet';
import type { PlayerShotLook } from '../config/shipSystems';
import { BULLET_POOL_SIZE } from '../utils/constants';
import { ensurePlayerBulletTexture } from '../utils/SpriteFactory';

Expand Down Expand Up @@ -27,10 +28,17 @@ export class BulletPool {
firstBullet.kill();
}

fire(x: number, y: number, velocityX: number = 0, velocityY?: number, behaviour?: BulletBehaviour): Bullet | null {
fire(
x: number,
y: number,
velocityX: number = 0,
velocityY?: number,
behaviour?: BulletBehaviour,
look?: PlayerShotLook
): Bullet | null {
const bullet = this.acquireBullet(x, y);
if (bullet) {
bullet.fire(x, y, velocityX, velocityY, behaviour);
bullet.fire(x, y, velocityX, velocityY, behaviour, look);
return bullet;
}
return null;
Expand Down
29 changes: 29 additions & 0 deletions src/systems/audio/sfx/recipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,35 @@ export const SFX = {
jitter: 0,
maxVoices: 1,
},
/**
* Changing the main gun: a dry unlatch tick, a short rising whir and a higher lock-in tick. Mechanical
* rather than chimed so it never reads as a menu sound, and quiet because it plays mid-fight.
*/
gunSwap: {
layers: [
{
source: 'noise',
filter: { type: 'bandpass', freq: [2600, 1800], q: 3 },
attack: 0.001,
decay: 0.03,
gain: 0.5,
},
{ source: 'square', freq: [220, 660], filter: SOFT_LOWPASS, attack: 0.02, decay: 0.12, gain: 0.35, at: 0.03 },
{
source: 'noise',
filter: { type: 'bandpass', freq: [4200, 3000], q: 3 },
attack: 0.001,
decay: 0.03,
gain: 0.5,
at: 0.15,
},
note(1318.5, 0.15, 0.08, 0.25, 'triangle'),
],
gain: 0.2,
variants: 1,
jitter: 0,
maxVoices: 1,
},
uiClick: {
layers: [
note(920, 0, 0.045, 0.6, 'sine', { freq: [920, 700] }),
Expand Down
28 changes: 24 additions & 4 deletions src/systems/mainGun.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { BulletBehaviour, BulletTargetFinder } from '../entities/Bullet';
import { PLAYER_CONFIG } from '../config/playerConfig';
import { getMainGunProfile, OVERDRIVE_COOLDOWN_STEP, WINGMAN, type ShipSystems } from '../config/shipSystems';
import {
getMainGunProfile,
OVERDRIVE_COOLDOWN_STEP,
WINGMAN,
type PlayerShotLook,
type ShipSystems,
} from '../config/shipSystems';
import { resolvePlayerFireCooldownMs } from './chainOverdrive';

interface Point {
Expand All @@ -17,7 +23,14 @@ export interface MainGunVolley {
direction: Point;
speed: number;
findTarget: BulletTargetFinder;
fire(x: number, y: number, velocityX: number, velocityY: number, behaviour?: BulletBehaviour): void;
fire(
x: number,
y: number,
velocityX: number,
velocityY: number,
behaviour?: BulletBehaviour,
look?: PlayerShotLook
): void;
}

function rotate(direction: Point, degrees: number): Point {
Expand All @@ -41,11 +54,18 @@ export function fireMainGunVolley(volley: MainGunVolley): void {

for (const degrees of profile.spreadDegrees) {
const heading = degrees === 0 ? volley.direction : rotate(volley.direction, degrees);
volley.fire(volley.origin.x, volley.origin.y, heading.x * volley.speed, heading.y * volley.speed, behaviour);
volley.fire(
volley.origin.x,
volley.origin.y,
heading.x * volley.speed,
heading.y * volley.speed,
behaviour,
profile.look
);
}

if (volley.systems.support === 'wingman' && volley.volleyIndex % WINGMAN.everyNthVolley === 0) {
// The drone fires a plain bolt straight ahead, whatever the main gun is.
// The drone fires a plain bolt straight ahead, in the standard look, whatever the main gun is.
volley.fire(
volley.origin.x + WINGMAN.offsetX,
volley.origin.y + WINGMAN.offsetY,
Expand Down
42 changes: 42 additions & 0 deletions src/utils/generatedTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,48 @@ export function withCanvasTexture(
return key;
}

/**
* Paints same-sized frames side by side on one canvas texture, named by `frames`' keys. A sprite that
* switches between them keeps its texture, so it keeps batching with its siblings and its size.
*/
export function withCanvasFrameStrip<Name extends string>(
scene: Phaser.Scene,
key: string,
width: number,
height: number,
frames: Readonly<Record<Name, (context: CanvasRenderingContext2D, width: number, height: number) => void>>,
density = 1
): string {
if (scene.textures.exists(key)) return key;
const names = Object.keys(frames) as Name[];
withCanvasTexture(
scene,
key,
width * names.length,
height,
(context) =>
names.forEach((name, index) => {
context.save();
context.translate(index * width, 0);
// A glow never bleeds into the neighbouring frame.
context.beginPath();
context.rect(0, 0, width, height);
context.clip();
frames[name](context, width, height);
context.restore();
}),
density
);
const texture = scene.textures.get(key);
const cuts = names.map((name, index) => {
const frame = texture.add(name, 0, index * width * density, 0, width * density, height * density);
if (!frame) throw new Error(`Unable to cut frame ${name} of ${key}`);
return frame;
});
setLogicalFrameSize(texture, density, width, height, cuts);
return key;
}

/**
* Makes a texture authored at `density` physical pixels per logical pixel display and collide at its
* logical size: Phaser draws the physical cut at source resolution while bounds use the trim.
Expand Down
Loading
Loading