Fixed crash in snake movement code

This commit is contained in:
Rob Pearce 2008-11-21 06:06:22 +00:00
parent 519ea7f54d
commit cb26714a27
1 changed files with 23 additions and 20 deletions

43
rc.c
View File

@ -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;
}
}
}
}