summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/flyterrain.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/flyterrain.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/flyterrain.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/noncore/games/sfcave-sdl/flyterrain.cpp b/noncore/games/sfcave-sdl/flyterrain.cpp
new file mode 100644
index 0000000..b1b8db5
--- a/dev/null
+++ b/noncore/games/sfcave-sdl/flyterrain.cpp
@@ -0,0 +1,103 @@
1
2#include "SDL_gfxPrimitives.h"
3
4#include "constants.h"
5#include "flyterrain.h"
6#include "random.h"
7
8
9 int FlyTerrain :: flyScoreZones[][3] = { { 0, 20, 5 },
10 { 20, 30, 2 },
11 { 30, 40, 0 },
12 { 40, 100, -1 },
13 { 100, 300, -2 },
14 { -1, -1, -1 } };
15
16FlyTerrain :: FlyTerrain( int w, int h )
17 : Terrain( w, h, false, true )
18{
19 showScoreZones = true;
20}
21
22FlyTerrain :: ~FlyTerrain()
23{
24}
25
26void FlyTerrain :: setPoint( int point )
27{
28 static int fly_difficulty_levels[] = { 5, 10, 15 };
29 if ( nextInt(100) >= 75 )
30 dir *= -1;
31
32 int prevPoint = mapBottom[point-1];
33
34 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[0] ) );
35
36 if ( nextPoint > sHeight )
37 {
38 nextPoint = sHeight;
39 dir *= -1;
40 }
41 else if ( nextPoint < maxHeight )
42 {
43 nextPoint = maxHeight;
44 dir *= 1;
45 }
46
47 mapBottom[point] = nextPoint;
48}
49
50void FlyTerrain :: drawTerrain( SDL_Surface *screen )
51{
52 Terrain::drawTerrain( screen );
53 int tmpOffset = offset + speed*segSize;
54
55 for ( int i = 0 ; i < MAPSIZE -1; ++i )
56 {
57
58 if ( showScoreZones )
59 {
60 int r = 0;
61 int g = 0;
62 int b = 0;
63 for ( int j = 1 ; flyScoreZones[j][0] != -1 ; ++j )
64 {
65 if ( flyScoreZones[j][2] == 0 )
66 {
67 g = 255;
68 b = r = 0;
69 }
70 else if ( flyScoreZones[j][2] < 0 )
71 {
72 r = 255;
73 b = g = 0;
74 }
75 else
76 {
77 b = 255;
78 r = g = 0;
79 }
80
81 lineRGBA( screen, (i*segSize) - tmpOffset, mapBottom[i]-flyScoreZones[j][0], ((i+1)*segSize)-tmpOffset, mapBottom[i+1]-flyScoreZones[j][0], r, g, b, 255 );
82
83 }
84
85 }
86 }
87}
88
89int FlyTerrain :: getScore( int difficulty, int dist )
90{
91 int score = 0;
92 for ( int i = 0 ; flyScoreZones[i][0] != -1 ; ++i )
93 {
94 if ( flyScoreZones[i][0] <= dist && flyScoreZones[i][1] > dist )
95 {
96 score = flyScoreZones[i][2];
97 break;
98 }
99 }
100
101 return score;
102}
103