Back to index

extremetuxracer  0.5beta
intro.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  *
00005  * Copyright (C) 1999-2001 Jasmin F. Patry
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00022 #include "intro.h"
00023 
00024 #include "ppgltk/audio/audio.h"
00025 #include "ppgltk/alg/defs.h"
00026 
00027 #include "keyframe.h"
00028 #include "course_render.h"
00029 #include "gl_util.h"
00030 #include "fps.h"
00031 #include "loop.h"
00032 #include "render_util.h"
00033 #include "view.h"
00034 #include "model_hndl.h"
00035 #include "tux_shadow.h"
00036 #include "fog.h"
00037 #include "hud.h"
00038 #include "viewfrustum.h"
00039 #include "phys_sim.h"
00040 #include "part_sys.h"
00041 #include "course_load.h"
00042 #include "joystick.h"
00043 #include "game_config.h"
00044 #include "winsys.h"
00045 #include "course_mgr.h"
00046 #include "snow.h"
00047 
00048 #include "game_mgr.h"
00049 
00050 #include "bench.h"
00051 
00052 Intro::Intro()
00053 {
00054        int i, num_items;
00055     Item *item_locs;
00056 
00057     pp::Vec2d start_pt = get_start_pt();
00058 
00059     init_key_frame();
00060 
00061     players[0].orientation_initialized = false;
00062 
00063     players[0].view.initialized = false;
00064 
00065     gameMgr->time = 0.0;
00066        gameMgr->airbornetime = 0.0;
00067     players[0].herring = 0;
00068     players[0].score = 0;
00069 
00070        if(Benchmark::getMode()==Benchmark::PAUSED){
00071               set_start_pt(Benchmark::getPosition());
00072        }else{
00073               players[0].pos.x = start_pt.x;
00074        players[0].pos.z = start_pt.y;
00075        }
00076     init_physical_simulation();
00077 
00078     players[0].vel = pp::Vec3d(0,0,0);
00079 
00080     clear_particles();
00081 
00082     set_view_mode( players[0], ABOVE );
00083     update_view( players[0], EPS ); 
00084 
00085     if(gameMgr->getCurrentRace().snowing) {
00086         int snowtype = gameMgr->getCurrentRace().snowtype;
00087         if(snowtype > -1) {
00088             SetSnowType(snowtype);
00089         }
00090         init_snow(players[0].pos);
00091     }
00092     
00093     if(gameMgr->getCurrentRace().windy) {
00094               int windtype = gameMgr->getCurrentRace().windtype;
00095         if(windtype > -1) {
00096             SetWindType(windtype);
00097         }
00098        }
00099     
00100     // reset all items as collectable 
00101     num_items = get_num_items();
00102     item_locs = get_item_locs();
00103     for (i = 0; i < num_items; i++ ) {
00104               item_locs[i].setCollected(false);
00105               /*            
00106               if(item_locs[i].getTypeCollectable()==Item::COLLECTED){
00107               item_locs[i].setCollectable(Item::YES);
00108               }
00109               */
00110     }
00111 
00112 if (gameMgr->gametype!=GameMgr::PRACTICING) {
00113 std::string mus = gameMgr->currentEvent->music;
00114 mus += "_intro";
00115 play_music( (char *)mus.c_str() );
00116 }
00117 else
00118 {
00119 play_music("intro");
00120 }    
00121 
00122 }
00123 
00124 Intro::~Intro()
00125 {
00126        
00127        
00128 }
00129 
00130 void
00131 Intro::loop(float timeStep)
00132 {
00133        int width, height;
00134 
00135     if ( getparam_do_intro_animation() == false ) {
00136         if(gameMgr->getCurrentRace().snowing) reset_snow();
00137               set_game_mode( RACING );
00138               return;
00139     }
00140 
00141     width = getparam_x_resolution();
00142     height = getparam_y_resolution();
00143 
00144     // Check joystick
00145     if ( is_joystick_active() ) {
00146               update_joystick();
00147 
00148               if ( is_joystick_continue_button_down() ) {
00149               abort( players[0] );
00150               return;
00151               }
00152     }
00153     
00154     fpsCounter.update();
00155 
00156     update_audio();
00157 
00158     update_key_frame( players[0], timeStep );
00159 
00160     clear_rendering_context();
00161 
00162     fogPlane.setup();
00163 
00164     update_view( players[0], timeStep );
00165 
00166     setup_view_frustum( players[0], NEAR_CLIP_DIST, 
00167                      getparam_forward_clip_distance() );
00168 
00169     draw_sky( players[0].view.pos );
00170 
00171     draw_fog_plane();
00172 
00173     set_course_clipping( true );
00174     set_course_eye_point( players[0].view.pos );
00175     setup_course_lighting();
00176     render_course( );
00177     //Draw snow
00178     if(gameMgr->getCurrentRace().snowing) {
00179         update_snow( timeStep, false, players[0].pos );
00180         draw_snow(players[0].view.pos);
00181     }
00182     draw_trees();
00183 
00184     ModelHndl->draw_tux();
00185     draw_tux_shadow();
00186 
00187     HUD1.draw(players[0]);
00188 
00189     reshape( width, height );
00190     winsys_swap_buffers();
00191        
00192        if( Benchmark::getMode() != Benchmark::NONE){
00193               abort(players[0]);
00194        }
00195 }
00196 
00197 void
00198 Intro::abort( Player& plyr )
00199 {
00200     pp::Vec2d start_pt = get_start_pt();
00201     
00202     if(gameMgr->getCurrentRace().snowing) reset_snow();
00203 
00204     set_game_mode( RACING );
00205 
00206        plyr.orientation_initialized = false;
00207     plyr.view.initialized = true;
00208 
00209        plyr.pos.x = start_pt.x;
00210     plyr.pos.z = start_pt.y;
00211     winsys_post_redisplay();
00212 }
00213 
00214 bool
00215 Intro::keyPressEvent(SDLKey key)
00216 { 
00217        abort( players[0] );
00218        
00219        return true;
00220 }