示例#1
0
static bonus_data_t * create_bonus(const char* text, int value) {
    char* buf, buf2[15];
    bonus_data_t * ret;
    ret = calloc(1,sizeof(bonus_data_t));

    ret->bonus=value;

    /*On initialise le nouveau bonus */
    if (value>0) {
        if (sprintf(buf2, ": %d pts" ,value) == -1) {
            buf2[0]='\0';
        }
    } else {
        buf2[0]='\0';
    }

    if (asprintf(&buf, "%s%s" , text,buf2 ) != -1) {
        ret->bonus_string=buf;
    } else ret->bonus_string = NULL;


    ret->start_time = g_game.time;

    player_data_t* plyr = get_player_data(local_player());
    ret->pos = plyr->pos;
    return ret;
}
示例#2
0
void game_over_init(void)
{
    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( mouse_cb );
    winsys_set_motion_func( ui_event_motion_func );
    winsys_set_passive_motion_func( ui_event_motion_func );

    remove_all_bonuses();

    halt_sound( "flying_sound" );
    halt_sound( "rock_sound" );
    halt_sound( "ice_sound" );
    halt_sound( "snow_sound" );

    play_music( "game_over" );

    aborted = g_game.race_aborted;

    if ( !aborted ) {
        update_player_score( get_player_data( local_player() ) );
    }

    if ( (!g_game.practicing &&!aborted) || (!g_game.practicing && aborted && !game_abort_is_for_tutorial())) {
        race_won = was_current_race_won();
        init_starting_tutorial_step(-100);
    }

    g_game.needs_save_or_display_rankings=false;
    g_game.rankings_displayed=false;
}
示例#3
0
void bonus_init() {
    assert(bonus_list == NULL);

    player_data_t* plyr = get_player_data(local_player());
    plyr->bonus_tricks=0;

    int i;
    for (i=0; i<8; i++) {
        tricks_count[i]=-1;
    }

    /* On assigne des score plus importants aux tricks pour le half pipe, f fois plus important */
    int f;
    if (!strcmp(get_calculation_mode(),"Half_Pipe")) {
        f=4;
    } else {
        f=1;
    }
    score_for_trick[HYPER_HEAVY_JUMP]=240*f;
    score_for_trick[RAY_STAR_HYBRID_JUMP]=250*f;
    score_for_trick[ROLL_LEFT]=120*f;
    score_for_trick[ROLL_RIGHT]=120*f;
    score_for_trick[SATURN_ICE_FEVER]=230*f;
    score_for_trick[WILD_PINGUIN_SHOW]=200*f;
    score_for_trick[BACK_FLIP]=80*f;
    score_for_trick[BARLOWS_WHEEL]=160*f;
}
示例#4
0
void racing_init(void) 
{
    player_data_t *plyr = get_player_data( local_player() );
    
    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( NULL );
    winsys_set_motion_func( NULL );
    winsys_set_passive_motion_func( NULL );
    winsys_set_mouse_func( NULL );
    
    /* Initialize view */
    if ( getparam_view_mode() < 0 || 
        getparam_view_mode() >= NUM_VIEW_MODES ) 
    {
        setparam_view_mode( ABOVE );
    }
    set_view_mode( plyr, (view_mode_t)getparam_view_mode() );
    
    /* We need to reset controls here since callbacks won't have been
     called in paused mode. This results in duplication between this
     code and init_physical_simulation.  Oh well. */
    left_turn = right_turn = paddling = False;
    trick_modifier = False;
    charging = False;
    plyr->control.turn_fact = 0.0;
    plyr->control.turn_animation = 0.0;
    plyr->control.is_braking = False;
    plyr->control.is_paddling = False;
    plyr->control.jumping = False;
    plyr->control.jump_charging = False;
    
#ifdef __APPLE__
    plyr->control.is_flying=False;
    plyr->control.fly_total_time=0;
#endif
    
    /* Set last_terrain to a value not used below */
    last_terrain = 0;
    
    if ( g_game.prev_mode != PAUSED ) {
        init_physical_simulation();
    }
    
    last_terrain = 0;
    
    g_game.race_aborted = False;
#ifdef __APPLE__
    g_game.race_time_over = False;
#endif
    
    play_music( "racing" );
    /* play_sound( "start_race", 0 ); */
}
示例#5
0
void saveAndDisplayRankings() {
    //save score online if a best resul was established
    if (g_game.practicing && !g_game.race_aborted && g_game.race.name!=NULL && did_player_beat_best_results()) {
        int minutes;
        int seconds;
        int hundredths;
        player_data_t *plyr = get_player_data( local_player() );
        get_time_components( g_game.time, &minutes, &seconds, &hundredths);
        //if the player choosed in his prefs not to save score online after ending a race but just to display rankings, the function below
        //will detect this case and redirect to the function displayRankingsAfterRace
    }
    //else display world rankings for this score
    else if (g_game.practicing && !g_game.race_aborted && g_game.race.name!=NULL && !did_player_beat_best_results()) {
        int minutes;
        int seconds;
        int hundredths;
        player_data_t *plyr = get_player_data( local_player() );
        get_time_components( g_game.time, &minutes, &seconds, &hundredths);
    }
}
示例#6
0
char* editSynchronizeScoresRequest()
{
    
    list_t race_list = NULL;
    list_elem_t cur_elem = NULL;
    player_data_t *plyr = NULL;
    
    open_course_data_t *data;
    
    plyr = get_player_data( local_player() );
    
    g_game.current_event = "__Practice_Event__";
    g_game.current_cup = "__Practice_Cup__";
    g_game.difficulty = 1;
    
    race_list = get_open_courses_list();
    
    cur_elem = get_list_head( race_list );
    
    scalar_t time;
    int herring;
    int score;
    int minutes;
    int seconds;
    int hundredths;
    int i=0;
    char request[10000];
    char* tempRequest;
    strcpy(request,"");
    do
    {
        data = (open_course_data_t*) get_list_elem_data( cur_elem );
        if ( get_saved_race_results( plyr->name,
                                    g_game.current_event,
                                    g_game.current_cup,
                                    data->name,
                                    g_game.difficulty,
                                    &time,
                                    &herring,
                                    &score ) )
        {
            if (i>0) strcat(request,"&");
            get_time_components( time, &minutes, &seconds, &hundredths);
            asprintf(&tempRequest,"piste[%d]=%s&score[%d]=%d&herring[%d]=%d&time[%d]=%02d:%02d:%02d",i,data->name,i,score,i,herring,i,minutes,seconds,hundredths);
            strcat(request,tempRequest);
            free(tempRequest);
            i++;
        }
    }
    while (cur_elem = get_next_list_elem(race_list, cur_elem));
    return request;
}
示例#7
0
/*! 
 Callback called when facebook button is clicked
 \author  Emmanuel de Roux
 \date    Created:  2009-09-12
 \date    Modified: 2000-09-12
 */
