diff --git a/data/levels/level99.dat b/data/levels/level99.dat index c9f56cc..312eab6 100644 --- a/data/levels/level99.dat +++ b/data/levels/level99.dat @@ -8,7 +8,8 @@ monsters 134 35 22 23 12 19 6 20 10 -12 24 19 +133 18 19 +133 26 19 endmonsters exitdir 1 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, diff --git a/rc.c b/rc.c index 292fece..f92f512 100644 --- a/rc.c +++ b/rc.c @@ -3006,46 +3006,47 @@ int movesprite(sprite_t *s) { int xdiff ,absxdiff; tiletype_t *tunder; + /* distance to closest player */ + xdiff = getxdisttoplayer(s, NULL); + absxdiff = abs(xdiff); - if (globpowerup == PW_CAMERA) { - move = B_TRUE; - } else { - /* distance to closest player */ - xdiff = getxdisttoplayer(s, NULL); - absxdiff = abs(xdiff); - - // tile in front and below - tt = gettileat(s->x + s->dir*getspeed(s) + (s->dir * (s->img->w/2)),s->y + (TILEH/2),NULL,NULL); - // tile below - tunder = gettileat(s->x ,s->y + 1,NULL,NULL); - /* if there's a hole in front of us and below*/ - if (tt->solid == S_NOTSOLID) { - // we're on a slope - if (tunder->solid == S_SLOPE) { - move = B_TRUE; - } else { - if (s->angry || boss) { - if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { - /* if player is below, fall off */ - if (xdiff <= (TILEW*8)) { - move = B_TRUE; - } - } else if ((player && (player->y == s->y)) || (player2 && player2->y == s->y)) { + // tile in front and below + tt = gettileat(s->x + s->dir*getspeed(s) + (s->dir * (s->img->w/2)),s->y + (TILEH/2),NULL,NULL); + // tile below + tunder = gettileat(s->x ,s->y + 1,NULL,NULL); + /* if there's a hole in front of us and below*/ + if (tt->solid == S_NOTSOLID) { + // we're on a slope + if (tunder->solid == S_SLOPE) { + move = B_TRUE; + } else { + if (s->angry || boss) { + if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { + /* if player is below, fall off */ + if (xdiff <= (TILEW*8)) { + move = B_TRUE; + } + } else if ((player && (player->y == s->y)) || (player2 && player2->y == s->y)) { + if (globpowerup != PW_CAMERA) { /* if player is at same level and close, jump */ if ((s->dir == D_RIGHT) && (xdiff > 0) && (xdiff <= (TILEW*7))) { jump(s,D_RIGHT); } else if ((s->dir == D_LEFT) && (xdiff < 0) && (xdiff >= -(TILEW*7))) { jump(s,D_LEFT); } - } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { - // if near bottom of the screen and can fall through... - move = B_TRUE; } + } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { + // if near bottom of the screen and can fall through... + move = B_TRUE; } } - } else { - move = B_TRUE; } + } else { + move = B_TRUE; + } + + if (globpowerup == PW_CAMERA) { + move = B_TRUE; } /* either move or turn around */ @@ -3109,30 +3110,32 @@ int movesprite(sprite_t *s) { int move = B_FALSE; int xdiff, absxdiff; - if (globpowerup == PW_CAMERA) { - move = B_TRUE; - } else { - /* distance to closest player */ - xdiff = getxdisttoplayer(s, NULL); - absxdiff = abs(xdiff); - tt = gettileat(s->x + s->dir+getspeed(s) + (s->dir * (s->img->w/2)),s->y,NULL,NULL); - /* if there's a hole in front of us */ - if (tt->solid == S_NOTSOLID) { - if (s->angry || boss) { - if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { - /* if player is below, fall off */ - if (xdiff <= (TILEW*8)) { - move = B_TRUE; - } - } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { - // if near bottom of the screen and can fall through... + /* distance to closest player */ + xdiff = getxdisttoplayer(s, NULL); + absxdiff = abs(xdiff); + + tt = gettileat(s->x + s->dir+getspeed(s) + (s->dir * (s->img->w/2)),s->y,NULL,NULL); + /* if there's a hole in front of us */ + if (tt->solid == S_NOTSOLID) { + if (s->angry || boss) { + if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { + /* if player is below, fall off */ + if (xdiff <= (TILEW*8)) { move = B_TRUE; } + } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { + // if near bottom of the screen and can fall through... + move = B_TRUE; } - } else { - move = B_TRUE; } + } else { + move = B_TRUE; + } + + if (globpowerup == PW_CAMERA) { + // always move + move = B_TRUE; } /* either move or turn around */ @@ -3192,43 +3195,42 @@ int movesprite(sprite_t *s) { if (!s->falling) { int move = B_FALSE; int xdiff, absxdiff; + sprite_t *target = NULL; + /* distance to closest player */ + xdiff = getxdisttoplayer(s, &target); + if (target != NULL) { + absxdiff = abs(xdiff); + xdiff = target->x - s->x; + + tt = gettileat(s->x + s->dir+getspeed(s),s->y,NULL,NULL); + /* if there's a hole in front of us */ + if (tt->solid == S_NOTSOLID) { + if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { + /* if player is below and nearby, fall off */ + if (xdiff <= (TILEW*16)) { + move = B_TRUE; + } + } else if ((player && (player->y == s->y)) || (player2 && player2->y == s->y)) { + if (globpowerup != PW_CAMERA) { + /* if player is at same level and close, try to jump over the gap */ + if ((s->dir == D_RIGHT) && (xdiff > 0) && (xdiff <= (TILEW*9))) { + jump(s,D_RIGHT); + } else if ((s->dir == D_LEFT) && (xdiff < 0) && (xdiff >= -(TILEW*9))) { + jump(s,D_LEFT); + } + } + } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { + // if near bottom of the screen and can fall through... + move = B_TRUE; + } + } else { + move = B_TRUE; + } + } if (globpowerup == PW_CAMERA) { move = B_TRUE; - } else { - sprite_t *target; - /* distance to closest player */ - xdiff = getxdisttoplayer(s, &target); - if (target != NULL) { - absxdiff = abs(xdiff); - xdiff = target->x - s->x; - - tt = gettileat(s->x + s->dir+getspeed(s),s->y,NULL,NULL); - /* if there's a hole in front of us */ - if (tt->solid == S_NOTSOLID) { - if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { - /* if player is below and nearby, fall off */ - if (xdiff <= (TILEW*16)) { - move = B_TRUE; - } - } else if ((player && (player->y == s->y)) || (player2 && player2->y == s->y)) { - /* if player is at same level and close, try to jump over the gap */ - if ((s->dir == D_RIGHT) && (xdiff > 0) && (xdiff <= (TILEW*9))) { - printf("jr\n"); - jump(s,D_RIGHT); - } else if ((s->dir == D_LEFT) && (xdiff < 0) && (xdiff >= -(TILEW*9))) { - printf("jl\n"); - jump(s,D_LEFT); - } - } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { - // if near bottom of the screen and can fall through... - move = B_TRUE; - } - } else { - move = B_TRUE; - } - } } /* either move or turn around */ @@ -3931,36 +3933,38 @@ printf("setting target to y = %d\n",ss->timer2); int xdiff, absxdiff; - if (globpowerup == PW_CAMERA) { - move = B_TRUE; - } else { - /* distance to player */ - xdiff = getxdisttoplayer(s, NULL); - absxdiff = abs(xdiff); + /* distance to player */ + xdiff = getxdisttoplayer(s, NULL); + absxdiff = abs(xdiff); - tt = gettileat(s->x + s->dir+getspeed(s),s->y,NULL,NULL); - /* if there's a hole in front of us */ - if (tt->solid == S_NOTSOLID) { - double ycutoff = s->y + (TILEH/2); - if ((player && (player->y >= ycutoff)) || (player2 && (player2->y >= ycutoff ))) { - /* if player is below and nearby, fall off */ - if (xdiff <= (TILEW*16)) { - move = B_TRUE; - } - } else if ((player && (player->y == s->y)) || (player2 && (player2->y == s->y ))) { + tt = gettileat(s->x + s->dir+getspeed(s),s->y,NULL,NULL); + /* if there's a hole in front of us */ + if (tt->solid == S_NOTSOLID) { + double ycutoff = s->y + (TILEH/2); + if ((player && (player->y >= ycutoff)) || (player2 && (player2->y >= ycutoff ))) { + /* if player is below and nearby, fall off */ + if (xdiff <= (TILEW*16)) { + move = B_TRUE; + } + } else if ((player && (player->y == s->y)) || (player2 && (player2->y == s->y ))) { + if (globpowerup != PW_CAMERA) { /* if player is at same level and close, jump */ if ((s->dir == D_RIGHT) && (xdiff > 0) && (xdiff <= (TILEW*7))) { jump(s,D_RIGHT); } else if ((s->dir == D_LEFT) && (xdiff < 0) && (xdiff >= -(TILEW*7))) { jump(s,D_LEFT); } - } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { - // if near bottom of the screen and can fall through... - move = B_TRUE; } - } else { + } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { + // if near bottom of the screen and can fall through... move = B_TRUE; } + } else { + move = B_TRUE; + } + + if (globpowerup == PW_CAMERA) { + move = B_TRUE; } /* either move or turn around */ @@ -4022,39 +4026,39 @@ printf("setting target to y = %d\n",ss->timer2); int xdiff, absxdiff,ydiff; - if (globpowerup == PW_CAMERA) { - move = B_TRUE; - } else { - /* distance to player */ - xdiff = getxdisttoplayer(s, NULL); - absxdiff = abs(xdiff); + /* distance to player */ + xdiff = getxdisttoplayer(s, NULL); + absxdiff = abs(xdiff); - tt = gettileat(s->x + s->dir+getspeed(s),s->y,NULL,NULL); - /* if there's a hole in front of us */ - if (tt->solid == S_NOTSOLID) { - if (s->angry) { - if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { - /* if player is below, fall off */ - if (xdiff <= (TILEW*8)) { - move = B_TRUE; - } - } else if ((player && (player->y == s->y)) || (player2 && player2->y == s->y)) { - if (s->angry) { - /* if player is at same level and close, jump */ - if ((s->dir == D_RIGHT) && (xdiff > 0) && (xdiff <= (TILEW*7))) { - jump(s,D_RIGHT); - } else if ((s->dir == D_LEFT) && (xdiff < 0) && (xdiff >= -(TILEW*7))) { - jump(s,D_LEFT); - } - } - } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { - // if near bottom of the screen and can fall through... + tt = gettileat(s->x + s->dir+getspeed(s),s->y,NULL,NULL); + /* if there's a hole in front of us */ + if (tt->solid == S_NOTSOLID) { + if (s->angry) { + if ((player && (player->y > s->y)) || (player2 && (player2->y > s->y))) { + /* if player is below, fall off */ + if (xdiff <= (TILEW*8)) { move = B_TRUE; } + } else if ((player && (player->y == s->y)) || (player2 && player2->y == s->y)) { + if (s->angry) { + /* if player is at same level and close, jump */ + if ((s->dir == D_RIGHT) && (xdiff > 0) && (xdiff <= (TILEW*7))) { + jump(s,D_RIGHT); + } else if ((s->dir == D_LEFT) && (xdiff < 0) && (xdiff >= -(TILEW*7))) { + jump(s,D_LEFT); + } + } + } else if (level->bottomopen && (s->y >= (480 - 100)) && isplayerabove(s)) { + // if near bottom of the screen and can fall through... + move = B_TRUE; } - } else { - move = B_TRUE; } + } else { + move = B_TRUE; + } + + if (globpowerup == PW_CAMERA) { + move = B_TRUE; } /* shoot */ @@ -4301,12 +4305,19 @@ printf("setting target to y = %d\n",ss->timer2); if (s->flies == F_FLYVERT) { ymod = sin(((double)timer * (double)3.6) * (M_PI/180)); //ymod *= 0.8; + // XXX + xmod = 0; if (s->ys * (ymod) > 0) absys = 1; else absys = -1; } else if (s->flies == F_FLYHORZ) { xmod = sin(((double)timer * (double)3.6) * (M_PI/180)); + // XXX + ymod = 0; if (s->xs * (xmod) > 0) absxs = 1; else absxs = -1; + } else { + xmod = 0; + ymod = 0; } @@ -4390,9 +4401,9 @@ printf("setting target to y = %d\n",ss->timer2); // take off if player is close if (player) { - playerdist = getdistance(player->x,player->y,s->x,s->y); + playerdist1 = getdistance(player->x,player->y,s->x,s->y); } else { - playerdist = 9999; + playerdist1 = 9999; } if (player2) { playerdist2 = getdistance(player2->x,player2->y,s->x,s->y); @@ -4531,39 +4542,43 @@ printf("setting target to y = %d\n",ss->timer2); } else { int move = B_FALSE; int xdiff; - sprite_t *pp ; + sprite_t *pp = NULL; + /* walk back and forwards */ /* drop if player is close */ xdiff = getxdisttoplayer(s, &pp); xdiff = abs(xdiff); - if ((pp->y > s->y) && (xdiff <= (TILEW*2)) && (s->timer1 == 0)) { - s->timer1 = 200; - s->flies = B_FALSE; - s->falling = B_TRUE; - s->fallspeed = 8; - } else { - int tx,ty; - s->flies = B_TRUE; + if (pp) { - /* if there's a hole in front of us */ - tt = gettileat(s->x + s->dir*((s->img->w/2)+2),s->y - s->img->h - 4,&tx,&ty); - if (tt->solid == S_NOTSOLID) { - move = B_FALSE; + if ((pp->y > s->y) && (xdiff <= (TILEW*2)) && (s->timer1 == 0)) { + s->timer1 = 200; + s->flies = B_FALSE; + s->falling = B_TRUE; + s->fallspeed = 8; } else { - move = B_TRUE; - } - - /* either move or turn around */ - if (move) { - rv = movex(s, s->dir*getspeed(s), B_TRUE); - if (rv) { - /* if we couldn't move (hit a wall), turn */ + int tx,ty; + s->flies = B_TRUE; + + /* if there's a hole in front of us */ + tt = gettileat(s->x + s->dir*((s->img->w/2)+2),s->y - s->img->h - 4,&tx,&ty); + if (tt->solid == S_NOTSOLID) { + move = B_FALSE; + } else { + move = B_TRUE; + } + + /* either move or turn around */ + if (move) { + rv = movex(s, s->dir*getspeed(s), B_TRUE); + if (rv) { + /* if we couldn't move (hit a wall), turn */ + s->dir = -s->dir; + } + } else { s->dir = -s->dir; } - } else { - s->dir = -s->dir; } } } @@ -5013,7 +5028,8 @@ void dotileeffects(sprite_t *s) { finished = B_TRUE; } else if (tt->id == T_TRAMPUP) { /* tile changes to trampoline down */ - if (!isfruit(s->id) && !iseffect(s->id) && !isbullet(s->id)) { + //if (!isfruit(s->id) && !iseffect(s->id) && !isbullet(s->id)) { + if (isplayer(s)) { // are we on a trampoline already? if (s->ontramp) { // a different one? @@ -5072,18 +5088,19 @@ void dotileeffects(sprite_t *s) { // initial transition to a new level void drawlevel(void) { - int x,y; + int x,y,i; int dstx[2],dsty[2],xdis[2],ydis[2]; double turns; double pspeed[2]; double dist[2]; SDL_Rect area,dst; int speed = 16; - SDL_Surface *playerbg, *playerbg2; - SDL_Surface *cloudbg,*cloudbg2; + SDL_Surface *playerbg = NULL, *playerbg2 = NULL; + SDL_Surface *cloudbg = NULL,*cloudbg2 = NULL; + int got1p = B_FALSE,got2p = B_FALSE; sprite_t tempcloud, tempcloud2; - sprite_t *cloud, *cloud2; + sprite_t *cloud = NULL, *cloud2 = NULL; if (temps) { @@ -5098,9 +5115,17 @@ void drawlevel(void) { SDL_DisplayFormat(temps); + if (player && player->lives > 0) got1p = B_TRUE; + if (player2 && player2->lives > 0) got2p = B_TRUE; + + if (!got1p && !got2p) { + // ERROR!! + printf("trying to transition level with no players!!\n "); + return; + } // init clouds - if (player && player->lives > 0) { + if (got1p) { cloud = &tempcloud; cloud->id = P_PINKCLOUD; cloud->iceimg = NULL; @@ -5123,9 +5148,8 @@ void drawlevel(void) { screen->format->Gmask,screen->format->Bmask, screen->format->Amask); SDL_DisplayFormat(cloudbg); - } - if (player2 && player2->lives > 0) { + if (got2p) { cloud2 = &tempcloud2; cloud2->id = P_PINKCLOUD; cloud2->iceimg = NULL; @@ -5151,6 +5175,7 @@ void drawlevel(void) { } + // draw the full level onto the temporary surface for (x = 0; x < LEVELW; x++) { for (y = 0; y < LEVELH; y++) { @@ -5159,6 +5184,16 @@ void drawlevel(void) { } + // initialise values so we don't accidentally use them + // uninitialied... + for (i = 0; i < 2; i++) { + dstx[i] = 0; + dsty[i] = 0; + xdis[i] = 0; + ydis[i] = 0; + pspeed[i] = 1; + } + // figure out where the players' new start positions are if (player) { dstx[0] = (curlevel->p1x * TILEW) + (TILEW/2); @@ -8039,9 +8074,9 @@ int dofruiteffect(sprite_t *pp, sprite_t *s) { playfx(FX_WAND); sprintf(tempm, "Weaken monsters!"); addoutlinetext(s->x,s->y - s->img->h/2, TEXTSIZE_POINTS, tempm,&white,&black,POINTSDELAY, TT_NORM); - // turn all flowers into explosions + // turn all live monsters into weaker versions for (s2 = sprite; s2 ; s2 = s2->next) { - if (ismonster(s2->id)) { + if (ismonster(s2->id) && !s2->dead) { // don't get ones which we just created! if (!strstr(s2->name, "created")) { int newtype = -1; @@ -10208,8 +10243,13 @@ if (cheat) { void swimup(sprite_t *pl) { int pnum; - if (pl == player) pnum = 0; - if (pl == player2) pnum = 1; + if (pl == player) { + pnum = 0; + } else if (pl == player2) { + pnum = 1; + } else return; // only valid for players + + pl->falling = B_FALSE; if (!isroofabove(pl)) { // is there water above us too? @@ -10261,10 +10301,14 @@ void swimdown(sprite_t *pl) { void trytojump(sprite_t *pl) { int pnum; + if (pl == player) { + pnum = 0; + } else if (pl == player2) { + pnum = 1; + } else return; // only valid for players + if (pl->caughtby) return; - if (pl == player) pnum = 0; - if (pl == player2) pnum = 1; // can't jump while slamming if (pl->slamming) return; @@ -11959,13 +12003,16 @@ double getdistance(double x1, double y1, double x2, double y2) { void doplayermovement(sprite_t *pl) { int pnum; + if (pl == player) { + pnum = 0; + } else if (pl == player2) { + pnum = 1; + } else return; // only valid for players + if (!pl) return; if (pl->caughtby) return; - if (pl == player) pnum = 0; - if (pl == player2) pnum = 1; - if (pl->powerup == PW_GUNNER) { // move crosshairs @@ -12121,7 +12168,7 @@ void doplayermovement(sprite_t *pl) { } double getxdisttoplayer(sprite_t *s, sprite_t **pl) { - double xdiff1,xdiff2,xdiff; + double xdiff1,xdiff2,xdiff = 9999; if (globpowerup == PW_CAMERA) return 9999; /* distance to closest player */ diff --git a/shared.c b/shared.c index b35cdee..7f5b286 100644 --- a/shared.c +++ b/shared.c @@ -2222,6 +2222,12 @@ void drawsprite(sprite_t *s) { SDL_Color col; double zapx,zapy; + // initialise + col.r = 0; + col.g = 0; + col.b = 0; + col.unused = 0; + switch (timer % 4) { case 0: col.r = 255; col.g = 255; col.b = 255; break; case 1: col.r = 0; col.g = 0; col.b = 0; break;