feat: add custom background rendering and speed scaling features for snake gameplay
This commit is contained in:
1 parent
93c0a44027
commit
60bf111400
13 files changed
+711
-26
No files matched your search
@@ -29,6 +29,7 @@ snakePlus/
|
||||
├── include/ # C++ Header declarations
|
||||
│ ├── consts.h # Grid dimensions, scores, tick rates, legacy bitmaps
|
||||
│ ├── game_audio.h # AudioContext struct, MaxMod sound & BGM declarations
|
||||
│ ├── game_bg.h # BackgroundContext struct, animated dual-screen BG declarations
|
||||
│ ├── game_input.h # InputContext struct, button scanning & menu logic
|
||||
│ ├── game_logic.h # Snake mechanics, collision detection, apple spawning
|
||||
│ ├── game_render.h # RenderAssets struct, dual-screen console/OAM draw routines
|
||||
@@ -37,6 +38,7 @@ snakePlus/
|
||||
├── source/ # C++ Implementation files
|
||||
│ ├── main.cpp # Hardware setup, VBlank IRQ, timer ticks, game bootstrap
|
||||
│ ├── game_audio.cpp # MaxMod soundbank loading, BGM loop, SFX dispatch
|
||||
│ ├── game_bg.cpp # Dual-screen procedural tilemaps, scrolling & VBlank palette cycling
|
||||
│ ├── game_input.cpp # Key mapping, inverted control logic, reverse-denial, menu navigation
|
||||
│ ├── game_logic.cpp # Position update, edge wrapping, collision resolution, RNG
|
||||
│ └── game_render.cpp # OAM sprite rendering, console text HUD & menu screens
|
||||
@@ -98,9 +100,16 @@ The game operates in one of two scenes ([`Scene`](include/game_state.h#L9-L12)):
|
||||
- **Cursed Apple (Purple):** Spawns occasionally. Inverts player steering controls (Up ↔ Down, Left ↔ Right) for `CURSE_DURATION_TICKS` (40 ticks). The sprite is procedurally constructed at startup in [`main.cpp:91-112`](source/main.cpp#L91-L112) by copying the rotten apple tile pixels and mapping them to dedicated palette entries (`CURSE_PAL_SHADOW`, `CURSE_PAL_OUTLINE`, `CURSE_PAL_FILL`, `CURSE_PAL_GLOW`).
|
||||
- **Reverse-Direction Denial:** Pressing the D-Pad in the exact opposite direction (i.e. into the snake's own neck) is silently denied instead of causing an immediate Game Over. The game computes the would-be next head position (including edge-wrapping) and compares it to the neck segment; if they match, the direction change is rejected and a subtle "denied" thud SFX plays.
|
||||
|
||||
### 3.4 Game Modes
|
||||
- **Normal Mode:** Starts with length 4, timer frequency `TIMER_FREQ_1024(5)`, background color `RGB15(5,5,5)`.
|
||||
- **Hard Mode:** Starts with length 2, timer frequency `TIMER_FREQ_1024(9)` (faster), background color `RGB15(10,5,5)`, spawns rotten apples.
|
||||
### 3.4 Game Modes & Progressive Speed Mechanics
|
||||
- **Normal Mode:** Starts with length 4, base timer frequency 5.0 Hz (`SPEED_BASE_NORMAL_MHZ = 5000`), scaling up to 13.0 Hz (`SPEED_MAX_NORMAL_MHZ = 13000`).
|
||||
- **Hard Mode:** Starts with length 2, base timer frequency 9.0 Hz (`SPEED_BASE_HARD_MHZ = 9000`), scaling up to 17.0 Hz (`SPEED_MAX_HARD_MHZ = 17000`), and spawns rotten apples.
|
||||
- **Progressive Speed Scaling:** Each consumed regular apple increases `state.applesEaten`. Game speed scales linearly with consumed apples up to `SPEED_APPLES_CAP = 40`, granting smooth +200 mHz acceleration per apple. Timer 0 reload registers are recomputed on the fly (`calculate_timer_reload()`).
|
||||
- **Progressive Background Intensity Scaling:** Visual effects intensify at the exact same rate (`calculate_intensity_31()`):
|
||||
- Hardware drift scroll speeds accelerate on both top and bottom screens.
|
||||
- Celestial node oscillation & twinkling breathing frequencies increase via fixed-point phase accumulation (`anim_phase_fp`).
|
||||
- Color palettes dynamically interpolate from calm cyber tones towards blazing electric plasma cyan (Normal) or volcanic hyper-crimson / solar white-gold (Hard).
|
||||
- Deep-space backdrop colors illuminate in tandem with the intensity level.
|
||||
- Apple pickup shockwave pulses flare with heightened luminance.
|
||||
|
||||
---
|
||||
|
||||
@@ -189,9 +198,22 @@ The repository includes preconfigured tasks in [`.vscode/tasks.json`](.vscode/ta
|
||||
- `bin2s` embeds `soundbank.bin` into assembly source `soundbank_bin.S` and header `soundbank_bin.h`.
|
||||
- Audio runs via `libnds`'s `maxmod9` (`mm9`).
|
||||
|
||||
### 6.3 Static Analysis & Tooling
|
||||
### 6.3 Background Pipeline ([`include/game_bg.h`](include/game_bg.h), [`source/game_bg.cpp`](source/game_bg.cpp))
|
||||
- **Dual-Engine Tiled Layers:** Both Main and Sub 2D engines allocate Background Layer 2 (`BgType_Text4bpp`, `BgSize_T_256x256`, `mapBase = 28`, `tileBase = 1`).
|
||||
- **Main Engine:** BG2 renders a dynamic cyber horizon, corner brackets, and starfield behind the top-screen console HUD and menu options (`bgSetPriority(topScreen.bgId, 0)`, `bgSetPriority(bgMainId, 3)`).
|
||||
- **Sub Engine:** BG2 renders an animated retro cyber-grid with 8x8 cell alignment dots, ambient celestial nodes, and circuit pathways behind the snake and apple sprites (`bgSetPriority(bottomScreen.bgId, 1)`, `bgSetPriority(bgSubId, 3)`, sprites at priority 0).
|
||||
- **Smooth 60 FPS Hardware Scrolling:** Both background layers use fixed-point 8.8 subpixel accumulators with `bgSetScroll()` and `bgUpdate()` during VBlank for silky smooth drift at 0% CPU cost. Drift speed accelerates dynamically as apples are consumed.
|
||||
- **Dynamic VBlank Palette Animation & Progressive Intensity:**
|
||||
- **Normal Mode:** Neon cyan / teal / midnight blue theme with oscillating sine-wave twinkling stars and breathing grid nodes, transitioning smoothly towards blazing electric plasma cyan at higher apple counts.
|
||||
- **Hard Mode:** Fiery amber / crimson cyber grid with faster pulse rate, transitioning towards volcanic hyper-crimson and incandescent solar white-gold.
|
||||
- **Cursed Mode:** Radioactive violet / magenta glitch strobe and high-speed warp drift during inverted controls (further intensified with apple count).
|
||||
- **Apple Pickup Wave:** Eating an apple triggers a glowing shockwave pulse (`bg_trigger_pulse()`) that ripples through the grid with luminance scaled by current intensity.
|
||||
- **Deep-Space Backdrop Glow:** Screen backdrops illuminate in sync with intensity levels.
|
||||
- **Game Over:** Palette dims to a somber dark charcoal / muted red tone with gentle drift deceleration.
|
||||
|
||||
### 6.4 Static Analysis & Tooling
|
||||
- **Clang-Tidy:** Configured in [`.clang-tidy`](.clang-tidy). Enforces modern C++ guidelines, bugprone checks, readability conventions, and snake_case / CamelCase identifiers.
|
||||
- **Clangd:** Configured in [`.clangd`](.clangd). Removes `-mthumb-interwork` (which clang warns against) and explicitly includes devkitARM GCC 15.2.0 system headers.
|
||||
- **Clangd:** Configured in [`.clangd`](.clangd). Removes `-mthumb-interwork` (which clang warns against) and explicitly includes devkitARM GCC 16.1.0 system headers.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user