Fixed crash when teleporting while pinkcloud was coming in

This commit is contained in:
Rob Pearce 2008-10-26 03:31:16 +00:00
parent e37ca153c9
commit 9ca91a014d
5 changed files with 84 additions and 29 deletions

View File

@ -1,7 +1,7 @@
all: rc edit all: rc edit
rc: rc.c shared.c rc.h shared.h globals.h defs.h rc: rc.c shared.c rc.h shared.h globals.h defs.h
gcc -Wall -O3 -o rc -g rc.c shared.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL_mixer gcc -Wall -o rc -g rc.c shared.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL_mixer
edit: edit.c shared.c edit.h shared.h globals.h defs.h edit: edit.c shared.c edit.h shared.h globals.h defs.h
gcc -D__EDITOR -Wall -o edit -g edit.c shared.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf gcc -D__EDITOR -Wall -o edit -g edit.c shared.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf

1
defs.h
View File

@ -775,6 +775,7 @@ typedef struct sprite_s {
int dir; // which way we are facing (1=right,-1=left) int dir; // which way we are facing (1=right,-1=left)
SDL_Surface *img; // current graphic image SDL_Surface *img; // current graphic image
SDL_Surface *netbg; // temp storage for area behind net SDL_Surface *netbg; // temp storage for area behind net
int allocimg; // have we allocated a special image?
// LINKED LIST STUFF // LINKED LIST STUFF
struct sprite_s *next; struct sprite_s *next;

80
rc.c
View File

@ -356,6 +356,11 @@ int main (int argc, char **argv) {
curlevel->iced = B_FALSE; curlevel->iced = B_FALSE;
undoflood(); undoflood();
} }
// stop teleporting
if (player->teleporting) {
stopteleporting(player);
}
} else if (levelcomplete == LV_WAIT) { } else if (levelcomplete == LV_WAIT) {
int mcount = 0; int mcount = 0;
sprite_t *s2; sprite_t *s2;
@ -554,10 +559,12 @@ int main (int argc, char **argv) {
// warning for cloud // warning for cloud
if ((gtime >= nexthurryup + 10) && (gtime < nexthurryup+15)) { // 15 secs after hurryup if ((gtime >= nexthurryup + 10) && (gtime < nexthurryup+15)) { // 15 secs after hurryup
if (timer % 4 == 0) { if (levelcomplete == LV_INPROGRESS) {
// add puffs if (timer % 4 == 0) {
puffin(-1, 320 + (rand() % (TILEW*4)) - (TILEW*2), // add puffs
240 + (rand() % (TILEH*2)) - TILEH, "cloudwarn", rand() % 5); puffin(-1, 320 + (rand() % (TILEW*4)) - (TILEW*2),
240 + (rand() % (TILEH*2)) - TILEH, "cloudwarn", rand() % 5);
}
} }
} }
@ -1712,7 +1719,6 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
SDL_Surface *ts; SDL_Surface *ts;
if (timer % 2 == 0) { if (timer % 2 == 0) {
/* shrink */ /* shrink */
// TODO: free old image first!!
if (s->teleporting == TP_SHRINKING) { if (s->teleporting == TP_SHRINKING) {
ts = rotozoomSurfaceXY(s->img,0, 0.9 , 0.9 ,0); ts = rotozoomSurfaceXY(s->img,0, 0.9 , 0.9 ,0);
s->img = ts; s->img = ts;
@ -1721,6 +1727,8 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
SDL_FreeSurface(s->img); SDL_FreeSurface(s->img);
s->img = ts; s->img = ts;
} }
// mark that we've allocated the player's teleport image
s->allocimg = B_TRUE;
if ((s->img->w <= 2) || (s->img->h <= 2)) { if ((s->img->w <= 2) || (s->img->h <= 2)) {
/* go to tele dest */ /* go to tele dest */
@ -1752,14 +1760,14 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
double size; double size;
if (timer % 2 == 0) { if (timer % 2 == 0) {
/* grow */ /* grow */
size = (double)-s->teleporting / 10; size = (double) -s->teleporting / 10;
SDL_FreeSurface(s->img); SDL_FreeSurface(s->img);
if (size >= 1) { if (size >= 1) {
s->allocimg = B_FALSE;
s->teleporting = 0; s->teleporting = 0;
s->img = imageset[s->id].img[F_WALK1]; s->img = imageset[s->id].img[F_WALK1];
} else { } else {
// TODO: free old image first!!
s->img = rotozoomSurfaceXY(imageset[s->id].img[F_WALK1],0,size,size,0); s->img = rotozoomSurfaceXY(imageset[s->id].img[F_WALK1],0,size,size,0);
s->teleporting--; s->teleporting--;
} }
@ -2829,6 +2837,10 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
s->rotated = 0; s->rotated = 0;
if (levelcomplete == LV_CLOUD) { if (levelcomplete == LV_CLOUD) {
levelcomplete = LV_CLOUDLOOP; levelcomplete = LV_CLOUDLOOP;
// stop the player teleporting if required
if (player->teleporting) {
stopteleporting(player);
}
} }
} else { } else {
@ -2850,7 +2862,6 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
s->angle += (360*(M_PI/180)); s->angle += (360*(M_PI/180));
} }
// figure out x/y speed // figure out x/y speed
s->xs = (cos(s->angle) * s->speed); s->xs = (cos(s->angle) * s->speed);
s->ys = (sin(s->angle) * s->speed); s->ys = (sin(s->angle) * s->speed);
@ -2860,6 +2871,9 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
// move // move
s->x += s->xs; s->x += s->xs;
s->y += s->ys; s->y += s->ys;
// keep on screen!!
keeponscreen(s);
} }
} }
} else if (levelcomplete == LV_CLOUDLOOP) { } else if (levelcomplete == LV_CLOUDLOOP) {
@ -2903,7 +2917,7 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
s->x += s->xs; s->x += s->xs;
s->y += s->ys; s->y += s->ys;
// keep on screen // keep on screen (but use player height
if (s->x > 640-(s->img->w/2)) { if (s->x > 640-(s->img->w/2)) {
s->x = 640 - (s->img->w/2); s->x = 640 - (s->img->w/2);
} }
@ -3046,14 +3060,16 @@ void dotileeffects(sprite_t *s) {
// teleporters // teleporters
if ((tt->id == T_TELEPORT) || (tt->id == T_TELEPORT2)) { if ((tt->id == T_TELEPORT) || (tt->id == T_TELEPORT2)) {
if (s == player || ismonster(s->id)) { //if (!isendoflev()) { // can't enter teleporters after level end to avoid cloud moving too far
if (s->id != P_BLACKCLOUD) { if (s == player || ismonster(s->id)) {
if (!s->teleporting) { if (s->id != P_BLACKCLOUD) {
playfx(FX_TELEPORT); if (!s->teleporting) {
s->teleporting = 1; playfx(FX_TELEPORT);
s->teleporting = 1;
}
} }
} }
} // }
} }
@ -8304,3 +8320,37 @@ void getinput(void) {
} }
} }
} }
int isendoflev(void) {
if (levelcomplete == LV_CLEAR) return B_TRUE;
if (levelcomplete == LV_WAIT) return B_TRUE;
if (levelcomplete == LV_FINAL) return B_TRUE;
if (levelcomplete == LV_CLOUD) return B_TRUE;
if (levelcomplete == LV_CLOUDLOOP) return B_TRUE;
if (levelcomplete == LV_NEXTLEV) return B_TRUE;
return B_FALSE;
}
void keeponscreen(sprite_t *s) {
if (s->x >= (640-(s->img->w/2))) {
s->x = 640 - (s->img->w/2)-1;
}
if (s->x <= s->img->w/2) {
s->x = (s->img->w/2)+1;
}
if (s->y <= s->img->h) {
s->y = s->img->h+1;
}
if (s->y >= 480) {
s->y = 480 - 1;
}
}
void stopteleporting(sprite_t *s) {
if (s->allocimg) {
SDL_FreeSurface(s->img);
}
s->allocimg = B_FALSE;
s->teleporting = 0;
s->img = imageset[s->id].img[F_WALK1];
}

