Пример #1
0
/*
 * check if one key is pressed
 */
static void mw_keys_loop ()
{
    if (GT_MP_PTPM && mw_check_players () >= 2 && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
        /* min 2 players are ready for the game and
         * the start key has pressed */
        bman.state = GS_ready;
        bman.updatestatusbar = 1; // force an update
    }

    if (GT_MP_PTPM && mw_check_players () < 2 && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
        font_gfxdraw (20,20,"There are not enough configured players", 0, COLOR_brown, 0x1000);
        font_gfxdraw (20,40,"(each player needs to press Ctrl to select the role)", 0, COLOR_brown, 0x1000);
    }

    if (keyb_gamekeys.state[BCK_fullscreen]  && !keyb_gamekeys.old[BCK_fullscreen]) {
        /* Switch Fullscreen */
        SDL_WM_ToggleFullScreen(gfx.screen);
        gfx.fullscreen = !gfx.fullscreen;
        bman.updatestatusbar = 1; // force an update
        bman.updatestatusbar = 1;
    }

    if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
        /* ESCAPE key was pressed */
        net_game_send_delplayer (bman.p_nr);
        bman.state = GS_startup;
    }

    if (((IS_LPLAYER2) && keyb_gamekeys.state[BCPK_max + BCPK_drop] && !keyb_gamekeys.old[BCPK_max + BCPK_drop])
            || ((!IS_LPLAYER2) && keyb_gamekeys.state[BCPK_drop] && !keyb_gamekeys.old[BCPK_drop])) {
        /* player 1 want to select a new gfx */
        playermenu_selgfx (bman.p_nr);
        bman.updatestatusbar = 1;
        keyb_loop (NULL);	// to reload the current keys
    }

    if (IS_LPLAYER2 && keyb_gamekeys.state[BCPK_max + BCPK_max + BCPK_drop] && !keyb_gamekeys.old[BCPK_max + BCPK_max + BCPK_drop]) {
        /* player 2 want to select a new gfx */
        playermenu_selgfx (bman.p2_nr);
        bman.updatestatusbar = 1;
        keyb_loop (NULL);	// to reload the current keys
    }

    if (keyb_gamekeys.state[BCK_mapmenu] && !keyb_gamekeys.old[BCK_mapmenu] && GT_MP_PTPM) {
        /* mapmenu */
        mapmenu ();
        bman.updatestatusbar = 1;
        keyb_loop (NULL);	// to reload the current keys
    }

    if (keyb_gamekeys.state[BCK_help] && !keyb_gamekeys.old[BCK_help]) {
        /* playermenu */
        help (HP_keyboard0);
        bman.updatestatusbar = 1;
        keyb_loop (NULL);	// to reload the current keys
    }


    if (keyb_gamekeys.state[BCK_playermenu] && !keyb_gamekeys.old[BCK_playermenu]) {
        /* playermenu */
        playermenu ();
        bman.updatestatusbar = 1;
        keyb_loop (NULL);	// to reload the current keys
    }
};
Пример #2
0
/* single player game win/point screen 
 * 1. setup all player data
 * 2. setup second local player and ai players
 * 3. setup all other game related data
 */
void
single_playergame (int second_player, int ai_players)
{
    int p,
      done = 0;

	bman.p_nr = -1;
	bman.p2_nr = -1;
	
    /* delete player and teams from the game */
    for (p = 0; p < MAX_PLAYERS; p++) {
        players[p].points = 0;
        players[p].wins = 0;
        players[p].state = 0;
		players[p].team_nr = -1;
        players[p].gfx_nr = -1;
        players[p].gfx = NULL;
		memset (&players[p].net, 0x0, sizeof (_net_player));
    }

	for (p = 0; p < MAX_TEAMS; p++) {
		teams[p].wins = 0;
		teams[p].points = 0;
		
		for (done = 0; done < MAX_PLAYERS; done++)
			teams[p].players[done] = NULL;
	}
	
	done = 0;
    for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++)
        if (!(PS_IS_used (players[p].state)))
            bman.p_nr = p;
	players[bman.p_nr].team_nr = 0;

    if (bman.p_nr >= MAX_PLAYERS) {
        printf ("ERROR in function (single_game_new): couldn't find any free player\n");
        exit (1);
    }

	strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);
	do {
		done = playermenu_selgfx (bman.p_nr);
	} while (players[bman.p_nr].gfx_nr == -1 && done != -1);
		
    players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing;
    strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);

	if (done != -1 && second_player) {
		player2_join ();
		do {
			done = playermenu_selgfx (bman.p2_nr);
		} while (players[bman.p2_nr].gfx_nr == -1 && done != -1);
		players[bman.p2_nr].team_nr = 0;
	}

	if (done == -1)
		return;
	
    single_create_ai (ai_players);
	
	if (bman.gametype == GT_team) {
		playermenu ();
		team_update ();
		ai_team_choosegfx ();
	}
	
    bman.state = GS_ready;

    while (!done && bman.state != GS_quit && bman.state != GS_startup) {
        single_game_new ();
        game_start ();
		bman.state = GS_running;
        game_loop ();
        game_end ();
    }
	
	gfx_blitdraw ();
	draw_logo ();
	gfx_blitdraw ();
};