static void fb_click_cb( button_t *button, void *userdata )
{
	
	scalar_t time;
	open_course_data_t *data;
	data = (open_course_data_t*)get_list_elem_data( cur_elem );
	char* race_name = data->name;
	
	char* mode = g_game.is_speed_only_mode?(char*)Localize("Time Trial","src/race_select.c"):(char*)Localize("classic","src/race_select.c");
	
	char *event,*cup;
	event = g_game.current_event;
	cup = g_game.current_cup;
	
	player_data_t *plyr = get_player_data( local_player() );
	
	int herring, score;
	int minutes, seconds, hundredths;
	
	if (g_game.practicing) {
		if ( get_saved_race_results( plyr->name,
									 event,
									 cup,
									 race_name,
									 g_game.difficulty,
									 &time,
									 &herring,
									 &score ) )
		{
			get_time_components( time, &minutes, &seconds, &hundredths );
		}
		
		if (!g_game.rankings_loaded) {
			facebookPublishDialogDisplayed = false;
			displayRankingsAfterRace(g_game.race.name,plyr->score,plyr->herring,minutes,seconds,hundredths);	
		}
    }
	
	char* scoreTxt;
	
	if (g_game.is_speed_only_mode) asprintf(&scoreTxt, "%02d:%02d:%02d", minutes, seconds, hundredths);
	else asprintf(&scoreTxt, "%d pts", plyr->score );
	
    if (g_game.rankings_loaded==true) { 
		publishNewHighScore(scoreTxt,race_name,mode,g_game.worldRanking,g_game.countryRanking,g_game.totalRanking);
		facebookPublishDialogDisplayed=True;
	}
	
	free(scoreTxt);
}
示例#8
0
void calc_jump_amt( scalar_t time_step )
{
    player_data_t *plyr = get_player_data( local_player() );
    
    if ( plyr->control.jump_charging ) {
        plyr->control.jump_amt = min( 
                                     MAX_JUMP_AMT, g_game.time - charge_start_time );
    } else if ( plyr->control.jumping ) {
        plyr->control.jump_amt *= 
	    ( 1.0 - ( g_game.time - plyr->control.jump_start_time ) / 
         JUMP_FORCE_DURATION );
    } else {
        plyr->control.jump_amt = 0;
    }
}
示例#9
0
void add_new_bonus(const char* text, int value) {

    player_data_t *plyr = get_player_data( local_player() );

    if(!bonus_list) {
        bonus_list = create_bonus(text,value);
        plyr->bonus_tricks+=value;
        return;
    }

    plyr->bonus_tricks+=value;
    bonus_data_t * bonus = bonus_list;
    bonus_list = create_bonus(text, value);
    bonus_list->next = bonus;
    bonus->previous = bonus_list;
}
示例#10
0
void draw_tux()
{
    if(get_player_data(local_player())->view.mode == TUXEYE) return;

    GLfloat dummy_colour[]  = { 0.0, 0.0, 0.0, 1.0 };

    /* XXX: For some reason, inserting this call here makes Tux render
     * with correct lighting under Mesa 3.1. I'm guessing it's a Mesa bug.
     */
    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dummy_colour );

    set_gl_options( TUX );

    /* Turn on lights
     */
    setup_course_lighting_for_tux(true);

    draw_scene_graph( tuxRootNode );
} 
示例#11
0
/*!
 Returns the last complete cup for the specified event
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
list_elem_t get_last_complete_cup_for_event( event_data_t *event_data )
{
    char *last_cup;
    list_elem_t cup;

    if ( get_last_completed_cup( g_game.player[local_player()].name,
                                 get_event_name( event_data ),
                                 g_game.difficulty,
                                 &last_cup ) )
    {
        cup = get_event_cup_by_name( event_data, last_cup );

        if ( cup == NULL ) {
            print_warning( IMPORTANT_WARNING,
                           "Couldn't find saved cup `%s'", last_cup );
        }
        return cup;
    } else {
        return NULL;
    }
}
示例#12
0
static void continue_click_cb( button_t *button, void *userdata )
{
    cup_data_t *cup_data;
    player_data_t *plyr = get_player_data( local_player() );
    
    check_assertion( userdata == NULL, "userdata is not null" );
    
    cur_event = listbox_get_current_item( event_listbox );
    event_data = (event_data_t*) get_list_elem_data( cur_event );
    
    cur_cup = listbox_get_current_item( cup_listbox );
    cup_data = (cup_data_t*) get_list_elem_data( cur_cup );
    
    g_game.current_event = get_event_name( event_data );
    g_game.current_cup = get_cup_name( cup_data );
    
    plyr->lives = INIT_NUM_LIVES;
    
    set_game_mode( RACE_SELECT );
    
    ui_set_dirty();
}
示例#13
0
/* ce init ne ser que pendant le tutorial, quand on souhaite faire revenir tux en arriere */
void racing_init_for_tutorial(point_t point) {
    player_data_t *plyr = get_player_data( local_player() );
    plyr->control.is_flying=False;
    plyr->control.fly_total_time=0;
    init_physical_simulation_at_point(plyr,point);
}
示例#14
0
void racing_loop( scalar_t time_step )
{
    int width, height;
    player_data_t *plyr = get_player_data( local_player() );
    bool_t joy_paddling = False;
    bool_t joy_braking = False;
    bool_t joy_charging = False;
    bool_t airborne;
    vector_t dir;
    scalar_t speed;
    scalar_t terrain_weights[NumTerrains];
    int new_terrain = 0;
    int slide_volume;
    
    
    dir = plyr->vel;
    speed = normalize_vector(&dir);
    
    airborne = plyr->airborne;
    
    width = getparam_x_resolution();
    height = getparam_y_resolution();
    
    check_gl_error();
    
    new_frame_for_fps_calc();
    
    update_audio();
    
    clear_rendering_context();
    
    setup_fog();
    
    /* Update braking */
    plyr->control.is_braking = (bool_t) ( braking || joy_braking );
    
    if ( airborne ) {
        new_terrain = (1<<NumTerrains);
        
        /*
         * Tricks
         */
        if ( trick_modifier) {
            if (left_turn) {
                plyr->control.barrel_roll_left = True;
            }

            if (right_turn) {
                plyr->control.barrel_roll_right = True;
            }

            if (paddling) {
                plyr->control.front_flip = True;
            }

            if (plyr->control.is_braking) {
                plyr->control.back_flip = True;
            }
            
            //Par défaut ca fait un front flip
            if(!plyr->control.front_flip && !plyr->control.back_flip &&
               !plyr->control.barrel_roll_right && !plyr->control.barrel_roll_left )
            {
                plyr->control.back_flip = True;
            }
#ifdef __APPLE__
            TRDebugLog("tricks : %d",plyr->tricks);
#endif
        }
        
        
    } else {
        
        get_surface_type(plyr->pos.x, plyr->pos.z, terrain_weights);
        if (terrain_weights[Snow] > 0) {
            new_terrain |= (1<<Snow);
        }
        if (terrain_weights[Rock] > 0) {
            new_terrain |= (1<<Rock);
        } 
        if (terrain_weights[Ice] > 0) {
            new_terrain |= (1<<Ice);
        }
        
    }
    
    /*
     * Jumping
     */
    calc_jump_amt( time_step );
    
    if ( ( charging || joy_charging ) && 
        !plyr->control.jump_charging && !plyr->control.jumping ) 
    {
        plyr->control.jump_charging = True;
        charge_start_time = g_game.time;
    }
    
    if ( ( !charging && !joy_charging ) && plyr->control.jump_charging ) {
        plyr->control.jump_charging = False;
        plyr->control.begin_jump = True;
    }
    
    
    /* 
     * Turning 
     */
    scalar_t iPhone_turn_fact=accelerometerTurnFact();

    iPhone_turn_fact=accelerometerTurnFact();
    
    /*left_turn and right_turn are informations useful for tricks*/
    if (iPhone_turn_fact>TURN_FACTOR_LIMIT) {
        left_turn=false;
        right_turn=true;
    }
    else if (iPhone_turn_fact<-TURN_FACTOR_LIMIT) {
        left_turn=true;
        right_turn=false;
    } else left_turn = right_turn = false;
    
    plyr->control.turn_fact = iPhone_turn_fact;
    plyr->control.turn_animation = iPhone_turn_fact;
    
    
    /*
     * Paddling
     */
    if ( ( paddling || joy_paddling ) && plyr->control.is_paddling == False ) {
        plyr->control.is_paddling = True;
        plyr->control.paddle_time = g_game.time;
    }
    
    /*
     * Play flying sound (__APPLE__ : and add Flying time to plyr->control.fly_total_time)
     */
    if (new_terrain & (1<<NumTerrains)) {
        set_sound_volume("flying_sound", min(128, speed*2));
        
        if (!(last_terrain & (1<<NumTerrains))) {
            play_sound( "flying_sound", -1 );
            plyr->control.is_flying=true;
            plyr->control.fly_start_time = g_game.time;
        }
    } else {
        if (last_terrain & (1<<NumTerrains)) {
            plyr->control.is_flying=false;
            plyr->control.fly_end_time = g_game.time;
            if (plyr->control.fly_end_time-plyr->control.fly_start_time>FLYING_TIME_LIMIT) {
                plyr->control.fly_total_time += plyr->control.fly_end_time-plyr->control.fly_start_time;
            }
            halt_sound( "flying_sound" );
        }
    }
    
    /*
     * Play sliding sound
     */
    slide_volume = min( (((pow(plyr->control.turn_fact, 2)*128)) +
                         (plyr->control.is_braking?128:0) +
                         (plyr->control.jumping?128:0) +
                         20) *
                       (speed/10), 128 );
    if (new_terrain & (1<<Snow)) {
        set_sound_volume("snow_sound", slide_volume * terrain_weights[Snow]);
        if (!(last_terrain & (1<<Snow))) {
            play_sound( "snow_sound", -1 );
        }
    } else {
        if (last_terrain & (1<<Snow)) {
            halt_sound( "snow_sound" );
        }
    }
    if (new_terrain & (1<<Rock)) {
        //set_sound_volume("rock_sound", 128*pow((speed/2), 2) * terrain_weights[Rock]);
        
        int rockvol = slide_volume * 10 * terrain_weights[Rock];
        
        if (rockvol > 400)
            rockvol = 400;
        
        set_sound_volume("rock_sound", rockvol);
        if (!(last_terrain & (1<<Rock))) {
            play_sound( "rock_sound", -1 );
        }
    } else {
        if (last_terrain & (1<<Rock)) {
            halt_sound( "rock_sound" );
        }
    }
    if (new_terrain & (1<<Ice)) {
        set_sound_volume("ice_sound", slide_volume * terrain_weights[Ice]);
        if (!(last_terrain & (1<<Ice))) {
            play_sound( "ice_sound", -1 );
        }
    } else {
        if (last_terrain & (1<<Ice)) {
            halt_sound( "ice_sound" );
        }
    }
    last_terrain = new_terrain; 
    
    
    /*
     * gs
     */
    bool roll = plyr->control.barrel_roll_left || plyr->control.barrel_roll_right;
    bool flip = plyr->control.front_flip || plyr->control.back_flip;
    if(roll && plyr->control.barrel_roll_factor == 0)
    {
        if(flip)
        {
            if(plyr->control.barrel_roll_left)
                add_new_bonus("Hyper heavy Jump", get_score_for_trick(HYPER_HEAVY_JUMP));
            else
                add_new_bonus("Ray star hybrid Jump", get_score_for_trick(RAY_STAR_HYBRID_JUMP));
        }
        else
        {
            if(plyr->control.barrel_roll_left)
                add_new_bonus("Roll Left", get_score_for_trick(ROLL_LEFT));
            else
                add_new_bonus("Roll Right", get_score_for_trick(ROLL_RIGHT));
        }
    }

    if(flip && plyr->control.flip_factor == 0)
    {
        if(roll)
        {
            if(plyr->control.back_flip)
                add_new_bonus("Saturn ice Fever", get_score_for_trick(SATURN_ICE_FEVER));
            else
                add_new_bonus("Wild pinguin Show", get_score_for_trick(WILD_PINGUIN_SHOW));
        }
        else
        {
            if(plyr->control.back_flip)
                add_new_bonus("Back Flip", get_score_for_trick(BACK_FLIP));
            else
                add_new_bonus("Barlow's Wheel", get_score_for_trick(BARLOWS_WHEEL));
        }
    }

    if (roll) {
        plyr->tricks+=1;
        plyr->control.barrel_roll_factor += 
		( plyr->control.barrel_roll_left ? -1 : 1 ) * 0.05 * time_step / 0.05;
        if ( (plyr->control.barrel_roll_factor  > 1) ||
            (plyr->control.barrel_roll_factor  < -1) ) {
            plyr->control.barrel_roll_factor = 0;
            plyr->control.barrel_roll_left = plyr->control.barrel_roll_right = False;
        }
    }
    if (flip) {
        plyr->tricks+=1;
        plyr->control.flip_factor += 
		( plyr->control.back_flip ? -1 : 1 ) * 0.05 * time_step / 0.05;
        if ( (plyr->control.flip_factor  > 1) ||
            (plyr->control.flip_factor  < -1) ) {
            plyr->control.flip_factor = 0;
            plyr->control.front_flip = plyr->control.back_flip = False;
        }
    }

    update_player_pos( plyr, time_step );
	
    /* 
     * Track Marks
     */
    add_track_mark( plyr );
    
    
    update_view( plyr, time_step );
    
    setup_view_frustum( plyr, NEAR_CLIP_DIST, 
                       getparam_forward_clip_distance() );
    
    draw_sky(plyr->view.pos);
    
    draw_fog_plane();
    
    set_course_clipping( True );
    set_course_eye_point( plyr->view.pos );
    setup_course_lighting();
    render_course();
    draw_trees();
    
    if ( getparam_draw_particles() ) {
        update_particles( time_step );
        draw_particles( plyr );
    }
    
    draw_tux();
    draw_tux_shadow();
    
    draw_hud( plyr );
    
    draw_hud_training(plyr);
    
    reshape( width, height );
    
    winsys_swap_buffers();
    
    g_game.time += time_step;
} 
示例#15
0
/*! 
 Draws a fog plane at the far clipping plane to mask out clipping of terrain.
 
 \return  none
 \author  jfpatry
 \date    Created:  2000-08-31
 \date    Modified: 2000-08-31
 */
