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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ All notable changes to this project will be documented in this file.
- Save slots in the main menu and the pause panel name the ship systems the saved run has picked.
- 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.



### Changed

- The pause panel's `SYSTEMS:` line is replaced by the SYSTEMS tab.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Bought during the planet intermission screen using score as currency:
- **Fire Rate** — improves firing speed
- **Shield** — increases hit absorption
- **AEGIS Picket** — installs and overclocks automatic flank-defense turrets
- **Ship systems** — free picks after sectors 2, 5 and 8 that change how the ship plays: a main gun (Lance, Scatter, Seekers), a support system (Magnet, Surge Core, Wingman) and a doctrine (Overdrive, Bulwark, Salvager). Picks can be changed mid-run: the main gun on Q or the touch swap button, the others from the pause panel
- **Ship systems** — free picks after sectors 2, 5 and 8 that change how the ship plays: a main gun (Lance, Scatter, Seekers), a support system (Magnet, Surge Core, Wingman) and a doctrine (Overdrive, Bulwark, Salvager). Picks can be changed freely at any later refit bay, and mid-run: the main gun on Q or the touch swap button, the others from the pause panel
- **A different run every time** — each run has its own sky and may fly sectors mirrored; RETRY replays the same run, NEW RUN starts a fresh one

Some upgrades unlock later in the campaign and use progression caps so the run scales in a controlled way.
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 cycle it to another option of that slot: the main gun mid-flight on Q or the touch swap key, support and doctrine from the pause panel's SYSTEMS tab. A gun change costs `GUN_SWAP` (0.5 s of silence, 2 s before the next change, both on the gameplay clock), so swapping is a decision and never a free best-of-all-guns. 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; 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: 17 additions & 5 deletions src/config/shipSystems.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Ship systems: free picks that change how the ship plays, offered at the refit bay. Once picked, a slot
* can be changed to another of its options mid-run: the main gun on the swap key or touch button
* (`GUN_SWAP` keeps it a decision), support and doctrine from the pause panel. Nothing else needs input,
* can be changed to another of its options: freely at any later refit bay, and mid-run the main gun on
* the swap key or touch button (`GUN_SWAP` keeps it a decision), support and doctrine from the pause panel. Nothing else needs input,
* so touch and keyboard stay equal. Stat upgrades are bought separately.
*/
export type MainGunId = 'lance' | 'scatter' | 'seekers';
Expand All @@ -26,6 +26,8 @@ interface ShipSystemOption {
export interface ShipSystemSlotDef {
slot: ShipSystemSlot;
title: string;
/** For narrow spaces, e.g. three systems side by side at the refit bay. */
shortTitle: string;
/** Offered at the refit bay after clearing this sector (and later, until a pick is made). */
offeredAfterLevel: number;
options: readonly [ShipSystemOption, ShipSystemOption, ShipSystemOption];
Expand All @@ -35,6 +37,7 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [
{
slot: 'gun',
title: 'MAIN GUN',
shortTitle: 'GUN',
offeredAfterLevel: 2,
options: [
{ id: 'lance', name: 'LANCE', description: 'Slower shots that pierce every ship in a line.' },
Expand All @@ -45,6 +48,7 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [
{
slot: 'support',
title: 'SUPPORT SYSTEM',
shortTitle: 'SUPPORT',
offeredAfterLevel: 5,
options: [
{ id: 'magnet', name: 'MAGNET', description: 'Pickups drift toward your ship.' },
Expand All @@ -59,6 +63,7 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [
{
slot: 'late',
title: 'COMBAT DOCTRINE',
shortTitle: 'DOCTRINE',
offeredAfterLevel: 8,
options: [
{ id: 'overdrive', name: 'OVERDRIVE', description: 'Every step of your score chain speeds up the gun.' },
Expand All @@ -70,8 +75,14 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [

export const NO_SHIP_SYSTEMS: ShipSystems = { gun: null, support: null, late: null };

/** A slot's title and options, e.g. to offer them again at the refit bay. */
export function getShipSystemSlot(slot: ShipSystemSlot): ShipSystemSlotDef {
// Every slot is authored above, so the lookup cannot miss.
return SHIP_SYSTEM_SLOTS.find((def) => def.slot === slot)!;
}

function optionIds(slot: ShipSystemSlot): readonly ShipSystemId[] {
return SHIP_SYSTEM_SLOTS.find((def) => def.slot === slot)?.options.map((option) => option.id) ?? [];
return getShipSystemSlot(slot).options.map((option) => option.id);
}

/** Clamps untrusted persisted picks to the authored options. */
Expand Down Expand Up @@ -104,14 +115,15 @@ interface PickedShipSystem {
slot: ShipSystemSlot;
/** The slot's title, e.g. `MAIN GUN`. */
title: string;
shortTitle: string;
option: ShipSystemOption;
}

/** The run's picks in slot order, for the pause panel; empty slots are left out. */
/** The run's picks in slot order, for the pause panel and the refit bay; empty slots are left out. */
export function describePickedShipSystems(systems: ShipSystems): PickedShipSystem[] {
return SHIP_SYSTEM_SLOTS.flatMap((def) => {
const option = def.options.find((candidate) => candidate.id === systems[def.slot]);
return option ? [{ slot: def.slot, title: def.title, option }] : [];
return option ? [{ slot: def.slot, title: def.title, shortTitle: def.shortTitle, option }] : [];
});
}

Expand Down
37 changes: 29 additions & 8 deletions src/scenes/PlanetIntermissionScene.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getPendingShipSystemSlot, setShipSystem } from '../config/shipSystems';
import {
getPendingShipSystemSlot,
getShipSystemSlot,
setShipSystem,
type ShipSystemSlotDef,
} from '../config/shipSystems';
import { createSystemPickDialog, type SystemPickDialog } from './planetIntermission/systemPickDialog';
import Phaser from 'phaser';

Expand Down Expand Up @@ -92,6 +97,7 @@ export class PlanetIntermissionScene extends Phaser.Scene {
: `Campaign complete. Final score ${score}.`,
evaluations: this.evaluate(),
onBuy: (key) => this.tryBuyUpgrade(key),
onSwapSystem: (slot) => this.openSystemPick(getShipSystemSlot(slot)),
onContinue: () => this.continueToNextLevel(),
});

Expand All @@ -109,17 +115,32 @@ export class PlanetIntermissionScene extends Phaser.Scene {
this.offerShipSystemPick();
}

/** A free ship-system pick is offered before the shop whenever one is due; the run waits for it. */
/**
* A free ship-system pick is offered before the shop whenever one is due; the run waits for it. Once
* none is due, the bay lists the run's picks so the player can swap them.
*/
private offerShipSystemPick(): void {
const slot = this.isFinalMissionComplete ? null : getPendingShipSystemSlot(this.state.level, this.state.systems);
this.view?.setInert(slot !== null);
if (!slot) return;
this.pickDialog = createSystemPickDialog(slot, (id) => {
this.state.systems = setShipSystem(this.state.systems, slot.slot, id);
setPlayerState(this.registry, this.state);
audioManager.playUi('uiConfirm');
if (slot) {
this.openSystemPick(slot);
return;
}
if (!this.isFinalMissionComplete) this.view?.showSystems(this.state.systems);
this.view?.setInert(false);
}

/** The pick dialog for `slot`: its first pick, or a free swap when the slot already has one. */
private openSystemPick(slot: ShipSystemSlotDef): void {
const current = this.state.systems[slot.slot];
this.view?.setInert(true);
this.pickDialog = createSystemPickDialog(slot, current, (id) => {
this.pickDialog?.destroy();
this.pickDialog = undefined;
if (id !== current) {
this.state.systems = setShipSystem(this.state.systems, slot.slot, id);
setPlayerState(this.registry, this.state);
audioManager.playUi('uiConfirm');
} else audioManager.playUi();
// A late start can owe more than one pick: offer the next before the shop opens.
this.offerShipSystemPick();
});
Expand Down
73 changes: 72 additions & 1 deletion src/scenes/planetIntermission/refitView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LevelConfig } from '../../config/LevelsConfig';
import type { UpgradeEvaluation, UpgradeKey } from '../../config/UpgradesConfig';
import { describePickedShipSystems, type ShipSystems, type ShipSystemSlot } from '../../config/shipSystems';
import { colorToHexString, mixColor } from '../../utils/colorUtils';
import { h, liveRegion, mountUiLayer, releaseFocus } from '../../ui/dom';
import { findArrowFocusIndex, findLinearFocusIndex, findNextPurchasableAfter } from './navigation';
Expand Down Expand Up @@ -111,6 +112,48 @@ function createUpgradeCard(evaluation: UpgradeEvaluation, onBuy: (key: UpgradeKe
};
}

const SYSTEM_SLOTS: readonly ShipSystemSlot[] = ['gun', 'support', 'late'];

interface SystemKey {
slot: ShipSystemSlot;
button: HTMLButtonElement;
refresh: (systems: ShipSystems) => void;
}

/**
* One picked system: its slot over its name, and what it does where there is room. Narrow keys swap in
* the slot's short title. Opens the swap dialog.
*/
function createSystemKey(slot: ShipSystemSlot, onSwap: (slot: ShipSystemSlot) => void): SystemKey {
const title = h('span', { className: 'refit-system__slot ui-ellipsis' });
const shortTitle = h('span', { className: 'refit-system__slot refit-system__slot--short ui-ellipsis' });
const name = h('span', { className: 'refit-system__name ui-ellipsis' });
const description = h('span', { className: 'refit-system__detail ui-ellipsis', id: `refit-system-${slot}` });
const button = h(
'button',
{ type: 'button', className: 'ui-btn refit-system', 'aria-describedby': description.id },
title,
shortTitle,
name,
description
);
button.addEventListener('click', () => onSwap(slot));
return {
slot,
button,
refresh(systems) {
const picked = describePickedShipSystems(systems).find((system) => system.slot === slot);
button.hidden = !picked;
if (!picked) return;
title.textContent = picked.title;
shortTitle.textContent = picked.shortTitle;
name.textContent = picked.option.name;
description.textContent = picked.option.description;
button.setAttribute('aria-label', `Swap ${picked.title.toLowerCase()}, now ${picked.option.name}`);
},
};
}

interface RefitViewConfig {
levelConfig: LevelConfig;
profile: PlanetIntermissionProfile;
Expand All @@ -123,6 +166,7 @@ interface RefitViewConfig {
summary: string;
evaluations: UpgradeEvaluation[];
onBuy: (key: UpgradeKey) => void;
onSwapSystem: (slot: ShipSystemSlot) => void;
onContinue: () => void;
}

Expand All @@ -131,9 +175,14 @@ export interface RefitView {
planetSlot: HTMLElement;
/** New balance and evaluations after a purchase: refreshes every card and announces the result. */
refresh: (credits: number, evaluations: UpgradeEvaluation[], purchased: UpgradeKey, message: string) => void;
/** Lists the run's picked systems beside the cards, each a key that swaps it; nothing before the first pick. */
showSystems: (systems: ShipSystems) => void;
/** Arrow keys and Enter / Space while no card holds focus; returns whether the key was used. */
handleUnfocusedKey: (code: string) => boolean;
/** Puts the whole bay out of reach of pointer and keyboard while a dialog is open over it. */
/**
* Puts the whole bay out of reach of pointer and keyboard while a dialog is open over it; when it
* comes back, focus returns to the system key that opened the dialog.
*/
setInert: (inert: boolean) => void;
/** Fades the UI out under the warp. */
leave: () => void;
Expand All @@ -151,6 +200,19 @@ export function createRefitView(config: RefitViewConfig): RefitView {
const cards = config.evaluations.map((evaluation) => createUpgradeCard(evaluation, config.onBuy));
cards.forEach((card, index) => card.refresh(config.evaluations[index]));
const grid = h('div', { className: 'refit__cards' }, ...cards.map((card) => card.button));
let swapOpener: HTMLButtonElement | null = null;
const systemKeys = SYSTEM_SLOTS.map((slot) =>
createSystemKey(slot, (picked) => {
swapOpener = systemKeys.find((key) => key.slot === picked)?.button ?? null;
config.onSwapSystem(picked);
})
);
// The systems fill the grid's last cell: beside the odd last card on two columns, a row of their own on one.
const systemsCell = h(
'div',
{ className: 'refit__systems', role: 'group', 'aria-label': 'Ship systems' },
...systemKeys.map((key) => key.button)
);
const status = liveRegion(config.summary);
const continueButton = h(
'button',
Expand Down Expand Up @@ -252,6 +314,12 @@ export function createRefitView(config: RefitViewConfig): RefitView {
// A card that just capped drops out of the focus order: hand focus to the next one that can buy.
if (hadFocus && !next[index].canPurchase) focusCard(findNextPurchasableAfter(purchasable(), index));
},
showSystems(systems) {
systemKeys.forEach((key) => key.refresh(systems));
// Appended once there is a pick, so the odd last card keeps spanning the row until then. Only once:
// moving the cell would drop the focus a closed dialog hands back.
if (!systemsCell.isConnected && describePickedShipSystems(systems).length > 0) grid.append(systemsCell);
},
handleUnfocusedKey(code) {
if (code !== 'Enter' && code !== 'Space') return moveFocus(code);
const first = findLinearFocusIndex(purchasable(), -1, 1);
Expand All @@ -262,6 +330,9 @@ export function createRefitView(config: RefitViewConfig): RefitView {
setInert(inert) {
if (inert) releaseFocus(layer);
layer.inert = inert;
if (inert) return;
swapOpener?.focus({ preventScroll: true });
swapOpener = null;
},
leave() {
releaseFocus(layer);
Expand Down
Loading
Loading