Fixed gunner effect in 2 player mode

This commit is contained in:
Rob Pearce 2008-11-12 20:39:03 +00:00
parent ba60418c90
commit f7eb491b03
4 changed files with 55 additions and 33 deletions

1
defs.h
View File

@ -901,6 +901,7 @@ extern SDL_Color black;
extern SDL_Color blue; extern SDL_Color blue;
extern SDL_Color white; extern SDL_Color white;
extern SDL_Color green; extern SDL_Color green;
extern SDL_Color purple;
extern SDL_Color yellow; extern SDL_Color yellow;
extern int vidargs; extern int vidargs;
extern int toggletimer; extern int toggletimer;

View File

@ -90,6 +90,7 @@ SDL_Color black;
SDL_Color blue; SDL_Color blue;
SDL_Color white; SDL_Color white;
SDL_Color green; SDL_Color green;
SDL_Color purple;
SDL_Color yellow; SDL_Color yellow;

61
rc.c
View File

@ -63,9 +63,9 @@ char tempm[BUFLEN];
int savemap[LEVELW*LEVELH]; int savemap[LEVELW*LEVELH];
int watertime; int watertime;
double gunorigx; double gunorigx[2];
double gunorigy; double gunorigy[2];
int gundelay; int gundelay[2];
int guntime; int guntime;
int playedbell; int playedbell;
@ -378,7 +378,6 @@ int main (int argc, char **argv) {
*/ */
if (levelcomplete == LV_CLEAR) { if (levelcomplete == LV_CLEAR) {
sprite_t *s2, *nexts; sprite_t *s2, *nexts;
sprite_t *pp;
addoutlinetext(320,240,TEXTSIZE_LEVEL,"Level Complete!",&green,&black,LEVELWINDELAY, TT_NORM); addoutlinetext(320,240,TEXTSIZE_LEVEL,"Level Complete!",&green,&black,LEVELWINDELAY, TT_NORM);
levelcomplete = LV_WAIT; levelcomplete = LV_WAIT;
playfx(FX_WINLEVEL); playfx(FX_WINLEVEL);
@ -390,8 +389,7 @@ int main (int argc, char **argv) {
curlevel->iced = B_FALSE; curlevel->iced = B_FALSE;
undoflood(); undoflood();
} else if (haspowerupany(PW_GUNNER)) { } else if (haspowerupany(PW_GUNNER)) {
pp = haspowerupany(PW_GUNNER); disablepowerups(PW_GUNNER);
losepowerup(pp);
} }
// kill all cards, so we don't have a pokereffect during endoflevel // kill all cards, so we don't have a pokereffect during endoflevel
@ -486,10 +484,8 @@ int main (int argc, char **argv) {
SDL_BlitSurface(redbox,NULL,screen,NULL); SDL_BlitSurface(redbox,NULL,screen,NULL);
} }
if (uncaughtmonsters() <= 0) { if (uncaughtmonsters() <= 0) {
sprite_t *pp;
// finish if no monsters are left alive & uncaught // finish if no monsters are left alive & uncaught
pp = haspowerupany(PW_GUNNER); disablepowerups(PW_GUNNER);
losepowerup(pp);
} }
} }
@ -842,10 +838,13 @@ int main (int argc, char **argv) {
if (toggletimer > 0) toggletimer--; if (toggletimer > 0) toggletimer--;
if (haspowerup(player, PW_GUNNER) || haspowerup(player2, PW_GUNNER)) { if (haspowerupany(PW_GUNNER)) {
int n;
// delay between shots // delay between shots
if (gundelay > 0) { for (n = 0; n < 2; n++) {
gundelay--; if (gundelay[n] > 0) {
gundelay[n]--;
}
} }
} }
@ -950,10 +949,8 @@ void tick(void) {
} }
// handle gunner effect // handle gunner effect
if (haspowerupany(PW_GUNNER)) { if (haspowerupany(PW_GUNNER)) {
sprite_t *pp;
char tempm[SMALLBUFLEN]; char tempm[SMALLBUFLEN];
pp = haspowerupany(PW_GUNNER);
// text // text
if (guntime > 0) { if (guntime > 0) {
sprintf(tempm, "%d",guntime); sprintf(tempm, "%d",guntime);
@ -968,7 +965,7 @@ void tick(void) {
guntime--; guntime--;
if (guntime < 0) { if (guntime < 0) {
// finished! // finished!
losepowerup(pp); disablepowerups(PW_GUNNER);
} }
} }
} }
@ -2000,7 +1997,8 @@ int movesprite(sprite_t *s) {
/* timer */ /* timer */
if (s->doomcount) { if (s->doomcount) {
if (s->powerup != PW_GUNNER) { // fruits don't time out in gunner mode
if (!haspowerupany(PW_GUNNER)) {
s->doomcount--; s->doomcount--;
} }
if (s->doomcount == 0) { if (s->doomcount == 0) {
@ -4023,7 +4021,7 @@ void dotileeffects(sprite_t *s) {
return; return;
} }
// no tile efffects for machine gun // no tile effects for machine gun
if (haspowerupany(PW_GUNNER)) { if (haspowerupany(PW_GUNNER)) {
if (isplayer(s)) { if (isplayer(s)) {
return; return;
@ -6842,21 +6840,25 @@ int dofruiteffect(sprite_t *pp, sprite_t *s) {
playfx(FX_ALARM); playfx(FX_ALARM);
sprintf(tempm, "Machine gunner!"); sprintf(tempm, "Machine gunner!");
addoutlinetext(s->x,s->y - s->img->h/2, TEXTSIZE_POINTS, tempm,&white,&black,POINTSDELAY, TT_NORM); addoutlinetext(s->x,s->y - s->img->h/2, TEXTSIZE_POINTS, tempm,&white,&black,POINTSDELAY, TT_NORM);
gunorigx = pp->x;
gunorigy = pp->y;
guntime = 10; guntime = 10;
gundelay = 0; // used to control shooting speed gundelay[0] = 0; // used to control shooting speed
pp->powerup = PW_GUNNER; gundelay[1] = 0; // used to control shooting speed
// turn off netting etc // gunner works on BOTH players
if (player) { if (player) {
player->netting = B_FALSE; player->netting = B_FALSE;
player->slamming = B_FALSE; player->slamming = B_FALSE;
player->powerup = PW_GUNNER;
gunorigx[0] = player->x;
gunorigy[0] = player->y;
} }
if (player2) { if (player2) {
player2->netting = B_FALSE; player2->netting = B_FALSE;
player2->slamming = B_FALSE; player2->slamming = B_FALSE;
player2->powerup = PW_GUNNER;
gunorigx[1] = player2->x;
gunorigy[1] = player2->y;
} }
return B_TRUE; return B_TRUE;
} else if (s->id == P_ZAPPOWERUP) { } else if (s->id == P_ZAPPOWERUP) {
sprite_t *newsp; sprite_t *newsp;
@ -10429,8 +10431,13 @@ void disablepowerups(int pid) {
void losepowerup(sprite_t *s) { void losepowerup(sprite_t *s) {
if (s->powerup == PW_GUNNER) { if (s->powerup == PW_GUNNER) {
// go back to original position // go back to original position
s->x = gunorigx; if (s == player) {
s->y = gunorigy; s->x = gunorigx[0];
s->y = gunorigy[0];
} else if (s == player2) {
s->x = gunorigx[1];
s->y = gunorigy[1];
}
// invulnerable for a little while // invulnerable for a little while
s->invuln = INVULNTIME/2; s->invuln = INVULNTIME/2;
} }
@ -10487,10 +10494,10 @@ void doplayermovement(sprite_t *pl) {
} }
if (keydown(pnum,SDLK_z)) { if (keydown(pnum,SDLK_z)) {
// shoot - add explosion // shoot - add explosion
if (gundelay == 0) { if (gundelay[pnum] == 0) {
playfx(FX_GUN); playfx(FX_GUN);
addsprite(P_SMASH, pl->x, pl->y+(TILEH/2), "gunexplosion"); addsprite(P_SMASH, pl->x, pl->y+(TILEH/2), "gunexplosion");
gundelay = GUNNERDELAY; gundelay[pnum] = GUNNERDELAY;
} }
} }
} else { } else {

View File

@ -2717,6 +2717,7 @@ void initglobals(void) {
white.r = 255; white.g = 255; white.b = 255; white.r = 255; white.g = 255; white.b = 255;
green.r = 0; green.g = 255; green.b = 0; green.r = 0; green.g = 255; green.b = 0;
yellow.r = 255; yellow.g = 255; yellow.b = 0; yellow.r = 255; yellow.g = 255; yellow.b = 0;
purple.r = 255; purple.g = 0; purple.b = 255;
} }
@ -2959,6 +2960,8 @@ int randompowerup(void) {
int num; int num;
num = rand() % 34; num = rand() % 34;
return P_GUN;
switch (num) { switch (num) {
case 0: case 0:
default: default:
@ -3617,16 +3620,26 @@ void drawplayer(sprite_t *s, SDL_Rect *where) {
#ifndef __EDITOR #ifndef __EDITOR
if (s->powerup == PW_GUNNER) { if (s->powerup == PW_GUNNER) {
SDL_Color *ccol;
SDL_Color purple;
purple.r = 255;
purple.g = 0;
purple.b = 255;
// just draw crosshairs // just draw crosshairs
if (s == player) {
ccol = &red;
} else {
ccol = &purple;
}
// box // box
drawbox16(screen, s->x-(TILEW/2),s->y-(TILEH/2),s->x+(TILEW/2),s->y+(TILEH/2), &green, NULL); drawbox16(screen, s->x-(TILEW/2),s->y-(TILEH/2),s->x+(TILEW/2),s->y+(TILEH/2), ccol, NULL);
// littlebox // littlebox
drawbox16(screen, s->x-1,s->y-1,s->x+1,s->y+1, &green, NULL); drawbox16(screen, s->x-1,s->y-1,s->x+1,s->y+1, ccol, NULL);
// lines // lines
drawline16(screen, s->x, 0, s->x, s->y-(TILEH/2), green); // top drawline16(screen, s->x, 0, s->x, s->y-(TILEH/2), *ccol); // top
drawline16(screen, s->x, s->y+(TILEH/2), s->x, 480-1, green); // bottom drawline16(screen, s->x, s->y+(TILEH/2), s->x, 480-1, *ccol); // bottom
drawline16(screen, 0, s->y, s->x-(TILEW/2), s->y, green); // left drawline16(screen, 0, s->y, s->x-(TILEW/2), s->y, *ccol); // left
drawline16(screen, s->x+(TILEW/2), s->y, 640-1, s->y, green); // right drawline16(screen, s->x+(TILEW/2), s->y, 640-1, s->y, *ccol); // right
return; return;
} }