diff --git a/src/basic.h b/src/basic.h index e418aa2..e9b60ec 100644 --- a/src/basic.h +++ b/src/basic.h @@ -124,6 +124,15 @@ enum _fieldtype { FT_max // just to know how many types there are }; + +enum _poweruptypes { + PWUP_good = 0, + PWUP_bad, + PWUP_special, + PWUP_max +}; + + enum _special { SP_nothing=0, // player has no special SP_trigger, // triggered bomb diff --git a/src/field.c b/src/field.c index 4de2100..25ce22e 100644 --- a/src/field.c +++ b/src/field.c @@ -1,4 +1,4 @@ -/* $Id: field.c,v 1.24 2003/06/01 23:08:34 stpohle Exp $ */ +/* $Id: field.c,v 1.25 2003/06/02 21:21:17 stpohle Exp $ */ /* field.c - procedures which are needed to control the field */ #include @@ -39,6 +39,14 @@ draw_stone (int x, int y) SDL_BlitSurface (gfx.field[FT_nothing].image, &srcbg, gfx.screen, &dest); } + if (stone->type == FT_mixed) { + i = 0; + while (i < FT_death || i == FT_mixed || i >= FT_max) + i = s_random (FT_max - FT_death) + FT_death; + } + else + i = stone->type; + /* animate the stone if needed only for exploding stone */ if (stone->type == FT_stone && stone->frame > 0) { field_animation_add (x, y); @@ -57,20 +65,29 @@ draw_stone (int x, int y) src.y = 0; srcimg = gfx.field[stone->type].image; } - + /* some powerup so we need to animate this too */ - else if (stone->type >= FT_death) { + if (i == FT_death) + d = PWUP_bad; + else if (i > FT_death && i < FT_sp_trigger) + d = PWUP_good; + else + d = PWUP_special; + + + if (i >= FT_death) { field_animation_add (x, y); - - srcimg = gfx.powerup.image; + srcimg = gfx.powerup[d].image; + if (stone->frame >= gfx.powerup[d].frames) + stone->frame = 0; src.y = stone->frame * gfx.block.y; - } - + } + if (srcimg != NULL) SDL_BlitSurface (srcimg, &src, gfx.screen, &dest); - if (stone->type >= FT_death) { /* draw now the powerup itself */ - srcimg = gfx.field[stone->type].image; + if (i >= FT_death) { /* draw now the powerup itself */ + srcimg = gfx.field[i].image; src.y = 0; SDL_BlitSurface (srcimg, &src, gfx.screen, &dest); } @@ -428,7 +445,7 @@ field_new (char *filename) void field_animation () { - int i; + int i,j; for (i = 0; i < MAX_FILEDANIMATION; i++) if (fieldani[i].x >= 0 && fieldani[i].x < bman.fieldsize.x && fieldani[i].y >= 0 @@ -449,13 +466,20 @@ field_animation () if (bman.field[fieldani[i].x][fieldani[i].y].frameto > 0) bman.field[fieldani[i].x][fieldani[i].y].frameto--; } - else { + else { /* animation is a powerup */ + /* select right powerup animation */ + if (bman.field[fieldani[i].x][fieldani[i].y].type == FT_death) + j = PWUP_bad; + else if (bman.field[fieldani[i].x][fieldani[i].y].type > FT_sp_trigger) + j = PWUP_special; + else + j = PWUP_good; if (bman.field[fieldani[i].x][fieldani[i].y].frameto-- <= 0 || bman.field[fieldani[i].x][fieldani[i].y].frameto > ANI_STONETIMEOUT) { bman.field[fieldani[i].x][fieldani[i].y].frameto = ANI_STONETIMEOUT; bman.field[fieldani[i].x][fieldani[i].y].frame++; } - if (bman.field[fieldani[i].x][fieldani[i].y].frame >= gfx.powerup.frames) + if (bman.field[fieldani[i].x][fieldani[i].y].frame >= gfx.powerup[j].frames) bman.field[fieldani[i].x][fieldani[i].y].frame = 0; } draw_stone (fieldani[i].x, fieldani[i].y); diff --git a/src/gfx.c b/src/gfx.c index 70287ab..c18eda6 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -775,6 +775,7 @@ gfx_copyscreen (SDL_Rect * wnd) return res; }; + /* load the tileset or if not present the files from the default folder */ void gfx_load_tileset (char *tilesetname) @@ -853,27 +854,40 @@ gfx_load_tileset (char *tilesetname) SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage1); - /* load the powerup image */ - sprintf (fullname, "%s/tileset/%s/powerup.bmp", bman.datapath, tileset); - tmpimage = SDL_LoadBMP (fullname); - if (tmpimage == NULL) { - /* file could not be load, so load teh default tileset */ - sprintf (fullname, "%s/tileset/default/powerup.bmp", bman.datapath); - tmpimage = SDL_LoadBMP (fullname); - if (tmpimage == NULL) { - printf ("default tileset could not be loaded.\n"); - exit (1); - } - } - gfx.powerup.frames = tmpimage->h / GFX_IMGSIZE; - tmpimage1 = - scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x, - gfx.powerup.frames * gfx.block.y); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 0, 255)); - gfx.powerup.image = SDL_DisplayFormat (tmpimage1); - SDL_FreeSurface (tmpimage); - SDL_FreeSurface (tmpimage1); - + /* load the powerup's image */ + for (i = 0; i < PWUP_max; i++) { + switch (i) { + case (PWUP_good): + sprintf (filename,"powerup.bmp"); + break; + case (PWUP_bad): + sprintf (filename,"powerbad.bmp"); + break; + default: + sprintf (filename,"powersp.bmp"); + break; + } + + sprintf (fullname, "%s/tileset/%s/%s", bman.datapath, tileset, filename); + tmpimage = SDL_LoadBMP (fullname); + if (tmpimage == NULL) { + /* file could not be load, so load teh default tileset */ + sprintf (fullname, "%s/tileset/default/%s", bman.datapath, filename); + tmpimage = SDL_LoadBMP (fullname); + if (tmpimage == NULL) { + printf ("default tileset could not be loaded.\n"); + exit (1); + } + } + gfx.powerup[i].frames = tmpimage->h / GFX_IMGSIZE; + tmpimage1 = + scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x, + gfx.powerup[i].frames * gfx.block.y); + SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 0, 255)); + gfx.powerup[i].image = SDL_DisplayFormat (tmpimage1); + SDL_FreeSurface (tmpimage); + SDL_FreeSurface (tmpimage1); + } /* loading the field images */ for (i = 0; i < FT_max; i++) { switch (i) { @@ -912,13 +926,7 @@ gfx_load_tileset (char *tilesetname) continue; // remove this if you find a kick image break; } - if (i == FT_mixed) { - tmpimage = - gfx_quater_image (gfx.field[FT_bomb].image, gfx.field[FT_fire].image, - gfx.field[FT_death].image, gfx.field[FT_shoe].image); - gfx.field[i].image = SDL_DisplayFormat (tmpimage); - } - else { + if (i != FT_mixed) { sprintf (fullname, "%s/tileset/%s/%s", bman.datapath, tileset, filename); tmpimage = SDL_LoadBMP (fullname); if (tmpimage == NULL) { @@ -959,8 +967,9 @@ gfx_free_tileset () SDL_FreeSurface (gfx.bomb.image); if (gfx.fire.image != NULL) SDL_FreeSurface (gfx.fire.image); - if (gfx.powerup.image != NULL) - SDL_FreeSurface (gfx.powerup.image); + for (i = 0; i < PWUP_max; i++) + if (gfx.powerup[i].image != NULL) + SDL_FreeSurface (gfx.powerup[i].image); gfx.bomb.image = NULL; gfx.fire.image = NULL; }; diff --git a/src/gfx.h b/src/gfx.h index 186ca17..b512379 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -46,7 +46,7 @@ struct __gfx { short int postab[256]; // table of points where we need to go to. _gfxani field[FT_max]; // the field animations - _gfxani powerup; // powerup field animation + _gfxani powerup[3]; // powerup field animation _gfxani fire; // fire (explostion) _gfxani bomb; // bomb animation _gfxani ill; // sick animation above the player