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

flyterrain.cpp

Go to the documentation of this file.
00001 #include <SDL/SDL_gfxPrimitives.h>
00002 
00003 #include "constants.h"
00004 #include "flyterrain.h"
00005 #include "random.h"
00006 
00007 
00008 int FlyTerrain :: flyScoreZones[][3] = {        { 0, 20, 5 },
00009                                                 { 20, 30, 2 },
00010                                                 { 30, 40, 0 },
00011                                                 { 40, 100, -1 },
00012                                                 { 100, 300, -2 },
00013                                                 { -1, -1, -1 } };
00014 
00015 FlyTerrain :: FlyTerrain( int w, int h )
00016                 : Terrain( w, h, false, true )
00017 {
00018         showScoreZones = true;
00019 }
00020 
00021 FlyTerrain :: ~FlyTerrain()
00022 {
00023 }
00024 
00025 void FlyTerrain :: setPoint( int point )
00026 {
00027     static int fly_difficulty_levels[] = { 5, 10, 15 };
00028     if ( nextInt(100) >= 75 )
00029         dir *= -1;
00030 
00031     int prevPoint = mapBottom[point-1];
00032     
00033     int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[0] ) );
00034 
00035     if ( nextPoint > sHeight )
00036     {
00037         nextPoint = sHeight;
00038         dir *= -1;
00039     }
00040     else if ( nextPoint < maxHeight )
00041     {
00042         nextPoint = maxHeight;
00043         dir *= 1;
00044     }
00045 
00046     mapBottom[point] = nextPoint;
00047 }
00048 
00049 void FlyTerrain :: drawTerrain( SDL_Surface *screen )
00050 {
00051         Terrain::drawTerrain( screen );
00052         int tmpOffset = offset + speed*segSize;
00053         
00054         for ( int i = 0 ; i < MAPSIZE -1; ++i )
00055         {
00056 
00057                 if ( showScoreZones )
00058                 {
00059                         int r = 0;
00060                         int g = 0;
00061                         int b = 0;
00062                         for ( int j = 1 ; flyScoreZones[j][0] != -1 ; ++j )
00063                         {
00064                                 if ( flyScoreZones[j][2] == 0 )
00065                                 {
00066                                         g = 255;
00067                                         b = r = 0;
00068                                 }
00069                                 else if ( flyScoreZones[j][2] < 0 )
00070                                 {
00071                                         r = 255;
00072                                         b = g = 0;
00073                                 }
00074                                 else
00075                                 {
00076                                         b = 255;
00077                                         r = g = 0;
00078                                 }
00079 
00080                                 lineRGBA( screen, (i*segSize) - tmpOffset, mapBottom[i]-flyScoreZones[j][0], ((i+1)*segSize)-tmpOffset, mapBottom[i+1]-flyScoreZones[j][0], r, g, b, 255 );
00081                                 
00082                         }
00083 
00084                 }        
00085         }
00086 }
00087 
00088 int FlyTerrain :: getScore( int difficulty, int dist )
00089 {
00090         int score = 0;
00091         for ( int i = 0 ; flyScoreZones[i][0] != -1 ; ++i )
00092         {
00093                 if ( flyScoreZones[i][0] <= dist && flyScoreZones[i][1] > dist )
00094                 {
00095                         score = flyScoreZones[i][2];
00096                         break;
00097                 }
00098         }
00099         
00100         return score;
00101 }
00102 

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