Back to index

extremetuxracer  0.5beta
paused.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #include "paused.h"
00021 
00022 #include "ppgltk/ui_mgr.h"
00023 #include "ppgltk/audio/audio.h"
00024 
00025 #include "game_config.h"
00026 #include "gl_util.h"
00027 #include "fps.h"
00028 #include "render_util.h"
00029 #include "phys_sim.h"
00030 #include "view.h"
00031 #include "course_render.h"
00032 #include "model_hndl.h"
00033 #include "tux_shadow.h"
00034 #include "loop.h"
00035 #include "fog.h"
00036 #include "snow.h"
00037 #include "viewfrustum.h"
00038 #include "hud.h"
00039 #include "part_sys.h"
00040 #include "joystick.h"
00041 #include "course_mgr.h"
00042 
00043 #include "game_mgr.h"
00044 
00045 #include "bench.h"
00046 
00047 Paused::Paused()
00048 {
00049        int centerX = getparam_x_resolution() / 2;
00050        int centerY = getparam_y_resolution() / 2;
00051        
00052        mp_backgroundFrm = new pp::Frame(pp::Vec2d(centerX-120,centerY-100),
00053                                                           pp::Vec2d(240,200));
00054        
00055        mp_pausedLbl = new pp::Label(pp::Vec2d(centerX,centerY+90),"paused",_("Paused"));
00056        mp_pausedLbl->alignment.center();
00057        mp_pausedLbl->alignment.top();
00058        
00059 
00060        mp_configBtn = new pp::Button(pp::Vec2d(centerX-150,centerY-15),
00061                                    pp::Vec2d(300, 40),
00062                                    "button_label",
00063                                    _("Configuration") );
00064        
00065     mp_configBtn->setHilitFontBinding("button_label_hilit");
00066        mp_configBtn->signalClicked.Connect(pp::CreateSlot(this,&Paused::configuration));
00067        
00068        mp_resumeBtn = new pp::Button(pp::Vec2d(centerX-150,centerY-55),
00069                                    pp::Vec2d(300, 40),
00070                                    "button_label",
00071                                    _("Resume") );
00072        
00073     mp_resumeBtn->setHilitFontBinding("button_label_hilit");
00074        mp_resumeBtn->signalClicked.Connect(pp::CreateSlot(this,&Paused::resume));
00075 
00076        mp_quitBtn = new pp::Button(pp::Vec2d(centerX-150,centerY-95),
00077                                    pp::Vec2d(300, 40),
00078                                    "button_label",
00079                                    _("Quit") );
00080        
00081     mp_quitBtn->setHilitFontBinding("button_label_hilit");
00082        mp_quitBtn->signalClicked.Connect(pp::CreateSlot(this,&Paused::quit));
00083 
00084 if (gameMgr->gametype!=GameMgr::PRACTICING) {
00085 std::string mus = gameMgr->currentEvent->music;
00086 mus += "_paused";
00087 play_music( (char *)mus.c_str() );
00088 }
00089 else
00090 {
00091 play_music("paused");
00092 }
00093 
00094 }
00095 
00096 Paused::~Paused()
00097 {
00098        delete mp_configBtn;
00099        delete mp_resumeBtn;
00100        delete mp_quitBtn;
00101        delete mp_backgroundFrm;
00102        delete mp_pausedLbl;
00103 }
00104        
00105 void
00106 Paused::loop(float timeStep)
00107 {
00108     int width, height;
00109     width = getparam_x_resolution();
00110     height = getparam_y_resolution();
00111 
00112     // Check joystick 
00113     if ( is_joystick_active() ) {
00114               update_joystick();
00115 
00116               if ( is_joystick_continue_button_down() )
00117               {
00118                      set_game_mode( RACING );
00119                      winsys_post_redisplay();
00120                   return;
00121               }
00122     }
00123 
00124     fpsCounter.update();
00125 
00126     update_audio();
00127 
00128     clear_rendering_context();
00129 
00130     fogPlane.setup();
00131 
00132     update_player_pos( players[0], 0 );
00133     update_view( players[0], 0 );
00134 
00135     setup_view_frustum( players[0], NEAR_CLIP_DIST, 
00136                      getparam_forward_clip_distance() );
00137 
00138     draw_sky( players[0].view.pos );
00139 
00140     draw_fog_plane( );
00141 
00142     set_course_clipping( true );
00143     set_course_eye_point( players[0].view.pos );
00144     setup_course_lighting();
00145     render_course();
00146     //Draw snow
00147     if(gameMgr->getCurrentRace().snowing) {
00148         draw_snow(players[0].view.pos);
00149     }
00150     draw_trees();
00151 
00152     if ( getparam_draw_particles() ) {
00153               draw_particles( players[0] );
00154     }
00155 
00156     ModelHndl->draw_tux();
00157     draw_tux_shadow();
00158 
00159     set_gl_options( GUI );
00160 
00161     UIMgr.setupDisplay();
00162 
00163     HUD1.draw(players[0]);
00164        
00165        if(Benchmark::getMode()!=Benchmark::PAUSED){
00166        UIMgr.draw();
00167        }      
00168        reshape( width, height );
00169     winsys_swap_buffers();
00170 }
00171 
00172 bool
00173 Paused::keyPressEvent(SDLKey key)
00174 {
00175        if(key=='q') {
00176               Paused::quit();
00177         } else {
00178               if(Benchmark::getMode() == Benchmark::PAUSED){
00179                      set_game_mode( GAME_OVER );
00180               }else{
00181                      set_game_mode( RACING );
00182               }
00183        }
00184        winsys_post_redisplay();
00185        return true;
00186 }
00187 
00188 void
00189 Paused::resume()
00190 {
00191        set_game_mode( RACING );
00192        winsys_post_redisplay();
00193 }
00194 
00195 void
00196 Paused::quit()
00197 {
00198        gameMgr->abortRace();
00199     set_game_mode( GAME_OVER );
00200 }
00201 
00202 void
00203 Paused::configuration()
00204 {
00205        set_game_mode( CONFIGURATION );
00206        UIMgr.setDirty();
00207 }