mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 08:55:38 +00:00
A complete, playable Pong game split across examples/pong/*.ne files
and pulled in from a top-level examples/pong.ne. Features:
- **Title screen** with a 3-option menu (CPU VS CPU / 1 PLAYER /
2 PLAYERS), a cursor sprite, blinking "PRESS A" prompt, brisk
title march on pulse 2, and autopilot that auto-confirms CPU VS
CPU after 45 frames of no input so the headless jsnes golden
harness reaches gameplay by frame 180.
- **Ball physics** with signed-magnitude velocity (u8 magnitude +
sign bit per axis), wall bounce at top/bottom, paddle AABB
collision with push-out, and score-out detection at left/right
exits.
- **Multi-ball** via parallel ball_* arrays (MAX_BALLS = 3). Each
ball scores a point independently; the round continues until the
last ball exits the playfield.
- **CPU AI** that tracks the nearest active ball heading toward its
side with a per-frame step, 4 px dead zone, and CPU_SPEED = 1 so
rallies can end naturally.
- **Three powerup types** that spawn every ~4 seconds, bounce off
all four walls, and are caught by paddle AABB overlap:
1. LONG — extends the catching paddle from 24 → 40 px for 5 hits
2. FAST — doubles ball x-velocity on the catcher's next hit
3. MULTI — spawns two extra balls on the catcher's next hit
- **Victory** at first-to-7 with a "PLAYER N WINS" banner and the
builtin fanfare, auto-returning to Title.
- **Audio**: 5 user-declared sfx (WallBounce, PaddleHit, Score,
PowerSpawn, PowerCatch) plus a title march and the builtin
fanfare for victory.
Source layout mirrors examples/war:
examples/pong.ne top-level game shell
examples/pong/PLAN.md living design doc
examples/pong/constants.ne layout + gameplay constants
examples/pong/assets.ne 45-tile Tileset (paddles, ball, alphabet,
digits, cursor, center-line, powerup icons)
examples/pong/audio.ne sfx + music declarations
examples/pong/state.ne all mutable globals
examples/pong/rng.ne 8-bit Galois LFSR
examples/pong/render.ne draw helpers
examples/pong/input.ne paddle step (human + CPU AI)
examples/pong/ball.ne multi-ball physics + paddle collision
examples/pong/powerup.ne powerup entity (spawn, bounce, catch, apply)
examples/pong/title_state.ne state Title + menu
examples/pong/play_state.ne state Playing (P_SERVE/P_PLAY/P_POINT)
examples/pong/victory_state.ne state Victory
Verification:
- 616 compiler unit tests pass (cargo test --all-targets)
- cargo fmt / cargo clippy --all-targets -- -D warnings clean
- 33/33 emulator harness goldens match
- examples/pong.nes builds byte-identically from source
https://claude.ai/code/session_0134F5uwDEVTes2Ee9S7JeXy
68 lines
1.9 KiB
Text
68 lines
1.9 KiB
Text
// pong/audio.ne — sfx + music declarations.
|
|
//
|
|
// Channel budget (same as war):
|
|
// pulse 1 — every `play Name` sfx
|
|
// pulse 2 — music (TitleTheme + builtin fanfare)
|
|
// triangle — reserved
|
|
// noise — reserved for a later low-thud on paddle hit
|
|
//
|
|
// The audio tick is linked in only because the title state uses
|
|
// `start_music`, so everything below ends up in PRG ROM.
|
|
|
|
// ── Sound effects ──────────────────────────────────────────
|
|
|
|
// Quick high click when the ball bounces off a top/bottom wall.
|
|
sfx WallBounce {
|
|
duty: 1
|
|
pitch: 0x30
|
|
envelope: [10, 6, 2]
|
|
}
|
|
|
|
// Brighter click with a slight descent when the ball hits a paddle.
|
|
sfx PaddleHit {
|
|
duty: 2
|
|
pitch: [0x28, 0x2C, 0x30]
|
|
volume: [14, 10, 5]
|
|
}
|
|
|
|
// Short descending beep when a side scores a point.
|
|
sfx Score {
|
|
duty: 2
|
|
pitch: [0x40, 0x50, 0x60, 0x70]
|
|
volume: [14, 12, 9, 4]
|
|
}
|
|
|
|
// Rising chirp when a powerup spawns in the middle of the field.
|
|
sfx PowerSpawn {
|
|
duty: 3
|
|
pitch: [0x80, 0x70, 0x60, 0x50, 0x40, 0x30]
|
|
volume: [12, 12, 12, 12, 12, 8]
|
|
}
|
|
|
|
// Bright ascending blip when a paddle catches a powerup.
|
|
sfx PowerCatch {
|
|
duty: 2
|
|
pitch: [0x60, 0x50, 0x40, 0x30, 0x28, 0x20]
|
|
volume: [15, 13, 11, 9, 7, 4]
|
|
}
|
|
|
|
// ── Music ──────────────────────────────────────────────────
|
|
|
|
// Brisk 4/4 title march on pulse 2. Four bars of a rising C-major
|
|
// phrase with punchy staccato notes so the menu feels energetic.
|
|
music TitleTheme {
|
|
duty: 2
|
|
volume: 10
|
|
repeat: true
|
|
tempo: 8
|
|
notes: [
|
|
// bar 1
|
|
C4 4, E4 4, G4 8, E4 8, C4 8, rest 4,
|
|
// bar 2
|
|
G4 4, G4 4, C5 8, G4 8, E4 8, rest 4,
|
|
// bar 3
|
|
E4 4, G4 4, C5 8, E5 8, C5 8, rest 4,
|
|
// bar 4 — resolution
|
|
G4 4, G4 4, C5 16, rest 8
|
|
]
|
|
}
|