From 56b1106ab2f4ed72c7c8a1e0f8503838676cd9f8 Mon Sep 17 00:00:00 2001 From: stpohle Date: Sat, 7 Feb 2004 13:35:28 +0000 Subject: [PATCH] MENU_image element added, Manual Screen in the game added. --- bomberclone.prj | 4 +- include/bomberclone.h | 8 +- include/menu.h | 10 ++- include/menugui.h | 5 +- src/Makefile.am | 4 +- src/game.c | 4 +- src/gfx.c | 14 +--- src/help.c | 127 +++++++++++++++++++++++++++++++ src/main.c | 14 ++-- src/menu.c | 24 ++++-- src/menuimages.c | 64 ++++++++++++++++ src/menulabels.c | 23 +++++- src/tileset.c | 171 +++++++++++++++++++++++------------------- 13 files changed, 363 insertions(+), 109 deletions(-) create mode 100644 src/help.c create mode 100644 src/menuimages.c diff --git a/bomberclone.prj b/bomberclone.prj index 5636c85..785d467 100644 --- a/bomberclone.prj +++ b/bomberclone.prj @@ -140,7 +140,9 @@ module.source.files=\ menulists.c\ ogcache-client.c\ netsrvlist.c\ - flyingitems.c + flyingitems.c\ + help.c\ + menuimages.c module.pixmap.name=pixmaps module.pixmap.type= diff --git a/include/bomberclone.h b/include/bomberclone.h index bd61308..240ce91 100644 --- a/include/bomberclone.h +++ b/include/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.22 2004/02/05 21:32:13 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.23 2004/02/07 13:35:28 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -282,8 +282,12 @@ extern void special_row (int p_nr); extern void special_trigger (int p_nr); extern void special_liquidmoved (int p_nr); -extern void tileset_load (char *tileset); +extern void tileset_load (char *tileset, int dx, int dy); extern void tileset_random (); extern void tileset_free (); + +// help +extern void help (); + #endif diff --git a/include/menu.h b/include/menu.h index 0b684e0..d000822 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,4 +1,4 @@ -/* $Id: menu.h,v 1.7 2004/02/07 11:47:09 stpohle Exp $ +/* $Id: menu.h,v 1.8 2004/02/07 13:35:28 stpohle Exp $ * GUI for menuhandling */ @@ -25,7 +25,8 @@ enum _menu_type { MENU_entryint16, MENU_entryfloat, MENU_bool, - MENU_list + MENU_list, + MENU_image }; @@ -39,6 +40,7 @@ struct __menuitem { _keybinput keybi; int state; char *ptrdata; // pointer to some data + SDL_Rect rect; // only used for images _charlist *list; struct __menuitem *next; @@ -67,8 +69,10 @@ extern void menu_delete (); extern void menu_create_list (char *name, int x, int y, int w, int h, _charlist *data, _charlist **selected, int id); extern void menu_create_entry (char *name, int x, int y, int w, void *data, int len, int typ, int id); extern void menu_create_label (char *name, int x, int y, int fontsize); +extern void menu_create_text (char *name, int x, int y, int maxlen, int maxlines, char *fmt,...); extern void menu_create_button (char *name, int x, int y, int w, int id); extern void menu_create_bool (char *name, int x, int y, int w, int *data, int id); +extern void menu_create_image (char *name, int x, int y, int layer, SDL_Surface *img, SDL_Rect *rect); extern int menu_loop (); extern void menu_draw_border (); extern void menu_draw_background (SDL_Rect *dest); @@ -85,6 +89,6 @@ extern int menu_create_dirlist (char *path, signed char dirflags, _charlist *cl, extern char *menu_dir_select (char *title, char *path, signed char dirflags); extern void menu_displaymessage (char *title, char *fmt,...); extern void menu_displaytext (char *title, char *fmt,...); -extern void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen); +extern void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen, int max_chars, int max_lines); #endif diff --git a/include/menugui.h b/include/menugui.h index 8be12d8..ef8797d 100644 --- a/include/menugui.h +++ b/include/menugui.h @@ -1,4 +1,4 @@ -/* $Id: menugui.h,v 1.1 2003/12/24 02:42:05 stpohle Exp $ +/* $Id: menugui.h,v 1.2 2004/02/07 13:35:28 stpohle Exp $ * Menuhandling: gui elements */ #ifndef _MENUGUI_H_ @@ -14,6 +14,9 @@ extern int menu_event_button (_menuitem *mi, SDL_Event *event); /* labels */ extern void menu_draw_label (_menuitem *mi); +/* images */ +extern void menu_draw_image (_menuitem *mi); + /* bools */ #define menu_draw_bool menu_draw_button extern int menu_event_bool (_menuitem *mi, SDL_Event *event); diff --git a/src/Makefile.am b/src/Makefile.am index 7a8543f..84db6d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ bomberclone_SOURCES = \ menuentrys.c\ menulabels.c\ menulists.c\ + menuimages.c\ map.c\ mapmenu.c\ tileset.c\ @@ -38,6 +39,7 @@ bomberclone_SOURCES = \ special.c \ sound.c\ ogcache-client.c\ - flyingitems.c + flyingitems.c\ + help.c ## bomberclone_LDADD = diff --git a/src/game.c b/src/game.c index e4126b2..9cf9491 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.78 2004/02/07 11:47:10 stpohle Exp $ +/* $Id: game.c,v 1.79 2004/02/07 13:35:28 stpohle Exp $ game.c - procedures for the game. */ #include @@ -366,7 +366,7 @@ game_start () flitems_reset (); init_map_tileset (); - tileset_load (map.tileset); + tileset_load (map.tileset, -1, -1); gfx_load_players (gfx.block.x, gfx.block.y); snd_load (map.tileset); snd_music_start (); diff --git a/src/gfx.c b/src/gfx.c index 5480446..480dea3 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,4 +1,4 @@ -/* $Id: gfx.c,v 1.33 2004/02/01 03:39:02 stpohle Exp $ */ +/* $Id: gfx.c,v 1.34 2004/02/07 13:35:28 stpohle Exp $ */ /* gfx.c */ #include "bomberclone.h" @@ -108,7 +108,7 @@ gfx_load_players (int sx, int sy) SDL_FreeSurface (tmpimage1); - /* load the illnessthing */ + /* load the respawn gfx */ sprintf (filename, "%s/player/respawn.png", bman.datapath); tmpimage = IMG_Load (filename); if (tmpimage == NULL) { @@ -174,7 +174,6 @@ void gfx_loaddata () { int i, j; - int r,g,b; char filename[255]; SDL_Surface *tmpimage, *tmpimage1; @@ -202,16 +201,11 @@ gfx_loaddata () /* load the menugraphics */ for (i = 0; i < 9; i++) { sprintf (filename, "%s/gfx/menu%d.png", bman.datapath, i); - tmpimage = IMG_Load (filename); - if (tmpimage == NULL) { + menu.images[i] = IMG_Load (filename); + if (menu.images[i] == NULL) { printf ("Can't load image: %s\n", SDL_GetError ()); exit (1); } - if (i == 0) - getRGBpixel (tmpimage, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, r,g,b)); - menu.images[i] = SDL_DisplayFormat (tmpimage); - SDL_FreeSurface (tmpimage); } /* load menu buttongraphic */ diff --git a/src/help.c b/src/help.c new file mode 100644 index 0000000..06393e4 --- /dev/null +++ b/src/help.c @@ -0,0 +1,127 @@ +/* $Id: help.c,v 1.1 2004/02/07 13:35:28 stpohle Exp $ + * Display complex help text and information screen about the game + */ + +#include "bomberclone.h" +#include "menu.h" + +#define HELP_MAXPAGES 3 + +void help () { + int page = 0, menuselect = 2, y = 0; + char title[255]; + SDL_Rect rect; + + menu_displaytext ("Please Wait", "Loading GFX Data"); + tileset_load ("default", 32, 32); + gfx_load_players (gfx.block.x, gfx.block.y); + + while (menuselect != -1 && menuselect != 1 && bman.state != GS_quit) { + if (page == 0) { + sprintf (title, "How To Play (%d/%d)", page + 1, HELP_MAXPAGES); + menu_new (title, 500, 400); + menu_create_text ("help", -1, 55, 53, 20, + "The goal of the game is to be the last one, " + "who is alive. You can drop bombs which will explode after " + "a certain time and destroy everything in horizontal and vertical " + "direction. So you can remove stones or kill other players. But take care. " + "Don't kill yourself otherwise the game will be over for you. During the " + "game you will find diffrenent powerups to raise your skills. If you are " + "running faster than your opponent and you have many bombs, you can catch " + "him within lots of bombs and he has no chance to escape."); + + menu_create_text ("help", -1, 255, 53, 10, + "You will get points for every player you have killed. " + "If you win the game, you can earn additional points " + "depending on how many players played the game. "); + } + else if (page == 1) { + sprintf (title, "Powerups (%d/%d)", page + 1, HELP_MAXPAGES); + menu_new (title, 500, 400); + + y = 50; + + rect.x = rect.y = 0; + rect.w = gfx.block.x; + rect.h = gfx.block.y; + + + menu_create_text ("help", -1, y, 53, 10, + "In the game you will find some diffend kind of powerups. " + "There are the powerups who give you more power for the whole game " + "and the special powerups which will hold only for a certain time."); + y += 80; + + menu_create_label ("Permanent Powerups", -1, y, 2); + y += (5 + font[2].size.y); + + menu_create_image ("pwback", 5, y, 0, gfx.powerup[0].image, &rect); + menu_create_image ("bomb", 5, y, 1, gfx.field[FT_bomb].image, &rect); + menu_create_text ("help", 55, y, 45, 10, + "Give you another bomb to drop. Maximum number of bombs is %d.", MAX_BOMBS); + y += 40; + + menu_create_image ("pwback", 5, y, 0, gfx.powerup[0].image, &rect); + menu_create_image ("fire", 5, y, 1, gfx.field[FT_fire].image, &rect); + menu_create_text ("help", 55, y, 45, 10, + "The range of your bombs will be increased. Maximum range is %d.", MAX_RANGE); + y += 40; + + menu_create_image ("pwback", 5, y, 0, gfx.powerup[0].image, &rect); + menu_create_image ("shoe", 5, y, 1, gfx.field[FT_shoe].image, &rect); + menu_create_text ("help", 55, y, 45, 10, + "This will make your player run faster. The maximum speed will be %1.2f.", MAX_SPEED); + y += 40; + + menu_create_text ("help", -1, y, 53, 10, + "Depends how the game is set up, you'll lose " + "these powerups if you die. Other players can collect them. " + "In the deathmatch mode you can keep the powerups you collected, " + "but this depends on the Game if you drop them or not."); + y += 40; + } + else if (page == 2) { + sprintf (title, "Powerups (%d/%d)", page + 1, HELP_MAXPAGES); + menu_new (title, 500, 400); + + y = 50; + + rect.x = rect.y = 0; + rect.w = gfx.block.x; + rect.h = gfx.block.y; + + menu_create_label ("Special Powerups", -1, y, 2); + y += (10 + font[2].size.y); + + menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); + menu_create_image ("kick", 5, y, 1, gfx.field[FT_sp_kick].image, &rect); + menu_create_text ("help", 55, y, 45, 10, + "Give you another bomb to drop. Maximum number of bombs is %d.", MAX_BOMBS); + y += 40; + + menu_create_image ("pwback", 5, y, 0, gfx.powerup[2].image, &rect); + menu_create_image ("push", 5, y, 1, gfx.field[FT_sp_push].image, &rect); + menu_create_text ("help", 55, y, 45, 10, + "Give you another bomb to drop. Maximum number of bombs is %d.", MAX_BOMBS); + y += 40; + } + + else break; + + if (page > 0) menu_create_button ("Previous Page", 20, 370, 150, 0); + else if (menuselect == 0) + menuselect = 2; + menu_create_button ("Main Menu", -1, 370, 150, 1); + if (page < HELP_MAXPAGES-1) menu_create_button ("Next Page", 350, 370, 150, 2); + + menu_focus_id (menuselect); + menuselect = menu_loop (); + if (menuselect == 0 && page > 0) + page--; + if (menuselect == 2 && page < HELP_MAXPAGES - 1) + page++; + menu_delete (); + } + gfx_free_players (); + tileset_free (); +}; diff --git a/src/main.c b/src/main.c index 859866c..114c8a5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.22 2004/02/07 11:47:10 stpohle Exp $ */ +/* $Id: main.c,v 1.23 2004/02/07 13:35:28 stpohle Exp $ */ #include "basic.h" #include "bomberclone.h" @@ -38,11 +38,12 @@ main (int argc, char **argv) while (menuselect != -1 && bman.state != GS_quit) { - menu_new (text, 400, 200); + menu_new (text, 400, 230); menu_create_button ("Single Game", -1, 70, 200, 0); menu_create_button ("Multiplayer Game", -1, 100, 200, 1); - menu_create_button ("Options", -1, 130, 200, 2); - menu_create_button ("Quit Game", -1, 160, 200, 3); + menu_create_button ("Options", -1, 130, 200, 2); + menu_create_button ("Manual", -1, 160, 200, 3); + menu_create_button ("Quit Game", -1, 190, 200, 4); menuselect = menu_loop (); menu_delete (); switch (menuselect) { @@ -55,7 +56,10 @@ main (int argc, char **argv) case (2) : // Options config_menu (); break; - case (3) : // Quit + case (3) : // Manual + help (); + break; + case (4) : // Quit bman.state = GS_quit; break; } diff --git a/src/menu.c b/src/menu.c index 8ad729d..3683656 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.40 2004/02/07 11:47:10 stpohle Exp $ +/* $Id: menu.c,v 1.41 2004/02/07 13:35:28 stpohle Exp $ * Menuhandling */ #include "basic.h" @@ -231,6 +231,9 @@ menu_draw_menuitem (_menuitem * m) case (MENU_list): menu_draw_list (m); break; + case (MENU_image): + menu_draw_image (m); + break; } }; @@ -578,7 +581,7 @@ menu_displaymessage (char *title, char *fmt,...) vsprintf (text, fmt, args); va_end (args); - menu_formattext (text, out, lines, &linenr, &maxlinelen); + menu_formattext (text, out, lines, &linenr, &maxlinelen, MENU_MESSAGES_MAXLINELEN, MENU_MESSAGES_MAXLINES); i = maxlinelen * font[0].size.x + 32; if (i < (strlen (title) * font[2].size.x + 16)) @@ -591,8 +594,15 @@ menu_displaymessage (char *title, char *fmt,...) menu_delete (); }; -/* format display messages */ -void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen) { +/* format messages to seperated lines + * input - input text + * out - outtext all lines will be hold in here seperated my \0 + * start - array of pointer to each line saved in out + * lines - returns number of lines saved (start must hold one pointer more as in lines defined) + * maxlinelen - returen the max lenght of chars used in one line + * max_chars - max number of chars in one line + * max_lines - max number of lines to use (start must olh one pointer more) */ +void menu_formattext (char *input, char *out, char **start, int *lines, int *maxlinelen, int max_chars, int max_lines) { int i, pos, outpos; char *tmpchar1, *tmpchar2; *maxlinelen = i = pos = outpos = *lines = 0; @@ -609,7 +619,7 @@ void menu_formattext (char *input, char *out, char **start, int *lines, int *max if (tmpchar1 == NULL) tmpchar1 = input + strlen (input); - if (tmpchar1 - (&input[i] - pos) >= MENU_MESSAGES_MAXLINELEN) { /* new line */ + if (tmpchar1 - (&input[i] - pos) >= max_chars) { /* new line */ out[outpos++] = 0; start[++(*lines)] = &out[outpos]; if (pos > *maxlinelen) @@ -632,7 +642,7 @@ void menu_formattext (char *input, char *out, char **start, int *lines, int *max pos++; } i++; - } while (i < strlen (input) && i < MENU_MESSAGES_MAXLINES * (MENU_MESSAGES_MAXLINELEN + 1) && *lines < MENU_MESSAGES_MAXLINES); + } while (i < strlen (input) && i < max_lines * (max_chars + 1) && *lines < max_lines); }; @@ -656,7 +666,7 @@ menu_displaytext (char *title, char *fmt,...) vsprintf (text, fmt, args); va_end (args); - menu_formattext (text, out, lines, &linenr, &maxlinelen); + menu_formattext (text, out, lines, &linenr, &maxlinelen, MENU_MESSAGES_MAXLINELEN, MENU_MESSAGES_MAXLINES); i = maxlinelen * font[0].size.x + 32; if (i < (strlen (title) * font[2].size.x + 16)) diff --git a/src/menuimages.c b/src/menuimages.c new file mode 100644 index 0000000..9581734 --- /dev/null +++ b/src/menuimages.c @@ -0,0 +1,64 @@ +/* $Id: menuimages.c,v 1.1 2004/02/07 13:35:28 stpohle Exp $ + * Menuhandling: labels */ + +#include "basic.h" +#include "bomberclone.h" +#include "menu.h" +#include "menugui.h" + + +/* draw the menuitem label + * menuitem->pos.[x|y] - Position inside the menu + * pos.w - Fontsize + * label - Text of the label + */ +void menu_draw_image (_menuitem *mi) { + SDL_Rect src, dest; + + if (mi->type != MENU_image) + return; + + if (mi->pos.x == -1) + dest.x = (menu.oldscreenpos.w - 2*menu.images[0]->w - mi->rect.w) / 2; + else + dest.x = mi->pos.x; + if (mi->pos.y == -1) + dest.y = (menu.oldscreenpos.h - 2*menu.images[0]->h - mi->rect.h) / 2; + else + dest.y = mi->pos.y; + + src.w = dest.w = mi->rect.w; + src.h = dest.h = mi->rect.h; + src.x = mi->rect.x; + src.y = mi->rect.y; + dest.x += menu.oldscreenpos.x + menu.images[0]->w; + dest.y += menu.oldscreenpos.y + menu.images[0]->h; + + gfx_blit ((SDL_Surface *) mi->ptrdata, &src, gfx.screen, &dest, 10000+mi->pos.w); +}; + + +void menu_create_image (char *name, int x, int y, int layer, SDL_Surface *img, SDL_Rect *rect) { + int i = menu_getlastitem(menu.items); + + if (i == -1) { /* first entry in the itemslist */ + menu.items = &menuitems[0]; + i = 0; + } + else if (i >= MENU_MAXENTRYS) { /* max items reached, ignore new item */ + d_fatal ("menu_create_image: MENU_MAXENTRYS reached. Item Ignored\n"); + return; + } + else { /* add new item to the list */ + menuitems[i].next = &menuitems[i+1]; + i++; + } + + menuitems[i].pos.x = x; + menuitems[i].pos.y = y; + menuitems[i].pos.w = layer; + menuitems[i].type = MENU_image; + menuitems[i].ptrdata = (char *) img; + menuitems[i].rect = *rect; + strncpy (menuitems[i].label, name, MENU_TITLELEN); +}; diff --git a/src/menulabels.c b/src/menulabels.c index d6bce30..d7a6bbf 100644 --- a/src/menulabels.c +++ b/src/menulabels.c @@ -1,4 +1,4 @@ -/* $Id: menulabels.c,v 1.2 2004/02/05 22:59:05 stpohle Exp $ +/* $Id: menulabels.c,v 1.3 2004/02/07 13:35:28 stpohle Exp $ * Menuhandling: labels */ #include "basic.h" @@ -53,3 +53,24 @@ void menu_create_label (char *name, int x, int y, int fontsize) { menuitems[i].type = MENU_label; strncpy (menuitems[i].label, name, MENU_TITLELEN); }; + + +/* this will wrap a text into more labels */ +void menu_create_text (char *name, int x, int y, int maxlen, int maxlines, char *fmt,...) { + char text[1024]; + char out[1024]; + char *lineptr[maxlines+1]; + int linecnt, maxchar, i; + va_list args; + + /* read the whole text and convert it to a normal char text */ + memset (text, 0, sizeof (text)); + memset (out, 0, sizeof (out)); + va_start (args, fmt); + vsprintf (text, fmt, args); + va_end (args); + + menu_formattext (text, out, lineptr, &linecnt, &maxchar, maxlen, maxlines); + for (i = 0; (i <= linecnt && i < maxlines); i++) + menu_create_label (lineptr[i], x, y + i * font[0].size.y, 0); +}; diff --git a/src/tileset.c b/src/tileset.c index 097e0f3..e381daa 100644 --- a/src/tileset.c +++ b/src/tileset.c @@ -1,4 +1,4 @@ -/* $Id: tileset.c,v 1.13 2004/01/25 02:21:01 stpohle Exp $ */ +/* $Id: tileset.c,v 1.14 2004/02/07 13:35:28 stpohle Exp $ */ /* load and select tilesets */ #include "bomberclone.h" @@ -6,37 +6,43 @@ extern int UpdateRects_nr; /* load a random tileset */ -void tileset_random () { - _direntry *destart, *de, *desel; - char path[LEN_PATHFILENAME]; - int max, sel; - - sprintf (path, "%s/tileset", bman.datapath); - desel = destart = s_getdir (path); - - for (max = 0, de = destart; de != NULL; de = de->next) - if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) - max++; - - sel = s_random (max); - d_printf ("Random Tileset %d of %d selected\n", sel, max); - - for (max = 0, de = destart; max <= sel && de != NULL; de = de->next) - if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) { - desel = de; - max++; - } - d_printf (" %s\n", desel->name); - - if (desel != NULL) - strncpy (map.tileset, desel->name, LEN_TILESETNAME); - map.tileset[LEN_TILESETNAME-1] = 0; +void +tileset_random () +{ + _direntry *destart, + *de, + *desel; + char path[LEN_PATHFILENAME]; + int max, + sel; + + sprintf (path, "%s/tileset", bman.datapath); + desel = destart = s_getdir (path); + + for (max = 0, de = destart; de != NULL; de = de->next) + if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) + max++; + + sel = s_random (max); + d_printf ("Random Tileset %d of %d selected\n", sel, max); + + for (max = 0, de = destart; max <= sel && de != NULL; de = de->next) + if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) { + desel = de; + max++; + } + d_printf (" %s\n", desel->name); + + if (desel != NULL) + strncpy (map.tileset, desel->name, LEN_TILESETNAME); + map.tileset[LEN_TILESETNAME - 1] = 0; } -/* load the tileset or if not present the files from the default folder */ +/* load the tileset or if not present the files from the default folder + * if dx or dy is set to -1 test for best tileset resolution */ void -tileset_load (char *tilesetname) +tileset_load (char *tilesetname, int dx, int dy) { int i, r, @@ -52,20 +58,27 @@ tileset_load (char *tilesetname) d_printf ("Loading Tileset: %s\n", tilesetname); strncpy (tileset, tilesetname, LEN_TILESETNAME); - /* Calculate the Best Size of the Images */ - gfx.block.x = gfx.res.x / (map.size.x + 1); - if (GT_MP && gfx.res.y == 480) - gfx.block.y = (gfx.res.y - 120) / (map.size.y + 1); - else if (GT_MP && gfx.res.y == 600) - gfx.block.y = (gfx.res.y - 140) / (map.size.y + 1); - else if (GT_MP && gfx.res.y > 600) - gfx.block.y = (gfx.res.y - 160) / (map.size.y + 1); - else - gfx.block.y = (gfx.res.y - 48) / (map.size.y + 1); - if (gfx.block.x < gfx.block.y) - gfx.block.y = gfx.block.x; - else - gfx.block.x = gfx.block.y; + /* set the block size to dx and dy, if one of both is -1 + * Calculate the Best Size of the Images */ + if (dx <= 0 || dy <= 0) { + gfx.block.x = gfx.res.x / (map.size.x + 1); + if (GT_MP && gfx.res.y == 480) + gfx.block.y = (gfx.res.y - 120) / (map.size.y + 1); + else if (GT_MP && gfx.res.y == 600) + gfx.block.y = (gfx.res.y - 140) / (map.size.y + 1); + else if (GT_MP && gfx.res.y > 600) + gfx.block.y = (gfx.res.y - 160) / (map.size.y + 1); + else + gfx.block.y = (gfx.res.y - 48) / (map.size.y + 1); + if (gfx.block.x < gfx.block.y) + gfx.block.y = gfx.block.x; + else + gfx.block.x = gfx.block.y; + } + else { + gfx.block.x = dx; + gfx.block.y = dy; + } /* create Table of points */ scale (gfx.postab, gfx.block.x, 256); @@ -165,9 +178,9 @@ tileset_load (char *tilesetname) case (FT_block): sprintf (filename, "block"); break; - case (FT_tunnel) : - sprintf (filename, "tunnel"); - break; + case (FT_tunnel): + sprintf (filename, "tunnel"); + break; case (FT_death): sprintf (filename, "pwdeath"); break; @@ -201,27 +214,31 @@ tileset_load (char *tilesetname) } if (i != FT_mixed) { sprintf (fullname, "%s/tileset/%s/%s.png", bman.datapath, tileset, filename); - gfx.field[i].w = GFX_IMGSIZE; - gfx.field[i].h = GFX_IMGSIZE; + gfx.field[i].w = GFX_IMGSIZE; + gfx.field[i].h = GFX_IMGSIZE; tmpimage = IMG_Load (fullname); if (tmpimage == NULL) { - sprintf (fullname, "%s/tileset/%s/%s96.png", bman.datapath, tileset, filename); - gfx.field[i].h = GFX_IMGBIGSIZE; - tmpimage = IMG_Load (fullname); - if (tmpimage == NULL) { - sprintf (fullname, "%s/tileset/default/%s.png", bman.datapath, filename); - gfx.field[i].h = GFX_IMGSIZE; - tmpimage = IMG_Load (fullname); - if (tmpimage == NULL) { - printf ("Can't load image: %s\n", SDL_GetError ()); - exit (1); - } - } + sprintf (fullname, "%s/tileset/%s/%s96.png", bman.datapath, tileset, filename); + gfx.field[i].h = GFX_IMGBIGSIZE; + tmpimage = IMG_Load (fullname); + if (tmpimage == NULL) { + sprintf (fullname, "%s/tileset/default/%s.png", bman.datapath, filename); + gfx.field[i].h = GFX_IMGSIZE; + tmpimage = IMG_Load (fullname); + if (tmpimage == NULL) { + printf ("Can't load image: %s\n", SDL_GetError ()); + exit (1); + } + } } gfx.field[i].frames = tmpimage->h / gfx.field[i].h; - gfx.field[i].h = (float)((float)gfx.field[i].h / (float)GFX_IMGSIZE) * (float)gfx.block.y; - gfx.field[i].w = (float)((float)gfx.field[i].w / (float)GFX_IMGSIZE) * (float)gfx.block.x; - tmpimage1 = scale_image (tmpimage, gfx.field[i].w * (tmpimage->w / GFX_IMGSIZE), gfx.field[i].frames * gfx.field[i].h); + gfx.field[i].h = + (float) ((float) gfx.field[i].h / (float) GFX_IMGSIZE) * (float) gfx.block.y; + gfx.field[i].w = + (float) ((float) gfx.field[i].w / (float) GFX_IMGSIZE) * (float) gfx.block.x; + tmpimage1 = + scale_image (tmpimage, gfx.field[i].w * (tmpimage->w / GFX_IMGSIZE), + gfx.field[i].frames * gfx.field[i].h); if (i == FT_nothing || i == FT_block || i == FT_stone) r = g = b = 255; else @@ -229,13 +246,14 @@ tileset_load (char *tilesetname) SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); gfx.field[i].image = SDL_DisplayFormat (tmpimage1); SDL_FreeSurface (tmpimage1); - if (i >= FT_sp_trigger && i < FT_max) { - // create the smal special thing - tmpimage1 = scale_image (tmpimage, 32, 32); + if (i >= FT_sp_trigger && i < FT_max) { + // create the smal special thing + tmpimage1 = scale_image (tmpimage, 32, 32); getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); - gfx.smal_special[i - FT_sp_trigger] = SDL_DisplayFormat (tmpimage1); - }; + SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, + SDL_MapRGB (tmpimage1->format, r, g, b)); + gfx.smal_special[i - FT_sp_trigger] = SDL_DisplayFormat (tmpimage1); + } SDL_FreeSurface (tmpimage); } } @@ -243,18 +261,19 @@ tileset_load (char *tilesetname) void -tileset_free () { +tileset_free () +{ int i; - + for (i = 0; i < FT_max; i++) { if (gfx.field[i].image != NULL) SDL_FreeSurface (gfx.field[i].image); gfx.field[i].image = NULL; - if (i >= FT_sp_trigger && i < FT_max) { - if (gfx.smal_special[i - FT_sp_trigger] != NULL) - SDL_FreeSurface (gfx.smal_special[i - FT_sp_trigger]); - gfx.smal_special[i - FT_sp_trigger] = NULL; - } + if (i >= FT_sp_trigger && i < FT_max) { + if (gfx.smal_special[i - FT_sp_trigger] != NULL) + SDL_FreeSurface (gfx.smal_special[i - FT_sp_trigger]); + gfx.smal_special[i - FT_sp_trigger] = NULL; + } } if (gfx.bomb.image != NULL) SDL_FreeSurface (gfx.bomb.image); @@ -263,7 +282,7 @@ tileset_free () { 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; };