From 3ce879fe98d94707792d71421683fb64d1573efb Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 1 Mar 2026 09:41:45 +0000 Subject: [PATCH] Fix asteroid double-impact and levelgen theme fallback Explode asteroid on player contact instead of letting it continue falling to the ground for a second impact. Return a safe default theme when theme_count is zero to avoid reading uninitialized data. --- src/game/hazards.c | 7 +++++++ src/game/levelgen.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/game/hazards.c b/src/game/hazards.c index cea1999..3e54fbd 100644 --- a/src/game/hazards.c +++ b/src/game/hazards.c @@ -699,10 +699,17 @@ static void asteroid_update(Entity *self, float dt, const Tilemap *map) { player->body.pos.y + player->body.size.y * 0.5f ); particle_emit_spark(hit_pos, (SDL_Color){180, 140, 80, 255}); + particle_emit_death_puff(hit_pos, (SDL_Color){140, 110, 80, 255}); if (s_asteroid_sfx_loaded) { audio_play_sound(s_sfx_asteroid_impact, 80); } + + /* Explode on contact — hide and start respawn */ + ad->falling = false; + ad->respawn_timer = ASTEROID_RESPAWN; + self->body.pos.y = -100.0f; + return; } } diff --git a/src/game/levelgen.c b/src/game/levelgen.c index 4b1be39..511c3ca 100644 --- a/src/game/levelgen.c +++ b/src/game/levelgen.c @@ -602,7 +602,7 @@ static void gen_transition(Tilemap *map, int x0, int w, /* Get the theme for a given segment index from the config */ static LevelTheme theme_for_segment(const LevelGenConfig *config, int seg_idx) { - if (config->theme_count <= 0) return config->themes[0]; + if (config->theme_count <= 0) return THEME_PLANET_SURFACE; if (seg_idx >= config->theme_count) return config->themes[config->theme_count - 1]; return config->themes[seg_idx]; }