In Game Menu Created, player will be ask if he want to leave the game

origin
stpohle 22 years ago
parent 521c78ef62
commit 516058157a

@ -5,7 +5,7 @@ dnl Please disable it in the Anjuta project configuration
AC_INIT(configure.in) AC_INIT(configure.in)
AC_CANONICAL_TARGET AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(bomberclone, 0.11.3) AM_INIT_AUTOMAKE(bomberclone, 0.11.3t4)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.26 2004/05/20 16:55:30 stpohle Exp $ */ /* $Id: bomberclone.h,v 1.27 2004/06/15 15:04:37 stpohle Exp $ */
/* bomberclone.h */ /* bomberclone.h */
#ifndef _BOMBERCLONE_H_ #ifndef _BOMBERCLONE_H_
@ -119,6 +119,10 @@ extern void game_end ();
extern void game_start(); extern void game_start();
extern void game_showresult (); extern void game_showresult ();
extern void game_menu_create ();
extern void game_menu_loop (SDL_Event *event, int eventstate);
// everything is declared in field.c // everything is declared in field.c
extern void draw_field (); extern void draw_field ();
extern void field_clear(int x, int y); extern void field_clear(int x, int y);

@ -1,4 +1,4 @@
/* $Id: menu.h,v 1.11 2004/06/08 22:35:20 stpohle Exp $ /* $Id: menu.h,v 1.12 2004/06/15 15:04:37 stpohle Exp $
* GUI for menuhandling * GUI for menuhandling
*/ */
@ -54,6 +54,7 @@ struct {
_menuitem *focus; _menuitem *focus;
SDL_Surface *oldscreen; // hold old screendata SDL_Surface *oldscreen; // hold old screendata
SDL_Rect oldscreenpos; SDL_Rect oldscreenpos;
int oldkey;
float focusto; float focusto;
int focusvis; int focusvis;
_menuitem menuitems[MENU_MAXENTRYS]; _menuitem menuitems[MENU_MAXENTRYS];

@ -162,16 +162,12 @@ chat_drawinput ()
src.y = chat.window.h - (font[0].size.y + 2); src.y = chat.window.h - (font[0].size.y + 2);
src.w = chat.window.w - 4; src.w = chat.window.w - 4;
src.h = font[0].size.y; src.h = font[0].size.y;
d_printsdlrect ("c.w: ", &chat.window);
d_printsdlrect ("src: ", &src);
d_printsdlrect ("dst: ", &dest);
SDL_BlitSurface (chat.oldscreen, &src, gfx.screen, &dest); SDL_BlitSurface (chat.oldscreen, &src, gfx.screen, &dest);
src.x = chat.window.x + 2; src.x = chat.window.x + 2;
src.y = chat.window.y + chat.window.h - (font[0].size.y + 2); src.y = chat.window.y + chat.window.h - (font[0].size.y + 2);
src.w = chat.window.x + chat.window.w - 4; src.w = chat.window.x + chat.window.w - 4;
src.h = chat.window.y + chat.window.h - 4; src.h = chat.window.y + chat.window.h - 4;
d_printsdlrect ("src: ", &src);
if (chat.active) if (chat.active)
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_BRIGHT); draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_BRIGHT);

