Let AI refactor everything and see if it breaks.

This commit is contained in:
2026-03-29 00:59:27 +01:00
parent 561b99b710
commit b873ac24ca
11 changed files with 656 additions and 576 deletions

33
include/game_audio.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef GAME_AUDIO_H
#define GAME_AUDIO_H
#include <maxmod9.h>
struct AudioContext {
bool musicEnabled = true;
mm_sound_effect sfx_pickup;
mm_sound_effect sfx_boom;
mm_sound_effect sfx_pause;
mm_sound_effect sfx_unpause;
mm_sound_effect sfx_plop;
mm_sound_effect sfx_fail;
};
void audio_setup(AudioContext &audio);
void audio_start_music(const AudioContext &audio);
void audio_stop_music();
void audio_pause_music_if_enabled(const AudioContext &audio);
void audio_resume_music_if_enabled(const AudioContext &audio);
void audio_play_pickup(const AudioContext &audio);
void audio_play_boom(const AudioContext &audio);
void audio_play_plop(const AudioContext &audio);
void audio_play_pause(const AudioContext &audio);
void audio_play_unpause(const AudioContext &audio);
void audio_play_fail(const AudioContext &audio);
bool audio_toggle_music(AudioContext &audio);
bool audio_is_music_enabled(const AudioContext &audio);
#endif

23
include/game_input.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef GAME_INPUT_H
#define GAME_INPUT_H
#include <nds.h>
#include "game_audio.h"
#include "game_render.h"
#include "game_state.h"
struct InputContext {
GameState *state = nullptr;
RenderAssets *renderAssets = nullptr;
AudioContext *audio = nullptr;
volatile bool *internals = nullptr;
PrintConsole *topScreen = nullptr;
void (*init_game)() = nullptr;
};
bool handle_input_frame(InputContext &ctx);
#endif

13
include/game_logic.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef GAME_LOGIC_H
#define GAME_LOGIC_H
#include "game_state.h"
void update_snake(GameState &state);
bool check_collision_self(GameState &state);
bool check_collision_apples(GameState &state);
bool check_collision_apples_rotten(GameState &state);
void spawn_apples(GameState &state);
void spawn_apples_rotten(GameState &state);
#endif

24
include/game_render.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef GAME_RENDER_H
#define GAME_RENDER_H
#include <nds.h>
#include "game_state.h"
struct RenderAssets {
PrintConsole *topScreen = nullptr;
PrintConsole *bottomScreen = nullptr;
u16 *gfx_segment = nullptr;
u16 *gfx_segment_small = nullptr;
u16 *gfx_head = nullptr;
u16 *gfx_apple = nullptr;
u16 *gfx_tail = nullptr;
u16 *gfx_apple_rotten = nullptr;
};
void draw_game(const GameState &state, const RenderAssets &assets);
void draw_stats(const GameState &state, bool internals, bool musicEnabled, uint8_t frame);
void blink_apples(const GameState &state, u16 *gfx_apple);
#endif

24
include/game_state.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef GAME_STATE_H
#define GAME_STATE_H
#include <array>
#include <deque>
#include <vector>
#include <nds/ndstypes.h>
struct GameState {
volatile uint16_t ticks = 0;
volatile uint16_t snakelength = 0;
volatile uint16_t snakeDirection = 1;
volatile uint16_t score = 0;
bool gameOver = false;
bool paused = false;
bool hardMode = false;
std::deque<std::array<int, 3>> snake;
std::vector<std::array<int, 2>> apples;
std::vector<std::array<int, 2>> bad_apples;
};
#endif