feat: add finite lifetimes and despawn mechanics for rotten and cursed apples
This commit is contained in:
1 parent
9a3a0bd9fd
commit
adda5db2f4
8 files changed
+159
-82
No files matched your search
+31
-37
@@ -37,7 +37,7 @@ bool &hardMode = gameState.hardMode;
|
||||
|
||||
std::deque<std::array<int, 3>> &snake = gameState.snake;
|
||||
std::vector<std::array<int, 2>> &apples = gameState.apples;
|
||||
std::vector<std::array<int, 2>> &bad_apples = gameState.bad_apples;
|
||||
std::vector<EvilItem> &bad_apples = gameState.bad_apples;
|
||||
|
||||
// 31x23
|
||||
PrintConsole topScreen;
|
||||
@@ -49,6 +49,7 @@ AudioContext audioContext;
|
||||
|
||||
RenderAssets renderAssets;
|
||||
BackgroundContext bgContext;
|
||||
InputContext inputContext;
|
||||
|
||||
const void * get_sprite_pointer(uint16_t spriteIndex) {
|
||||
return &tilemapTiles[spriteIndex*16];
|
||||
@@ -172,6 +173,11 @@ void setup() {
|
||||
dest_barrier_warn[i] = src_barrier_warn[i];
|
||||
}
|
||||
|
||||
// Pre-reserve capacities to eliminate dynamic heap allocations inside Timer 0 ISR (do_tick)
|
||||
gameState.bad_apples.reserve(32);
|
||||
gameState.cursed_apples.reserve(4);
|
||||
gameState.apples.reserve(4);
|
||||
|
||||
audio_setup(audioContext);
|
||||
|
||||
}
|
||||
@@ -229,6 +235,7 @@ void do_tick() {
|
||||
if (check_collision_apples_cursed(gameState)) {
|
||||
audio_play_boom(audioContext);
|
||||
}
|
||||
tick_evil_items(gameState);
|
||||
spawn_apples(gameState);
|
||||
spawn_apples_rotten(gameState);
|
||||
spawn_apples_cursed(gameState);
|
||||
@@ -245,51 +252,41 @@ void do_tick() {
|
||||
}
|
||||
|
||||
void init_game() {
|
||||
timerStop(0);
|
||||
applesEaten = 0;
|
||||
reset_barriers(gameState);
|
||||
gameState.bad_apples.reserve(32);
|
||||
gameState.cursed_apples.reserve(4);
|
||||
gameState.apples.reserve(4);
|
||||
score = 0;
|
||||
ticks = 0;
|
||||
gameOver = false;
|
||||
snakeDirection = 1;
|
||||
gameState.curseTicksRemaining = 0;
|
||||
apples.clear();
|
||||
bad_apples.clear();
|
||||
gameState.cursed_apples.clear();
|
||||
|
||||
if (hardMode) {
|
||||
timerStart(0, ClockDivider_1024, calculate_timer_reload(gameState), do_tick);
|
||||
setBackdropColorSub(RGB15(8, 3, 3));
|
||||
setBackdropColor(RGB15(6, 2, 2));
|
||||
score = 0;
|
||||
snakelength = START_LENGTH_HARD;
|
||||
snake = { {2,1,1}, {1,1,1} };
|
||||
apples.clear();
|
||||
bad_apples.clear();
|
||||
snakeDirection = 1;
|
||||
ticks = 0;
|
||||
gameOver=false;
|
||||
gameState.curseTicksRemaining = 0;
|
||||
gameState.cursed_apples.clear();
|
||||
consoleSelect(&topScreen);
|
||||
consoleClear();
|
||||
invalidate_hud(renderAssets);
|
||||
consoleSelect(&bottomScreen);
|
||||
consoleClear();
|
||||
oamClear(&oamSub,0,128);
|
||||
audio_start_music(audioContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
timerStart(0, ClockDivider_1024, calculate_timer_reload(gameState), do_tick);
|
||||
} else {
|
||||
setBackdropColorSub(RGB15(3, 4, 7));
|
||||
setBackdropColor(RGB15(2, 3, 6));
|
||||
score = 0;
|
||||
snakelength = START_LENGTH;
|
||||
snake = { {4,1,1}, {3,1,1}, {2,1,1}, {1,1,1} };
|
||||
snakeDirection = 1;
|
||||
ticks = 0;
|
||||
gameOver=false;
|
||||
gameState.curseTicksRemaining = 0;
|
||||
gameState.cursed_apples.clear();
|
||||
consoleSelect(&topScreen);
|
||||
consoleClear();
|
||||
invalidate_hud(renderAssets);
|
||||
consoleSelect(&bottomScreen);
|
||||
consoleClear();
|
||||
oamClear(&oamSub,0,128);
|
||||
audio_start_music(audioContext);
|
||||
}
|
||||
|
||||
consoleSelect(&topScreen);
|
||||
consoleClear();
|
||||
invalidate_hud(renderAssets);
|
||||
consoleSelect(&bottomScreen);
|
||||
consoleClear();
|
||||
oamClear(&oamSub, 0, 128);
|
||||
audio_start_music(audioContext);
|
||||
timerStart(0, ClockDivider_1024, calculate_timer_reload(gameState), do_tick);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@@ -302,7 +299,6 @@ int main(void) {
|
||||
setBackdropColorSub(RGB15(2, 2, 6));
|
||||
draw_menu(gameState, renderAssets, audio_is_music_enabled(audioContext));
|
||||
|
||||
InputContext inputContext;
|
||||
inputContext.state = &gameState;
|
||||
inputContext.renderAssets = &renderAssets;
|
||||
inputContext.audio = &audioContext;
|
||||
@@ -310,12 +306,10 @@ int main(void) {
|
||||
inputContext.topScreen = &topScreen;
|
||||
inputContext.init_game = init_game;
|
||||
|
||||
|
||||
while(1) {
|
||||
if (!handle_input_frame(inputContext)) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user