feat: add custom background rendering and speed scaling features for snake gameplay

This commit is contained in:
phillip committed 2026-10-03 20:58:33 +02:00
1 parent 93c0a44027
commit 60bf111400
13 files changed
+711 -26

No files matched your search

+9 -2
View File
@@ -3,11 +3,18 @@
#endif
const int START_LENGTH = 4;
const int START_LENGTH_HARD =2;
const int START_LENGTH_HARD = 2;
const int APPLE_SCORE = 10;
const int CURSE_DURATION_TICKS = 40;
//Screen size
// Speed scaling configuration (gradual acceleration based on consumed apples)
const int SPEED_BASE_NORMAL_MHZ = 5000; // 5.0 Hz (~200 ms per step)
const int SPEED_BASE_HARD_MHZ = 9000; // 9.0 Hz (~111 ms per step)
const int SPEED_MAX_NORMAL_MHZ = 13000; // 13.0 Hz (~77 ms per step)
const int SPEED_MAX_HARD_MHZ = 17000; // 17.0 Hz (~59 ms per step)
const int SPEED_APPLES_CAP = 40; // Apples consumed to reach max intensity & speed
// Screen size
const int X_MAX = 31;
const int Y_MAX = 23;
+34
View File
@@ -0,0 +1,34 @@
#ifndef GAME_BG_H
#define GAME_BG_H
#include <nds.h>
#include "game_state.h"
struct BackgroundContext {
int bg_main_id = -1;
int bg_sub_id = -1;
// Fixed-point (8.8) scroll accumulators for smooth 60fps drift
uint16_t scroll_main_x_fp = 0;
uint16_t scroll_main_y_fp = 0;
uint16_t scroll_sub_x_fp = 0;
uint16_t scroll_sub_y_fp = 0;
// Animation frame counter & timers
uint8_t anim_phase = 0;
uint16_t anim_phase_fp = 0; // Fixed-point (8.8) phase accumulator
uint8_t pulse_timer = 0; // Triggered when an apple is eaten
// Cached state to optimize updates
bool hard_mode = false;
bool is_cursed = false;
bool game_over = false;
Scene scene = Scene::Menu;
};
void bg_setup(BackgroundContext &bg_ctx, int top_console_bg_id, int bottom_console_bg_id);
void bg_update(BackgroundContext &bg_ctx, const GameState &state, uint8_t frame);
void bg_trigger_pulse(BackgroundContext &bg_ctx);
void bg_set_scene(BackgroundContext &bg_ctx, Scene scene, bool hard_mode);
#endif // GAME_BG_H
+4
View File
@@ -13,4 +13,8 @@ void spawn_apples_rotten(GameState &state);
void spawn_apples_cursed(GameState &state);
void tick_status_effects(GameState &state);
uint8_t calculate_intensity_31(const GameState &state);
uint16_t calculate_timer_freq_mhz(const GameState &state);
uint16_t calculate_timer_reload(const GameState &state);
#endif
+3
View File
@@ -15,9 +15,12 @@ struct HudCache {
bool dirty = true;
};
struct BackgroundContext;
struct RenderAssets {
PrintConsole *topScreen = nullptr;
PrintConsole *bottomScreen = nullptr;
BackgroundContext *bg_context = nullptr;
u16 *gfx_segment = nullptr;
u16 *gfx_segment_small = nullptr;
+1
View File
@@ -18,6 +18,7 @@ struct GameState {
volatile uint16_t snakelength = 0;
volatile uint16_t snakeDirection = 1;
volatile uint16_t score = 0;
volatile uint16_t applesEaten = 0;
bool gameOver = false;
bool paused = false;