Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

help.cpp

Go to the documentation of this file.
00001 #include <SDL/SDL.h>
00002 #include "constants.h"
00003 
00004 #include "font.h"
00005 #include "help.h"
00006 #include "sfcave.h"
00007 #include "starfield.h"
00008 
00009 Help :: Help( SFCave *p )
00010 {
00011     parent = p;
00012         stars = new StarField( false, 200 );
00013 
00014     loadText();
00015 
00016     init();
00017 }
00018 
00019 Help :: ~Help()
00020 {
00021     delete stars;
00022 }
00023 
00024 void Help :: handleKeys( SDL_KeyboardEvent &key )
00025 {
00026         if ( key.type == SDL_KEYDOWN )
00027         {
00028         if ( key.keysym.sym == SDLK_SPACE )
00029             parent->changeState( STATE_MENU );
00030         else if ( key.keysym.sym == SDLK_DOWN )
00031             textSpeed = 5;
00032         else if ( key.keysym.sym == SDLK_UP )
00033         {
00034             if ( textSpeed > 0 )
00035                 textSpeed = 0;
00036             else textSpeed = 1;
00037         }
00038 
00039         }
00040         else if ( key.type == SDL_KEYUP )
00041         {
00042         if ( key.keysym.sym == SDLK_DOWN )
00043             textSpeed = 1;
00044     }
00045 }
00046 void Help :: init()
00047 {
00048         startPos = 320;
00049         currLine = 0;
00050         textSpeed = 1;
00051 
00052         // Create our coloured font
00053         FontHandler :: changeColor( FONT_HELP_FONT, 0, 0, 255 );
00054 }
00055 
00056 void Help :: draw( SDL_Surface *screen )
00057 {
00058     stars->draw( screen );
00059 
00060         list<string>::iterator it = textList.begin();
00061 
00062         // Move to start of text
00063         for ( int i = 0 ; i < currLine && it != textList.end() ; ++i )
00064                 it++;
00065 
00066         int pos = startPos;
00067         while ( pos < 320 && it != textList.end() )
00068         {
00069                 // get next line
00070                 string text = *it;
00071 
00072                 // draw text
00073                 FontHandler::draw( screen, FONT_COLOURED_TEXT, text.c_str(), -1, pos );
00074                 pos += FontHandler::FontHeight( FONT_COLOURED_TEXT );
00075                 it ++;
00076         }
00077 
00078 }
00079 
00080 void Help :: update()
00081 {
00082     stars->move();
00083 
00084         startPos -= textSpeed;
00085         if ( startPos <= -FontHandler::FontHeight( FONT_COLOURED_TEXT ) )
00086         {
00087                 startPos = 0;
00088                 currLine ++;
00089 
00090                 if ( currLine > textList.size() )
00091                 {
00092                         startPos = 320;
00093                         currLine = 0;
00094                 }
00095         }
00096 
00097 }
00098 
00099 void Help :: loadText()
00100 {
00101         textList.push_back( "SFCave" );
00102         textList.push_back( "Written By AndyQ" );
00103         textList.push_back( "" );
00104         textList.push_back( "Instructions" );
00105         textList.push_back( "To return to the menu" );
00106         textList.push_back( "press the space or " );
00107         textList.push_back( "middle button." );
00108         textList.push_back( "" );
00109         textList.push_back( "To speed up the text" );
00110         textList.push_back( "hold the down button" );
00111         textList.push_back( "(releasing will return" );
00112         textList.push_back( "to normal speed)" );
00113         textList.push_back( "" );
00114         textList.push_back( "" );
00115         textList.push_back( "SFCave is a flying game" );
00116         textList.push_back( "writtin originally for the" );
00117         textList.push_back( "Sharp Zaurus." );
00118         textList.push_back( "" );
00119         textList.push_back( "The aim is to stay alive" );
00120         textList.push_back( "for as long as possible," );
00121         textList.push_back( "and get the highest score" );
00122         textList.push_back( "you can." );
00123         textList.push_back( "" );
00124         textList.push_back( "There are currently three" );
00125         textList.push_back( "game types - SFCave," );
00126         textList.push_back( "Gates, and Fly." );
00127         textList.push_back( "" );
00128         textList.push_back( "SFCave is a remake of" );
00129         textList.push_back( "the classic SFCave game." );
00130         textList.push_back( "Fly through the cavern" );
00131         textList.push_back( "avoiding all the blocks" );
00132         textList.push_back( "that just happen to be" );
00133         textList.push_back( "hanging in mid-air" );
00134         textList.push_back( "" );
00135         textList.push_back( "Gates is similar to" );
00136         textList.push_back( "SFCave but instead of" );
00137         textList.push_back( "avoiding blocks you must" );
00138         textList.push_back( "fly through gates without" );
00139         textList.push_back( "crashing." );
00140         textList.push_back( "" );
00141         textList.push_back( "Fly is a different kettle of" );
00142         textList.push_back( "fish altogether. Instead," );
00143         textList.push_back( "you are flying in the " );
00144         textList.push_back( "open air above a" );
00145         textList.push_back( "scrolling landscape and" );
00146         textList.push_back( "the aim is to fly as close" );
00147         textList.push_back( "to the land as possible." );
00148         textList.push_back( "The closer to the land" );
00149         textList.push_back( "you fly the more points" );
00150         textList.push_back( "you score. But beware," );
00151         textList.push_back( "fly too high above the" );
00152         textList.push_back( "land and points get" );
00153         textList.push_back( "deducted." );
00154         textList.push_back( "" );
00155         textList.push_back( "How to play" );
00156         textList.push_back( "Press the space or middle" );
00157         textList.push_back( "button (Zaurus only) to " );
00158         textList.push_back( "apply thrust (makes you" );
00159         textList.push_back( "go up) and release it" );
00160         textList.push_back( "to go down." );
00161         textList.push_back( "" );
00162         textList.push_back( "Have fun" );
00163         textList.push_back( "AndyQ" );
00164 }
00165 
00166 // Test
00167 #ifdef DEBUG_HELP
00168 SDL_Surface *screen;
00169 Help *help;
00170 
00171 void go()
00172 {
00173         FontHandler :: init();
00174 
00175         /* Initialize SDL */
00176         if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
00177         {
00178                 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
00179                 exit(1);
00180         }
00181         atexit(SDL_Quit);
00182 
00183         int videoflags = SDL_SWSURFACE ;
00184 
00185         if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
00186         {
00187                 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
00188                 exit(2);
00189         }
00190 
00191         help = new Help();
00192 
00193         bool done = false;
00194         while ( !done )
00195         {
00196                 SDL_FillRect( screen, 0, 0 );
00197                 help->draw( screen );
00198                 help->update( );
00199 
00200                 SDL_Flip( screen );
00201 
00202                 SDL_Delay( 10 );
00203 
00204                 SDL_Event event;
00205                 while ( SDL_PollEvent(&event) )
00206                 {
00207                         switch (event.type)
00208                         {
00209                                 case SDL_KEYDOWN:
00210                                         // Escape keypress quits the app
00211                                         if ( event.key.keysym.sym != SDLK_ESCAPE )
00212                                         {
00213                                                 break;
00214                                         }
00215                                 case SDL_QUIT:
00216                                         done = 1;
00217                                         break;
00218                                 default:
00219                                         break;
00220                         }
00221                 }
00222         }
00223  }
00224 
00225 
00226 
00227 
00228 #ifdef __cplusplus
00229 extern "C"
00230 #endif
00231 int main( int argc, char *argv[] )
00232 {
00233         go();
00234 }
00235 
00236 #endif

Generated on Sat Nov 5 16:17:24 2005 for OPIE by  doxygen 1.4.2