feat: add finite lifetimes and despawn mechanics for rotten and cursed apples

This commit is contained in:
phillip committed 2026-10-03 21:57:13 +02:00
1 parent 9a3a0bd9fd
commit adda5db2f4
8 files changed
+159 -82

No files matched your search

+6
View File
@@ -8,6 +8,12 @@ const int START_LENGTH_HARD = 2;
const int APPLE_SCORE = 10;
const int CURSE_DURATION_TICKS = 40;
// Evil item lifetimes (in game ticks, so density stays balanced across speed scaling)
const int BAD_APPLE_LIFETIME_TICKS = 80; // Rotten apple lasts 80 ticks (~8 spawn cycles)
const int CURSED_APPLE_LIFETIME_TICKS = 90; // Cursed apple lasts 90 ticks before despawning
const int EVIL_ITEM_BLINK_TICKS = 20; // Last 20 ticks: flashes to warn player of imminent despawn
const int EVIL_ITEM_FAST_BLINK_TICKS = 8; // Last 8 ticks: rapid strobe before disappearing
// Cursed apple palette indices in SPRITE_PALETTE_SUB
const uint16_t CURSE_PAL_OUTLINE = 16;
const uint16_t CURSE_PAL_FILL = 17;
+1
View File
@@ -12,6 +12,7 @@ void spawn_apples(GameState &state);
void spawn_apples_rotten(GameState &state);
void spawn_apples_cursed(GameState &state);
void tick_status_effects(GameState &state);
void tick_evil_items(GameState &state);
uint8_t calculate_intensity_31(const GameState &state);
uint16_t calculate_timer_freq_mhz(const GameState &state);
+9 -2
View File
@@ -32,6 +32,13 @@ struct Barrier {
uint16_t framesLeft = 0; // Frames remaining in the current phase
};
// Evil item (rotten apple or cursed apple) with position and lifetime in game ticks
struct EvilItem {
int8_t x = 0;
int8_t y = 0;
uint16_t ticksRemaining = 0;
};
struct GameState {
volatile uint16_t ticks = 0;
volatile uint16_t snakelength = 0;
@@ -55,8 +62,8 @@ struct GameState {
std::deque<std::array<int, 3>> snake;
std::vector<std::array<int, 2>> apples;
std::vector<std::array<int, 2>> bad_apples;
std::vector<std::array<int, 2>> cursed_apples;
std::vector<EvilItem> bad_apples;
std::vector<EvilItem> cursed_apples;
};
#endif