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
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
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)
SDL_Surface *img; // current graphic image
SDL_Surface *netbg; // temp storage for area behind net
int allocimg; // have we allocated a special image?
// LINKED LIST STUFF
struct sprite_s *next;

60
rc.c
View File

@ -356,6 +356,11 @@ int main (int argc, char **argv) {
curlevel->iced = B_FALSE;
undoflood();
}
// stop teleporting
if (player->teleporting) {
stopteleporting(player);
}
} else if (levelcomplete == LV_WAIT) {
int mcount = 0;
sprite_t *s2;
@ -554,12 +559,14 @@ int main (int argc, char **argv) {
// warning for cloud
if ((gtime >= nexthurryup + 10) && (gtime < nexthurryup+15)) { // 15 secs after hurryup
if (levelcomplete == LV_INPROGRESS) {
if (timer % 4 == 0) {
// add puffs
puffin(-1, 320 + (rand() % (TILEW*4)) - (TILEW*2),
240 + (rand() % (TILEH*2)) - TILEH, "cloudwarn", rand() % 5);
}
}
}
// poker effect
// this must come last as it clears the screen and blanks out other sprites
@ -1712,7 +1719,6 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
SDL_Surface *ts;
if (timer % 2 == 0) {
/* shrink */
// TODO: free old image first!!
if (s->teleporting == TP_SHRINKING) {
ts = rotozoomSurfaceXY(s->img,0, 0.9 , 0.9 ,0);
s->img = ts;
@ -1721,6 +1727,8 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
SDL_FreeSurface(s->img);
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)) {
/* go to tele dest */
@ -1752,14 +1760,14 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
double size;
if (timer % 2 == 0) {
/* grow */
size = (double)-s->teleporting / 10;
size = (double) -s->teleporting / 10;
SDL_FreeSurface(s->img);
if (size >= 1) {
s->allocimg = B_FALSE;
s->teleporting = 0;
s->img = imageset[s->id].img[F_WALK1];
} else {
// TODO: free old image first!!
s->img = rotozoomSurfaceXY(imageset[s->id].img[F_WALK1],0,size,size,0);
s->teleporting--;
}
@ -2829,6 +2837,10 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
s->rotated = 0;
if (levelcomplete == LV_CLOUD) {
levelcomplete = LV_CLOUDLOOP;
// stop the player teleporting if required
if (player->teleporting) {
stopteleporting(player);
}
}
} else {
@ -2850,7 +2862,6 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
s->angle += (360*(M_PI/180));
}
// figure out x/y speed
s->xs = (cos(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
s->x += s->xs;
s->y += s->ys;
// keep on screen!!
keeponscreen(s);
}
}
} else if (levelcomplete == LV_CLOUDLOOP) {
@ -2903,7 +2917,7 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n");
s->x += s->xs;
s->y += s->ys;
// keep on screen
// keep on screen (but use player height
if (s->x > 640-(s->img->w/2)) {
s->x = 640 - (s->img->w/2);
}
@ -3046,6 +3060,7 @@ void dotileeffects(sprite_t *s) {
// teleporters
if ((tt->id == T_TELEPORT) || (tt->id == T_TELEPORT2)) {
//if (!isendoflev()) { // can't enter teleporters after level end to avoid cloud moving too far
if (s == player || ismonster(s->id)) {
if (s->id != P_BLACKCLOUD) {
if (!s->teleporting) {
@ -3054,6 +3069,7 @@ void dotileeffects(sprite_t *s) {
}
}
}
// }
}
@ -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);
int submithiscore(int score,int level, char *name);
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->allocimg = B_FALSE;
s->frame = 0;
@ -3179,27 +3180,27 @@ void drawplayer(sprite_t *s, SDL_Rect *where) {
wingframe = 0;
}
wingarea.x = player->x - (imageset[P_WINGRIGHT].img[wingframe]->w/2);
wingarea.y = player->y - (imageset[P_WINGRIGHT].img[wingframe]->h);
wingarea.x = s->x - (imageset[P_WINGRIGHT].img[wingframe]->w/2);
wingarea.y = s->y - (imageset[P_WINGRIGHT].img[wingframe]->h);
if (wingframe == 0) { // still
wingarea.x += (4*player->dir);
wingarea.x += (4*s->dir);
wingarea.y += 2;
} else if ((wingframe >= 1) && (wingframe <= 2)) { // flapping
wingarea.x += (11*player->dir);
wingarea.x += (11*s->dir);
wingarea.y -= 9;
}
// when climbing, show "left" wing twice instead
// when swimming, only show left wing
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);
}
}
#endif
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
@ -3222,33 +3223,33 @@ void drawplayer(sprite_t *s, SDL_Rect *where) {
wingframe = 0;
}
wingarea.x = player->x - (imageset[P_WINGLEFT].img[wingframe]->w/2);
wingarea.y = player->y - (imageset[P_WINGLEFT].img[wingframe]->h);
wingarea.x = s->x - (imageset[P_WINGLEFT].img[wingframe]->w/2);
wingarea.y = s->y - (imageset[P_WINGLEFT].img[wingframe]->h);
if (wingframe == 0) { // still
if (s->climbing) {
wingarea.x -= 4;
wingarea.y += 2;
} else {
wingarea.x -= (6*player->dir);
wingarea.x -= (6*s->dir);
wingarea.y += 2;
}
} else if ((wingframe >= 1) && (wingframe <= 2)) { // flapping
wingarea.x -= (11*player->dir);
wingarea.x -= (11*s->dir);
wingarea.y -= 9;
} else if (wingframe == 3) {
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);
if (s->climbing) {
// draw the other wing
wingarea.x += 8;
// reverse it
if (player->dir == -1) wingframe -= MAXFRAMES;
if (s->dir == -1) wingframe -= MAXFRAMES;
else wingframe += MAXFRAMES;
doblit(imageset[P_WINGLEFT].img[wingframe], screen, &wingarea);
}