void draw_fog_plane()
{
	plane_t left_edge_plane, right_edge_plane;
	plane_t left_clip_plane, right_clip_plane;
	plane_t far_clip_plane;
	plane_t bottom_clip_plane;
	plane_t bottom_plane, top_plane;
	
	scalar_t course_width, course_length;
	scalar_t course_angle, slope;
	
	point_t left_pt, right_pt, pt;
	point_t top_left_pt, top_right_pt;
	point_t bottom_left_pt, bottom_right_pt;
	vector_t left_vec, right_vec;
	scalar_t height;
	
	GLfloat *fog_colour;
	
	if ( is_fog_on() == False ) {
		return;
	}
	
	set_gl_options( FOG_PLANE );
	
	get_course_dimensions( &course_width, &course_length );
	course_angle = get_course_angle();
	slope = tan( ANGLES_TO_RADIANS( course_angle ) );
	
	left_edge_plane = make_plane( 1.0, 0.0, 0.0, 0.0 );
	
	right_edge_plane = make_plane( -1.0, 0.0, 0.0, course_width );
	
	far_clip_plane = get_far_clip_plane();
	left_clip_plane = get_left_clip_plane();
	right_clip_plane = get_right_clip_plane();
	bottom_clip_plane = get_bottom_clip_plane();
	
	
	/* Find the bottom plane */
	bottom_plane.nml = make_vector( 0.0, 1, -slope );
	height = get_terrain_base_height( 0 );
	
	/* Unoptimized version
	 pt = make_point( 0, height, 0 );
	 bottom_plane.d = -( pt.x * bottom_plane.nml.x +
	 pt.y * bottom_plane.nml.y +
	 pt.z * bottom_plane.nml.z );
	 */
	bottom_plane.d = -height * bottom_plane.nml.y;
	
	/* Find the top plane */
	top_plane.nml = bottom_plane.nml;
	height = get_terrain_max_height( 0 );
	top_plane.d = -height * top_plane.nml.y;
	
	
	if(get_player_data(local_player())->view.mode == TUXEYE)
	{
		bottom_clip_plane.nml = make_vector( 0.0, 1, -slope );
		height = get_terrain_base_height( 0 ) - 40;
		bottom_clip_plane.d = -height * bottom_clip_plane.nml.y;
	}
	
	/* Now find the bottom left and right points of the fog plane */
	if ( !intersect_planes( bottom_plane, far_clip_plane, left_clip_plane, &left_pt ) )
		return;
	
	if ( !intersect_planes( bottom_plane, far_clip_plane, right_clip_plane, &right_pt ) )
		return;
	
	if ( !intersect_planes( top_plane, far_clip_plane, left_clip_plane, &top_left_pt ) )
		return;
	
	if ( !intersect_planes( top_plane, far_clip_plane, right_clip_plane, &top_right_pt ) )
		return;
	
	if ( !intersect_planes( bottom_clip_plane, far_clip_plane, left_clip_plane, &bottom_left_pt ) )
		return;
	
	if ( !intersect_planes( bottom_clip_plane, far_clip_plane, right_clip_plane, &bottom_right_pt ) )
		return;
	
	left_vec = subtract_points( top_left_pt, left_pt );
	right_vec = subtract_points( top_right_pt, right_pt );
	
	
	/* Now draw the fog plane */
	
	set_gl_options( FOG_PLANE );
	
	fog_colour = get_fog_colour();
	
	glColor4fv( fog_colour );
	
#ifdef __APPLE__DISABLED__
#undef glEnableClientState
#undef glDisableClientState
#undef glVertexPointer
#undef glColorPointer
#undef glDrawArrays
	
	point_t pt1,pt2,pt3,pt4;
	
	pt1 = move_point( top_left_pt, left_vec );
	pt2 = move_point( top_right_pt, right_vec );
	pt3 = move_point( top_left_pt, scale_vector( 3.0, left_vec ) );
	pt4 = move_point( top_right_pt, scale_vector( 3.0, right_vec ) );
	
	const GLfloat verticesFog []=
	{
		bottom_left_pt.x, bottom_left_pt.y, bottom_left_pt.z,
		bottom_right_pt.x, bottom_right_pt.y, bottom_right_pt.z,
		left_pt.x, left_pt.y, left_pt.z,
		right_pt.x, right_pt.y, right_pt.z,
		
		top_left_pt.x, top_left_pt.y, top_left_pt.z,
		top_right_pt.x, top_right_pt.y, top_right_pt.z,
		
		pt1.x, pt1.y, pt1.z,
		pt2.x, pt2.y, pt2.z,
		pt3.x, pt3.y, pt3.z,
		pt4.x, pt4.y, pt4.z	
	};
	
	const GLfloat colorsFog []=
	{
		fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3],
		fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3],
		fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3],
		fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3],
		fog_colour[0], fog_colour[1], fog_colour[2], 0.9 ,
		fog_colour[0], fog_colour[1], fog_colour[2], 0.9 ,
		fog_colour[0], fog_colour[1], fog_colour[2], 0.3 ,
		fog_colour[0], fog_colour[1], fog_colour[2], 0.3 ,
		fog_colour[0], fog_colour[1], fog_colour[2], 0.0 ,
		fog_colour[0], fog_colour[1], fog_colour[2], 0.0 ,	
	};
	
	glEnableClientState (GL_VERTEX_ARRAY);
	//   glEnableClientState (GL_COLOR_ARRAY);
	//  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glVertexPointer (3, GL_FLOAT , 0, verticesFog);	
	glColorPointer(4, GL_FLOAT, 0, colorsFog);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
	//glDisableClientState(GL_COLOR_ARRAY_POINTER);
	
#else
	glBegin( GL_QUAD_STRIP );
	
	glVertex3f( bottom_left_pt.x, bottom_left_pt.y, bottom_left_pt.z );
	glVertex3f( bottom_right_pt.x, bottom_right_pt.y, bottom_right_pt.z );
	glVertex3f( left_pt.x, left_pt.y, left_pt.z );
	glVertex3f( right_pt.x, right_pt.y, right_pt.z );
	
	glColor4f( fog_colour[0], fog_colour[1], fog_colour[2], 0.9 );
	glVertex3f( top_left_pt.x, top_left_pt.y, top_left_pt.z );
	glVertex3f( top_right_pt.x, top_right_pt.y, top_right_pt.z );
	
	glColor4f( fog_colour[0], fog_colour[1], fog_colour[2], 0.3 );
	pt = move_point( top_left_pt, left_vec );
	glVertex3f( pt.x, pt.y, pt.z );
	pt = move_point( top_right_pt, right_vec );
	glVertex3f( pt.x, pt.y, pt.z );
	
	glColor4f( fog_colour[0], fog_colour[1], fog_colour[2], 0.0 );
	pt = move_point( top_left_pt, scale_vector( 3.0, left_vec ) );
	glVertex3f( pt.x, pt.y, pt.z );
	pt = move_point( top_right_pt, scale_vector( 3.0, right_vec ) );
	glVertex3f( pt.x, pt.y, pt.z );
	
	glEnd();
	
#endif
}
示例#16
0
/*! 
 Sets the widget positions and draws other on-screen goo 
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void set_widget_positions_and_draw_decorations()
{
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    int box_width, box_height, box_max_y;
    int x_org, y_org;
    char *string;
    font_t *font;
    char *current_course;
    int text_width, asc, desc;
    GLuint texobj;
    
    /* set the dimensions of the box in which all widgets should fit */
#ifdef __APPLE__
    box_width = w;
    box_height = 200 * mHeight / 320;
    box_max_y = h - 128 * mHeight / 320;
    x_org = 10 * mHeight / 320;
    y_org = box_height/2 * mHeight / 320;
    
    if ( y_org + box_height > box_max_y ) {
        y_org = box_max_y - box_height + 50 * mHeight / 320;
    }
    
    button_set_position( 
                        back_btn,
                        make_point2d( 0,
                                     0 ) );
    
    button_set_position(
                        start_btn,
                        make_point2d( box_width - button_get_width( start_btn ),
                                     0 ) );
    
    listbox_set_position(
                         race_listbox,
                         make_point2d( 160 * mHeight / 320,
                                       box_height/2.0+40 * mHeight / 320 ) );
