From cb26714a279373e6765465e212c4cdd57e9bf6e1 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Fri, 21 Nov 2008 06:06:22 +0000 Subject: [PATCH] Fixed crash in snake movement code --- rc.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/rc.c b/rc.c index 5ffa793..f437efb 100644 --- a/rc.c +++ b/rc.c @@ -3545,32 +3545,35 @@ int movesprite(sprite_t *s) { int shoot = B_FALSE; if (player && (s->y - player->y <= (TILEH*4)) ) { closeplayer = player; - } else { + } else if (player2 && (s->y - player2->y <= (TILEH*4))) { closeplayer = player2; + } else { + closeplayer = NULL; } - - if (s->bullet == NULL) { // if we don't already have a bullet - // if we are facing the player - if ( (closeplayer->x < s->x) && (s->dir == D_LEFT) ) { - shoot = B_TRUE; - } else if ( (closeplayer->x > s->x) && (s->dir == D_RIGHT) ) { - shoot = B_TRUE; + if (closeplayer) { + if (s->bullet == NULL) { // if we don't already have a bullet + // if we are facing the player + if ( (closeplayer->x < s->x) && (s->dir == D_LEFT) ) { + shoot = B_TRUE; + } else if ( (closeplayer->x > s->x) && (s->dir == D_RIGHT) ) { + shoot = B_TRUE; + } } - } - if (shoot) { - // if our shooting timer is okay - if (s->timer1 == 0) { - ss = addsprite(P_SPIT,s->x,s->y - s->img->h/2,"spit" ); - ss->ys = 0; - ss->xs = s->dir * (getspeed(s)*2); - ss->dir = s->dir; - ss->owner = s; + if (shoot) { + // if our shooting timer is okay + if (s->timer1 == 0) { + ss = addsprite(P_SPIT,s->x,s->y - s->img->h/2,"spit" ); + ss->ys = 0; + ss->xs = s->dir * (getspeed(s)*2); + ss->dir = s->dir; + ss->owner = s; - s->bullet = ss; + s->bullet = ss; - // start timer for shooting again - s->timer1 = 200; + // start timer for shooting again + s->timer1 = 200; + } } } }