Beispiel #1
0
/* the loop itself */
void wait_for_players ()
{
    SDL_Event event;

    mw_init ();

    do {
        if (s_fetchevent (&event) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                bman.state = GS_quit;
                break;
            }

        /*
         * check some little things and do the network stuff
         */
        network_loop ();

        /*
         * the drawing stuff
         */
        if (mw_check_screenredraw()) {
            d_printf ("Draw Status\n");
            gfx_blitdraw ();
            draw_logo ();
            if (bman.gametype==GT_team) mw_draw_all_teams();
            else mw_draw_all_player ();
        }
        gfx_blitdraw ();

        /*
         *	input handling
         */
        keyb_loop (&event);
        mw_keys_loop ();

        chat_loop (&event);
        chat.active = 1;

        s_calctimesync ();
    } while (bman.state == GS_wait && bman.sock != -1);

    mw_shutdown ();
};
Beispiel #2
0
/* load the images with the right scaleing */
void
game_start ()
{
    int p,
        i;

    menu_displaytext ("Loading..", "Please Wait");

    bman.players_nr_s = 0;
    bman.playnum += 1;
    for (p = 0; p < MAX_PLAYERS; p++) {
        if (PS_IS_used (players[p].state)) {
            bman.players_nr_s++;
            if (players[p].gfx_nr == -1) {
                players[p].gfx = NULL;
                players[p].state &= (0xff - (PSF_alife + PSF_playing));
            } else {
                players[p].state |= PSF_alife + PSF_playing;
                players[p].gfx = &gfx.players[players[p].gfx_nr];
            }
        } else
            players[p].state = 0;

        players[p].bombs_n = bman.start_bombs;
        players[p].range = bman.start_range;
        players[p].speed = bman.start_speed;
        players[p].collect_shoes = 0;
        players[p].special.type = SP_nothing;
        players[p].special.use = 0;
        players[p].special.clear = 0;
        players[p].m = 0;
        players[p].old.x = 0;
        players[p].old.y = 0;
        bman.updatestatusbar = 1;
        players[p].frame = 0.0f;
        players[p].d = 0;
        players[p].pos.x = 0.0;
        players[p].pos.y = 0.0;
        players[p].tunnelto = 0.0f;
        players[p].ready = 0;
        // add reset nbrKilled value
        players[p].nbrKilled = 0;

        /* all types of illnes turn them off */
        for (i = 0; i < PI_max; i++)
            players[p].ill[i].to = 0.0f;

        // reset bombs
        for (i = 0; i < MAX_BOMBS; i++) {
            players[p].bombs[i].state = BS_off;
            players[p].bombs[i].ex_nr = -1;
            players[p].bombs[i].fdata = 0;
            players[p].bombs[i].dest.x = 0;
            players[p].bombs[i].dest.y = 0;
            players[p].bombs[i].mode = BM_normal;
            players[p].bombs[i].id.p = p;
            players[p].bombs[i].id.pIgnition = p;
            players[p].bombs[i].id.b = i;
            players[p].pos.x = 0;
            players[p].pos.x = 0;
        }
    }

    flitems_reset ();
    init_map_tileset ();

    tileset_load (map.tileset, -1, -1);

    gfx_load_players (gfx.block.x, gfx.block.y);

    snd_load (map.tileset);
    snd_music_start ();

    map.state = MS_normal;
    bman.timeout = bman.init_timeout;
    s_calctimesync ();          // to clean up the timesyc
    s_calctimesync ();          // data run this twice
    if (GT_MP_PTPM)
        net_send_servermode ();
};
Beispiel #3
0
void
game_loop ()
{
    SDL_Event event;
    int done = 0,
        eventstate;

    if (GT_MP)
        net_game_fillsockaddr ();
    if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 ) {
        fprintf ( stderr, "Unable to initialize Joystick: %s\n", SDL_GetError() );
    }
    printf ( "%i joysticks found\n", SDL_NumJoysticks () );

    menu = NULL;
    bman.updatestatusbar = 1;   // force an update
    timestamp = SDL_GetTicks (); // needed for time sync.
    d_gamedetail ("GAME START");

    gfx_blitupdaterectclear ();
    draw_logo ();
    draw_field ();
    SDL_Flip (gfx.screen);
    draw_players ();

    if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) {
        players[bman.p_nr].ready = 1;
        if (GT_MP_PTPS)
            send_playerdata (&players[bman.p_servnr].net.addr, bman.p_nr, &players[bman.p_nr]);
    }
    if (bman.p2_nr >= 0 && bman.p2_nr < MAX_PLAYERS) {
        players[bman.p2_nr].ready = 1;
        if (GT_MP_PTPS)
            send_playerdata (&players[bman.p_servnr].net.addr, bman.p2_nr, &players[bman.p2_nr]);
    }
	fire_init();
    while (!done && (bman.state == GS_running || bman.state == GS_ready)) {
        SDL_JoystickUpdate ();
        if ((eventstate = SDL_PollEvent (&event)) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                done = 1;
                bman.state = GS_quit;
            }

        /*
         * input handling
         */
        keyb_loop (&event);

        game_keys_loop ();

        if (GT_MP)
            chat_loop (&event);

        if ((!IS_LPLAYER2) && (!chat.active))
            chat_setactive (1, 1);

        restore_players_screen ();

        player_check (bman.p_nr);
        if (IS_LPLAYER2)
            player_check (bman.p2_nr);

        dead_playerani ();

        special_loop ();

        player_move (bman.p_nr);
        if (IS_LPLAYER2)
            player_move (bman.p2_nr);

        if (GT_MP) {
            player_calcpos ();
            network_loop ();
        }

        if (bman.state == GS_running)
            single_loop ();

        bomb_loop ();
		/* wind_loop (); SOON */
		fire_loop ();
        field_loop ();
        flitems_loop ();

        draw_players ();
        game_draw_info ();      // will set the var bman.player_nr

        /* check if there is only one player left and the game is in multiplayer mode
           and if there the last dieing animation is done */
        if (game_check_endgame () && bman.timeout >= 0.0f)
            bman.timeout = 0.0f;

        if ((GT_SP || GT_MP_PTPM) && bman.timeout < -GAME_OVERTIMEOUT) {
            d_printf ("GAME: Game Over\n");
            done = 1;
        }

        stonelist_draw ();

        /* if there is any menu displayed do so */
        if (menu != NULL)
            game_menu_loop (&event, eventstate);

        gfx_blitdraw ();

        s_calctimesync ();
        bman.timeout -= timediff;

    }

    if (menu != NULL) {
        menu_delete (menu);
        menu = NULL;
    }

    gfx_blitdraw ();

    chat_show (-1, -1, -1, -1);
    draw_logo ();
    gfx_blitupdaterectclear ();
    SDL_Flip (gfx.screen);

    d_gamedetail ("GAME END");
    d_printf ("done = %d\n", done);
};
Beispiel #4
0
/* singleplayer menü with some options you can make */
void
single_menu ()
{
    int i,
		p,
		eventstate = 0,
        done = 0,
		second_player = 0;
    _charlist nrplayerlist[MAX_PLAYERS + 1];
    _charlist *selnrplayer = &nrplayerlist[bman.ai_players];
	_menu *menu;
	_menuitem *aiplayer = NULL;
	SDL_Event event;

    /* fill in the nrplayerlist */
    for (p = 0, i = 0; p < MAX_PLAYERS + 1; i++) {
        sprintf (nrplayerlist[i].text, "%d", p);
        if (p < MAX_PLAYERS - 1)
            nrplayerlist[i].next = &nrplayerlist[i + 1];
        else
            nrplayerlist[i].next = NULL;
        p++;
    }
	
	game_resetdata ();
	
	menu = menu_new ("Single Game", 380,240);
	
	menu_create_text (menu, "numpl", 20, 50, 12, 2, COLOR_yellow, "Number of\nAI Players");
	aiplayer = menu_create_list (menu, "AI Players", 40, 90, 50, 100, nrplayerlist, &selnrplayer, 3);
	
	menu_create_button (menu,"Change Playernames" ,160, 50, 210, 4);

	menu_create_bool (menu, "Use Second Player", 160, 90, 210, &second_player, 5);

	menu_create_button (menu, "Game Options", 180, 130, 150, 6);
	menu_create_button (menu, "Map Options", 180, 170, 150, 7);
	menu_create_button (menu, "Main Menu", 30, 220, 150, 1);
	menu_create_button (menu, "Start", 220, 220, 150, 2);
	
	menu_focus_id (menu, 2);
	menu->looprunning = 1;
	menu_draw (menu);
	
	do {
		gfx_blitdraw ();
		eventstate = s_fetchevent (&event);

		done = menu_event_loop (menu, &event, eventstate);

		if (done > 0 && menu->focus->id == 6) {
			done = 0;
			mapgamesetting ();
		}
		
		if (done > 0 && menu->focus->id == 7) {
			done = 0;
			mapmenu ();
		}
		
		if (done > 0 && menu->focus->id == 4) {
			done = 0;
			playernamemenu ();
		}
		
		if (done > 0 && menu->focus->id == 3)
			done = 0;
		
		s_calctimesync ();
	} while (!done); 
	
	bman.ai_players = selnrplayer - &nrplayerlist[0];
	
	if (menu->focus->id == 2)
		single_playergame (second_player, bman.ai_players);

	menu_delete (menu);
};