#ifdef __APPLE__    
    textarea_set_position( 
                          desc_ta,
                          make_point2d( 1000,
                                        1000 ) );
#else
    textarea_set_position( 
                          desc_ta,
                          make_point2d( x_org,
                                       y_org + 66 * mHeight / 320 ) );
#endif
    
    if ( g_game.practicing || 
        ( cup_complete &&
         conditions_ssbtn &&
         wind_ssbtn &&
         snow_ssbtn &&
         mirror_ssbtn ) ) 
    {
        ssbutton_set_position(
                              conditions_ssbtn,
                              make_point2d( x_org + box_width - 4*36 + 4,
                                           y_org + 151 ) );
        
        ssbutton_set_position(
                              wind_ssbtn,
                              make_point2d( x_org + box_width - 3*36 + 4 ,
                                           y_org + 151 ) );
        
        ssbutton_set_position(
                              snow_ssbtn,
                              make_point2d( x_org + box_width - 2*36 + 4,
                                           y_org + 151 ) );
        
        ssbutton_set_position(
                              mirror_ssbtn,
                              make_point2d( x_org + box_width - 1*36 + 4,
                                           y_org + 151 ) );
        
#else
        box_width = 460;
        box_height = 310;
        box_max_y = h - 128;
        x_org = w/2 - box_width/2;
        y_org = h/2 - box_height/2;
        
        if ( y_org + box_height > box_max_y ) {
            y_org = box_max_y - box_height;
        }
        
        button_set_position( 
                            back_btn,
                            make_point2d( x_org + 131 - button_get_width( back_btn )/2.0,
                                         42 ) );
        
        button_set_position(
                            start_btn,
                            make_point2d( x_org + 343 - button_get_width( start_btn )/2.0,
                                         42 ) );
        
        listbox_set_position(
                             race_listbox,
                             make_point2d( x_org,
                                          y_org + 221 ) );
        
        textarea_set_position( 
                              desc_ta,
                              make_point2d( x_org,
                                           y_org + 66 ) );
        
        if ( g_game.practicing || 
            ( cup_complete &&
             conditions_ssbtn &&
             wind_ssbtn &&
             snow_ssbtn &&
             mirror_ssbtn ) ) 
        {
            ssbutton_set_position(
                                  conditions_ssbtn,
                                  make_point2d( x_org + box_width - 4*36 + 4,
                                               y_org + 181 ) );
            
            ssbutton_set_position(
                                  wind_ssbtn,
                                  make_point2d( x_org + box_width - 3*36 + 4 ,
                                               y_org + 181 ) );
            
            ssbutton_set_position(
                                  snow_ssbtn,
                                  make_point2d( x_org + box_width - 2*36 + 4,
                                               y_org + 181 ) );
            
            ssbutton_set_position(
                                  mirror_ssbtn,
                                  make_point2d( x_org + box_width - 1*36 + 4,
                                               y_org + 181 ) );
#endif
        } else {
            /* Draw tux life icons */
            GLuint texobj;
            int i;
            
            glPushMatrix();
            {
#ifdef __APPLE__
                glTranslatef( 10 * mHeight / 320,
                             60 * mHeight / 320,
                             0 );
#else
                glTranslatef( x_org + box_width - 4*36 + 4,
                             y_org + 181,
                             0 );
#endif
                
                
                check_assertion( INIT_NUM_LIVES == 4, 
                                "Assumption about number of lives invalid -- "
                                "need to recode this part" );
                
                if ( !get_texture_binding( "tux_life", &texobj ) ) {
                    texobj = 0;
                }
                
                glBindTexture( GL_TEXTURE_2D, texobj );
                
                for ( i=0; i<4; i++ ) {
                    point2d_t ll, ur;
                    if ( plyr->lives > i ) {
                        ll = make_point2d( 0, 0.5 );
                        ur = make_point2d( 1, 1 );
                    } else {
                        ll = make_point2d( 0, 0 );
                        ur = make_point2d( 1, 0.5 );
                    }
                    
                    glBegin( GL_QUADS );
                    {
                        glTexCoord2f( ll.x, ll.y );
                        glVertex2f( 0, 0 );
                        
                        glTexCoord2f( ur.x, ll.y );
                        glVertex2f( 32 * mHeight / 320, 0 );
                        
                        glTexCoord2f( ur.x, ur.y );
                        glVertex2f( 32 * mHeight / 320, 32 * mHeight / 320 );
                        
                        glTexCoord2f( ll.x, ur.y );
                        glVertex2f( 0, 32 * mHeight / 320 );
                    }
                    glEnd();
                    glTranslatef( 36 * mHeight / 320, 0, 0 );
                }
            }
            glPopMatrix();
        }

#ifndef __APPLE__ // We don't care about that stuff

        /* Draw other stuff */
        if ( !get_font_binding( "menu_label", &font ) ) {
            print_warning( IMPORTANT_WARNING,
                          "Couldn't get font for binding menu_label" );
        } else {
            bind_font_texture( font );
            string = "Select a race";
            get_font_metrics( font, string, &text_width,  &asc, &desc );
            
            glPushMatrix();
            {
                glTranslatef( x_org + box_width/2.0 - text_width/2.0,
                             y_org + 310 - asc, 
                             0 );
                
                draw_string( font, string );
            }
            glPopMatrix();
        }
        /* Draw text indicating race requirements (if race not completed), 
         or results in race if race completed. */
        draw_status_msg( x_org, y_org, box_width, box_height );

#else

        /* Draw text indicating race requirements (if race not completed), 
         or results in race if race completed. */
        draw_status_msg( x_org, y_org, box_width, box_height );

#endif


        /* Draw preview */
        if ( g_game.practicing ) {
            list_elem_t elem;
            open_course_data_t *data;
            
            elem = listbox_get_current_item( race_listbox );
            data = (open_course_data_t*) get_list_elem_data( elem );
            current_course = data->course;
        } else {
            list_elem_t elem;
            race_data_t *data;
            
            elem = listbox_get_current_item( race_listbox );
            data = (race_data_t*) get_list_elem_data( elem );
            current_course = data->course;
        }
        
        glDisable( GL_TEXTURE_2D );
        
        glColor4f( 0.0, 0.0, 0.0, 0.3 );
        
#ifdef __APPLE__
        float margin = 4.f * mHeight / 320;
        float yoffset = 26 * mHeight / 320 + 30 * mHeight / 320;
        glBegin( GL_QUADS );
        {
            glVertex2f( x_org, y_org + yoffset );
            glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset );
            glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset+107 * mHeight / 320 );
            glVertex2f( x_org, y_org + yoffset+107 * mHeight / 320 );
        }
        glEnd();
#else
        glBegin( GL_QUADS );
        {
            glVertex2f( x_org+box_width-140, y_org+66 );
            glVertex2f( x_org+box_width, y_org+66 );
            glVertex2f( x_org+box_width, y_org+66+107 );
            glVertex2f( x_org+box_width-140, y_org+66+107 );
        }
        glEnd();
#endif

        glColor4f( 1.0, 1.0, 1.0, 1.0 );
        glEnable( GL_TEXTURE_2D );
        
        if ( !get_texture_binding( current_course, &texobj ) ) {
            if ( !get_texture_binding( "no_preview", &texobj ) ) {
                texobj = 0;
            }
        }
        
        glBindTexture( GL_TEXTURE_2D, texobj );
        
#ifdef __APPLE__
        glBegin( GL_QUADS );
        {
            glTexCoord2d( 0, 0);
            glVertex2f( x_org + margin, y_org + yoffset+margin );
            
            glTexCoord2d( 1, 0);
            glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin );
            
            glTexCoord2d( 1, 1);
            glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin+99 * mHeight / 320 );
            
            glTexCoord2d( 0, 1);
            glVertex2f( x_org + margin, y_org + yoffset+margin+99 * mHeight / 320 );
        }
        glEnd();
        
#else
        glBegin( GL_QUADS );
        {
            glTexCoord2d( 0, 0);
            glVertex2f( x_org+box_width-136, y_org+70 );
            
            glTexCoord2d( 1, 0);
            glVertex2f( x_org+box_width-4, y_org+70 );
            
            glTexCoord2d( 1, 1);
            glVertex2f( x_org+box_width-4, y_org+70+99 );
            
            glTexCoord2d( 0, 1);
            glVertex2f( x_org+box_width-136, y_org+70+99 );
        }
        glEnd();
