Exemple #1
0
 /*! 
  Mode loop function
  \author  jfpatry
  \date    Created:  2000-09-24
  \date    Modified: 2000-09-24
  */
 static void race_select_loop( scalar_t time_step )
 {
     check_gl_error();
     
     update_audio();
     
     set_gl_options( GUI );
     
     clear_rendering_context();
     
     ui_setup_display();
     
     if (getparam_ui_snow()) {
         update_ui_snow( time_step, 
                        (bool_t) ( wind_ssbtn != NULL && 
                                  ssbutton_get_state( wind_ssbtn ) ) );
         draw_ui_snow();
     }
     
     ui_draw_menu_decorations();
     
     set_widget_positions_and_draw_decorations();
     
     ui_draw();
     
     reshape( getparam_x_resolution(), getparam_y_resolution() );
     
     winsys_swap_buffers();
 }
void draw_ui_snow( void )
{
    GLuint   texture_id;
    char *binding;
    pp::Vec2d *pt, *tex_min, *tex_max;
    double size;
    double xres, yres;
    int i;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    
    UIMgr.setupDisplay();

    binding = "ui_snow_particle";
    if (!get_texture_binding( "ui_snow_particle", &texture_id ) ) {
	print_warning( IMPORTANT_WARNING,
		       "Couldn't get texture for binding %s", 
		       binding );
	texture_id = 0;
    } 

    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

    glBindTexture( GL_TEXTURE_2D, texture_id );

    glColor4f( particleColor[0], 
	       particleColor[1], 
	       particleColor[2],
	       particleColor[3] );

    glPushMatrix();
    {
	for ( i=0; i<num_particles; i++) {
	    pt = &particles[i].pt;
	    size = particles[i].size;
	    tex_min = &particles[i].tex_min;
	    tex_max = &particles[i].tex_max;
	    glPushMatrix();
	    {
		glTranslatef( pt->x*xres, pt->y*yres, 0 );
		glBegin( GL_QUADS );
		{
		    glTexCoord2f( tex_min->x, tex_min->y );
		    glVertex2f( 0, 0 );
		    glTexCoord2f( tex_max->x, tex_min->y );
		    glVertex2f( size, 0 );
		    glTexCoord2f( tex_max->x, tex_max->y );
		    glVertex2f( size, size );
		    glTexCoord2f( tex_min->x, tex_max->y );
		    glVertex2f( 0, size );
		}
		glEnd();
	    }
	    glPopMatrix();
	} 
    }
    glPopMatrix();

} 
Exemple #3
0
static void preference_loop( scalar_t time_step )
{
    check_gl_error();
    
    update_audio();
    
    set_gl_options( GUI );
    
    clear_rendering_context();
    
    ui_setup_display();
    
    if (getparam_ui_snow()) {
        update_ui_snow( time_step, False );
        draw_ui_snow();
    }
    
    ui_draw_menu_decorations();
    
    draw_preference();
    
    ui_draw();
    
    reshape( getparam_x_resolution(), getparam_y_resolution() );
    
    winsys_swap_buffers();
}
Exemple #4
0
/*! 
 Draws the text for the loading screen
 \author  jfpatry
 */
void draw_loading_text( void )
{
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    int x_org, y_org;
    const char *string;
    int string_w, asc, desc;
    font_t *font;
    
    x_org = w/2.0;
    y_org = h/2.0;
    
    if ( !get_font_binding( "loading", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                      "Couldn't get font for binding loading" );
    } else {
        string = Localize("Loading, Please Wait...","");
        get_font_metrics( font, string, &string_w, &asc, &desc );
        
        glPushMatrix();
        {
            glTranslatef( w/2.0 - string_w/2.0,
                         h/2.0 - desc-30, 
                         0 );
            bind_font_texture( font );
            draw_string( font, string );
        }
        glPopMatrix();
    }
}
Exemple #5
0
static void credits_loop( scalar_t time_step )
{
    int width, height;
    width = getparam_x_resolution();
    height = getparam_y_resolution();
    
    check_gl_error();
    
    update_audio();
    
    clear_rendering_context();
    
    set_gl_options( GUI );
    
    ui_setup_display();
    
    draw_credits_text( time_step );
    
    if (getparam_ui_snow()) {
        update_ui_snow( time_step, False );
        draw_ui_snow();
    }
    
    ui_draw_menu_decorations();
    
    ui_draw();
    
    reshape( width, height );
    
    winsys_swap_buffers();
} 
  void