3
rc.h
View File

@ -99,3 +99,6 @@ int gethiscores(void);
void drawhiscores(void); void drawhiscores(void);
int submithiscore(int score,int level, char *name); int submithiscore(int score,int level, char *name);
void getinput(void); void getinput(void);
int isendoflev(void);
void keeponscreen(sprite_t *s);
void stopteleporting(sprite_t *s);

View File

@ -588,6 +588,7 @@ void setdefaults(sprite_t *s) {
s->doublejumpready = B_FALSE; s->doublejumpready = B_FALSE;
s->allocimg = B_FALSE;
s->frame = 0; s->frame = 0;
@ -3179,27 +3180,27 @@ void drawplayer(sprite_t *s, SDL_Rect *where) {
wingframe = 0; wingframe = 0;
} }
wingarea.x = player->x - (imageset[P_WINGRIGHT].img[wingframe]->w/2); wingarea.x = s->x - (imageset[P_WINGRIGHT].img[wingframe]->w/2);
wingarea.y = player->y - (imageset[P_WINGRIGHT].img[wingframe]->h); wingarea.y = s->y - (imageset[P_WINGRIGHT].img[wingframe]->h);
if (wingframe == 0) { // still if (wingframe == 0) { // still
wingarea.x += (4*player->dir); wingarea.x += (4*s->dir);
wingarea.y += 2; wingarea.y += 2;
} else if ((wingframe >= 1) && (wingframe <= 2)) { // flapping } else if ((wingframe >= 1) && (wingframe <= 2)) { // flapping
wingarea.x += (11*player->dir); wingarea.x += (11*s->dir);
wingarea.y -= 9; wingarea.y -= 9;
} }
// when climbing, show "left" wing twice instead // when climbing, show "left" wing twice instead
// when swimming, only show left wing // when swimming, only show left wing
if (!s->climbing && !s->swimming) { if (!s->climbing && !s->swimming) {
if (player->dir == -1) wingframe += MAXFRAMES; if (s->dir == -1) wingframe += MAXFRAMES;
doblit(imageset[P_WINGRIGHT].img[wingframe], screen, &wingarea); doblit(imageset[P_WINGRIGHT].img[wingframe], screen, &wingarea);
} }
} }
#endif #endif
if ((levelcomplete == LV_CLOUDLOOP) || (levelcomplete == LV_NEXTLEV)) { if ((levelcomplete == LV_CLOUDLOOP) || (levelcomplete == LV_NEXTLEV)) {
player->img = imageset[player->id].img[F_SHOOT]; s->img = imageset[s->id].img[F_SHOOT];
} }
// draw the sprite // draw the sprite
@ -3222,33 +3223,33 @@ void drawplayer(sprite_t *s, SDL_Rect *where) {
wingframe = 0; wingframe = 0;
} }
wingarea.x = player->x - (imageset[P_WINGLEFT].img[wingframe]->w/2); wingarea.x = s->x - (imageset[P_WINGLEFT].img[wingframe]->w/2);
wingarea.y = player->y - (imageset[P_WINGLEFT].img[wingframe]->h); wingarea.y = s->y - (imageset[P_WINGLEFT].img[wingframe]->h);
if (wingframe == 0) { // still if (wingframe == 0) { // still
if (s->climbing) { if (s->climbing) {
wingarea.x -= 4; wingarea.x -= 4;
wingarea.y += 2; wingarea.y += 2;
} else { } else {
wingarea.x -= (6*player->dir); wingarea.x -= (6*s->dir);
wingarea.y += 2; wingarea.y += 2;
} }
} else if ((wingframe >= 1) && (wingframe <= 2)) { // flapping } else if ((wingframe >= 1) && (wingframe <= 2)) { // flapping
wingarea.x -= (11*player->dir); wingarea.x -= (11*s->dir);
wingarea.y -= 9; wingarea.y -= 9;
} else if (wingframe == 3) { } else if (wingframe == 3) {
wingarea.y -= 9; wingarea.y -= 9;
wingarea.x -= (6*player->dir); wingarea.x -= (6*s->dir);
} }
if (player->dir == -1) wingframe += MAXFRAMES; if (s->dir == -1) wingframe += MAXFRAMES;
doblit(imageset[P_WINGLEFT].img[wingframe], screen, &wingarea); doblit(imageset[P_WINGLEFT].img[wingframe], screen, &wingarea);
if (s->climbing) { if (s->climbing) {
// draw the other wing // draw the other wing
wingarea.x += 8; wingarea.x += 8;
// reverse it // reverse it
if (player->dir == -1) wingframe -= MAXFRAMES; if (s->dir == -1) wingframe -= MAXFRAMES;
else wingframe += MAXFRAMES; else wingframe += MAXFRAMES;
doblit(imageset[P_WINGLEFT].img[wingframe], screen, &wingarea); doblit(imageset[P_WINGLEFT].img[wingframe], screen, &wingarea);
} }