#endif
    }
    
    
    /*---------------------------------------------------------------------------*/
    /*! 
     Mode initialization function
     \author  jfpatry
     \date    Created:  2000-09-24
     \date    Modified: 2000-09-24
     */
    static void race_select_init(void)
    {
        listbox_list_elem_to_string_fptr_t conv_func = NULL;
        point2d_t dummy_pos = {0, 0};
        int i;
        
        winsys_set_display_func( main_loop );
        winsys_set_idle_func( main_loop );
        winsys_set_reshape_func( reshape );
        winsys_set_mouse_func( ui_event_mouse_func );
        winsys_set_motion_func( ui_event_motion_func );
        winsys_set_passive_motion_func( ui_event_motion_func );
        
        plyr = get_player_data( local_player() );
        
        /* Setup the race list */
        if ( g_game.practicing ) {
            g_game.current_event = "__Practice_Event__";
            g_game.current_cup = "__Practice_Cup__";
            race_list = get_open_courses_list();
            conv_func = get_name_from_open_course_data;
            cup_data = NULL;
            last_completed_race = NULL;
            event_data = NULL;
        } else {
            event_data = (event_data_t*) get_list_elem_data( 
                                                            get_event_by_name( g_game.current_event ) );
            check_assertion( event_data != NULL,
                            "Couldn't find current event." );
            cup_data = (cup_data_t*) get_list_elem_data(
                                                        get_event_cup_by_name( event_data, g_game.current_cup ) );
            check_assertion( cup_data != NULL,
                            "Couldn't find current cup." );
            race_list = get_cup_race_list( cup_data );
            conv_func = get_name_from_race_data;
        }
        
        /* Unless we're coming back from a race, initialize the race data to 
         defaults.
         */
        if ( g_game.prev_mode != GAME_OVER ) {
            /* Make sure we don't play previously loaded course */
            cup_complete = False;
            
            /* Initialize the race data */
            cur_elem = get_list_head( race_list );
            
            if ( g_game.practicing ) {
                g_game.race.course = NULL;
                g_game.race.name = NULL;
                g_game.race.description = NULL;
                
                for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
                    g_game.race.herring_req[i] = 0;
                    g_game.race.time_req[i] = 0;
                    g_game.race.score_req[i] = 0;
                }
                
                g_game.race.mirrored = False;
                g_game.race.conditions = RACE_CONDITIONS_SUNNY;
                g_game.race.windy = False;
                g_game.race.snowing = False;
            } else {
                /* Not practicing */
                
                race_data_t *data;
                data = (race_data_t*) get_list_elem_data( cur_elem );
                g_game.race = *data;
                
                if ( is_cup_complete( event_data, 
                                     get_event_cup_by_name( 
                                                           event_data, 
                                                           g_game.current_cup ) ) )
                {
                    cup_complete = True;
                    last_completed_race = get_list_tail( race_list );
                } else {
                    cup_complete = False;
                    last_completed_race = NULL;
                }
            }
        } else {
            /* Back from a race */
            if ( !g_game.race_aborted ) {
                update_race_results();
            }
            
            if (!g_game.practicing && !cup_complete) {
                if ( was_current_race_won() ) {
                    update_for_won_race();
                    
                    /* Advance to next race */
                    if ( cur_elem != get_list_tail( race_list ) ) {
                        cur_elem = get_next_list_elem( race_list, cur_elem );
                    }
                } else {
                    /* lost race */
                    plyr->lives -= 1;
                }
                print_debug( DEBUG_GAME_LOGIC, "Current lives: %d", plyr->lives );
            }
        }
        
        back_btn = button_create( dummy_pos,
                                 80 * mWidth / 480, 48 * mHeight / 320, 
                                 "button_label", 
                                 (mWidth>320)?"Back":"<< " );
        button_set_hilit_font_binding( back_btn, "button_label_hilit" );
        button_set_visible( back_btn, True );
        button_set_click_event_cb( back_btn, back_click_cb, NULL );
        
        start_btn = button_create( dummy_pos,
                                  80 * mWidth / 480, 48 * mHeight / 320,
                                  "button_label",
                                  (mWidth>320)?"Race":" >>" );
        button_set_hilit_font_binding( start_btn, "button_label_hilit" );
        button_set_disabled_font_binding( start_btn, "button_label_disabled" );
        button_set_visible( start_btn, True );
        button_set_click_event_cb( start_btn, start_click_cb, NULL );
        
#ifdef __APPLE__
        race_listbox = listbox_create( dummy_pos,
                                      mWidth - 170 * mHeight / 320, 44 * mHeight / 320,
                                      "course_name_label",
                                      race_list,
                                      conv_func );
        
#else
        race_listbox = listbox_create( dummy_pos,
                                      460 * mHeight / 320, 44 * mHeight / 320,
                                      "listbox_item",
                                      race_list,
                                      conv_func );
        
#endif
        
        
        listbox_set_current_item( race_listbox, cur_elem );
        
        listbox_set_item_change_event_cb( race_listbox, 
                                         race_listbox_item_change_cb, 
                                         NULL );
        
        listbox_set_visible( race_listbox, True );
        
        /* 
         * Create text area 
         */
#ifdef __APPLE__
        desc_ta = textarea_create( dummy_pos,
                                  150, 147,
                                  "race_description",
                                  "" );
        
#else
        desc_ta = textarea_create( dummy_pos,
                                  312, 107,
                                  "race_description",
                                  "" );
        
#endif
        
        if ( g_game.practicing ) {
            open_course_data_t *data;
            data = (open_course_data_t*) get_list_elem_data( cur_elem );
            textarea_set_text( desc_ta, data->description );
        } else {
            race_data_t *data;
            data = (race_data_t*) get_list_elem_data( cur_elem );
            textarea_set_text( desc_ta, data->description );
        }
        
        textarea_set_visible( desc_ta, True );
        
        
        /* 
         * Create state buttons - only if practicing or if cup_complete
         */
        
        if ( g_game.practicing || cup_complete ) {
            /* mirror */
            mirror_ssbtn = ssbutton_create( dummy_pos,
                                           32, 32,
                                           2 );
            ssbutton_set_state_image( mirror_ssbtn, 
                                     0, 
                                     "mirror_button",
                                     make_point2d( 0.0/64.0, 32.0/64.0 ),
                                     make_point2d( 32.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state_image( mirror_ssbtn, 
                                     1, 
                                     "mirror_button",
                                     make_point2d( 32.0/64.0, 32.0/64.0 ),
                                     make_point2d( 64.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored );
#ifdef __APPLE__
            ssbutton_set_visible( mirror_ssbtn, False );
#else
            ssbutton_set_visible( mirror_ssbtn, True );
#endif
            
            /* conditions */
            conditions_ssbtn = ssbutton_create( dummy_pos,
                                               32, 32,
                                               4 );

            float border = 2.0;
            ssbutton_set_state_image( conditions_ssbtn, 
                                     0, 
                                     "conditions_button",
                                     make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ),
                                     make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ),
                                     white );
            
            ssbutton_set_state_image( conditions_ssbtn, 
                                     1, 
                                     "conditions_button",
                                     make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ),
                                     make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ),
                                     white );
            
            ssbutton_set_state_image( conditions_ssbtn, 
                                     2, 
                                     "conditions_button",
                                     make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ),
                                     make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ),
                                     white );

            ssbutton_set_state_image( conditions_ssbtn, 
                                     3, 
                                     "conditions_button",
                                     make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ),
                                     make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ),
                                     white );
            
            ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions );
            ssbutton_set_visible( conditions_ssbtn, True );

#ifdef __APPLE__
            ssbutton_set_visible( conditions_ssbtn, False );
#else
            ssbutton_set_visible( conditions_ssbtn, True );