GameOver::loop(float timeStep)
{
  int width, height;
  width = getparam_x_resolution();
  height = getparam_y_resolution();

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

    if ( is_joystick_continue_button_down() )
    {
      if ( gameMgr->gametype != GameMgr::PRACTICING ) {
        set_game_mode( EVENT_RACE_SELECT );
      }else{
        set_game_mode( RACE_SELECT );
      }
      winsys_post_redisplay();
      return;
    }
  }
  fpsCounter.update();

  update_audio();

  clear_rendering_context();

  fogPlane.setup();
  update_player_pos( players[0], 0 );
  update_view( players[0], 0 );

  setup_view_frustum( players[0], NEAR_CLIP_DIST, 
      getparam_forward_clip_distance() );

  draw_sky(players[0].view.pos);
  draw_fog_plane();

  set_course_clipping( true );
  set_course_eye_point( players[0].view.pos );
  setup_course_lighting();
  render_course();
  draw_trees();
  if ( getparam_draw_particles() ) {
    draw_particles( players[0] );
  }

  ModelHndl->draw_tux();
  draw_tux_shadow();
  set_gl_options( GUI );

  UIMgr.setupDisplay();
  UIMgr.draw();

  HUD1.draw(players[0]);
  reshape( width, height );

  winsys_swap_buffers();
}
static void set_widget_positions()
{
    button_t **button_list[] = { &enter_event_btn,
				  &practice_btn,
                  //&rankings_btn,
                  &preference_btn,
       			  &credits_btn,
       			  &help_btn,
				  &quit_btn
                  };
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    int box_height;
    int box_max_y;
    int top_y;
    int bottom_y;
    int num_buttons = sizeof( button_list ) / sizeof( button_list[0] );
    int i;
    int tot_button_height = 0;
    int button_sep =0;
    int cur_y_pos;

    box_height = 200 * mHeight / 320;
    box_max_y = h - 150 * mHeight / 320;

    bottom_y = 0.4*h - box_height/2 + 30 * mHeight / 320;

    if ( bottom_y + box_height > box_max_y ) {
	bottom_y = box_max_y - box_height + 30 * mHeight / 320;
    }

    top_y = bottom_y + box_height;

    for (i=0; i<num_buttons; i++) {
	tot_button_height += button_get_height( *button_list[i] );
    }

    if ( num_buttons > 1 ) {
	button_sep = ( top_y - bottom_y - tot_button_height ) / 
	    ( num_buttons - 1 );
	button_sep = max( 0, button_sep );
    }

    cur_y_pos = top_y;
    for (i=0; i<num_buttons; i+=2) {
	cur_y_pos -= button_get_height( *button_list[i] );
	button_set_position( 
	    *button_list[i],
	    make_point2d( w/4.0 - button_get_width( *button_list[i] )/2.0,
			  cur_y_pos ) );
    button_set_position( 
	    *button_list[i+1],
	    make_point2d( w/4.0*3.0 - button_get_width( *button_list[i+1] )/2.0,
			  cur_y_pos ) );
	cur_y_pos -= button_sep;
    }
}
Exemple #8
0
/* This is the main loop of the game.  It dispatches into the loop
   functions of the various game modes.  */
