Back to index

extremetuxracer  0.5beta
credits_trans.cpp
Go to the documentation of this file.
00001 /* 
00002  * Extreme Tux Racer (Not Copyrighted)
00003  * 
00004  * based on Planet Penguin Racer, Open Racer, and Tux Racer: 
00005  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00006  *
00007  * Copyright (C) 1999-2001 Jasmin F. Patry
00008  * 
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License
00011  * as published by the Free Software Foundation; either version 2
00012  * of the License, or (at your option) any later version.
00013  * 
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022  */
00023 
00024 
00025 #include "credits.h"
00026 
00027 #include "ppgltk/audio/audio.h"
00028 #include "ppgltk/font.h"
00029 
00030 
00031 #define CREDITS_MAX_Y -140
00032 #define CREDITS_MIN_Y 64
00033 
00034 typedef struct {
00035     pp::Font *font;
00036        char *binding;
00037     char *text;
00038 } credit_line_t;
00039 
00040 static credit_line_t credit_lines[] = 
00041 {
00042        { NULL, "credits_h2", N_("Translators") },
00043        { NULL, "credits_text", "Nicosmos (French)" },
00044        { NULL, "credits_text", "teksturi (Finnish)" },
00045        { NULL, "credits_text", "arith, spacedwarv, and JoyFM (German)" },
00046        { NULL, "credits_text", "spectrum (Italian)" },
00047        { NULL, "credits_text", "Karl Ove Hufthammer (Norwegian Bokmål)" },
00048        { NULL, "credits_text", "Karl Ove Hufthammer (Norwegian Nynorsk)" },
00049        { NULL, "credits_text", "Andreas Tarandi and pingvin (Swedish)" },
00050        { NULL, "credits_text", "Asciimonster (Dutch)" },
00051        { NULL, "credits_text", "woody (Polish)" },
00052        { NULL, "credits_text", "ttsmj (Slovak)" },             
00053        { NULL, "credits_text", "Jonan (Spanish)" },     
00054        { NULL, "credits_text", "EFU (Russian)" },              
00055        { NULL, "credits_text_small", N_("Other (incomplete) translations are from the PPRacer Project.") },
00056 };
00057 
00058 CreditsTrans::CreditsTrans()
00059  : m_yOffset(0.0)
00060 {
00061        for (unsigned int i=0; i<sizeof( credit_lines ) / sizeof( credit_lines[0] ); i++) {
00062               credit_lines[i].font = pp::Font::get(credit_lines[i].binding);        
00063        }
00064        
00065   play_music( "credits_screen" );
00066 }
00067 
00068 
00069 CreditsTrans::~CreditsTrans()
00070 {      
00071 }
00072 
00073 void
00074 CreditsTrans::loop(float timeStep)
00075 {
00076        int width, height;
00077 
00078   width = getparam_x_resolution();
00079   height = getparam_y_resolution();
00080 
00081   update_audio();
00082 
00083   clear_rendering_context();
00084 
00085   set_gl_options( GUI );
00086 
00087   UIMgr.setupDisplay();
00088 
00089   drawText( timeStep );
00090 
00091        drawSnow(timeStep);
00092 
00093        theme.drawMenuDecorations();
00094 
00095   UIMgr.draw();
00096 
00097   reshape( width, height );
00098 
00099   winsys_swap_buffers();
00100 }
00101 
00102 
00103 void
00104 CreditsTrans::drawText( float timeStep )
00105 {
00106     int w = getparam_x_resolution();
00107     int h = getparam_y_resolution();
00108     float y;
00109 
00110     m_yOffset += timeStep * 30;
00111     y = CREDITS_MIN_Y + m_yOffset;
00112 
00113        //loop through all credit lines
00114        for (unsigned int i=0; i<sizeof( credit_lines ) / sizeof( credit_lines[0] ); i++) {
00115            credit_line_t line = credit_lines[i];
00116 
00117               //get the font and sizes for the binding
00118               //pp::Font *font = pp::Font::get(line.binding);
00119         
00120               float width = line.font->advance(_(line.text));
00121               float desc = line.font->descender();
00122               float asc = line.font->ascender();
00123               
00124               //draw the line on the screen
00125               line.font->draw(_(line.text), w/2 - width/2, y);
00126 
00127               //calculate the y value for the next line
00128               y-=asc-desc;
00129        }
00130 
00131        //if the last string reaches the top, reset the y offset
00132     if ( y > h+CREDITS_MAX_Y ) {
00133               m_yOffset = 0;
00134     }
00135 
00136     // Draw strips at the top and bottom to clip out text 
00137     glDisable( GL_TEXTURE_2D );
00138 
00139     glColor4dv( (double*)&theme.background );
00140 
00141     glRectf( 0, 0, w, CREDITS_MIN_Y );
00142 
00143     glBegin( GL_QUADS );
00144     {
00145        glVertex2f( 0, CREDITS_MIN_Y );
00146        glVertex2f( w, CREDITS_MIN_Y );
00147        glColor4f( theme.background.r, 
00148                  theme.background.g,
00149                  theme.background.b,
00150                  0 );
00151        glVertex2f( w, CREDITS_MIN_Y + 30 );
00152        glVertex2f( 0, CREDITS_MIN_Y + 30 );
00153     }
00154     glEnd();
00155 
00156     glColor4dv( (double*)&theme.background );
00157 
00158     glRectf( 0, h+CREDITS_MAX_Y, w, h );
00159 
00160     glBegin( GL_QUADS );
00161     {
00162        glVertex2f( w, h+CREDITS_MAX_Y );
00163        glVertex2f( 0, h+CREDITS_MAX_Y );
00164        glColor4f( theme.background.r, 
00165                  theme.background.g,
00166                  theme.background.b,
00167                  0 );
00168        glVertex2f( 0, h+CREDITS_MAX_Y - 30 );
00169        glVertex2f( w, h+CREDITS_MAX_Y - 30 );
00170     }
00171     glEnd();
00172 
00173     glColor4f( 1, 1, 1, 1 );
00174 
00175     glEnable( GL_TEXTURE_2D );
00176 }
00177 
00178 bool
00179 CreditsTrans::mouseButtonReleaseEvent(int button, int x, int y)
00180 {
00181        set_game_mode( GAME_TYPE_SELECT );
00182     winsys_post_redisplay();
00183        return true;
00184 }
00185 
00186 bool
00187 CreditsTrans::keyPressEvent(SDLKey key)
00188 {
00189        set_game_mode( GAME_TYPE_SELECT );
00190     winsys_post_redisplay();
00191        return true;
00192 }
00193