#endif
            
            /* wind */
            wind_ssbtn = ssbutton_create( dummy_pos,
                                         32, 32,
                                         2 );
            ssbutton_set_state_image( wind_ssbtn, 
                                     0, 
                                     "wind_button",
                                     make_point2d( 0.0/64.0, 32.0/64.0 ),
                                     make_point2d( 32.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state_image( wind_ssbtn, 
                                     1, 
                                     "wind_button",
                                     make_point2d( 32.0/64.0, 32.0/64.0 ),
                                     make_point2d( 64.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy );
#ifdef __APPLE__
            ssbutton_set_visible( wind_ssbtn, False );
#else
            ssbutton_set_visible( wind_ssbtn, True );
#endif
            
            /* snow */
            snow_ssbtn = ssbutton_create( dummy_pos,
                                         32, 32,
                                         2 );
            ssbutton_set_state_image( snow_ssbtn, 
                                     0, 
                                     "snow_button",
                                     make_point2d( 0.0/64.0, 32.0/64.0 ),
                                     make_point2d( 32.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state_image( snow_ssbtn, 
                                     1, 
                                     "snow_button",
                                     make_point2d( 32.0/64.0, 32.0/64.0 ),
                                     make_point2d( 64.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing );
#ifdef __APPLE__
            ssbutton_set_visible( snow_ssbtn, False );
#else
            ssbutton_set_visible( snow_ssbtn, True );
#endif
            /* XXX snow button doesn't do anything, so disable for now */
            ssbutton_set_enabled( snow_ssbtn, False );
            
            /* Can't change conditions if in cup mode */
            if ( !g_game.practicing ) {
                ssbutton_set_enabled( conditions_ssbtn, False );
                ssbutton_set_enabled( wind_ssbtn, False );
                ssbutton_set_enabled( snow_ssbtn, False );
                ssbutton_set_enabled( mirror_ssbtn, False );
            }
            
        } else {
            conditions_ssbtn = NULL;
            wind_ssbtn = NULL;
            snow_ssbtn = NULL;
            mirror_ssbtn = NULL;
        }
        
        update_race_data();
        update_button_enabled_states();
        
        play_music( "start_screen" );
    }
示例#17
0
/*! 
 Mode initialization function
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void race_select_init(void)
{
    listbox_list_elem_to_string_fptr_t conv_func = NULL;
    point2d_t dummy_pos = {0, 0};
    int i;
    
    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( ui_event_mouse_func );
    winsys_set_motion_func( ui_event_motion_func );
    winsys_set_passive_motion_func( ui_event_motion_func );
    
    plyr = get_player_data( local_player() );
    
    /* Setup the race list */
    if ( g_game.practicing ) {
        g_game.current_event = "__Practice_Event__";
        g_game.current_cup = "__Practice_Cup__";
        if(g_game.is_speed_only_mode)
            race_list = get_speed_courses_list();
        else
            race_list = get_score_courses_list();
        conv_func = get_name_from_open_course_data;
        cup_data = NULL;
        last_completed_race = NULL;
        event_data = NULL;
    } else {
        event_data = (event_data_t*) get_list_elem_data( 
                                                        get_event_by_name( g_game.current_event ) );
        check_assertion( event_data != NULL,
                        "Couldn't find current event." );
        cup_data = (cup_data_t*) get_list_elem_data(
                                                    get_event_cup_by_name( event_data, g_game.current_cup ) );
        check_assertion( cup_data != NULL,
                        "Couldn't find current cup." );
        race_list = get_cup_race_list( cup_data );
        conv_func = get_name_from_race_data;
    }
    
    /* Unless we're coming back from a race, initialize the race data to 
     defaults.
     */
    if ( g_game.prev_mode != GAME_OVER ) {
        /* Make sure we don't play previously loaded course */
        cup_complete = False;
        
        /* Initialize the race data */
        cur_elem = get_list_head( race_list );
        
        if ( g_game.practicing ) {
            g_game.race.course = NULL;
            g_game.race.name = NULL;
            g_game.race.description = NULL;
            
            for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
                g_game.race.herring_req[i] = 0;
                g_game.race.time_req[i] = 0;
                g_game.race.score_req[i] = 0;
            }
            
            g_game.race.mirrored = False;
            g_game.race.conditions = RACE_CONDITIONS_SUNNY;
            g_game.race.windy = False;
            g_game.race.snowing = False;
        } else {
            /* Not practicing */
            
            race_data_t *data;
            data = (race_data_t*) get_list_elem_data( cur_elem );
            g_game.race = *data;
            
            if ( is_cup_complete( event_data, 
                                 get_event_cup_by_name( 
                                                       event_data, 
                                                       g_game.current_cup ) ) )
            {
                cup_complete = True;
                last_completed_race = get_list_tail( race_list );
            } else {
                cup_complete = False;
                last_completed_race = NULL;
            }
        }
    } else {
        /* Back from a race */
        if ( !g_game.race_aborted ) {
            update_race_results();
        }
        
    }
    
    back_btn = button_create( dummy_pos,
                             150, 40, 
                             "button_label", 
                             Localize("Back","") );
    button_set_hilit_font_binding( back_btn, "button_label_hilit" );
    button_set_visible( back_btn, True );
    button_set_click_event_cb( back_btn, back_click_cb, NULL );
    
    start_btn = button_create( dummy_pos,
                              150, 40,
                              "button_label",
                              Localize("Race!","") );
    button_set_hilit_font_binding( start_btn, "button_label_hilit" );
    button_set_disabled_font_binding( start_btn, "button_label_disabled" );
    button_set_visible( start_btn, True );
    button_set_click_event_cb( start_btn, start_click_cb, NULL );
    
#ifdef __APPLE__
    race_listbox = listbox_create( dummy_pos,
                                  300, 44,
                                  "course_name_label",
                                  race_list,
                                  conv_func );
    
#else
    race_listbox = listbox_create( dummy_pos,
                                  460, 44,
                                  "listbox_item",
                                  race_list,
                                  conv_func );
    
#endif
    
    
    listbox_set_current_item( race_listbox, cur_elem );
    
    listbox_set_item_change_event_cb( race_listbox, 
                                     race_listbox_item_change_cb, 
                                     NULL );
    
    listbox_set_visible( race_listbox, True );
    
    /* 
     * Create text area 
     */
#ifdef __APPLE__
    desc_ta = textarea_create( dummy_pos,
                              170, 147,
                              "race_description",
                              "" );
    
#else
    desc_ta = textarea_create( dummy_pos,
                              312, 107,
                              "race_description",
                              "" );
    
#endif
    
    if ( g_game.practicing ) {
        open_course_data_t *data;
        data = (open_course_data_t*) get_list_elem_data( cur_elem );
        textarea_set_text( desc_ta, data->description );
    } else {
        race_data_t *data;
        data = (race_data_t*) get_list_elem_data( cur_elem );
        textarea_set_text( desc_ta, data->description );
    }
    
    textarea_set_visible( desc_ta, True );
    
    
    /* 
     * Create state buttons - only if practicing or if cup_complete
     */
    
    if ( g_game.practicing || cup_complete ) {
        /* mirror */
        mirror_ssbtn = ssbutton_create( dummy_pos,
                                       32, 32,
                                       2 );
        ssbutton_set_state_image( mirror_ssbtn, 
                                 0, 
                                 "mirror_button",
                                 make_point2d( 0.0/64.0, 32.0/64.0 ),
                                 make_point2d( 32.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state_image( mirror_ssbtn, 
                                 1, 
                                 "mirror_button",
                                 make_point2d( 32.0/64.0, 32.0/64.0 ),
                                 make_point2d( 64.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored );
#ifdef __APPLE__
        ssbutton_set_visible( mirror_ssbtn, False );
#else
        ssbutton_set_visible( mirror_ssbtn, True );
#endif
        
        /* conditions */
        conditions_ssbtn = ssbutton_create( dummy_pos,
                                           32, 32,
                                           4 );
        
        float border = 2.0;
        ssbutton_set_state_image( conditions_ssbtn, 
                                 0, 
                                 "conditions_button",
                                 make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ),
                                 make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state_image( conditions_ssbtn, 
                                 1, 
                                 "conditions_button",
                                 make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ),
                                 make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state_image( conditions_ssbtn, 
                                 2, 
                                 "conditions_button",
                                 make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ),
                                 make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state_image( conditions_ssbtn, 
                                 3, 
                                 "conditions_button",
                                 make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ),
                                 make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions );
        ssbutton_set_visible( conditions_ssbtn, True );
        
#ifdef __APPLE__
        ssbutton_set_visible( conditions_ssbtn, False );
#else
        ssbutton_set_visible( conditions_ssbtn, True );
#endif
        
        /* wind */
        wind_ssbtn = ssbutton_create( dummy_pos,
                                     32, 32,
                                     2 );
        ssbutton_set_state_image( wind_ssbtn, 
                                 0, 
                                 "wind_button",
                                 make_point2d( 0.0/64.0, 32.0/64.0 ),
                                 make_point2d( 32.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state_image( wind_ssbtn, 
                                 1, 
                                 "wind_button",
                                 make_point2d( 32.0/64.0, 32.0/64.0 ),
                                 make_point2d( 64.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy );
#ifdef __APPLE__
        ssbutton_set_visible( wind_ssbtn, False );
#else
        ssbutton_set_visible( wind_ssbtn, True );
#endif
        
        /* snow */
        snow_ssbtn = ssbutton_create( dummy_pos,
                                     32, 32,
                                     2 );
        ssbutton_set_state_image( snow_ssbtn, 
                                 0, 
                                 "snow_button",
                                 make_point2d( 0.0/64.0, 32.0/64.0 ),
                                 make_point2d( 32.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state_image( snow_ssbtn, 
                                 1, 
                                 "snow_button",
                                 make_point2d( 32.0/64.0, 32.0/64.0 ),
                                 make_point2d( 64.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing );
#ifdef __APPLE__
        ssbutton_set_visible( snow_ssbtn, False );
#else
        ssbutton_set_visible( snow_ssbtn, True );
#endif
        /* XXX snow button doesn't do anything, so disable for now */
        ssbutton_set_enabled( snow_ssbtn, False );
        
        /* Can't change conditions if in cup mode */
        if ( !g_game.practicing ) {
            ssbutton_set_enabled( conditions_ssbtn, False );
            ssbutton_set_enabled( wind_ssbtn, False );
            ssbutton_set_enabled( snow_ssbtn, False );
            ssbutton_set_enabled( mirror_ssbtn, False );
        }
        
    } else {
        conditions_ssbtn = NULL;
        wind_ssbtn = NULL;
        snow_ssbtn = NULL;
        mirror_ssbtn = NULL;
    }
    
    update_race_data();
    update_button_enabled_states();
    
    play_music( "start_screen" );
}
示例#18
0
static void race_select_init(void)
{
    point2d_t dummy_pos = {0, 0};
	coord_t button_coord;
	list_elem_t tmp;
    int i;
    
    scoreboard_open=True;
    
    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( GameMenu_mouse_func );
    winsys_set_motion_func( GameMenu_motion_func );
    winsys_set_passive_motion_func( GameMenu_motion_func );
	winsys_set_joystick_func( NULL );
	winsys_set_joystick_button_func( NULL );
    
	winsys_reset_js_bindings();
	winsys_add_js_axis_bindings();
	winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_A, SDLK_RETURN);
	winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_B, SDLK_ESCAPE);
    
	winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDLK_LEFT);
	winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDLK_RIGHT);

	GameMenu_init();
	setup_gui();

    plyr = get_player_data( local_player() );
    
    /* Setup the race list */
    if ( g_game.practicing ) {
        g_game.current_event = "__Practice_Event__";
        g_game.current_cup = "__Practice_Cup__";
#ifdef SPEED_MODE
        if(g_game.is_speed_only_mode)
            race_list = get_speed_courses_list();
        else
            race_list = get_score_courses_list();
#else
        race_list = get_score_courses_list();
#endif
        cup_data = NULL;
        last_completed_race = NULL;
        event_data = NULL;
    }
    
    /* Unless we're coming back from a race, initialize the race data to 
     defaults.
     */
    if ( g_game.prev_mode != GAME_OVER ) {
        /* Make sure we don't play previously loaded course */
        cup_complete = False;
        
        /* Initialize the race data */
		if (cur_elem==NULL)
		{
			cur_elem = get_list_head( race_list );
		}
		else
		{
			bool_t needs_changing=False;
			tmp=get_list_head(race_list);
			while (tmp!=cur_elem && tmp!=NULL)
			{
				tmp=get_next_list_elem(race_list, tmp);
			}
			if (!tmp)
			{
				cur_elem = get_list_head( race_list );
			}
		}
        
        if ( g_game.practicing ) {
            g_game.race.course = NULL;
            g_game.race.name = NULL;
            g_game.race.description = NULL;
            
            for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
                g_game.race.herring_req[i] = 0;
                g_game.race.time_req[i] = 0;
                g_game.race.score_req[i] = 0;
            }
            
            g_game.race.mirrored = False;
            g_game.race.conditions = RACE_CONDITIONS_SUNNY;
            g_game.race.windy = False;
            g_game.race.snowing = False;
        } else {
            /* Not practicing */
            
            race_data_t *data;
            data = (race_data_t*) get_list_elem_data( cur_elem );
            g_game.race = *data;
            
            if ( is_cup_complete( event_data, 
                                 get_event_cup_by_name( 
                                                       event_data, 
                                                       g_game.current_cup ) ) )
            {
                cup_complete = True;
                last_completed_race = get_list_tail( race_list );
            } else {
                cup_complete = False;
                last_completed_race = NULL;
            }
        }
    } else {
        /* Back from a race */
        if ( !g_game.race_aborted ) {
            update_race_results();
        }
	}
    
    /* 
     * Create text area 
     */
    desc_ta = textarea_create( make_point2d(
		0.1*getparam_x_resolution(), 0.2*getparam_y_resolution()),
		0.4*getparam_x_resolution(), 0.23*getparam_y_resolution(), "race_description", "" );
    
    textarea_set_visible( desc_ta, True );
    
    update_race_data();
    
	button_coord.x_coord_type=button_coord.y_coord_type=NORMALIZED_COORD;
	button_coord.x=0.50;
	button_coord.y=0.85;
	button_coord.x_just=CENTER_JUST;
	button_coord.y_just=CENTER_JUST;
    
	gui_add_widget(course_title_label=create_label(""), &button_coord);
    
	button_coord.x=0.1;
	button_coord.x_just=LEFT_JUST;
	gui_add_widget(prev_course_btn=create_button(LEFT_ARROW, prev_cb), &button_coord);
    
	button_coord.x=0.9;
	button_coord.x_just=RIGHT_JUST;
	gui_add_widget(next_course_btn=create_button(RIGHT_ARROW, next_cb), &button_coord);
    
	course_title_label->font_binding="race_selection_title";
	prev_course_btn->font_binding="race_selection_title";
	next_course_btn->font_binding="race_selection_title";
    
	button_coord.x=0.30;
	button_coord.y=0.09;
	button_coord.x_just=CENTER_JUST;
	gui_add_widget(back_button=create_button(get_back_text(), back_cb), &button_coord);
    
	button_coord.x=0.70;
	gui_add_widget(play_button=create_button(get_race_text(), play_cb), &button_coord);
    
	init_scoreboard_labels();
	init_scoreboard();

    play_music( "start_screen" );
}
示例#19
0
void game_over_loop( scalar_t time_step )
{
    player_data_t *plyr = get_player_data( local_player() );
    int width, height;
    width = getparam_x_resolution();
    height = getparam_y_resolution();

    check_gl_error();

    /* Check joystick */
    if ( is_joystick_active() ) {
        update_joystick();

        if ( is_joystick_continue_button_down() )
        {
            set_game_mode( NEXT_MODE );
            winsys_post_redisplay();
            return;
        }
    }

    new_frame_for_fps_calc();

    update_audio();

    clear_rendering_context();

    setup_fog();

    update_player_pos( plyr, 0 );
    update_view( plyr, 0 );

    setup_view_frustum( plyr, NEAR_CLIP_DIST,
                        getparam_forward_clip_distance() );

    draw_sky(plyr->view.pos);

    draw_fog_plane();

    set_course_clipping( True );
    set_course_eye_point( plyr->view.pos );
    setup_course_lighting();
    render_course();
    draw_trees();

    if ( getparam_draw_particles() ) {
        draw_particles( plyr );
    }

    draw_tux();
    draw_tux_shadow();

    set_gl_options( GUI );

    ui_setup_display();

    draw_game_over_text();

#ifndef __APPLE__
    draw_hud( plyr );
#endif
    draw_hud_training(plyr);
    reshape( width, height );

    winsys_swap_buffers();
}
示例#20
0
void racing_loop( scalar_t time_step )
{
    int width, height;
    player_data_t *plyr = get_player_data( local_player() );
    bool_t joy_left_turn = False;
    bool_t joy_right_turn = False;
    scalar_t joy_turn_fact = 0.0;
    bool_t joy_paddling = False;
    bool_t joy_braking = False;
    bool_t joy_tricks = False;
    bool_t joy_charging = False;
    bool_t airborne;
    vector_t dir;
    scalar_t speed;
    scalar_t terrain_weights[NumTerrains];
    int new_terrain = 0;
    int slide_volume;


    dir = plyr->vel;
    speed = normalize_vector(&dir);

    airborne = (bool_t) ( plyr->pos.y > ( find_y_coord(plyr->pos.x, 
						       plyr->pos.z) + 
					  JUMP_MAX_START_HEIGHT ) );

    width = getparam_x_resolution();
    height = getparam_y_resolution();

    check_gl_error();

    new_frame_for_fps_calc();

    update_audio();

    clear_rendering_context();

    setup_fog();


    /*
     * Joystick
     */
    if ( is_joystick_active() ) {
	scalar_t joy_x;
	scalar_t joy_y;

	update_joystick();

	joy_x = get_joystick_x_axis();
	joy_y = get_joystick_y_axis();

	if ( joy_x > 0.1 ) {
	    joy_right_turn = True;
	    joy_turn_fact = joy_x;
	} else if ( joy_x < -0.1 ) {
	    joy_left_turn = True;
	    joy_turn_fact = joy_x;
	}

	if ( getparam_joystick_brake_button() >= 0 ) {
	    joy_braking = 
		is_joystick_button_down( getparam_joystick_brake_button() );
	} 
	if ( !joy_braking ) {
	    joy_braking = (bool_t) ( joy_y > 0.5 );
	}

	if ( getparam_joystick_paddle_button() >= 0 ) {
	    joy_paddling = 
		is_joystick_button_down( getparam_joystick_paddle_button() );
	}
	if ( !joy_paddling ) {
	    joy_paddling = (bool_t) ( joy_y < -0.5 );
	}

	if ( getparam_joystick_jump_button() >= 0 ) {
	    joy_charging = 
		is_joystick_button_down( getparam_joystick_jump_button() );
	}

	if ( getparam_joystick_trick_button() >= 0 ) {
	    joy_tricks = 
		is_joystick_button_down( getparam_joystick_trick_button() );
	}
    }

    /* Update braking */
    plyr->control.is_braking = (bool_t) ( braking || joy_braking );

    if ( airborne ) {
	new_terrain = (1<<NumTerrains);

	/*
	 * Tricks
	 */
	if ( trick_modifier || joy_tricks ) {
	    if ( left_turn || joy_left_turn ) {
		plyr->control.barrel_roll_left = True;
	    }
	    if ( right_turn || joy_right_turn ) {
		plyr->control.barrel_roll_right = True;
	    }
	    if ( paddling || joy_paddling ) {
		plyr->control.front_flip = True;
	    }
	    if ( plyr->control.is_braking ) {
		plyr->control.back_flip = True;
	    }
	}


    } else {

	get_surface_type(plyr->pos.x, plyr->pos.z, terrain_weights);
	if (terrain_weights[Snow] > 0) {
	    new_terrain |= (1<<Snow);
	}
	if (terrain_weights[Rock] > 0) {
	    new_terrain |= (1<<Rock);
	} 
	if (terrain_weights[Ice] > 0) {
	    new_terrain |= (1<<Ice);
	}

    }

    /*
     * Jumping
     */
    calc_jump_amt( time_step );

    if ( ( charging || joy_charging ) && 
	 !plyr->control.jump_charging && !plyr->control.jumping ) 
    {
	plyr->control.jump_charging = True;
	charge_start_time = g_game.time;
    }

    if ( ( !charging && !joy_charging ) && plyr->control.jump_charging ) {
	plyr->control.jump_charging = False;
	plyr->control.begin_jump = True;
    }


    /* 
     * Turning 
     */
    if ( ( left_turn || joy_left_turn )  ^ (right_turn || joy_right_turn ) ) {
	bool_t turning_left = (bool_t) ( left_turn || joy_left_turn );

	if ( joy_left_turn || joy_right_turn ) {
	    plyr->control.turn_fact = joy_turn_fact;
	} else {
	    plyr->control.turn_fact = (turning_left?-1:1);
	}

	plyr->control.turn_animation += (turning_left?-1:1) *
	    0.15 * time_step / 0.05;
	plyr->control.turn_animation = 
	    min(1.0, max(-1.0, plyr->control.turn_animation));
    } else {
	plyr->control.turn_fact = 0;

	/* Decay turn animation */
	if ( time_step < ROLL_DECAY_TIME_CONSTANT ) {
	    plyr->control.turn_animation *= 
		1.0 - time_step/ROLL_DECAY_TIME_CONSTANT;
	} else {
	    plyr->control.turn_animation = 0.0;
	}
    }

    
    /*
     * Paddling
     */
    if ( ( paddling || joy_paddling ) && plyr->control.is_paddling == False ) {
	plyr->control.is_paddling = True;
	plyr->control.paddle_time = g_game.time;
    }

    /*
     * Play flying sound
     */
    if (new_terrain & (1<<NumTerrains)) {
	set_sound_volume("flying_sound", min(128, speed*2));
	if (!(last_terrain & (1<<NumTerrains))) {
	    play_sound( "flying_sound", -1 );
	}
    } else {
	if (last_terrain & (1<<NumTerrains)) {
	    halt_sound( "flying_sound" );
	}
    }

    /*
     * Play sliding sound
     */
    slide_volume = min( (((pow(plyr->control.turn_fact, 2)*128)) +
			 (plyr->control.is_braking?128:0) +
			 (plyr->control.jumping?128:0) +
			 20) *
			(speed/10), 128 );
    if (new_terrain & (1<<Snow)) {
	set_sound_volume("snow_sound", slide_volume * terrain_weights[Snow]);
	if (!(last_terrain & (1<<Snow))) {
	    play_sound( "snow_sound", -1 );
	}
    } else {
	if (last_terrain & (1<<Snow)) {
	    halt_sound( "snow_sound" );
	}
    }
    if (new_terrain & (1<<Rock)) {
	set_sound_volume("rock_sound", 128*pow((speed/2), 2) * 
			 terrain_weights[Rock]);
	if (!(last_terrain & (1<<Rock))) {
	    play_sound( "rock_sound", -1 );
	}
    } else {
	if (last_terrain & (1<<Rock)) {
	    halt_sound( "rock_sound" );
	}
    }
    if (new_terrain & (1<<Ice)) {
	set_sound_volume("ice_sound", slide_volume * terrain_weights[Ice]);
	if (!(last_terrain & (1<<Ice))) {
	    play_sound( "ice_sound", -1 );
	}
    } else {
	if (last_terrain & (1<<Ice)) {
	    halt_sound( "ice_sound" );
	}
    }
    last_terrain = new_terrain; 


    /*
     * Tricks
     */
    if ( plyr->control.barrel_roll_left || plyr->control.barrel_roll_right ) {
	plyr->control.barrel_roll_factor += 
		( plyr->control.barrel_roll_left ? -1 : 1 ) * 0.15 * time_step / 0.05;
	if ( (plyr->control.barrel_roll_factor  > 1) ||
	     (plyr->control.barrel_roll_factor  < -1) ) {
	    plyr->control.barrel_roll_factor = 0;
	    plyr->control.barrel_roll_left = plyr->control.barrel_roll_right = False;
	}
    }
    if ( plyr->control.front_flip || plyr->control.back_flip ) {
	plyr->control.flip_factor += 
		( plyr->control.back_flip ? -1 : 1 ) * 0.15 * time_step / 0.05;
	if ( (plyr->control.flip_factor  > 1) ||
	     (plyr->control.flip_factor  < -1) ) {
	    plyr->control.flip_factor = 0;
	    plyr->control.front_flip = plyr->control.back_flip = False;
	}
    }

    update_player_pos( plyr, time_step );
	
    /* 
     * Track Marks
     */
    add_track_mark( plyr );


    update_view( plyr, time_step );

    setup_view_frustum( plyr, NEAR_CLIP_DIST, 
			getparam_forward_clip_distance() );

    draw_sky(plyr->view.pos);

    draw_fog_plane();

    set_course_clipping( True );
    set_course_eye_point( plyr->view.pos );
    setup_course_lighting();
    render_course();
    draw_trees();

    if ( getparam_draw_particles() ) {
	update_particles( time_step );
	draw_particles( plyr );
    }

    draw_tux();
    draw_tux_shadow();

    draw_hud( plyr );

    reshape( width, height );

    winsys_swap_buffers();

    g_game.time += time_step;
} 
示例#21
0
/*!
 Draws the text for the game over screen
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
void draw_game_over_text( void )
{
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    int x_org, y_org;
    int box_width, box_height;
    const char *string;
    int string_w, asc, desc;
    char buff[BUFF_LEN];
    font_t *font;
    font_t *stat_label_font;
    player_data_t *plyr = get_player_data( local_player() );

    box_width = 200;
    box_height = 250;

    x_org = w/2.0 - box_width/2.0;
    y_org = h/2.0 - box_height/2.0;

    if ( !get_font_binding( "race_over", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                       "Couldn't get font for binding race_over" );
    } else {

        if ( !g_game.race_aborted && g_game.practicing && g_game.needs_save_or_display_rankings) {
            string = Localize("World rankings", "");
        } else string = Localize("Race Over", "");

        get_font_metrics( font, string, &string_w, &asc, &desc );

        glPushMatrix();
        {
            glTranslatef( x_org + box_width/2.0 - string_w/2.0,
                          y_org + box_height - asc,
                          0 );
            bind_font_texture( font );
            draw_string( font, string );
        }
        glPopMatrix();
    }

    /* If race was aborted, don't print stats, and if doesnt need to print rankings, dont print them */

    if ( !g_game.race_aborted && !g_game.needs_save_or_display_rankings && g_game.practicing)

    {
        if ( !get_font_binding( "race_stats_label", &stat_label_font ) ||
                !get_font_binding( "race_stats", &font ) )
        {
            print_warning( IMPORTANT_WARNING,
                           "Couldn't get fonts for race stats" );
        } else {
            int asc2;
            int desc2;
            get_font_metrics( font, "", &string_w, &asc, &desc );
            get_font_metrics( stat_label_font, "", &string_w, &asc2, &desc2 );

            if ( asc < asc2 ) {
                asc = asc2;
            }
            if ( desc < desc2 ) {
                desc = desc2;
            }

            glPushMatrix();
            {
                int minutes;
                int seconds;
                int hundredths;

                glTranslatef( x_org,
                              y_org + 150,
                              0 );

                bind_font_texture( stat_label_font );

                if (!strcmp(get_calculation_mode(),"jump") )
                {

                    draw_string( stat_label_font, Localize("Flying time: ","src/game_over.c"));
                    g_game.time = plyr->control.fly_total_time;
                }
                //default mode
                else {
                    draw_string( stat_label_font, Localize("Time: ","src/game_over.c"));
                }
                get_time_components( g_game.time, &minutes, &seconds, &hundredths );
                sprintf( buff, "%02d:%02d:%02d", minutes, seconds, hundredths );

                bind_font_texture( font );
                draw_string( font, buff );
            }
            glPopMatrix();

            glPushMatrix();
            {
                glTranslatef( x_org,
                              y_org + 150 - (asc + desc),
                              0 );

                bind_font_texture( stat_label_font );
#ifdef __APPLE__
                if (!g_game.is_speed_only_mode)
#endif
                    draw_string( stat_label_font, Localize("Fish: ","") );

                sprintf( buff, "%3d", plyr->herring );

                bind_font_texture( font );
#ifdef __APPLE__
                if (!g_game.is_speed_only_mode)
#endif
                    draw_string( font, buff );
            }
            glPopMatrix();

            glPushMatrix();
            {
                glTranslatef( x_org,
                              y_org + 150 - 2*(asc + desc),
                              0 );

                bind_font_texture( stat_label_font );
#ifdef __APPLE__
                if (!g_game.is_speed_only_mode)
#endif
                    draw_string( stat_label_font, "Score: " );

                sprintf( buff, "%6d", plyr->score );

                bind_font_texture( font );

#ifdef __APPLE__
                if (!g_game.is_speed_only_mode)
#endif
                    draw_string( font, buff );
            }
            glPopMatrix();
        }
    }
#ifdef __APPLE__
    //display rankings if needed
    else if ( !g_game.race_aborted && g_game.practicing && g_game.needs_save_or_display_rankings)
    {
        if ( !get_font_binding( "race_stats_label", &stat_label_font ) ||
                !get_font_binding( "race_stats", &font ) )
        {
            print_warning( IMPORTANT_WARNING,
                           "Couldn't get fonts for race stats" );
        } else {
            int asc2;
            int desc2;
            get_font_metrics( font, "", &string_w, &asc, &desc );
            get_font_metrics( stat_label_font, "", &string_w, &asc2, &desc2 );

            if ( asc < asc2 ) {
                asc = asc2;
            }
            if ( desc < desc2 ) {
                desc = desc2;
            }

            glPushMatrix();
            {
                glTranslatef( x_org - 50,
                              y_org + 150,
                              0 );

                bind_font_texture( stat_label_font );
                draw_string( stat_label_font, Localize("Friends: ","") );
                if (strcmp(friendsRanking, "Empty friends list.")==0) {
                    free(friendsRanking);
                    friendsRanking = strdup(Localize("No friends",""));
                }

                if (friendsPercent>=0)
                    sprintf( buff, "%s (%.1f%%)", friendsRanking , friendsPercent);
                else
                    sprintf( buff, "%s", friendsRanking);

                bind_font_texture( font );
                draw_string( font, buff );
            }
            glPopMatrix();

            glPushMatrix();
            {
                glTranslatef( x_org -50 ,
                              y_org + 150 - (asc + desc),
                              0 );

                bind_font_texture( stat_label_font );
                draw_string( stat_label_font, Localize("Country: ","") );

                sprintf( buff, "%s (%.1f%%)", countryRanking , countryPercent );

                bind_font_texture( font );
                draw_string( font, buff );
            }
            glPopMatrix();

            glPushMatrix();
            {
                glTranslatef( x_org - 50,
                              y_org + 150 - 2*(asc + desc),
                              0 );

                bind_font_texture( stat_label_font );
                draw_string( stat_label_font, Localize("World: ","") );

                sprintf( buff, "%s (%.1f%%)", worldRanking , worldPercent);

                bind_font_texture( font );
                draw_string( font, buff );
            }
            glPopMatrix();
        }
    }
#endif

    if ( g_game.race_aborted && !g_game.race_time_over) {
        string = Localize("Race aborted.","");
    } else if ( g_game.race_aborted && g_game.race_time_over) {
        string = Localize("Time is up.","");
    } else if ( ( g_game.practicing || is_current_cup_complete() ) &&
                did_player_beat_best_results() )
    {

        if ( !g_game.race_aborted && g_game.practicing && g_game.needs_save_or_display_rankings) {
            string = "";
        } else string = Localize("You beat your best score!","");

    } else {
        string = "";
    }

    if ( !get_font_binding( "race_result_msg", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                       "Couldn't get font for binding race_result_msg" );
    } else {
        get_font_metrics( font, string, &string_w, &asc, &desc );
        glPushMatrix();
        {
            glTranslatef( x_org + box_width/2. - string_w/2.,
                          y_org + desc +20.,
                          0 );
            bind_font_texture( font );
            draw_string( font, string );
        }
        glPopMatrix();
    }
#ifdef __APPLE__
    //Draws "touch screen to contin"ue
    string = Localize("Touch screen to continue","");

    if ( !get_font_binding( "fps", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                       "Couldn't get font for binding race_result_msg" );
    } else {
        get_font_metrics( font, string, &string_w, &asc, &desc );
        glPushMatrix();
        {
            glTranslatef( x_org + box_width/2. - string_w/2.,
                          y_org + desc-20.,
                          0 );
            bind_font_texture( font );
            draw_string( font, string );
        }
        glPopMatrix();
    }
#endif

}