void main_loop()
{
    if ( getparam_capture_mouse() ) {
        int w = getparam_x_resolution();
        int h = getparam_y_resolution();
        point2d_t pos;

        pos = ui_get_mouse_position();

        /* Flip y coordinates */
        pos.y = h - pos.y;

        if ( pos.x < 0 ) {
            pos.x = 0;
        }
        if ( pos.x > w-1 ) {
            pos.x = w-1;
        }
        if ( pos.y < 0 ) {
            pos.y = 0;
        }
        if ( pos.y > h-1 ) {
            pos.y = h-1;
        }

        winsys_warp_pointer( pos.x, pos.y );
    }

    if ( g_game.mode != new_mode ) {

        if ( g_game.mode >= 0 &&
                mode_funcs[ g_game.mode ].term_func != NULL )
        {
            ( mode_funcs[ g_game.mode ].term_func )( );
        }

        g_game.prev_mode = g_game.mode;

        g_game.mode = new_mode;

        if ( mode_funcs[ g_game.mode ].init_func != NULL ) {
            ( mode_funcs[ g_game.mode ].init_func )( );

            /* Reset time step clock so that there isn't a sudden
               jump when we start the new mode */
            reset_time_step_clock();
        }
    }

    g_game.time_step = calc_time_step();
    g_game.secs_since_start += g_game.time_step;

    if ( mode_funcs[ g_game.mode ].loop_func != NULL ) {
        ( mode_funcs[ g_game.mode ].loop_func )( g_game.time_step );
    }
}
Exemple #9
0
void init_ui_snow( void )
{
    int i;

	num_particles=orig_num_particles=PARTICLE_DENSITY*getparam_x_resolution()*getparam_y_resolution();

    for( i=0; i<num_particles; i++) {
	make_particle( i, frand(), frand() );
    }
    push_position = make_point2d( 0.0, 0.0 );
}
Exemple #10
0
void
reset_ui_snow_cursor_pos( point2d_t pos ) 
{
    scalar_t xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    push_position = make_point2d( pos.x/(scalar_t)xres,
				  pos.y/(scalar_t)yres );
    last_push_position = push_position;
    push_position_initialized = True;
}
Exemple #11
0
void
reset_ui_snow_cursor_pos( pp::Vec2d pos ) 
{
    double xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    push_position = pp::Vec2d( pos.x/(double)xres,
				  pos.y/(double)yres );
    last_push_position = push_position;
    push_position_initialized = true;
}
Exemple #12
0
void
make_ui_snow( point2d_t pos ) {
    scalar_t xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();

    if ( num_particles < MAX_NUM_PARTICLES ) {
	make_particle( num_particles, pos.x/xres, pos.y/yres );
	num_particles++;
    }
}
Exemple #13
0
void
make_ui_snow( pp::Vec2d pos ) {
    double xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();

    if ( num_particles < MAX_NUM_PARTICLES ) {
	make_particle( num_particles, pos.x/xres, pos.y/yres );
	num_particles++;
    }
}
Exemple #14
0
void
UIManager::setupDisplay()
{
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, getparam_x_resolution(), 
	     	0, getparam_y_resolution(), -1.0, 1.0 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslatef( 0.0, 0.0, -1.0 );

    glColor4f( 1.0, 1.0, 1.0, 1.0 );
}
Exemple #15
0
/*! 
  Sets up OpenGL rendering context for draw UI widgets

  \return  None
  \author  jfpatry
  \date    Created:  2000-09-16
  \date    Modified: 2000-09-16
*/
void ui_setup_display()
{
    scalar_t offset = OFFSET_AMT;

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrthof( 0, getparam_x_resolution(), 
	     0, getparam_y_resolution(), -1.0, 1.0 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslatef( offset, offset, -1.0 );

    glColor4f( 1.0, 1.0, 1.0, 1.0 );
}
Exemple #16
0
void 
push_ui_snow( pp::Vec2d pos )
{
    double xres, yres;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    push_position = pp::Vec2d( pos.x/(double)xres,
				  pos.y/(double)yres );
    if ( !push_position_initialized ) {
	last_push_position = push_position;
    }
    push_position_initialized = true;
}
Exemple #17
0
void draw_sponsor_loading()
{
    GLuint texobj;
	
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
	
    glEnable( GL_TEXTURE_2D );
    
    /* loading */
    if ( get_texture_binding( sponsor_selected, &texobj ) ) {
        glBindTexture( GL_TEXTURE_2D, texobj );
        draw_quad(0,0, w, h );
    }
	
}
Exemple #18
0
void 
push_ui_snow( point2d_t pos )
{
    scalar_t xres, yres;

	return;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    push_position = make_point2d( pos.x/(scalar_t)xres,
				  pos.y/(scalar_t)yres );
    if ( !push_position_initialized ) {
	last_push_position = push_position;
    }
    push_position_initialized = True;
}
Exemple #19
0
void loading_init(void) 
{
    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( NULL );
    
    passInLoop = 0;
    
    draw_loading_text();
	
	choose_sponsor();
    
    reshape( getparam_x_resolution(), getparam_y_resolution() );
    
    stop_music();
}
Exemple #20
0
/*! 
 Scrolls the credits text up the screen.
 \author  jfpatry
 \date    Created:  2000-09-27
 \date    Modified: 2000-09-27
 */
static void draw_credits_text( scalar_t time_step )
{
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    font_t* font;
    coord_t text_coord;
    int i, string_w, asc, desc;
    scalar_t y;
    
    y_offset += time_step * winsys_scale(CREDITS_SPEED + time_step*joystick_y*CREDITS_JOYSTICK_SPEED);
	if (y_offset<0)
	{
		y_offset=0;
	}
    y = CREDITS_MIN_Y+y_offset;
    
    text_coord.x=w/2;
    text_coord.y=y;
    text_coord.x_coord_type=ABSOLUTE_COORD;
    text_coord.y_coord_type=ABSOLUTE_COORD;
    text_coord.x_just=text_coord.y_just=CENTER_JUST;
    
    for (i=0; i<sizeof( credit_lines ) / sizeof( credit_lines[0] ); i++) {
        credit_line_t line = credit_lines[i];
        
        if ( !get_font_binding( line.binding, &font ) ) {
            print_warning( IMPORTANT_WARNING,
                          "Couldn't get font for binding %s",
                          line.binding );
        } else {
            get_font_metrics( font, line.text, &string_w, &asc, &desc );
            
            text_coord.y -= asc+desc;

            GameMenu_draw_text( line.text, 0, text_coord, line.binding );
        }
    }
    
    if ( text_coord.y > h+CREDITS_MAX_Y ) {
        go_back();
    }
}
Exemple #21
0
void
reset_ui_snow( void ) {
    scalar_t xres, yres;
	int i;
    
    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    
    /* Kill off & regenerate particles */
    for (i=0; i<num_particles; i++) {
        particle_t *p = &particles[i];
        
                /* Delete the particle */
                *p = particles[num_particles-1];
                num_particles -= 1;
    }
    
    num_particles = orig_num_particles;
    
    init_ui_snow();
}
Exemple #22
0
void init_arrays_for_particle(particle_t particle, GLfloat* vertices, GLfloat* tex_coords)
{
    point2d_t pt = particle.pt;
    scalar_t size = particle.size;
    point2d_t* tex_min = &particle.tex_min;
    point2d_t* tex_max = &particle.tex_max;
    scalar_t xres, yres;

#define TO_RELATIVE(screen, val) (((val)/screen*2.0)-1.0)

    xres=getparam_x_resolution();
    yres=getparam_y_resolution();
    
    vertices[0]=TO_RELATIVE(xres, pt.x*xres);
    vertices[1]=TO_RELATIVE(yres, pt.y*yres);
    
    vertices[2]=TO_RELATIVE(xres, pt.x*xres);
    vertices[3]=TO_RELATIVE(yres, pt.y*yres+size);
    
    vertices[4]=TO_RELATIVE(xres, pt.x*xres+size);
    vertices[5]=TO_RELATIVE(yres, pt.y*yres+size);
    
    vertices[6]=TO_RELATIVE(xres, pt.x*xres+size);
    vertices[7]=TO_RELATIVE(yres, pt.y*yres);
    
#undef TO_RELATIVE
    
    tex_coords[0]=tex_min->x;
    tex_coords[1]=tex_min->y;
    
    tex_coords[2]=tex_min->x;
    tex_coords[3]=tex_max->y;
    
    tex_coords[4]=tex_max->x;
    tex_coords[5]=tex_max->y;
    
    tex_coords[6]=tex_max->x;
    tex_coords[7]=tex_min->y;
}
Exemple #23
0
/*! 
 Mode loop function
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void race_select_loop( scalar_t time_step )
{
    use_hud_program();
    
    check_gl_error();
    
    update_audio();
    
    set_gl_options( GUI );
    
    clear_rendering_context();
    
    ui_setup_display();
    
    if (getparam_ui_snow()) {
        update_ui_snow( time_step, False );
        draw_ui_snow();
    }
    
    ui_draw_menu_decorations(False);
	
	if (price_update)
	{
		update_text();
		price_update = False;
	}
    
	GameMenu_draw();

	draw_preview();
    
	winsys_update_joysticks();

    ui_draw();
    
    reshape( getparam_x_resolution(), getparam_y_resolution() );
    
    winsys_swap_buffers();
}
Exemple #24
0
Paused::Paused()
{
	int centerX = getparam_x_resolution() / 2;
	int centerY = getparam_y_resolution() / 2;
	
	mp_backgroundFrm = new pp::Frame(pp::Vec2d(centerX-120,centerY-100),
								  pp::Vec2d(240,200));
	
	mp_pausedLbl = new pp::Label(pp::Vec2d(centerX,centerY+90),"paused",_("Paused"));
	mp_pausedLbl->alignment.center();
	mp_pausedLbl->alignment.top();
	

	mp_configBtn = new pp::Button(pp::Vec2d(centerX-150,centerY-15),
				     	pp::Vec2d(300, 40),
				     	"button_label",
				     	_("Configuration") );
	
    mp_configBtn->setHilitFontBinding("button_label_hilit");
	mp_configBtn->signalClicked.Connect(pp::CreateSlot(this,&Paused::configuration));
	
	mp_resumeBtn = new pp::Button(pp::Vec2d(centerX-150,centerY-55),
				     	pp::Vec2d(300, 40),
				     	"button_label",
				     	_("Resume") );
	
    mp_resumeBtn->setHilitFontBinding("button_label_hilit");
	mp_resumeBtn->signalClicked.Connect(pp::CreateSlot(this,&Paused::resume));

	mp_quitBtn = new pp::Button(pp::Vec2d(centerX-150,centerY-95),
				     	pp::Vec2d(300, 40),
				     	"button_label",
				     	_("Quit") );
	
    mp_quitBtn->setHilitFontBinding("button_label_hilit");
	mp_quitBtn->signalClicked.Connect(pp::CreateSlot(this,&Paused::quit));

	play_music( "paused" );
}
Exemple #25
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 draw_preview()
{
    GLuint texobj;
    
	{
		rect_t screen_rect;
		open_course_data_t *data;
        int w=getparam_x_resolution();
        int h=getparam_y_resolution();
        float colors[]={1, 1, 1, 1};
        shader_set_color(colors);

        data = (open_course_data_t*) get_list_elem_data( cur_elem );
		if ( !get_texture_binding( data->course, &texobj ) ) {
			if ( !get_texture_binding( "no_preview", &texobj ) ) {
				texobj = 0;
			}
		}
        
        glBindTexture( GL_TEXTURE_2D, texobj );

        draw_textured_quad(0.105*w, 0.45*h, 0.34*w, 0.34*h);
	}
}
Exemple #26
0
static void set_widget_positions_and_draw_decorations()
{
    int h = getparam_y_resolution();
    int box_width, box_height, box_max_y;
    int x_org, y_org;
    char *string;
    font_t *font;
    int text_width, asc, desc;
    list_t cup_list;
    GLuint texobj;
    
#ifdef __APPLE__
    /* set the dimensions of the box in which all widgets should fit */
    box_width = 300;
    box_height = 310;
    box_max_y = h - 128;
    x_org = 10;
    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 + 40 - button_get_width( back_btn )/2.0,
                                     12 ) );
    
    button_set_position(
                        continue_btn,
                        make_point2d( x_org + 232 - button_get_width( continue_btn )/2.0,
                                     12 ) );
                                     
    button_set_position(
                        howToPlay_btn,
                        make_point2d( x_org + 160 - button_get_width( continue_btn )/2.0,
                                     100 ) );
    //Out of the field of view
    //in Tux Rider World Challenge, there is no more events and cup, just training
    //I'm adapting from The Tux Racer system by selecting the first and only event
    //I hide its list box out of the field of view
    //and each cup for this event is a training
    
    listbox_set_position( 
                         event_listbox,
                         make_point2d( x_org+500,
                                      y_org + 500 ) );
    
    listbox_set_position( 
                         cup_listbox,
                         make_point2d( x_org+50,
                                      y_org + 193 ) );
    
