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.
This commit is contained in:
@@ -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
|
player->body.pos.y + player->body.size.y * 0.5f
|
||||||
);
|
);
|
||||||
particle_emit_spark(hit_pos, (SDL_Color){180, 140, 80, 255});
|
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) {
|
if (s_asteroid_sfx_loaded) {
|
||||||
audio_play_sound(s_sfx_asteroid_impact, 80);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 */
|
/* Get the theme for a given segment index from the config */
|
||||||
static LevelTheme theme_for_segment(const LevelGenConfig *config, int seg_idx) {
|
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];
|
if (seg_idx >= config->theme_count) return config->themes[config->theme_count - 1];
|
||||||
return config->themes[seg_idx];
|
return config->themes[seg_idx];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user