@ -1,4 +1,4 @@
/* $Id: game.c,v 1.86 2004/06/11 20:29:10 stpohle Exp $ /* $Id: game.c,v 1.87 2004/06/15 15:04:37 stpohle Exp $
game.c - procedures for the game. */ game.c - procedures for the game. */
#include <string.h> #include <string.h>
@ -20,6 +20,7 @@ extern int blitdb_nr,
Uint32 game_timediff, game_timediff1; Uint32 game_timediff, game_timediff1;
static float hurrywarn_to; static float hurrywarn_to;
static int hurrywarn_state; static int hurrywarn_state;
static _menu *menu;
void void
game_draw_info () game_draw_info ()
@ -148,41 +149,55 @@ game_draw_info ()
* in the GS_wait mode the chat will always be active. * in the GS_wait mode the chat will always be active.
*/ */
void game_keys_loop () { void game_keys_loop () {
if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
/* Server is starting the game */ if (menu != NULL) {
/* delete all movement keys */
int i;
for (i = 0; i < BCPK_max * 2; i++)
keyb_gamekeys.state[i] = 0;
}
else {
/* don't go into the game_keys if there is no menu displayed */
if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
/* Server is starting the game */
bman.state = GS_running; bman.state = GS_running;
net_send_servermode (); net_send_servermode ();
bman.updatestatusbar = 1; // force an update bman.updatestatusbar = 1; // force an update
} }
if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) { if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) {
/* Switch Fullscreen */ /* Switch Fullscreen */
SDL_WM_ToggleFullScreen(gfx.screen); SDL_WM_ToggleFullScreen(gfx.screen);
gfx.fullscreen = !gfx.fullscreen; gfx.fullscreen = !gfx.fullscreen;
bman.updatestatusbar = 1; // force an update bman.updatestatusbar = 1; // force an update
} }
/* /*
if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) { if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) {
// Switch Debugmode // Switch Debugmode
debug = !debug; debug = !debug;
bman.updatestatusbar = 1; // force an update bman.updatestatusbar = 1; // force an update
} }
*/ */
if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) { if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) { if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) {
chat.active = 0; chat.active = 0;
d_printf ("Chatmode Disabled\n"); d_printf ("Chatmode Disabled\n");
}
else
game_menu_create ();
} }
else
bman.state = GS_startup;
}
if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) { if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) {
chat_setactive (1, 0); chat_setactive (1, 0);
chat.changed = 1; chat.changed = 1;
d_printf ("Chatmode Enabled\n"); d_printf ("Chatmode Enabled\n");
}
} }
}; };
@ -192,7 +207,7 @@ void
game_loop () game_loop ()
{ {
SDL_Event event; SDL_Event event;
int done = 0, i; int done = 0, i, eventstate;
gfx_blitupdaterectclear (); gfx_blitupdaterectclear ();
@ -202,13 +217,15 @@ game_loop ()
net_game_fillsockaddr (); net_game_fillsockaddr ();
SDL_Flip (gfx.screen); SDL_Flip (gfx.screen);
menu = NULL;
bman.updatestatusbar = 1; // force an update bman.updatestatusbar = 1; // force an update
timestamp = SDL_GetTicks (); // needed for time sync. timestamp = SDL_GetTicks (); // needed for time sync.
d_gamedetail ("GAME START"); d_gamedetail ("GAME START");
draw_players (); draw_players ();
while (!done && (bman.state == GS_running || bman.state == GS_ready)) { while (!done && (bman.state == GS_running || bman.state == GS_ready)) {
if (SDL_PollEvent (&event) != 0) if ((eventstate = SDL_PollEvent (&event)) != 0)
switch (event.type) { switch (event.type) {
case (SDL_QUIT): case (SDL_QUIT):
done = 1; done = 1;
@ -269,6 +286,11 @@ game_loop ()
} }
stonelist_draw (); stonelist_draw ();
/* if there is any menu displayed do so */
if (menu != NULL)
game_menu_loop (&event, eventstate);
gfx_blitdraw (); gfx_blitdraw ();
s_calctimesync (); s_calctimesync ();
bman.timeout -= timediff; bman.timeout -= timediff;
@ -495,7 +517,6 @@ void game_showresult () {
if ((keys[SDLK_RETURN] || keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed) && (event.type = SDL_KEYDOWN)) { if ((keys[SDLK_RETURN] || keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed) && (event.type = SDL_KEYDOWN)) {
done = 1; done = 1;
keypressed = 1; keypressed = 1;
bman.state = GS_running;
} }
if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) { if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) {
@ -512,4 +533,66 @@ void game_showresult () {
s_delay (25); s_delay (25);
} }
if (bman.state != GS_quit && bman.state != GS_startup)
bman.state = GS_running;
};
/*
* create the in game menu
*/
void game_menu_create () {
if (menu != NULL)
return;
menu = menu_new ("Gamemenu", 300, 150);
menu_create_button (menu, "Back to the Game", -1, 50, 200, 1);
if (GT_SP || GT_MP_PTPM)
menu_create_button (menu, "End this Round", -1, 80, 200, 2);
menu_create_button (menu, "Quit the Game", -1, 110, 200, 3);
menu_focus_id (menu, 1);
menu->looprunning = 1;
};
/*
* in game menu_loop, will called every game loop.
* As long as this menu is displayed the gamekeys will not work.
*
* the drawings will be done from the main loop. So we won't
* have to draw anything on our own.
*
* Pressing ESC will bring you back to the game.
*/
void game_menu_loop (SDL_Event *event, int eventstate) {
int done;
if (menu == NULL)
return;
menu_draw (menu);
done = menu_event_loop (menu, event, eventstate);
/*
* check if one of the buttons was pressed
*/
if (done != 0) {
if (menu->focus->id == 2 && (GT_MP_PTPM || GT_SP)) { /* End Round */
bman.timeout = -GAME_OVERTIMEOUT;
}
else if (menu->focus->id == 3) /* End Game */
bman.state = GS_startup;
else { /* Quit Menu */
menu_delete (menu);
menu = NULL;
gfx_blitdraw ();
draw_field ();
}
}
}; };

@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.44 2004/06/08 22:35:26 stpohle Exp $ /* $Id: menu.c,v 1.45 2004/06/15 15:04:37 stpohle Exp $
* Menuhandling */ * Menuhandling */
#include "basic.h" #include "basic.h"
@ -45,6 +45,8 @@ menu_new (char *title, int x, int y)
menu->focus = NULL; menu->focus = NULL;
menu->looprunning = 0; menu->looprunning = 0;
menu->oldkey = 1;
return menu; return menu;
}; };
@ -435,6 +437,11 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate)
int done = 0; int done = 0;
if (eventstate >= 1) { if (eventstate >= 1) {
/* make sure no old key is disturbing us */
if (event->type != SDL_KEYDOWN)
menu->oldkey = 0;
switch (event->type) { switch (event->type) {
case (SDL_QUIT): case (SDL_QUIT):
bman.state = GS_quit; bman.state = GS_quit;
@ -442,7 +449,7 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate)
return 1; return 1;
break; break;
case (SDL_KEYDOWN): /* focus next element */ case (SDL_KEYDOWN): /* focus next element */
if (event->key.keysym.sym == SDLK_TAB) { if (menu->oldkey == 0 && event->key.keysym.sym == SDLK_TAB) {
keys = SDL_GetKeyState (NULL); keys = SDL_GetKeyState (NULL);
if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])
menu_focus_prev (menu); menu_focus_prev (menu);
@ -450,7 +457,7 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate)
menu_focus_next (menu); menu_focus_next (menu);
break; break;
} }
else if (event->key.keysym.sym == SDLK_ESCAPE) { else if (menu->oldkey == 0 && event->key.keysym.sym == SDLK_ESCAPE) {
return -1; return -1;
break; break;
} }
@ -476,6 +483,8 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate)
} }
} }
} }
else
menu->oldkey = 0;
menu->focusto -= timediff; menu->focusto -= timediff;
if (menu->focusto <= 0.0f) { if (menu->focusto <= 0.0f) {

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.66 2004/06/13 23:34:10 stpohle Exp $ */ /* $Id: single.c,v 1.67 2004/06/15 15:04:37 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"
@ -637,9 +637,12 @@ single_playergame (int second_player, int ai_players)
game_start (); game_start ();
bman.state = GS_running; bman.state = GS_running;
game_loop (); game_loop ();
bman.state = GS_ready;
game_end (); game_end ();
} }
gfx_blitdraw ();
draw_logo ();
gfx_blitdraw ();
}; };

Loading…
Cancel
Save