#else
    int w = getparam_x_resolution();

    /* set the dimensions of the box in which all widgets should fit */
    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(
                        continue_btn,
                        make_point2d( x_org + 329 - button_get_width( continue_btn )/2.0,
                                     42 ) );
    
    listbox_set_position( 
                         cup_listbox,
                         make_point2d( x_org + 52,
                                      y_org + 103 ) );
    
    listbox_set_position( 
                         event_listbox,
                         make_point2d( x_org + 52,
                                      y_org + 193 ) );
    
#endif
    
    /* 
     * Draw other stuff 
     */
    
    /* Event & cup icons */
    if ( !get_texture_binding( get_event_icon_texture_binding( event_data ),
                              &texobj ) ) {
        texobj = 0;
    }
    
    glBindTexture( GL_TEXTURE_2D, texobj );
    
    glBegin( GL_QUADS );
    {
        point2d_t tll, tur;
        point2d_t ll, ur;
        
#ifdef __APPLE__
        //out of the field of view
        ll = make_point2d( x_org, y_org + 500 );
        ur = make_point2d( x_org + 44, y_org + 500 + 44 );
        tll = make_point2d( 0, 0 );
        tur = make_point2d( 44.0/64.0, 44.0/64.0 );
#else
        ll = make_point2d( x_org, y_org + 193 );
        ur = make_point2d( x_org + 44, y_org + 193 + 44 );
        tll = make_point2d( 0, 0 );
        tur = make_point2d( 44.0/64.0, 44.0/64.0 );
#endif
        
        glTexCoord2f( tll.x, tll.y );
        glVertex2f( ll.x, ll.y );
        
        glTexCoord2f( tur.x, tll.y );
        glVertex2f( ur.x, ll.y );
        
        glTexCoord2f( tur.x, tur.y );
        glVertex2f( ur.x, ur.y );
        
        glTexCoord2f( tll.x, tur.y );
        glVertex2f( ll.x, ur.y );
    }
    glEnd();
    
    
    if ( !get_texture_binding( 
                              get_cup_icon_texture_binding( 
                                                           (cup_data_t*) get_list_elem_data( cur_cup ) ), &texobj ) ) 
    {
        texobj = 0;
    }
    
    glBindTexture( GL_TEXTURE_2D, texobj );
    
