From aaeb189cb2e7eb6eb95188c707791be71067e802 Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Sun, 16 Jun 2019 21:02:19 +0000 Subject: Remove segfault when character dies --- foes.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/foes.c b/foes.c index 704023a..a5ce522 100644 --- a/foes.c +++ b/foes.c @@ -215,10 +215,11 @@ try_escape (struct foe *f) f->state &= ~STATE_TRAPPED; } -static void +static int update_foe_pos (const struct coord *hero_pos, struct foe *f) { struct coord posorig; + int retval = 0; coord_set_yx (&posorig, f->pos.y, f->pos.x); compute_move (hero_pos, f); @@ -229,8 +230,10 @@ update_foe_pos (const struct coord *hero_pos, struct foe *f) gfx_move_sprite (SP_FOE, &posorig, &f->pos); check_trap (f); check_hole (f); - if (coord_equal (&f->pos, hero_pos)) + if (coord_equal (&f->pos, hero_pos)) { hero_die (); + retval = 1; /* signal reset of lists */ + } } else { @@ -244,6 +247,7 @@ update_foe_pos (const struct coord *hero_pos, struct foe *f) f->current_move == MOV_FALL ? MOV_NONE : coord_opposite_dir (f->current_move); } + return retval; } void @@ -268,8 +272,8 @@ foes_update_pos (void) if (foe->state & STATE_TRAPPED) try_escape (foe); - else - update_foe_pos (&hero_pos, foe); + else if (update_foe_pos (&hero_pos, foe) > 0) + break; } timer_get_time (&foes_timer); } -- cgit v1.2.3