From eb3a39084abf29a4eb198b4aab32433f592bedd8 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 6 Feb 2018 22:27:53 +0000 Subject: [PATCH] Added unit reappear code. --- src/entities/unit.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/entities/unit.c b/src/entities/unit.c index d4b0430..337aae7 100644 --- a/src/entities/unit.c +++ b/src/entities/unit.c @@ -133,8 +133,7 @@ static void tick(void) u->spawnedInTimer = FPS * 5; } - u->spawnedInTimer--; - if (u->spawnedInTimer <= 0) + if (--u->spawnedInTimer <= 0) { u->alive = ALIVE_DEAD; } @@ -143,6 +142,28 @@ static void tick(void) static void reappear(void) { + int valid, r; + + valid = 0; + + do + { + r = rand() % MAX_CHECKPOINTS; + self->x = world.bob->checkpoints[r].x; + self->y = world.bob->checkpoints[r].y; + valid = (self->x != 0 && self->y != 0); + } + while (!valid); + + self->y -= (self->h + 10); + + self->action = self->walk; + + self->flags &= ~EF_GONE; + + addTeleportStars(self); + + playSound(SND_APPEAR, CH_ANY); } static void applyDamage(int damage)