#ifdef __APPLE__DISABLED__
    {
        point2d_t tll, tur;
        point2d_t ll, ur;
        
        ll = make_point2d( x_org, y_org + 103 );
        ur = make_point2d( x_org + 44, y_org + 103 + 44 );
        tll = make_point2d( 0, 0 );
        tur = make_point2d( 44.0/64.0, 44.0/64.0 );
        
        const GLfloat vertices []=
        {
            ll.x, ll.y,
            ur.x, ll.y,
            ur.x, ur.y,
            ll.x, ur.y
        };
        
        const GLfloat texCoords []=
        {
            tll.x, tll.y,
            tur.x, tll.y,
            tur.x, tur.y,
            tll.x, tur.y,
        };
        
        glEnableClientState (GL_VERTEX_ARRAY);
        glVertexPointer (2, GL_FLOAT , 0, vertices);	
        glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    }
#else
    glBegin( GL_QUADS );
    {
        point2d_t tll, tur;
        point2d_t ll, ur;
        
#ifdef __APPLE__
        ll = make_point2d( x_org, y_org + 193 );
        ur = make_point2d( x_org + 44, y_org + 193 + 44 );
        tll = make_point2d( 0, 0 );
        tur = make_point2d( 44.0/64.0, 44.0/64.0 );
#else
        ll = make_point2d( x_org, y_org + 103 );
        ur = make_point2d( x_org + 44, y_org + 103 + 44 );
        tll = make_point2d( 0, 0 );
        tur = make_point2d( 44.0/64.0, 44.0/64.0 );
#endif
        
        glTexCoord2f( tll.x, tll.y );
        glVertex2f( ll.x, ll.y );
        
        glTexCoord2f( tur.x, tll.y );
        glVertex2f( ur.x, ll.y );
        
        glTexCoord2f( tur.x, tur.y );
        glVertex2f( ur.x, ur.y );
        
        glTexCoord2f( tll.x, tur.y );
        glVertex2f( ll.x, ur.y );
    }
    glEnd();
