Add cursed apple: a status-effect apple that inverts controls

Eating a cursed apple inverts the snake's steering for
CURSE_DURATION_TICKS ticks, shown on the top screen while active. The
sprite is a recolored copy of the rotten-apple tile since all existing
sprite tiles are already in use.
This commit is contained in:
phillip committed 2026-09-03 22:27:22 +02:00
1 parent df9b859601
commit 0e7477031f
8 files changed
+96 -5

No files matched your search

+30
View File
@@ -89,6 +89,23 @@ bool check_collision_apples_rotten(GameState &state) {
return true;
}
bool check_collision_apples_cursed(GameState &state) {
const std::array<int, 3> headpos = state.snake.front();
auto it = std::find_if(state.cursed_apples.begin(), state.cursed_apples.end(),
[&](const std::array<int, 2> &apple) {
return apple[0] == headpos[0] && apple[1] == headpos[1];
});
if (it == state.cursed_apples.end()) {
return false;
}
state.cursed_apples.erase(it);
state.curseTicksRemaining = CURSE_DURATION_TICKS;
return true;
}
void spawn_apples(GameState &state) {
if (state.apples.size() < 1) {
std::array<int, 2> apple = { rand() % (X_MAX + 1), rand() % (Y_MAX + 1) };
@@ -102,3 +119,16 @@ void spawn_apples_rotten(GameState &state) {
state.bad_apples.push_back(badApple);
}
}
void spawn_apples_cursed(GameState &state) {
if (state.cursed_apples.empty() && (state.ticks % 20 == 0) && ((rand() % 5) == 0)) {
std::array<int, 2> cursedApple = { rand() % (X_MAX + 1), rand() % (Y_MAX + 1) };
state.cursed_apples.push_back(cursedApple);
}
}
void tick_status_effects(GameState &state) {
if (state.curseTicksRemaining > 0) {
state.curseTicksRemaining--;
}
}