From 175b59863c50c239244afa7cbc1ac5e168fcfe15 Mon Sep 17 00:00:00 2001 From: stpohle Date: Fri, 25 Jul 2003 12:28:50 +0000 Subject: [PATCH] Single Playerselection finished --- ChangeLog | 11 +- src/game.c | 2 +- src/gfx.h | 3 +- src/gfxengine.c | 4 +- src/menu.c | 4 +- src/single.c | 352 ++++++++++++++++++++++++++++++++++++++---------- 6 files changed, 292 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac667d3..4cd6dd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,15 @@ -$Id: ChangeLog,v 1.31 2003/07/24 13:04:50 stpohle Exp $ +$Id: ChangeLog,v 1.32 2003/07/25 12:28:50 stpohle Exp $ Version 0.9.10 ============== -- scaling routine speeded up a little. Using inline functions - and much less "switch case". +- Makefile.am fixed in the data direktory. Added + ${prefix}/ and changed @PREFIX_PACKAGE_DATA_DIR@ to + @NO_PREFIX_PACKAGE_DATA_DIR@ . So debian packages + can be generated easyly soon. + +- scaling routine speeded up a little bit. Using inline + functions and much less "switch case". - TekKRat made two new players, the first two tilesets with the pseudo 3D effect diff --git a/src/game.c b/src/game.c index 598e9dd..fcaa880 100644 --- a/src/game.c +++ b/src/game.c @@ -70,7 +70,7 @@ game_draw_info () x = x + 170; if (x >= gfx.res.x - (120 + 170)) { x = 0; - j = j + font[0].size.x; + j = j + 2 * font[0].size.x; } } diff --git a/src/gfx.h b/src/gfx.h index 01004e6..749c4d7 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -1,4 +1,4 @@ -/* $Id: gfx.h,v 1.17 2003/07/24 13:04:50 stpohle Exp $ */ +/* $Id: gfx.h,v 1.18 2003/07/25 12:28:50 stpohle Exp $ */ #ifndef _GFX_H_ #define _GFX_H_ @@ -31,7 +31,6 @@ struct __gfxani { struct __gfxplayer { _gfxani ani; _point offset; -// _point size; // height of the image.. needed for faster access. _point smal_size; SDL_Surface *smal_image; // smal size of the animation } typedef _gfxplayer; diff --git a/src/gfxengine.c b/src/gfxengine.c index 2ca19a3..2aa0c63 100644 --- a/src/gfxengine.c +++ b/src/gfxengine.c @@ -1,4 +1,4 @@ -/* $Id: gfxengine.c,v 1.1 2003/07/22 18:29:08 stpohle Exp $ */ +/* $Id: gfxengine.c,v 1.2 2003/07/25 12:28:50 stpohle Exp $ */ /* GFX Game Engine */ #include "bomberclone.h" @@ -95,7 +95,7 @@ gfx_blitdraw () { int i; - if (blitdb_nr <= 0) { + if (blitdb_nr < 0) { blitdb_nr = 0; return; } diff --git a/src/menu.c b/src/menu.c index f68cb88..407caa6 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.28 2003/07/22 18:29:08 stpohle Exp $ */ +/* $Id: menu.c,v 1.29 2003/07/25 12:28:50 stpohle Exp $ */ /* menu's for the game */ #include @@ -180,7 +180,7 @@ menu_loop (char *menutitle, _menu menu[], int lastselect) ds = 1; } - if (keys[SDLK_RETURN] && (!keypressed) && (event.type = SDL_KEYDOWN)) { + if ((keys[SDLK_LCTRL] || keys[SDLK_RCTRL] || keys[SDLK_RETURN]) && (!keypressed) && (event.type = SDL_KEYDOWN)) { done = 1; keypressed = 1; // d_printf("return pressed - done=1\n"); diff --git a/src/single.c b/src/single.c index 41492a9..a7b8c9f 100644 --- a/src/single.c +++ b/src/single.c @@ -1,4 +1,4 @@ -/* $Id: single.c,v 1.37 2003/07/24 01:47:48 stpohle Exp $ */ +/* $Id: single.c,v 1.38 2003/07/25 12:28:50 stpohle Exp $ */ /* single player */ #include "basic.h" @@ -34,9 +34,9 @@ single_game_new () for (i = 0; i < MAX_BOMBS; i++) { bman.players[p].bombs[i].state = BS_off; bman.players[p].bombs[i].ex_nr = -1; - bman.players[p].bombs[i].moves = 0; - bman.players[p].bombs[i].moveto.x = 0; - bman.players[p].bombs[i].moveto.y = 0; + bman.players[p].bombs[i].moves = 0; + bman.players[p].bombs[i].moveto.x = 0; + bman.players[p].bombs[i].moveto.y = 0; } for (i = 0; i < PI_max; i++) @@ -60,7 +60,9 @@ single_game_new () inline int ai_checkfield (int x, int y) { - return ((map.field[x][y].type == FT_nothing || map.field[x][y].type == FT_fire || map.field[x][y].type == FT_shoe || map.field[x][y].type == FT_bomb ) && map.bfield[x][y] == 0); + return ((map.field[x][y].type == FT_nothing || map.field[x][y].type == FT_fire + || map.field[x][y].type == FT_shoe || map.field[x][y].type == FT_bomb) + && map.bfield[x][y] == 0); } @@ -290,11 +292,13 @@ ai_bombpoints (_point pos, int range) p.y += m.y; } - if (map.field[p.x][p.y].type != FT_nothing && (map.field[p.x][p.y].type != FT_block || map.field[p.x][p.y].type == FT_shoe || map.field[p.x][p.y].type == FT_bomb || map.field[p.x][p.y].type == FT_fire)) + if (map.field[p.x][p.y].type != FT_nothing + && (map.field[p.x][p.y].type != FT_block || map.field[p.x][p.y].type == FT_shoe + || map.field[p.x][p.y].type == FT_bomb || map.field[p.x][p.y].type == FT_fire)) points++; - if (map.field[p.x][p.y].type == FT_shoe || map.field[p.x][p.y].type == FT_bomb || - map.field[p.x][p.y].type == FT_fire) - points += 2; + if (map.field[p.x][p.y].type == FT_shoe || map.field[p.x][p.y].type == FT_bomb || + map.field[p.x][p.y].type == FT_fire) + points += 2; } } @@ -313,8 +317,8 @@ ai_findbestbombdir (_point pos, int dir, int range) int d, done = 0, j, - maxpoints = 0, - bestd; + maxpoints = 0, + bestd; _point m[4], p[4]; @@ -352,36 +356,35 @@ ai_findbestbombdir (_point pos, int dir, int range) if (d < 4) { p[d].x += m[d].x; p[d].y += m[d].y; - if (p[d].x > 0 && p[d].y > 0 && p[d].x < map.size.x - 1 - && p[d].y < map.size.y - 1) { - if (ai_checkfield (p[d].x, p[d].y)) { - /* we are opn a empty field go on with the test */ - done = 0; - j = ai_bombpoints (p[d], range); - if (points[d] < j) - points[d] = j; - } - else /* no empty field */ - p[d].x = p[d].y = -1; + if (p[d].x > 0 && p[d].y > 0 && p[d].x < map.size.x - 1 && p[d].y < map.size.y - 1) { + if (ai_checkfield (p[d].x, p[d].y)) { + /* we are opn a empty field go on with the test */ + done = 0; + j = ai_bombpoints (p[d], range); + if (points[d] < j) + points[d] = j; + } + else /* no empty field */ + p[d].x = p[d].y = -1; } } - if (maxpoints < points[d]) - maxpoints = points[d]; + if (maxpoints < points[d]) + maxpoints = points[d]; } } - bestd = 0; - if (maxpoints > 2) - maxpoints--; + bestd = 0; + if (maxpoints > 2) + maxpoints--; + + for (d = 0; d < 5; d++) + if (points[d] >= maxpoints) + bestd |= (1 << d); - for (d = 0; d < 5; d++) - if (points[d] >= maxpoints) - bestd |= (1 << d); - - /* prevent from turning around */ - if (dir != -1 && (bestd & (0xFF -(1 << ai_invertdir(dir))))) - bestd &= (0xFF - (1 << ai_invertdir(dir))); + /* prevent from turning around */ + if (dir != -1 && (bestd & (0xFF - (1 << ai_invertdir (dir))))) + bestd &= (0xFF - (1 << ai_invertdir (dir))); return bestd; } @@ -568,7 +571,10 @@ ai_checknewpos (_point pos, int d) void single_create_ai (int players) { - int p, count, gfx_sel, i = 0; + int p, + count, + gfx_sel, + i = 0; _player *pl; for (count = 0; count < players; count++) { @@ -576,15 +582,15 @@ single_create_ai (int players) for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++) if (!(PS_IS_used (bman.players[p].state))) { pl = &bman.players[p]; - sprintf (pl->name, "AI %d", count+1); + sprintf (pl->name, "AI %d", count + 1); pl->state |= PSF_used + PSF_alife + PSF_playing; - do { - gfx_sel = s_random (MAX_PLAYERS); - MW_IS_GFX_SELECT (gfx_sel, i); - } while (i != -1); + do { + gfx_sel = s_random (MAX_PLAYERS); + MW_IS_GFX_SELECT (gfx_sel, i); + } while (i != -1); player_set_gfx (pl, gfx_sel); } - + if (pl == NULL) return; } @@ -595,16 +601,17 @@ single_create_ai (int players) void single_playergame () { - int p, done = 0; + int p, + done = 0; /* delete player from the game */ for (p = 0; p < MAX_PLAYERS; p++) { - bman.players[p].points = 0; - bman.players[p].wins = 0; + bman.players[p].points = 0; + bman.players[p].wins = 0; bman.players[p].state = 0; - } - - for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++) + } + + for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++) if (!(PS_IS_used (bman.players[p].state))) bman.p_nr = p; @@ -613,20 +620,20 @@ single_playergame () exit (1); } - if ((bman.players[bman.p_nr].gfx_nr = single_select_player ()) == -1) - return; + if ((bman.players[bman.p_nr].gfx_nr = single_select_player ()) == -1) + return; - bman.players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing; - strncpy (bman.players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME); + bman.players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing; + strncpy (bman.players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME); single_create_ai (bman.ai_players); - bman.state = GS_ready; - - while (!done && bman.state != GS_quit && bman.state != GS_startup) { - single_game_new (); - game_start (); - game_loop (); - game_end (); - } + bman.state = GS_ready; + + while (!done && bman.state != GS_quit && bman.state != GS_startup) { + single_game_new (); + game_start (); + game_loop (); + game_end (); + } }; @@ -689,8 +696,10 @@ single_loop () }; -/* singleplayer menü with some options you can make */ -void single_menu () { +/* singleplayer menü with some options you can make */ + void +single_menu () +{ int menuselect = 0; _menu menu[] = { {1, "Start Game"}, @@ -701,23 +710,23 @@ void single_menu () { }; while (menuselect != -1 && bman.state != GS_quit) { - sprintf (menu[1].text, "%d AI Player", bman.ai_players); + sprintf (menu[1].text, "%d AI Player", bman.ai_players); menuselect = menu_loop ("Single Player", menu, menuselect); switch (menuselect) { case (0): // Start Game - single_playergame (); + single_playergame (); break; case (1): // Change number of Player - bman.ai_players++; - if (bman.ai_players >= MAX_PLAYERS) { - if (debug) - bman.ai_players = 0; // null players with debugging on - else - bman.ai_players = 1; - } - break; + bman.ai_players++; + if (bman.ai_players >= MAX_PLAYERS) { + if (debug) + bman.ai_players = 0; // null players with debugging on + else + bman.ai_players = 1; + } + break; case (2): // Map Options - mapmenu(); + mapmenu (); break; case (3): menuselect = -1; @@ -729,6 +738,201 @@ void single_menu () { /* single player selection return value the gfx of the player or -1 for escape */ -int single_select_player () { - return 0; +int +single_select_player () +{ + int selgfx = 0, + done = 0, + x, + y, + keypressed = 0, + frame = 0, + d = 0, + dto = 2, + newplayer = -1, + pos = 0, + i; + SDL_Rect dest, + src; + char text[255]; + SDL_Event event; + Uint8 *keys; + Uint32 timeloop1, timediff; + + menu_displaytext ("Loading..", "Please Wait", 32, 128, 32); + + dest.x = dest.y = 0; + dest.w = gfx.res.x; + dest.h = gfx.res.y; + + gfx_load_players (64, 64); + gfx_blitupdaterectclear (); + + draw_logo (); + + strcpy (text, "Select your Player"); + x = (gfx.res.x - (font[2].size.x * strlen (text)) - 64) / 2; + y = (gfx.res.y - font[2].size.y - 64 - 128) / 2; + font_setcolor (128, 128, 0, 2); + font_draw (x - 2, y, text, 2); + font_draw (x + 2, y, text, 2); + font_draw (x, y - 2, text, 2); + font_draw (x, y + 2, text, 2); + font_setcolor (255, 255, 128, 2); + font_draw (x, y, text, 2); + + gfx_blitupdaterectadd (&dest); + + while (!done) { + + /* draw selected player */ + frame++; + if (frame >= gfx.players[selgfx].ani.frames) { + frame = 0; + if (dto-- <= 0 && newplayer == -1) { + dto = 5; + if (d == up) + d = left; + else if (d == left) + d = down; + else if (d == down) + d = right; + else + d = up; + } + } + + if (newplayer != -1) { + SDL_Rect dest1, + src1; + + pos += 8; + + if (d == left) { + /* image 1 */ + src.h = dest.h = gfx.players[selgfx].ani.h; + src.w = dest.w = gfx.players[selgfx].ani.w; + src.x = gfx.players[selgfx].ani.w * d; + src.y = gfx.players[selgfx].ani.h * frame; + dest.x = ((gfx.res.x - gfx.players[selgfx].ani.w) / 2) - pos; + dest.y = y + font[0].size.y + 64; + + /* image 2 */ + src1.h = dest1.h = gfx.players[newplayer].ani.h; + src1.w = dest1.w = gfx.players[newplayer].ani.w; + src1.x = gfx.players[newplayer].ani.w * d; + src1.y = gfx.players[newplayer].ani.h * frame; + dest1.x = ((gfx.res.x - gfx.players[newplayer].ani.w) / 2) + ((gfx.res.x / 2)+ 128) - pos; + dest1.y = y + font[0].size.y + 64; + } + else { + /* image 1 */ + src.h = dest.h = gfx.players[selgfx].ani.h; + src.w = dest.w = gfx.players[selgfx].ani.w; + src.x = gfx.players[selgfx].ani.w * d; + src.y = gfx.players[selgfx].ani.h * frame; + dest.x = ((gfx.res.x - gfx.players[selgfx].ani.w) / 2) + pos; + dest.y = y + font[0].size.y + 64; + + /* image 2 */ + src1.h = dest1.h = gfx.players[newplayer].ani.h; + src1.w = dest1.w = gfx.players[newplayer].ani.w; + src1.x = gfx.players[newplayer].ani.w * d; + src1.y = gfx.players[newplayer].ani.h * frame; + dest1.x = ((gfx.res.x - gfx.players[newplayer].ani.w) / 2) - ((gfx.res.x / 2)+ 128) + pos; + dest1.y = y + font[0].size.y + 64; + } + + redraw_logo (0, y + font[0].size.y + 64, gfx.res.x, 128); + + if (dest.x + dest.w > 0) + gfx_blit (gfx.players[selgfx].ani.image, &src, gfx.screen, &dest, 0); + if (dest1.x + dest1.w > 0) + gfx_blit (gfx.players[newplayer].ani.image, &src1, gfx.screen, &dest1, 0); + + if (pos > (gfx.res.x / 2)+ 128) { + selgfx = newplayer; + newplayer = -1; + pos = 0; + } + frame++; + } + else { + src.h = dest.h = gfx.players[selgfx].ani.h; + src.w = dest.w = gfx.players[selgfx].ani.w; + src.x = gfx.players[selgfx].ani.w * d; + src.y = gfx.players[selgfx].ani.h * frame; + dest.x = (gfx.res.x - gfx.players[selgfx].ani.w) / 2; + dest.y = y + font[0].size.y + 64; + redraw_logo (dest.x, dest.y, dest.w, dest.h); + gfx_blit (gfx.players[selgfx].ani.image, &src, gfx.screen, &dest, 0); + } + + gfx_blitdraw (); + + /* do the keyboard handling */ + if (SDL_PollEvent (&event) != 0) + switch (event.type) { + case (SDL_QUIT): + bman.state = GS_quit; + bman.p_nr = -1; + done = 1; + selgfx = -1; + } + + keys = SDL_GetKeyState (NULL); + + if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) { + /* we want to quit */ + done = 1; + bman.p_nr = -1; + keypressed = 1; + bman.state = GS_startup; + selgfx = -1; + } + + if (keys[SDLK_LEFT] && (!keypressed) && newplayer == -1) { + newplayer = selgfx - 1; + if (newplayer < 0) + newplayer = MAX_PLAYERS - 1; + d = left; + } + + if (keys[SDLK_RIGHT] && (!keypressed) && newplayer == -1) { + newplayer = selgfx + 1; + if (newplayer >= MAX_PLAYERS) + newplayer = 0; + d = right; + } + + if (keys[SDLK_RETURN] && (!keypressed) && (event.type = SDL_KEYDOWN) && newplayer == -1) { + done = 1; + keypressed = 1; + // d_printf("return pressed - done=1\n"); + } + if (event.type == SDL_KEYUP) + keypressed = 0; + else if (event.type == SDL_KEYDOWN) + keypressed = 1; + + // calculate time sync. + timeloop1 = SDL_GetTicks (); + timediff = timeloop1 - timestamp; // only for debugging needed + + if (newplayer != -1) + i = 17; + else + i = 25; + + while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < i) { + s_delay (i - (timeloop1 - timestamp) - 1); + timeloop1 = SDL_GetTicks (); + } + + timestamp = timeloop1; + } + + gfx_free_players (); + + return selgfx; };