#endif
    
    if ( !get_font_binding( "menu_label", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                      "Couldn't get font for binding menu_label" );
    } else {
        bind_font_texture( font );
#ifdef __APPLE__
        string = "Select a training";
#else
        string = "Select event and cup";
#endif
        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();
    }
    
    if ( !get_font_binding( "event_and_cup_label", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                      "Couldn't get font for binding menu_label" );
    } 
#ifdef __APPLE__
    
    cur_event = listbox_get_current_item( event_listbox );
    event_data = (event_data_t*) get_list_elem_data( cur_event );
    cup_list = get_event_cup_list( event_data );
    cur_cup = listbox_get_current_item( cup_listbox );
    
    if ( is_cup_complete( event_data, cur_cup ) ) {
        string = "You've won this Training !";
    } else if ( is_cup_first_incomplete_cup( event_data, cur_cup ) ) {
        string = "You must complete this training first";
    } else {
        string = "You cannot enter this training yet"; 
    }
    
    if ( !get_font_binding( "cup_status", &font ) ) {
        print_warning( IMPORTANT_WARNING,
                      "Couldn't get font for binding cup_status" );
    } else {
        bind_font_texture( font );
        
        get_font_metrics( font, string, &text_width, &asc, &desc );
        
        glPushMatrix();
        {
            glTranslatef( x_org + box_width/2.0 - text_width/2.0,
                         y_org+140, 
                         0 );
            
            draw_string( font, string );
        }
        glPopMatrix();
    }
    
#else
    else {
Exemple #27
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" );
    }
Exemple #28
0
void draw_ui_snow( void )
{
    GLuint   texture_id;
    char *binding;
    point2d_t *pt, *tex_min, *tex_max;
    scalar_t size;
    scalar_t xres, yres;
    int i;

    xres = getparam_x_resolution();
    yres = getparam_y_resolution();
    
    ui_setup_display();

    binding = "snow_particle";
    if (!get_texture_binding( "snow_particle", &texture_id ) ) {
	print_warning( IMPORTANT_WARNING,
		       "Couldn't get texture for binding %s", 
		       binding );
	texture_id = 0;
    }

    glBindTexture( GL_TEXTURE_2D, texture_id );
    
    shader_set_color(particle_colour);
    
    {
        GLfloat* vertices=(GLfloat*)malloc(8*num_particles*sizeof(GLfloat));
        GLfloat* tex_coords=(GLfloat*)malloc(8*num_particles*sizeof(GLfloat));
        GLushort* indices=(GLushort*)malloc(6*num_particles*sizeof(GLushort));
        
        for ( i=0; i<num_particles; i++) {
            init_arrays_for_particle(particles[i], vertices+i*8, tex_coords+i*8);
            int firstvert=i*4;
            int firstindex=i*6;
            indices[0+firstindex]=0+firstvert;
            indices[1+firstindex]=1+firstvert;
            indices[2+firstindex]=2+firstvert;
            indices[3+firstindex]=2+firstvert;
            indices[4+firstindex]=3+firstvert;
            indices[5+firstindex]=0+firstvert;

        }
        
        //print_debug(DEBUG_OTHER, "indices %d %d %d %d %d %d %d %d %d %d %d %d", indices[0], indices[1], indices[2], indices[3], indices[4], indices[5], indices[6], indices[7], indices[8], indices[9], indices[10], indices[11]);
        //print_debug(DEBUG_OTHER, "vertices %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5], vertices[6], vertices[7], vertices[8], vertices[9], vertices[10], vertices[11], vertices[12], vertices[13], vertices[14], vertices[15]);
        
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        
        glVertexAttribPointer(shader_get_attrib_location(SHADER_VERTEX_NAME), 2, GL_FLOAT, GL_FALSE, 0, vertices);
        glEnableVertexAttribArray(shader_get_attrib_location(SHADER_VERTEX_NAME));
        
        glVertexAttribPointer(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME), 2, GL_FLOAT, GL_FALSE, 0, tex_coords);
        glEnableVertexAttribArray(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME));
        
        glDrawElements(GL_TRIANGLES, num_particles*6, GL_UNSIGNED_SHORT, indices);
        
        glVertexAttribPointer(shader_get_attrib_location(SHADER_VERTEX_NAME), 2, GL_FLOAT, GL_FALSE, 0, 0);
        glDisableVertexAttribArray(shader_get_attrib_location(SHADER_VERTEX_NAME));
        
        glVertexAttribPointer(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME), 2, GL_FLOAT, GL_FALSE, 0, 0);
        glDisableVertexAttribArray(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME));

        free(vertices);
        free(tex_coords);
    }
} 
Exemple #29
0
static void draw_preference()
{
    int h = getparam_y_resolution();
    int box_width, box_height, box_max_y;
    int x_org, y_org;
    char *string;
    font_t *font;
    int text_width, asc, desc;
    list_t cup_list;
    GLuint texobj;
    
    box_width = getparam_x_resolution();
    box_height = 310 * mHeight / 320;
    box_max_y = h - 128 * mHeight / 320;
    x_org = 0;
    y_org = h/2 - box_height/2 + 30 * mHeight / 320;
    
    if ( y_org + box_height > box_max_y ) {
        y_org = box_max_y - box_height;
    }
    
    button_set_position( 
                        chancel_btn,
                        make_point2d( 0,
                                     0 ) );
    
    button_set_position(
                        save_btn,
                        make_point2d( box_width - button_get_width( save_btn ),
                                     0 ) );
    listbox_set_position( 
                         sound_listbox,
                         make_point2d( box_width - 140 * mHeight / 320,
                                      y_org + 290 * mHeight / 320 ) );

    listbox_set_position( 
                         video_listbox,
                         make_point2d( box_width - 140 * mHeight / 320,
                                      y_org + 190 * mHeight / 320 ) );
    
    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 = "Audio enabled";
        
        glPushMatrix();
        {
            glTranslatef( x_org + 70 * mHeight / 320,
                         y_org + 300 * mHeight / 320, 
                         0 );
            
            draw_string( font, string );
        }
        glPopMatrix();

        string = "Video quality";
        
        glPushMatrix();
        {
            glTranslatef( x_org + 70 * mHeight / 320,
                         y_org + 200 * mHeight / 320, 
                         0 );
            
            draw_string( font, string );
        }
        glPopMatrix();
    }
    
}
Exemple #30
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;
}