summaryrefslogtreecommitdiff
authorsudonix <sudonix>2004-02-26 02:25:15 (UTC)
committer sudonix <sudonix>2004-02-26 02:25:15 (UTC)
commitb339031e14a607ff18e404e0395b1c2782b92fdc (patch) (unidiff)
treeecd65299976322166ee5dfb2c30f045dd542c1e1
parentcb72ff620022306e493421006b024b971449f864 (diff)
downloadopie-b339031e14a607ff18e404e0395b1c2782b92fdc.zip
opie-b339031e14a607ff18e404e0395b1c2782b92fdc.tar.gz
opie-b339031e14a607ff18e404e0395b1c2782b92fdc.tar.bz2
SDL includes corrected, CRs in some files removed, just for consistency :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/animatedimage.cpp4
-rw-r--r--noncore/games/sfcave-sdl/animatedimage.h2
-rw-r--r--noncore/games/sfcave-sdl/bfont.cpp2
-rw-r--r--noncore/games/sfcave-sdl/bfont.h2
-rw-r--r--noncore/games/sfcave-sdl/fly_game.cpp2
-rw-r--r--noncore/games/sfcave-sdl/fly_game.h2
-rw-r--r--noncore/games/sfcave-sdl/flyterrain.cpp3
-rw-r--r--noncore/games/sfcave-sdl/flyterrain.h2
-rw-r--r--noncore/games/sfcave-sdl/font.h2
-rw-r--r--noncore/games/sfcave-sdl/game.cpp4
-rw-r--r--noncore/games/sfcave-sdl/gates_game.cpp2
-rw-r--r--noncore/games/sfcave-sdl/gates_game.h2
-rw-r--r--noncore/games/sfcave-sdl/help.cpp472
-rw-r--r--noncore/games/sfcave-sdl/help.h70
-rw-r--r--noncore/games/sfcave-sdl/menu.cpp4
-rw-r--r--noncore/games/sfcave-sdl/menu.h2
-rw-r--r--noncore/games/sfcave-sdl/player.cpp4
-rw-r--r--noncore/games/sfcave-sdl/rect.h122
-rw-r--r--noncore/games/sfcave-sdl/sfcave-sdl.pro108
-rw-r--r--noncore/games/sfcave-sdl/sfcave.cpp4
-rw-r--r--noncore/games/sfcave-sdl/sfcave.h2
-rw-r--r--noncore/games/sfcave-sdl/sfcave_game.cpp2
-rw-r--r--noncore/games/sfcave-sdl/sfcave_game.h2
-rw-r--r--noncore/games/sfcave-sdl/sound.cpp314
-rw-r--r--noncore/games/sfcave-sdl/sound.h70
-rw-r--r--noncore/games/sfcave-sdl/starfield.cpp590
-rw-r--r--noncore/games/sfcave-sdl/starfield.h82
-rw-r--r--noncore/games/sfcave-sdl/stringtokenizer.h46
-rw-r--r--noncore/games/sfcave-sdl/terrain.cpp6
-rw-r--r--noncore/games/sfcave-sdl/terrain.h2
-rw-r--r--noncore/games/sfcave-sdl/util.cpp150
-rw-r--r--noncore/games/sfcave-sdl/util.h20
32 files changed, 1050 insertions, 1051 deletions
diff --git a/noncore/games/sfcave-sdl/animatedimage.cpp b/noncore/games/sfcave-sdl/animatedimage.cpp
index 441c647..680b603 100644
--- a/noncore/games/sfcave-sdl/animatedimage.cpp
+++ b/noncore/games/sfcave-sdl/animatedimage.cpp
@@ -1,68 +1,68 @@
1#include "SDL.h" 1#include <SDL/SDL.h>
2#include "SDL_image.h" 2#include <SDL/SDL_image.h>
3 3
4#include "constants.h" 4#include "constants.h"
5#include "animatedimage.h" 5#include "animatedimage.h"
6 6
7AnimatedImage :: AnimatedImage( string file, int nFrames ) 7AnimatedImage :: AnimatedImage( string file, int nFrames )
8{ 8{
9 nrFrames = nFrames; 9 nrFrames = nFrames;
10 currentFrame = 0; 10 currentFrame = 0;
11 11
12 // Load image 12 // Load image
13 image = IMG_Load( (const char *)file.c_str() ); 13 image = IMG_Load( (const char *)file.c_str() );
14 if ( !image ) 14 if ( !image )
15 { 15 {
16 nrFrames = 0; 16 nrFrames = 0;
17 image = 0; 17 image = 0;
18 return; 18 return;
19 } 19 }
20 20
21 SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); 21 SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) );
22 frameWidth = image->w/nrFrames; 22 frameWidth = image->w/nrFrames;
23 frameHeight = image->h; 23 frameHeight = image->h;
24} 24}
25 25
26AnimatedImage :: ~AnimatedImage() 26AnimatedImage :: ~AnimatedImage()
27{ 27{
28 if ( image != 0 ) 28 if ( image != 0 )
29 SDL_FreeSurface( image ); 29 SDL_FreeSurface( image );
30} 30}
31 31
32bool AnimatedImage :: nextFrame() 32bool AnimatedImage :: nextFrame()
33{ 33{
34 bool rc = true; 34 bool rc = true;
35 currentFrame ++; 35 currentFrame ++;
36 if ( currentFrame >= nrFrames ) 36 if ( currentFrame >= nrFrames )
37 { 37 {
38 currentFrame --; 38 currentFrame --;
39 rc = false; 39 rc = false;
40 } 40 }
41 41
42 return rc; 42 return rc;
43} 43}
44 44
45void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) 45void AnimatedImage :: draw( SDL_Surface *screen, int x, int y )
46{ 46{
47 if ( !image ) 47 if ( !image )
48 return; 48 return;
49 49
50 SDL_Rect dst; 50 SDL_Rect dst;
51 dst.x = currentFrame * frameWidth; 51 dst.x = currentFrame * frameWidth;
52 dst.y = 0; 52 dst.y = 0;
53 dst.w = frameWidth; 53 dst.w = frameWidth;
54 dst.h = frameHeight; 54 dst.h = frameHeight;
55 55
56 SDL_Rect dst2; 56 SDL_Rect dst2;
57 dst2.x = x - (frameWidth/2); 57 dst2.x = x - (frameWidth/2);
58 dst2.y = y - (frameHeight/2);; 58 dst2.y = y - (frameHeight/2);;
59 SDL_BlitSurface( image, &dst, screen, &dst2 ); 59 SDL_BlitSurface( image, &dst, screen, &dst2 );
60} 60}
61 61
62bool AnimatedImage :: AtEnd() 62bool AnimatedImage :: AtEnd()
63{ 63{
64 if ( currentFrame +1 >= nrFrames || image == 0 ) 64 if ( currentFrame +1 >= nrFrames || image == 0 )
65 return true; 65 return true;
66 return false; 66 return false;
67} 67}
68 68
diff --git a/noncore/games/sfcave-sdl/animatedimage.h b/noncore/games/sfcave-sdl/animatedimage.h
index 3c03f52..ecebf03 100644
--- a/noncore/games/sfcave-sdl/animatedimage.h
+++ b/noncore/games/sfcave-sdl/animatedimage.h
@@ -1,25 +1,25 @@
1#ifndef __ANIMATED_IMAGE_H 1#ifndef __ANIMATED_IMAGE_H
2#define __ANIMATED_IMAGE_H 2#define __ANIMATED_IMAGE_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5 5
6class AnimatedImage 6class AnimatedImage
7{ 7{
8public: 8public:
9 AnimatedImage( string file, int nFrames ); 9 AnimatedImage( string file, int nFrames );
10 ~AnimatedImage(); 10 ~AnimatedImage();
11 11
12 bool nextFrame(); 12 bool nextFrame();
13 void draw( SDL_Surface *screen, int x, int y ); 13 void draw( SDL_Surface *screen, int x, int y );
14 bool AtEnd(); 14 bool AtEnd();
15 void reset() { currentFrame = 0; } 15 void reset() { currentFrame = 0; }
16private: 16private:
17 17
18 SDL_Surface *image; 18 SDL_Surface *image;
19 int nrFrames; 19 int nrFrames;
20 int currentFrame; 20 int currentFrame;
21 21
22 int frameWidth; 22 int frameWidth;
23 int frameHeight; 23 int frameHeight;
24}; 24};
25#endif 25#endif
diff --git a/noncore/games/sfcave-sdl/bfont.cpp b/noncore/games/sfcave-sdl/bfont.cpp
index 7dec8f5..3ba0f4f 100644
--- a/noncore/games/sfcave-sdl/bfont.cpp
+++ b/noncore/games/sfcave-sdl/bfont.cpp
@@ -1,438 +1,438 @@
1/***********************************************************/ 1/***********************************************************/
2/* */ 2/* */
3/* BFONT.c v. 1.0.2 - Billi Font Library by Diego Billi */ 3/* BFONT.c v. 1.0.2 - Billi Font Library by Diego Billi */
4/* BFONT++ C++ port by Gianluigi Davassi */ 4/* BFONT++ C++ port by Gianluigi Davassi */
5/***********************************************************/ 5/***********************************************************/
6#include "iostream" 6#include "iostream"
7using namespace std; 7using namespace std;
8#include "string.h" 8#include "string.h"
9#include "stdlib.h" 9#include "stdlib.h"
10#include "stdarg.h" 10#include "stdarg.h"
11 11
12#include "SDL_image.h" 12#include <SDL/SDL_image.h>
13#include "bfont.h" 13#include "bfont.h"
14 14
15void BFont::InitFont() 15void BFont::InitFont()
16{ 16{
17 int x = 0, i = '!'; 17 int x = 0, i = '!';
18 Uint32 sentry = GetPixel(0,0); 18 Uint32 sentry = GetPixel(0,0);
19 19
20 if (SDL_MUSTLOCK(Surface)) 20 if (SDL_MUSTLOCK(Surface))
21 SDL_LockSurface(Surface); 21 SDL_LockSurface(Surface);
22 22
23 while ( x < (Surface->w-1)) 23 while ( x < (Surface->w-1))
24 { 24 {
25 if(GetPixel(x,0) != sentry) 25 if(GetPixel(x,0) != sentry)
26 { 26 {
27 Chars[i].x = x; 27 Chars[i].x = x;
28 Chars[i].y = 1; 28 Chars[i].y = 1;
29 Chars[i].h = Surface->h; 29 Chars[i].h = Surface->h;
30 for (; GetPixel(x, 0) != sentry && x < (Surface->w); ++x) ; 30 for (; GetPixel(x, 0) != sentry && x < (Surface->w); ++x) ;
31 Chars[i].w = (x - Chars[i].x); 31 Chars[i].w = (x - Chars[i].x);
32 i++; 32 i++;
33 } else 33 } else
34 { x++; } 34 { x++; }
35 } 35 }
36 Chars[' '].x = 0; 36 Chars[' '].x = 0;
37 Chars[' '].y = 0; 37 Chars[' '].y = 0;
38 Chars[' '].h = Surface->h; 38 Chars[' '].h = Surface->h;
39 Chars[' '].w = Chars['!'].w; 39 Chars[' '].w = Chars['!'].w;
40 40
41 if (SDL_MUSTLOCK(Surface)) 41 if (SDL_MUSTLOCK(Surface))
42 SDL_UnlockSurface(Surface); 42 SDL_UnlockSurface(Surface);
43 43
44 h = Surface->h; 44 h = Surface->h;
45 45
46 SDL_SetColorKey(Surface, SDL_SRCCOLORKEY, GetPixel(0, Surface->h-1)); 46 SDL_SetColorKey(Surface, SDL_SRCCOLORKEY, GetPixel(0, Surface->h-1));
47} 47}
48 48
49 49
50/* Load the font and stores it in the BFont_Info structure */ 50/* Load the font and stores it in the BFont_Info structure */
51void BFont::LoadFont (const char *filename) 51void BFont::LoadFont (const char *filename)
52{ 52{
53 SDL_Surface *surface(NULL); 53 SDL_Surface *surface(NULL);
54 int x; 54 int x;
55 // tutta roba inutile in C++.... :-) 55 // tutta roba inutile in C++.... :-)
56 /* BFont_Info *Font=NULL; 56 /* BFont_Info *Font=NULL;
57 Font = (BFont_Info *) malloc(sizeof(BFont_Info));*/ 57 Font = (BFont_Info *) malloc(sizeof(BFont_Info));*/
58 58
59 if ((filename != NULL ) && (this != NULL)) 59 if ((filename != NULL ) && (this != NULL))
60 { 60 {
61 surface = IMG_Load( filename ); 61 surface = IMG_Load( filename );
62 62
63 if (surface != NULL) 63 if (surface != NULL)
64 { 64 {
65 Surface = surface; 65 Surface = surface;
66 for (x=0; x<256; x++) 66 for (x=0; x<256; x++)
67 { 67 {
68 Chars[x].x = 0; 68 Chars[x].x = 0;
69 Chars[x].y = 0; 69 Chars[x].y = 0;
70 Chars[x].h = 0; 70 Chars[x].h = 0;
71 Chars[x].w = 0; 71 Chars[x].w = 0;
72 } 72 }
73 InitFont(); // Init the font 73 InitFont(); // Init the font
74 } 74 }
75 } 75 }
76} 76}
77 77
78BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) 78BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b)
79{ 79{
80 int x,y; 80 int x,y;
81 81
82 BFont *newfont; 82 BFont *newfont;
83 SDL_Surface *surface = NULL; 83 SDL_Surface *surface = NULL;
84 84
85 Uint32 pixel; 85 Uint32 pixel;
86 Uint8 old_r, old_g, old_b; 86 Uint8 old_r, old_g, old_b;
87 Uint8 new_r, new_g, new_b; 87 Uint8 new_r, new_g, new_b;
88 Uint32 color_key; 88 Uint32 color_key;
89 89
90 newfont = new BFont(NULL); 90 newfont = new BFont(NULL);
91 91
92 if (newfont != NULL) { 92 if (newfont != NULL) {
93 93
94 newfont->h = h; 94 newfont->h = h;
95 95
96 for (x=0; x<256; x++) { 96 for (x=0; x<256; x++) {
97 newfont->Chars[x].x = Chars[x].x; 97 newfont->Chars[x].x = Chars[x].x;
98 newfont->Chars[x].y = Chars[x].y; 98 newfont->Chars[x].y = Chars[x].y;
99 newfont->Chars[x].h = Chars[x].h; 99 newfont->Chars[x].h = Chars[x].h;
100 newfont->Chars[x].w = Chars[x].w; 100 newfont->Chars[x].w = Chars[x].w;
101 } 101 }
102 102
103 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, Surface->w, Surface->h, 32, 103 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, Surface->w, Surface->h, 32,
104 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000); 104 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000);
105 if (surface != NULL) { 105 if (surface != NULL) {
106 106
107 if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); 107 if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface);
108 if (SDL_MUSTLOCK(Surface)) SDL_LockSurface(Surface); 108 if (SDL_MUSTLOCK(Surface)) SDL_LockSurface(Surface);
109 109
110 color_key = xGetPixel(Surface, 0, Surface->h-1); 110 color_key = xGetPixel(Surface, 0, Surface->h-1);
111 111
112 for( x=0; x < Surface->w; x++) { 112 for( x=0; x < Surface->w; x++) {
113 for( y=0; y < Surface->h; y++) { 113 for( y=0; y < Surface->h; y++) {
114 old_r = old_g = old_b = 0; 114 old_r = old_g = old_b = 0;
115 pixel = xGetPixel(Surface,x,y); 115 pixel = xGetPixel(Surface,x,y);
116 116
117 if (pixel != color_key) { 117 if (pixel != color_key) {
118 SDL_GetRGB(pixel, Surface->format, &old_r,&old_g,&old_b); 118 SDL_GetRGB(pixel, Surface->format, &old_r,&old_g,&old_b);
119 119
120 new_r = (Uint8) ((old_r * r) / 255); 120 new_r = (Uint8) ((old_r * r) / 255);
121 new_g = (Uint8) ((old_g * g) / 255); 121 new_g = (Uint8) ((old_g * g) / 255);
122 new_b = (Uint8) ((old_b * b) / 255); 122 new_b = (Uint8) ((old_b * b) / 255);
123 123
124 pixel = SDL_MapRGB(surface->format,new_r,new_g,new_b); 124 pixel = SDL_MapRGB(surface->format,new_r,new_g,new_b);
125 } 125 }
126 PutPixel(surface,x,y,pixel); 126 PutPixel(surface,x,y,pixel);
127 } 127 }
128 } 128 }
129 129
130 if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); 130 if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
131 if (SDL_MUSTLOCK(Surface)) SDL_UnlockSurface(Surface); 131 if (SDL_MUSTLOCK(Surface)) SDL_UnlockSurface(Surface);
132 132
133 SDL_SetColorKey(surface, SDL_SRCCOLORKEY, color_key); 133 SDL_SetColorKey(surface, SDL_SRCCOLORKEY, color_key);
134 } 134 }
135 135
136 newfont->Surface = surface; 136 newfont->Surface = surface;
137 } 137 }
138 return newfont; 138 return newfont;
139} 139}
140 140
141 141
142/* Puts a single char on the surface with the specified font */ 142/* Puts a single char on the surface with the specified font */
143int BFont::PutChar(SDL_Surface *screen, int x, int y, char c) 143int BFont::PutChar(SDL_Surface *screen, int x, int y, char c)
144{ 144{
145 int r=0; 145 int r=0;
146 SDL_Rect dest; 146 SDL_Rect dest;
147 147
148 dest.w = CharWidth(' '); 148 dest.w = CharWidth(' ');
149 dest.h = FontHeight(); 149 dest.h = FontHeight();
150 dest.x = x; 150 dest.x = x;
151 dest.y = y; 151 dest.y = y;
152 152
153 if (c != ' ') 153 if (c != ' ')
154 SDL_BlitSurface( Surface, &Chars[c], screen, &dest); 154 SDL_BlitSurface( Surface, &Chars[c], screen, &dest);
155 155
156 r = dest.w; 156 r = dest.w;
157 return r; 157 return r;
158} 158}
159 159
160 160
161void BFont::PutString(SDL_Surface *screen, int x, int y, const char *text) 161void BFont::PutString(SDL_Surface *screen, int x, int y, const char *text)
162{ 162{
163 int i(0); 163 int i(0);
164 while (text[i]!='\0') 164 while (text[i]!='\0')
165 { 165 {
166 x += PutChar(screen,x,y,text[i]); 166 x += PutChar(screen,x,y,text[i]);
167 i++; 167 i++;
168 } 168 }
169} 169}
170 170
171int BFont::TextWidth(const char *text) 171int BFont::TextWidth(const char *text)
172{ 172{
173 int i(0),x(0); 173 int i(0),x(0);
174 174
175 while (text[i]!='\0') 175 while (text[i]!='\0')
176 { 176 {
177 x += CharWidth(text[i]); 177 x += CharWidth(text[i]);
178 i++; 178 i++;
179 } 179 }
180 return x; 180 return x;
181} 181}
182 182
183 183
184/* counts the spaces of the strings */ 184/* counts the spaces of the strings */
185int BFont::count (const char *text) 185int BFont::count (const char *text)
186{ 186{
187 char *p(NULL); 187 char *p(NULL);
188 int pos(-1),i(0); 188 int pos(-1),i(0);
189 189
190 /* Calculate the space occupied by the text without spaces */ 190 /* Calculate the space occupied by the text without spaces */
191 while ((p=strchr(&text[pos+1],' ')) != NULL) 191 while ((p=strchr(&text[pos+1],' ')) != NULL)
192 { 192 {
193 i++; 193 i++;
194 pos = p - text; 194 pos = p - text;
195 } 195 }
196 return i; 196 return i;
197} 197}
198 198
199 199
200void BFont::JustifiedPutString( SDL_Surface *screen, int y, const char *text) 200void BFont::JustifiedPutString( SDL_Surface *screen, int y, const char *text)
201{ 201{
202 int spaces(0),gap,single_gap,dif; 202 int spaces(0),gap,single_gap,dif;
203 char *strtmp,*p; 203 char *strtmp,*p;
204 int pos(-1),xpos(0); 204 int pos(-1),xpos(0);
205 205
206 206
207 if (strchr(text,' ') == NULL) 207 if (strchr(text,' ') == NULL)
208 { 208 {
209 PutString(screen, 0, y, text); 209 PutString(screen, 0, y, text);
210 } 210 }
211 else { 211 else {
212 gap = (screen->w-1) - TextWidth(text); 212 gap = (screen->w-1) - TextWidth(text);
213 213
214 if (gap <= 0) { 214 if (gap <= 0) {
215 PutString(screen, 0,y,text); 215 PutString(screen, 0,y,text);
216 } else { 216 } else {
217 spaces = count(text); 217 spaces = count(text);
218 dif = gap % spaces; 218 dif = gap % spaces;
219 single_gap = (gap - dif) / spaces; 219 single_gap = (gap - dif) / spaces;
220 xpos=0; 220 xpos=0;
221 pos = -1; 221 pos = -1;
222 while ( spaces > 0 ) 222 while ( spaces > 0 )
223 { 223 {
224 p = strstr(&text[pos+1]," "); 224 p = strstr(&text[pos+1]," ");
225 strtmp = NULL; 225 strtmp = NULL;
226 strtmp = (char *) calloc ( (p - &text[pos+1]) + 1,sizeof(char)); 226 strtmp = (char *) calloc ( (p - &text[pos+1]) + 1,sizeof(char));
227 if (strtmp != NULL) 227 if (strtmp != NULL)
228 { 228 {
229 strncpy (strtmp, &text[pos+1], (p - &text[pos+1])); 229 strncpy (strtmp, &text[pos+1], (p - &text[pos+1]));
230 PutString(screen, xpos, y, strtmp); 230 PutString(screen, xpos, y, strtmp);
231 xpos = xpos + TextWidth(strtmp) + single_gap + CharWidth(' '); 231 xpos = xpos + TextWidth(strtmp) + single_gap + CharWidth(' ');
232 if (dif >= 0) 232 if (dif >= 0)
233 { 233 {
234 xpos ++; 234 xpos ++;
235 dif--; 235 dif--;
236 } 236 }
237 pos = p - text; 237 pos = p - text;
238 spaces--; 238 spaces--;
239 free(strtmp); 239 free(strtmp);
240 } 240 }
241 } 241 }
242 strtmp = NULL; 242 strtmp = NULL;
243 strtmp = (char *) calloc ( strlen( &text[pos+1]) + 1,sizeof(char)); 243 strtmp = (char *) calloc ( strlen( &text[pos+1]) + 1,sizeof(char));
244 244
245 if (strtmp != NULL) { 245 if (strtmp != NULL) {
246 strncpy (strtmp, &text[pos+1], strlen( &text[pos+1])); 246 strncpy (strtmp, &text[pos+1], strlen( &text[pos+1]));
247 PutString(screen, xpos, y, strtmp); 247 PutString(screen, xpos, y, strtmp);
248 free(strtmp); 248 free(strtmp);
249 } 249 }
250 } 250 }
251 } 251 }
252} 252}
253 253
254 254
255void BFont::CenteredPutString(SDL_Surface *screen, int y, const char *text) 255void BFont::CenteredPutString(SDL_Surface *screen, int y, const char *text)
256{ 256{
257 printf( "xpos - %d, %d <%s>\n", screen->w/2-TextWidth(text)/2, TextWidth(text), text ); 257 printf( "xpos - %d, %d <%s>\n", screen->w/2-TextWidth(text)/2, TextWidth(text), text );
258 PutString( screen, screen->w/2-TextWidth(text)/2, y, text); 258 PutString( screen, screen->w/2-TextWidth(text)/2, y, text);
259} 259}
260 260
261 261
262void BFont::RightPutString(SDL_Surface *screen, int y, const char *text) 262void BFont::RightPutString(SDL_Surface *screen, int y, const char *text)
263{ 263{
264 PutString( screen, screen->w - TextWidth(text) - 1, y, text); 264 PutString( screen, screen->w - TextWidth(text) - 1, y, text);
265} 265}
266 266
267void BFont::LeftPutString(SDL_Surface *screen, int y, const char *text) 267void BFont::LeftPutString(SDL_Surface *screen, int y, const char *text)
268{ 268{
269 PutString( screen, 0, y, text); 269 PutString( screen, 0, y, text);
270} 270}
271 271
272/******/ 272/******/
273 273
274void BFont::PrintString (SDL_Surface *screen, int x, int y, char *fmt, ...) 274void BFont::PrintString (SDL_Surface *screen, int x, int y, char *fmt, ...)
275{ 275{
276 va_list args; 276 va_list args;
277 char *temp; 277 char *temp;
278 va_start (args,fmt); 278 va_start (args,fmt);
279 279
280 if ( (temp = (char *) malloc(1000+1)) != NULL) { 280 if ( (temp = (char *) malloc(1000+1)) != NULL) {
281 vsprintf(temp,fmt,args); 281 vsprintf(temp,fmt,args);
282 PutString(screen, x, y, temp); 282 PutString(screen, x, y, temp);
283 free (temp); 283 free (temp);
284 } 284 }
285 va_end(args); 285 va_end(args);
286} 286}
287 287
288void BFont::CenteredPrintString(SDL_Surface *screen, int y, char *fmt, ...) 288void BFont::CenteredPrintString(SDL_Surface *screen, int y, char *fmt, ...)
289{ 289{
290 va_list args; 290 va_list args;
291 char *temp; 291 char *temp;
292 va_start (args,fmt); 292 va_start (args,fmt);
293 293
294 if ( (temp = (char *) malloc(1000+1)) != NULL) { 294 if ( (temp = (char *) malloc(1000+1)) != NULL) {
295 vsprintf(temp,fmt,args); 295 vsprintf(temp,fmt,args);
296 CenteredPutString(screen, y, temp); 296 CenteredPutString(screen, y, temp);
297 free (temp); 297 free (temp);
298 } 298 }
299 va_end(args); 299 va_end(args);
300} 300}
301 301
302void BFont::RightPrintString(SDL_Surface *screen, int y, char *fmt, ...) 302void BFont::RightPrintString(SDL_Surface *screen, int y, char *fmt, ...)
303{ 303{
304 va_list args; 304 va_list args;
305 char *temp; 305 char *temp;
306 va_start (args,fmt); 306 va_start (args,fmt);
307 307
308 if ( (temp = (char *) malloc(1000+1)) != NULL) { 308 if ( (temp = (char *) malloc(1000+1)) != NULL) {
309 vsprintf(temp,fmt,args); 309 vsprintf(temp,fmt,args);
310 RightPutString(screen, y, temp); 310 RightPutString(screen, y, temp);
311 free (temp); 311 free (temp);
312 } 312 }
313 va_end(args); 313 va_end(args);
314} 314}
315 315
316void BFont::LeftPrintString( SDL_Surface *screen, int y, char *fmt, ...) 316void BFont::LeftPrintString( SDL_Surface *screen, int y, char *fmt, ...)
317{ 317{
318 va_list args; 318 va_list args;
319 char *temp; 319 char *temp;
320 va_start (args,fmt); 320 va_start (args,fmt);
321 321
322 if ( (temp = (char *) malloc(1000+1)) != NULL) { 322 if ( (temp = (char *) malloc(1000+1)) != NULL) {
323 vsprintf(temp,fmt,args); 323 vsprintf(temp,fmt,args);
324 LeftPutString(screen, y, temp); 324 LeftPutString(screen, y, temp);
325 free (temp); 325 free (temp);
326 } 326 }
327 va_end(args); 327 va_end(args);
328} 328}
329 329
330void BFont::JustifiedPrintString( SDL_Surface *screen, int y, char *fmt, ...) 330void BFont::JustifiedPrintString( SDL_Surface *screen, int y, char *fmt, ...)
331{ 331{
332 va_list args; 332 va_list args;
333 char *temp; 333 char *temp;
334 va_start (args,fmt); 334 va_start (args,fmt);
335 335
336 if ( (temp = (char *) malloc(1000+1)) != NULL) { 336 if ( (temp = (char *) malloc(1000+1)) != NULL) {
337 vsprintf(temp,fmt,args); 337 vsprintf(temp,fmt,args);
338 JustifiedPutString( screen, y,temp); 338 JustifiedPutString( screen, y,temp);
339 free (temp); 339 free (temp);
340 } 340 }
341 va_end(args); 341 va_end(args);
342} 342}
343 343
344 344
345void BFont::PutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) 345void BFont::PutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
346{ 346{
347 int bpp = surface->format->BytesPerPixel; 347 int bpp = surface->format->BytesPerPixel;
348 /* Here p is the address to the pixel we want to set */ 348 /* Here p is the address to the pixel we want to set */
349 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; 349 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
350 350
351 switch(bpp) { 351 switch(bpp) {
352 case 1: 352 case 1:
353 *p = pixel; 353 *p = pixel;
354 break; 354 break;
355 355
356 case 2: 356 case 2:
357 *(Uint16 *)p = pixel; 357 *(Uint16 *)p = pixel;
358 break; 358 break;
359 359
360 case 3: 360 case 3:
361 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { 361 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
362 p[0] = (pixel >> 16) & 0xff; 362 p[0] = (pixel >> 16) & 0xff;
363 p[1] = (pixel >> 8) & 0xff; 363 p[1] = (pixel >> 8) & 0xff;
364 p[2] = pixel & 0xff; 364 p[2] = pixel & 0xff;
365 } else { 365 } else {
366 p[0] = pixel & 0xff; 366 p[0] = pixel & 0xff;
367 p[1] = (pixel >> 8) & 0xff; 367 p[1] = (pixel >> 8) & 0xff;
368 p[2] = (pixel >> 16) & 0xff; 368 p[2] = (pixel >> 16) & 0xff;
369 } 369 }
370 break; 370 break;
371 371
372 case 4: 372 case 4:
373 *(Uint32 *)p = pixel; 373 *(Uint32 *)p = pixel;
374 break; 374 break;
375 } 375 }
376} 376}
377 377
378Uint32 BFont :: xGetPixel(SDL_Surface *surface, int x, int y) 378Uint32 BFont :: xGetPixel(SDL_Surface *surface, int x, int y)
379{ 379{
380 int bpp = surface->format->BytesPerPixel; 380 int bpp = surface->format->BytesPerPixel;
381 /* Here p is the address to the pixel we want to retrieve */ 381 /* Here p is the address to the pixel we want to retrieve */
382 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; 382 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
383 383
384 switch(bpp) { 384 switch(bpp) {
385 case 1: 385 case 1:
386 return *p; 386 return *p;
387 387
388 case 2: 388 case 2:
389 return *(Uint16 *)p; 389 return *(Uint16 *)p;
390 390
391 case 3: 391 case 3:
392 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 392 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
393 return p[0] << 16 | p[1] << 8 | p[2]; 393 return p[0] << 16 | p[1] << 8 | p[2];
394 else 394 else
395 return p[0] | p[1] << 8 | p[2] << 16; 395 return p[0] | p[1] << 8 | p[2] << 16;
396 396
397 case 4: 397 case 4:
398 return *(Uint32 *)p; 398 return *(Uint32 *)p;
399 399
400 default: 400 default:
401 return 0; /* shouldn't happen, but avoids warnings */ 401 return 0; /* shouldn't happen, but avoids warnings */
402 } 402 }
403} 403}
404 404
405Uint32 BFont::GetPixel( Sint32 X, Sint32 Y) 405Uint32 BFont::GetPixel( Sint32 X, Sint32 Y)
406{ 406{
407 407
408 Uint8 *bits; 408 Uint8 *bits;
409 Uint32 Bpp; 409 Uint32 Bpp;
410 410
411 if (X<0) puts("x too small in GetPixel!"); 411 if (X<0) puts("x too small in GetPixel!");
412 if (X>=Surface->w) puts("x too big in GetPixel!"); 412 if (X>=Surface->w) puts("x too big in GetPixel!");
413 413
414 Bpp = Surface->format->BytesPerPixel; 414 Bpp = Surface->format->BytesPerPixel;
415 415
416 bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp; 416 bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;
417 417
418 // Get the pixel 418 // Get the pixel
419 switch(Bpp) { 419 switch(Bpp) {
420 case 1: 420 case 1:
421 return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X); 421 return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);
422 break; 422 break;
423 case 2: 423 case 2:
424 return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X); 424 return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);
425 break; 425 break;
426 case 3: { // Format/endian independent 426 case 3: { // Format/endian independent
427 Uint8 r, g, b; 427 Uint8 r, g, b;
428 r = *((bits)+Surface->format->Rshift/8); 428 r = *((bits)+Surface->format->Rshift/8);
429 g = *((bits)+Surface->format->Gshift/8); 429 g = *((bits)+Surface->format->Gshift/8);
430 b = *((bits)+Surface->format->Bshift/8); 430 b = *((bits)+Surface->format->Bshift/8);
431 return SDL_MapRGB(Surface->format, r, g, b); 431 return SDL_MapRGB(Surface->format, r, g, b);
432 } 432 }
433 break; 433 break;
434 case 4: 434 case 4:
435 return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X); 435 return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);
436 break; 436 break;
437 } 437 }
438} 438}
diff --git a/noncore/games/sfcave-sdl/bfont.h b/noncore/games/sfcave-sdl/bfont.h
index dee97f1..5c2d7e7 100644
--- a/noncore/games/sfcave-sdl/bfont.h
+++ b/noncore/games/sfcave-sdl/bfont.h
@@ -1,70 +1,70 @@
1 1
2/************************************************************ 2/************************************************************
3 3
4 BFONT v. 1.0.2 - Billi Font Library by Diego Billi 4 BFONT v. 1.0.2 - Billi Font Library by Diego Billi
5 BFONT++ C++ port by Gianluigi Davassi 5 BFONT++ C++ port by Gianluigi Davassi
6************************************************************/ 6************************************************************/
7 7
8#ifndef __BFONT_HEADER_H__ 8#ifndef __BFONT_HEADER_H__
9#define __BFONT_HEADER_H__ 9#define __BFONT_HEADER_H__
10 10
11#include <iostream> 11#include <iostream>
12#include "SDL.h" 12#include <SDL/SDL.h>
13 13
14class BFont 14class BFont
15{ 15{
16 int h; // font height 16 int h; // font height
17 SDL_Surface *Surface; // font surface 17 SDL_Surface *Surface; // font surface
18 SDL_Rect Chars[256]; // characters width 18 SDL_Rect Chars[256]; // characters width
19 const char* name; // font name 19 const char* name; // font name
20 20
21 BFont(const BFont&); 21 BFont(const BFont&);
22 22
23 void InitFont(); 23 void InitFont();
24 int count(const char *text); 24 int count(const char *text);
25public: 25public:
26 26
27 BFont(const char *__filename) // generator bill 27 BFont(const char *__filename) // generator bill
28 : name(__filename) 28 : name(__filename)
29 { LoadFont(__filename); } 29 { LoadFont(__filename); }
30 30
31 ~BFont() 31 ~BFont()
32 { SDL_FreeSurface(Surface); } // screen must be free by application 32 { SDL_FreeSurface(Surface); } // screen must be free by application
33 33
34 int FontHeight () // Returns the font height 34 int FontHeight () // Returns the font height
35 { return h; } 35 { return h; }
36 36
37 void SetFontHeight (int height) // Change the font height 37 void SetFontHeight (int height) // Change the font height
38 { h = height ; } 38 { h = height ; }
39 39
40 int CharWidth (char c) // Returns the character width of the specified font 40 int CharWidth (char c) // Returns the character width of the specified font
41 { return Chars[c].w; } 41 { return Chars[c].w; }
42 42
43 void LoadFont (const char *filename); // Load and store le font in the BFont structure 43 void LoadFont (const char *filename); // Load and store le font in the BFont structure
44 int PutChar (SDL_Surface *screen, int x, int y, char c); // Write a single character on the "Surface" with the current font 44 int PutChar (SDL_Surface *screen, int x, int y, char c); // Write a single character on the "Surface" with the current font
45 int TextWidth (const char *text ); // Returns the width, in pixels, of the text calculated with the current font 45 int TextWidth (const char *text ); // Returns the width, in pixels, of the text calculated with the current font
46 46
47 BFont *SetFontColor(Uint8 r, Uint8 g, Uint8 b); // Returns a new font colored with the color (r,g,b) 47 BFont *SetFontColor(Uint8 r, Uint8 g, Uint8 b); // Returns a new font colored with the color (r,g,b)
48 48
49 void PutString ( SDL_Surface *screen, int x, int y, const char *text); // Write a string on the "Surface" with the specified font 49 void PutString ( SDL_Surface *screen, int x, int y, const char *text); // Write a string on the "Surface" with the specified font
50 void LeftPutString ( SDL_Surface *screen, int y, const char *text); // Write a left-aligned string on the "Surface" with the specified font 50 void LeftPutString ( SDL_Surface *screen, int y, const char *text); // Write a left-aligned string on the "Surface" with the specified font
51 void CenteredPutString ( SDL_Surface *screen, int y, const char *text); // Write a center-aligned string on the "Surface" with the specified font 51 void CenteredPutString ( SDL_Surface *screen, int y, const char *text); // Write a center-aligned string on the "Surface" with the specified font
52 void RightPutString ( SDL_Surface *screen, int y, const char *text); // Write a right-aligned string on the "Surface" with the specified font 52 void RightPutString ( SDL_Surface *screen, int y, const char *text); // Write a right-aligned string on the "Surface" with the specified font
53 void JustifiedPutString ( SDL_Surface *screen, int y, const char *text); // Write a justify-aligned string on the "Surface" with the specified font 53 void JustifiedPutString ( SDL_Surface *screen, int y, const char *text); // Write a justify-aligned string on the "Surface" with the specified font
54 54
55 // The following functions do the same task but have the classic "printf" sintax 55 // The following functions do the same task but have the classic "printf" sintax
56 void PrintString ( SDL_Surface *screen, int x, int y, char *fmt, ...); 56 void PrintString ( SDL_Surface *screen, int x, int y, char *fmt, ...);
57 void CenteredPrintString ( SDL_Surface *screen, int y, char *fmt, ...); 57 void CenteredPrintString ( SDL_Surface *screen, int y, char *fmt, ...);
58 void RightPrintString ( SDL_Surface *screen, int y, char *fmt, ...); 58 void RightPrintString ( SDL_Surface *screen, int y, char *fmt, ...);
59 void LeftPrintString ( SDL_Surface *screen, int y, char *fmt, ...); 59 void LeftPrintString ( SDL_Surface *screen, int y, char *fmt, ...);
60 void JustifiedPrintString ( SDL_Surface *screen, int y, char *fmt, ...); 60 void JustifiedPrintString ( SDL_Surface *screen, int y, char *fmt, ...);
61 61
62private: 62private:
63 Uint32 GetPixel( Sint32 X, Sint32 Y); 63 Uint32 GetPixel( Sint32 X, Sint32 Y);
64 Uint32 xGetPixel(SDL_Surface *surface, int x, int y); 64 Uint32 xGetPixel(SDL_Surface *surface, int x, int y);
65 void PutPixel( SDL_Surface *,int x, int y, Uint32 pixel); 65 void PutPixel( SDL_Surface *,int x, int y, Uint32 pixel);
66 66
67}; 67};
68 68
69#endif // __BFONT_HEADER_H__ 69#endif // __BFONT_HEADER_H__
70 70
diff --git a/noncore/games/sfcave-sdl/fly_game.cpp b/noncore/games/sfcave-sdl/fly_game.cpp
index 8b05d8f..69413ba 100644
--- a/noncore/games/sfcave-sdl/fly_game.cpp
+++ b/noncore/games/sfcave-sdl/fly_game.cpp
@@ -1,111 +1,111 @@
1#include "SDL_gfxPrimitives.h" 1#include <SDL/SDL_gfxPrimitives.h>
2 2
3#include "constants.h" 3#include "constants.h"
4#include "fly_game.h" 4#include "fly_game.h"
5#include "random.h" 5#include "random.h"
6 6
7FlyGame :: FlyGame( SFCave *p, int w, int h, int diff ) 7FlyGame :: FlyGame( SFCave *p, int w, int h, int diff )
8 : Game( p, w, h, diff ) 8 : Game( p, w, h, diff )
9{ 9{
10 gameName = "Fly"; 10 gameName = "Fly";
11 difficulty = MENU_DIFFICULTY_EASY; 11 difficulty = MENU_DIFFICULTY_EASY;
12 12
13 terrain = new FlyTerrain( w, h ); 13 terrain = new FlyTerrain( w, h );
14 player = new Player( w, h ); 14 player = new Player( w, h );
15 highScore = 0; 15 highScore = 0;
16} 16}
17 17
18FlyGame :: ~FlyGame() 18FlyGame :: ~FlyGame()
19{ 19{
20 // terrain and player get deleted by parent class 20 // terrain and player get deleted by parent class
21} 21}
22 22
23void FlyGame :: init() 23void FlyGame :: init()
24{ 24{
25 switch( difficulty ) 25 switch( difficulty )
26 { 26 {
27 case MENU_DIFFICULTY_EASY: 27 case MENU_DIFFICULTY_EASY:
28 player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 ); 28 player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 );
29 break; 29 break;
30 case MENU_DIFFICULTY_NORMAL: 30 case MENU_DIFFICULTY_NORMAL:
31 player->setMovementInfo( 0.35, 0.4, 2.5, 3 ); 31 player->setMovementInfo( 0.35, 0.4, 2.5, 3 );
32 break; 32 break;
33 case MENU_DIFFICULTY_HARD: 33 case MENU_DIFFICULTY_HARD:
34 player->setMovementInfo( 0.4, 0.6, 4, 5 ); 34 player->setMovementInfo( 0.4, 0.6, 4, 5 );
35 break; 35 break;
36 case MENU_DIFFICULTY_CUSTOM: 36 case MENU_DIFFICULTY_CUSTOM:
37 { 37 {
38 double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 ); 38 double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 );
39 double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 ); 39 double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 );
40 double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 ); 40 double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 );
41 double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 ); 41 double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 );
42 player->setMovementInfo( thrust, gravity, maxUp, maxDown ); 42 player->setMovementInfo( thrust, gravity, maxUp, maxDown );
43 break; 43 break;
44 } 44 }
45 } 45 }
46 46
47 startScoring = false; 47 startScoring = false;
48 Game :: init(); 48 Game :: init();
49} 49}
50 50
51void FlyGame :: update( int state ) 51void FlyGame :: update( int state )
52{ 52{
53 Game::update( state ); 53 Game::update( state );
54 54
55 if ( state == STATE_PLAYING ) 55 if ( state == STATE_PLAYING )
56 { 56 {
57 57
58 if ( nrFrames % 3 == 0 ) 58 if ( nrFrames % 3 == 0 )
59 { 59 {
60 int diff = terrain->getMapBottom( 10 ) - player->getY(); 60 int diff = terrain->getMapBottom( 10 ) - player->getY();
61 int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); 61 int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff );
62 62
63 if ( !startScoring ) 63 if ( !startScoring )
64 { 64 {
65 if ( tmpScore > 0 ) 65 if ( tmpScore > 0 )
66 startScoring = true; 66 startScoring = true;
67 } 67 }
68 68
69 if ( startScoring ) 69 if ( startScoring )
70 { 70 {
71 // Update score 71 // Update score
72 // get distance between landscape and ship 72 // get distance between landscape and ship
73 73
74 // the closer the difference is to 0 means more points 74 // the closer the difference is to 0 means more points
75 score += tmpScore; 75 score += tmpScore;
76 } 76 }
77 } 77 }
78 78
79 if ( checkCollisions() ) 79 if ( checkCollisions() )
80 { 80 {
81 parent->changeState( STATE_CRASHING ); 81 parent->changeState( STATE_CRASHING );
82 return; 82 return;
83 } 83 }
84 84
85 // Game logic goes here 85 // Game logic goes here
86 terrain->moveTerrain( 5 ); 86 terrain->moveTerrain( 5 );
87 player->move( press ); 87 player->move( press );
88 } 88 }
89} 89}
90 90
91void FlyGame :: draw( SDL_Surface *screen ) 91void FlyGame :: draw( SDL_Surface *screen )
92{ 92{
93 Game::preDraw( screen ); 93 Game::preDraw( screen );
94 94
95 // Screen drawing goes here 95 // Screen drawing goes here
96 terrain->drawTerrain( screen ); 96 terrain->drawTerrain( screen );
97 97
98 player->draw( screen ); 98 player->draw( screen );
99 99
100 Game::draw( screen ); 100 Game::draw( screen );
101} 101}
102 102
103 103
104bool FlyGame :: checkCollisions() 104bool FlyGame :: checkCollisions()
105{ 105{
106 bool ret = false; 106 bool ret = false;
107 107
108 // Check collision with landscape 108 // Check collision with landscape
109 109
110 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() ); 110 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
111} 111}
diff --git a/noncore/games/sfcave-sdl/fly_game.h b/noncore/games/sfcave-sdl/fly_game.h
index 1ab081a..f648deb 100644
--- a/noncore/games/sfcave-sdl/fly_game.h
+++ b/noncore/games/sfcave-sdl/fly_game.h
@@ -1,28 +1,28 @@
1#ifndef __FLY_GAME_H 1#ifndef __FLY_GAME_H
2#define __FLY_GAME_H 2#define __FLY_GAME_H
3 3
4#include "sfcave.h" 4#include "sfcave.h"
5#include "flyterrain.h" 5#include "flyterrain.h"
6#include "player.h" 6#include "player.h"
7#include "game.h" 7#include "game.h"
8#include "SDL.h" 8#include <SDL/SDL.h>
9 9
10class FlyGame : public Game 10class FlyGame : public Game
11{ 11{
12public: 12public:
13 FlyGame( SFCave *p, int w, int h, int diff ); 13 FlyGame( SFCave *p, int w, int h, int diff );
14 ~FlyGame(); 14 ~FlyGame();
15 15
16 void init(); 16 void init();
17 void update( int state ); 17 void update( int state );
18 void draw( SDL_Surface *screen ); 18 void draw( SDL_Surface *screen );
19 19
20private: 20private:
21 21
22 //int movePlayer; 22 //int movePlayer;
23 bool startScoring; 23 bool startScoring;
24 24
25 bool checkCollisions(); 25 bool checkCollisions();
26}; 26};
27 27
28#endif 28#endif
diff --git a/noncore/games/sfcave-sdl/flyterrain.cpp b/noncore/games/sfcave-sdl/flyterrain.cpp
index b1b8db5..bffe5c9 100644
--- a/noncore/games/sfcave-sdl/flyterrain.cpp
+++ b/noncore/games/sfcave-sdl/flyterrain.cpp
@@ -1,103 +1,102 @@
1 1#include <SDL/SDL_gfxPrimitives.h>
2#include "SDL_gfxPrimitives.h"
3 2
4#include "constants.h" 3#include "constants.h"
5#include "flyterrain.h" 4#include "flyterrain.h"
6#include "random.h" 5#include "random.h"
7 6
8 7
9 int FlyTerrain :: flyScoreZones[][3] = { { 0, 20, 5 }, 8 int FlyTerrain :: flyScoreZones[][3] = { { 0, 20, 5 },
10 { 20, 30, 2 }, 9 { 20, 30, 2 },
11 { 30, 40, 0 }, 10 { 30, 40, 0 },
12 { 40, 100, -1 }, 11 { 40, 100, -1 },
13 { 100, 300, -2 }, 12 { 100, 300, -2 },
14 { -1, -1, -1 } }; 13 { -1, -1, -1 } };
15 14
16FlyTerrain :: FlyTerrain( int w, int h ) 15FlyTerrain :: FlyTerrain( int w, int h )
17 : Terrain( w, h, false, true ) 16 : Terrain( w, h, false, true )
18{ 17{
19 showScoreZones = true; 18 showScoreZones = true;
20} 19}
21 20
22FlyTerrain :: ~FlyTerrain() 21FlyTerrain :: ~FlyTerrain()
23{ 22{
24} 23}
25 24
26void FlyTerrain :: setPoint( int point ) 25void FlyTerrain :: setPoint( int point )
27{ 26{
28 static int fly_difficulty_levels[] = { 5, 10, 15 }; 27 static int fly_difficulty_levels[] = { 5, 10, 15 };
29 if ( nextInt(100) >= 75 ) 28 if ( nextInt(100) >= 75 )
30 dir *= -1; 29 dir *= -1;
31 30
32 int prevPoint = mapBottom[point-1]; 31 int prevPoint = mapBottom[point-1];
33 32
34 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[0] ) ); 33 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[0] ) );
35 34
36 if ( nextPoint > sHeight ) 35 if ( nextPoint > sHeight )
37 { 36 {
38 nextPoint = sHeight; 37 nextPoint = sHeight;
39 dir *= -1; 38 dir *= -1;
40 } 39 }
41 else if ( nextPoint < maxHeight ) 40 else if ( nextPoint < maxHeight )
42 { 41 {
43 nextPoint = maxHeight; 42 nextPoint = maxHeight;
44 dir *= 1; 43 dir *= 1;
45 } 44 }
46 45
47 mapBottom[point] = nextPoint; 46 mapBottom[point] = nextPoint;
48} 47}
49 48
50void FlyTerrain :: drawTerrain( SDL_Surface *screen ) 49void FlyTerrain :: drawTerrain( SDL_Surface *screen )
51{ 50{
52 Terrain::drawTerrain( screen ); 51 Terrain::drawTerrain( screen );
53 int tmpOffset = offset + speed*segSize; 52 int tmpOffset = offset + speed*segSize;
54 53
55 for ( int i = 0 ; i < MAPSIZE -1; ++i ) 54 for ( int i = 0 ; i < MAPSIZE -1; ++i )
56 { 55 {
57 56
58 if ( showScoreZones ) 57 if ( showScoreZones )
59 { 58 {
60 int r = 0; 59 int r = 0;
61 int g = 0; 60 int g = 0;
62 int b = 0; 61 int b = 0;
63 for ( int j = 1 ; flyScoreZones[j][0] != -1 ; ++j ) 62 for ( int j = 1 ; flyScoreZones[j][0] != -1 ; ++j )
64 { 63 {
65 if ( flyScoreZones[j][2] == 0 ) 64 if ( flyScoreZones[j][2] == 0 )
66 { 65 {
67 g = 255; 66 g = 255;
68 b = r = 0; 67 b = r = 0;
69 } 68 }
70 else if ( flyScoreZones[j][2] < 0 ) 69 else if ( flyScoreZones[j][2] < 0 )
71 { 70 {
72 r = 255; 71 r = 255;
73 b = g = 0; 72 b = g = 0;
74 } 73 }
75 else 74 else
76 { 75 {
77 b = 255; 76 b = 255;
78 r = g = 0; 77 r = g = 0;
79 } 78 }
80 79
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 ); 80 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 81
83 } 82 }
84 83
85 } 84 }
86 } 85 }
87} 86}
88 87
89int FlyTerrain :: getScore( int difficulty, int dist ) 88int FlyTerrain :: getScore( int difficulty, int dist )
90{ 89{
91 int score = 0; 90 int score = 0;
92 for ( int i = 0 ; flyScoreZones[i][0] != -1 ; ++i ) 91 for ( int i = 0 ; flyScoreZones[i][0] != -1 ; ++i )
93 { 92 {
94 if ( flyScoreZones[i][0] <= dist && flyScoreZones[i][1] > dist ) 93 if ( flyScoreZones[i][0] <= dist && flyScoreZones[i][1] > dist )
95 { 94 {
96 score = flyScoreZones[i][2]; 95 score = flyScoreZones[i][2];
97 break; 96 break;
98 } 97 }
99 } 98 }
100 99
101 return score; 100 return score;
102} 101}
103 102
diff --git a/noncore/games/sfcave-sdl/flyterrain.h b/noncore/games/sfcave-sdl/flyterrain.h
index 63b5731..6258fa0 100644
--- a/noncore/games/sfcave-sdl/flyterrain.h
+++ b/noncore/games/sfcave-sdl/flyterrain.h
@@ -1,29 +1,29 @@
1#ifndef __FLYTERRAIN_H 1#ifndef __FLYTERRAIN_H
2#define __FLYTERRAIN_H 2#define __FLYTERRAIN_H
3 3
4#include <SDL.h> 4#include <SDL/SDL.h>
5 5
6#include "terrain.h" 6#include "terrain.h"
7 7
8class FlyTerrain : public Terrain 8class FlyTerrain : public Terrain
9{ 9{
10public: 10public:
11 FlyTerrain( int w, int h ); 11 FlyTerrain( int w, int h );
12 ~FlyTerrain(); 12 ~FlyTerrain();
13 13
14 void drawTerrain( SDL_Surface *screen ); 14 void drawTerrain( SDL_Surface *screen );
15 int getScore( int difficulty, int dist ); 15 int getScore( int difficulty, int dist );
16 16
17 void displayScoreZones( bool val ) { showScoreZones = val; } 17 void displayScoreZones( bool val ) { showScoreZones = val; }
18 18
19protected: 19protected:
20 bool showScoreZones; 20 bool showScoreZones;
21 21
22 static int flyScoreZones[][3]; 22 static int flyScoreZones[][3];
23 23
24 void setPoint( int point ); 24 void setPoint( int point );
25}; 25};
26 26
27 27
28#endif 28#endif
29 29
diff --git a/noncore/games/sfcave-sdl/font.h b/noncore/games/sfcave-sdl/font.h
index 5f0674a..ed9c590 100644
--- a/noncore/games/sfcave-sdl/font.h
+++ b/noncore/games/sfcave-sdl/font.h
@@ -1,33 +1,33 @@
1#ifndef __FONT_H 1#ifndef __FONT_H
2#define __FONT_H 2#define __FONT_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5#include "bfont.h" 5#include "bfont.h"
6 6
7 #define FONT_MENU_HIGHLIGHTED 1 7 #define FONT_MENU_HIGHLIGHTED 1
8 #define FONT_MENU_UNHIGHLIGHTED 2 8 #define FONT_MENU_UNHIGHLIGHTED 2
9 #define FONT_WHITE_TEXT 3 9 #define FONT_WHITE_TEXT 3
10 #define FONT_COLOURED_TEXT 4 10 #define FONT_COLOURED_TEXT 4
11 #define FONT_HELP_FONT 5 11 #define FONT_HELP_FONT 5
12 12
13class FontHandler 13class FontHandler
14{ 14{
15public: 15public:
16 static bool init(); 16 static bool init();
17 static void cleanUp(); 17 static void cleanUp();
18 18
19 static int TextWidth( int font, const char *text ); 19 static int TextWidth( int font, const char *text );
20 static int FontHeight( int font ); 20 static int FontHeight( int font );
21 static void draw( SDL_Surface *screen, int font, const char *text, int x, int y ); 21 static void draw( SDL_Surface *screen, int font, const char *text, int x, int y );
22 static void changeColor( int font, int r, int g, int b ); 22 static void changeColor( int font, int r, int g, int b );
23 23
24 static BFont *getFont( int font ); 24 static BFont *getFont( int font );
25private: 25private:
26 static BFont *menuSelFont; 26 static BFont *menuSelFont;
27 static BFont *menuUnSelFont; 27 static BFont *menuUnSelFont;
28 static BFont *whiteFont; 28 static BFont *whiteFont;
29 static BFont *colouredFont; 29 static BFont *colouredFont;
30 static BFont *helpFont; 30 static BFont *helpFont;
31}; 31};
32 32
33#endif 33#endif
diff --git a/noncore/games/sfcave-sdl/game.cpp b/noncore/games/sfcave-sdl/game.cpp
index 1ee0230..bf9c46f 100644
--- a/noncore/games/sfcave-sdl/game.cpp
+++ b/noncore/games/sfcave-sdl/game.cpp
@@ -1,332 +1,332 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <time.h> 2#include <time.h>
3 3
4#include <SDL.h> 4#include <SDL/SDL.h>
5#include <SDL_image.h> 5#include <SDL/SDL_image.h>
6 6
7#include "font.h" 7#include "font.h"
8 8
9#include "constants.h" 9#include "constants.h"
10#include "game.h" 10#include "game.h"
11#include "player.h" 11#include "player.h"
12#include "random.h" 12#include "random.h"
13#include "sound.h" 13#include "sound.h"
14#include "stringtokenizer.h" 14#include "stringtokenizer.h"
15 15
16#include "sfcave_game.h" 16#include "sfcave_game.h"
17#include "gates_game.h" 17#include "gates_game.h"
18#include "fly_game.h" 18#include "fly_game.h"
19#include "starfield.h" 19#include "starfield.h"
20 20
21Game :: Game( SFCave *p, int w, int h, int diff ) 21Game :: Game( SFCave *p, int w, int h, int diff )
22{ 22{
23 parent = p; 23 parent = p;
24 sHeight = h; 24 sHeight = h;
25 sWidth = w; 25 sWidth = w;
26 difficulty = diff; 26 difficulty = diff;
27 replayIt = 0; 27 replayIt = 0;
28 replay = false; 28 replay = false;
29 terrain = 0; 29 terrain = 0;
30 player = 0; 30 player = 0;
31 thrustChannel = -1; 31 thrustChannel = -1;
32} 32}
33 33
34Game :: ~Game() 34Game :: ~Game()
35{ 35{
36 if ( terrain ) 36 if ( terrain )
37 delete terrain; 37 delete terrain;
38 38
39 if ( player ) 39 if ( player )
40 delete player; 40 delete player;
41 41
42 replayList.clear(); 42 replayList.clear();
43} 43}
44 44
45void Game :: init() 45void Game :: init()
46{ 46{
47 if ( replay ) 47 if ( replay )
48 { 48 {
49 setSeed( currentSeed ); 49 setSeed( currentSeed );
50 replayIt = replayList.begin(); 50 replayIt = replayList.begin();
51 } 51 }
52 else 52 else
53 { 53 {
54 setSeed( -1 ); 54 setSeed( -1 );
55 replayList.clear(); 55 replayList.clear();
56 } 56 }
57 57
58 score = 0; 58 score = 0;
59 nrFrames = 0; 59 nrFrames = 0;
60 press = false; 60 press = false;
61 61
62 // Load highscore 62 // Load highscore
63 string key = getGameName() + "_" + getGameDifficultyText() + "_highscore"; 63 string key = getGameName() + "_" + getGameDifficultyText() + "_highscore";
64 highScore = atoi( parent->loadSetting( key, "0" ).c_str() ); 64 highScore = atoi( parent->loadSetting( key, "0" ).c_str() );
65 65
66 terrain->initTerrain(); 66 terrain->initTerrain();
67 player->init(); 67 player->init();
68} 68}
69 69
70void Game :: handleKeys( SDL_KeyboardEvent &key ) 70void Game :: handleKeys( SDL_KeyboardEvent &key )
71{ 71{
72 if ( !replay && 72 if ( !replay &&
73 (key.keysym.sym == SDLK_SPACE || 73 (key.keysym.sym == SDLK_SPACE ||
74 key.keysym.sym == SDLK_KP_ENTER || 74 key.keysym.sym == SDLK_KP_ENTER ||
75 key.keysym.sym == SDLK_RETURN || 75 key.keysym.sym == SDLK_RETURN ||
76 key.keysym.sym == SDLK_UP) ) 76 key.keysym.sym == SDLK_UP) )
77 { 77 {
78 if ( key.type == SDL_KEYDOWN ) 78 if ( key.type == SDL_KEYDOWN )
79 { 79 {
80 if ( !press ) 80 if ( !press )
81 replayList.push_back( nrFrames ); 81 replayList.push_back( nrFrames );
82 press = true; 82 press = true;
83 } 83 }
84 else 84 else
85 { 85 {
86 if ( press ) 86 if ( press )
87 replayList.push_back( nrFrames ); 87 replayList.push_back( nrFrames );
88 press = false; 88 press = false;
89 89
90 } 90 }
91 } 91 }
92} 92}
93 93
94 94
95 95
96string Game :: getGameDifficultyText() 96string Game :: getGameDifficultyText()
97{ 97{
98 string ret; 98 string ret;
99 99
100 if ( difficulty == MENU_DIFFICULTY_EASY ) 100 if ( difficulty == MENU_DIFFICULTY_EASY )
101 ret = "Easy"; 101 ret = "Easy";
102 else if ( difficulty == MENU_DIFFICULTY_NORMAL ) 102 else if ( difficulty == MENU_DIFFICULTY_NORMAL )
103 ret = "Medium"; 103 ret = "Medium";
104 else if ( difficulty == MENU_DIFFICULTY_HARD ) 104 else if ( difficulty == MENU_DIFFICULTY_HARD )
105 ret = "Hard"; 105 ret = "Hard";
106 else if ( difficulty == MENU_DIFFICULTY_CUSTOM ) 106 else if ( difficulty == MENU_DIFFICULTY_CUSTOM )
107 ret = "Custom"; 107 ret = "Custom";
108 108
109 return ret; 109 return ret;
110} 110}
111 111
112void Game :: setDifficulty( string diff ) 112void Game :: setDifficulty( string diff )
113{ 113{
114 if ( diff == "Easy" ) 114 if ( diff == "Easy" )
115 difficulty = MENU_DIFFICULTY_EASY; 115 difficulty = MENU_DIFFICULTY_EASY;
116 else if ( diff == "Medium" ) 116 else if ( diff == "Medium" )
117 difficulty = MENU_DIFFICULTY_NORMAL; 117 difficulty = MENU_DIFFICULTY_NORMAL;
118 else if ( diff == "Hard" ) 118 else if ( diff == "Hard" )
119 difficulty = MENU_DIFFICULTY_HARD; 119 difficulty = MENU_DIFFICULTY_HARD;
120 else if ( diff == "Custom" ) 120 else if ( diff == "Custom" )
121 difficulty = MENU_DIFFICULTY_CUSTOM; 121 difficulty = MENU_DIFFICULTY_CUSTOM;
122 122
123 init(); 123 init();
124} 124}
125 125
126void Game :: setDifficulty( int diff ) 126void Game :: setDifficulty( int diff )
127{ 127{
128 difficulty = diff; 128 difficulty = diff;
129 init(); 129 init();
130} 130}
131 131
132void Game :: update( int state ) 132void Game :: update( int state )
133{ 133{
134 nrFrames ++; 134 nrFrames ++;
135 135
136 if ( score > highScore ) 136 if ( score > highScore )
137 highScore = score; 137 highScore = score;
138 138
139 139
140 if ( state == STATE_PLAYING ) 140 if ( state == STATE_PLAYING )
141 { 141 {
142 if ( replay ) 142 if ( replay )
143 { 143 {
144 while( replayIt != replayList.end() && (*replayIt) == nrFrames-1 ) 144 while( replayIt != replayList.end() && (*replayIt) == nrFrames-1 )
145 { 145 {
146 press = !press; 146 press = !press;
147 replayIt ++; 147 replayIt ++;
148 } 148 }
149 } 149 }
150 150
151 if ( press && thrustChannel == -1 ) 151 if ( press && thrustChannel == -1 )
152 thrustChannel = SoundHandler :: playSound( SND_THRUST, -1, -1, false ); 152 thrustChannel = SoundHandler :: playSound( SND_THRUST, -1, -1, false );
153 153
154 if ( !press &&thrustChannel != -1 ) 154 if ( !press &&thrustChannel != -1 )
155 { 155 {
156 SoundHandler :: stopSound( thrustChannel, true, 300 ); 156 SoundHandler :: stopSound( thrustChannel, true, 300 );
157 thrustChannel = -1; 157 thrustChannel = -1;
158 } 158 }
159 } 159 }
160 160
161 if ( state == STATE_CRASHING || state == STATE_CRASHED ) 161 if ( state == STATE_CRASHING || state == STATE_CRASHED )
162 { 162 {
163 // fade out any trail marks remainin 163 // fade out any trail marks remainin
164 if ( player->updateCrashing() ) 164 if ( player->updateCrashing() )
165 parent->changeState( STATE_CRASHED ); 165 parent->changeState( STATE_CRASHED );
166 166
167 } 167 }
168} 168}
169 169
170void Game :: preDraw( SDL_Surface *screen ) 170void Game :: preDraw( SDL_Surface *screen )
171{ 171{
172} 172}
173 173
174void Game :: draw( SDL_Surface *screen ) 174void Game :: draw( SDL_Surface *screen )
175{ 175{
176 char tmp[100]; 176 char tmp[100];
177 string scoreText; 177 string scoreText;
178 sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore ); 178 sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore );
179 FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 ); 179 FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 );
180 180
181 if ( parent->getState() == STATE_CRASHED ) 181 if ( parent->getState() == STATE_CRASHED )
182 { 182 {
183 string crashText; 183 string crashText;
184 crashText = "Game Over"; 184 crashText = "Game Over";
185 int x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2; 185 int x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2;
186 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 ); 186 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 );
187 187
188 int fontHeight = FontHandler::FontHeight( FONT_WHITE_TEXT ); 188 int fontHeight = FontHandler::FontHeight( FONT_WHITE_TEXT );
189 crashText = "Press Middle Button to play again"; 189 crashText = "Press Middle Button to play again";
190 x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2; 190 x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2;
191 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 + fontHeight ); 191 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 + fontHeight );
192 192
193 crashText = "or OK for menu"; 193 crashText = "or OK for menu";
194 x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2; 194 x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2;
195 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 + 2*fontHeight ); 195 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 + 2*fontHeight );
196 } 196 }
197 197
198 if ( parent->showFPS() ) 198 if ( parent->showFPS() )
199 { 199 {
200 sprintf( tmp, "FPS : %d", parent->getFPS() ); 200 sprintf( tmp, "FPS : %d", parent->getFPS() );
201 FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 20, 300 ); 201 FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 20, 300 );
202 } 202 }
203} 203}
204 204
205void Game :: stateChanged( int from, int to ) 205void Game :: stateChanged( int from, int to )
206{ 206{
207 if ( from != STATE_CRASHING && to == STATE_CRASHING ) 207 if ( from != STATE_CRASHING && to == STATE_CRASHING )
208 { 208 {
209 // play explosion sound 209 // play explosion sound
210 SoundHandler :: stopSound( -1, false ); 210 SoundHandler :: stopSound( -1, false );
211 SoundHandler :: playSound( SND_EXPLOSION ); 211 SoundHandler :: playSound( SND_EXPLOSION );
212 212
213 // Check and save highscore 213 // Check and save highscore
214 printf( "Got Highscore = %d\n", gotHighScore() ); 214 printf( "Got Highscore = %d\n", gotHighScore() );
215 if ( gotHighScore() ) 215 if ( gotHighScore() )
216 { 216 {
217 string key = getGameName() + "_" + getGameDifficultyText() + "_highscore"; 217 string key = getGameName() + "_" + getGameDifficultyText() + "_highscore";
218 parent->saveSetting( key, getHighScore() ); 218 parent->saveSetting( key, getHighScore() );
219 } 219 }
220 220
221 } 221 }
222} 222}
223 223
224void Game :: setSeed( int seed ) 224void Game :: setSeed( int seed )
225{ 225{
226 if ( seed == -1 ) 226 if ( seed == -1 )
227 currentSeed = ((unsigned long) time((time_t *) NULL)); 227 currentSeed = ((unsigned long) time((time_t *) NULL));
228 else 228 else
229 currentSeed = seed; 229 currentSeed = seed;
230 PutSeed( currentSeed ); 230 PutSeed( currentSeed );
231} 231}
232 232
233void Game :: saveReplay( string file ) 233void Game :: saveReplay( string file )
234{ 234{
235 FILE *out; 235 FILE *out;
236 out = fopen( file.c_str(), "w" ); 236 out = fopen( file.c_str(), "w" );
237 if ( !out ) 237 if ( !out )
238 { 238 {
239 printf( "Couldn't write to /home/root/%s\n", file.c_str() ); 239 printf( "Couldn't write to /home/root/%s\n", file.c_str() );
240 parent->setMenuStatusText( "Couldn't save replay file" ); 240 parent->setMenuStatusText( "Couldn't save replay file" );
241 return; 241 return;
242 } 242 }
243 243
244 // Build up string of values 244 // Build up string of values
245 // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... 245 // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>.......
246 string val; 246 string val;
247 char tmp[20]; 247 char tmp[20];
248 sprintf( tmp, "%d %d ", currentSeed, difficulty ); 248 sprintf( tmp, "%d %d ", currentSeed, difficulty );
249 val = tmp; 249 val = tmp;
250 250
251 list<int>::iterator it = replayList.begin(); 251 list<int>::iterator it = replayList.begin();
252 while( it != replayList.end() ) 252 while( it != replayList.end() )
253 { 253 {
254 sprintf( tmp, "%d ", *it ); 254 sprintf( tmp, "%d ", *it );
255 val += tmp; 255 val += tmp;
256 256
257 it++; 257 it++;
258 } 258 }
259 val += "\n"; 259 val += "\n";
260 260
261 string line; 261 string line;
262 sprintf( tmp, "%d\n", val.length() ); 262 sprintf( tmp, "%d\n", val.length() );
263 line = tmp; 263 line = tmp;
264 fwrite( line.c_str(), 1, line.length(), out ); 264 fwrite( line.c_str(), 1, line.length(), out );
265 265
266 fwrite( val.c_str(), 1, val.length(), out ); 266 fwrite( val.c_str(), 1, val.length(), out );
267 267
268 fclose( out ); 268 fclose( out );
269} 269}
270 270
271void Game :: loadReplay( string file ) 271void Game :: loadReplay( string file )
272{ 272{
273 273
274 FILE *in = fopen( (const char *)file.c_str(), "r" ); 274 FILE *in = fopen( (const char *)file.c_str(), "r" );
275 275
276 if ( in == 0 ) 276 if ( in == 0 )
277 { 277 {
278 printf( "Couldn't load replay file %s!\n", (const char *)file.c_str() ); 278 printf( "Couldn't load replay file %s!\n", (const char *)file.c_str() );
279 parent->setMenuStatusText( "Couldn't load replay file" ); 279 parent->setMenuStatusText( "Couldn't load replay file" );
280 return; 280 return;
281 } 281 }
282 282
283 // Read next line - contains the size of the options 283 // Read next line - contains the size of the options
284 char line[10+1]; 284 char line[10+1];
285 fgets( line, 10, in ); 285 fgets( line, 10, in );
286 286
287 int length = -1; 287 int length = -1;
288 sscanf( line, "%d", &length ); 288 sscanf( line, "%d", &length );
289 char *data = new char[length+1]; 289 char *data = new char[length+1];
290 290
291 fread( data, 1, length, in ); 291 fread( data, 1, length, in );
292 292
293 string sep = " "; 293 string sep = " ";
294 294
295 StringTokenizer st( data, sep ); 295 StringTokenizer st( data, sep );
296 296
297 // print it out 297 // print it out
298 vector<string>::iterator it = st.begin(); 298 vector<string>::iterator it = st.begin();
299 currentSeed = atoi( (*it).c_str() ); 299 currentSeed = atoi( (*it).c_str() );
300 ++it; 300 ++it;
301 difficulty = atoi( (*it).c_str() ); 301 difficulty = atoi( (*it).c_str() );
302 ++it; 302 ++it;
303 303
304 replayList.clear(); 304 replayList.clear();
305 for ( ; it != st.end(); ++it ) 305 for ( ; it != st.end(); ++it )
306 { 306 {
307 int v = atoi( (*it).c_str() ); 307 int v = atoi( (*it).c_str() );
308 replayList.push_back( v ); 308 replayList.push_back( v );
309 } 309 }
310 310
311 delete data; 311 delete data;
312 312
313 fclose( in ); 313 fclose( in );
314} 314}
315 315
316 316
317Game *Game :: createGame( SFCave *p, int w, int h, string game, string difficulty ) 317Game *Game :: createGame( SFCave *p, int w, int h, string game, string difficulty )
318{ 318{
319 Game *g; 319 Game *g;
320 320
321 if ( game == "SFCave" ) 321 if ( game == "SFCave" )
322 g = new SFCaveGame( p, w, h, 0 ); 322 g = new SFCaveGame( p, w, h, 0 );
323 else if ( game == "Gates" ) 323 else if ( game == "Gates" )
324 g = new GatesGame( p, w, h, 0 ); 324 g = new GatesGame( p, w, h, 0 );
325 else if ( game == "Fly" ) 325 else if ( game == "Fly" )
326 g = new FlyGame( p, w, h, 0 ); 326 g = new FlyGame( p, w, h, 0 );
327 327
328 if ( g ) 328 if ( g )
329 g->setDifficulty( difficulty ); 329 g->setDifficulty( difficulty );
330 330
331 return g; 331 return g;
332} 332}
diff --git a/noncore/games/sfcave-sdl/gates_game.cpp b/noncore/games/sfcave-sdl/gates_game.cpp
index 700a6ec..638658b 100644
--- a/noncore/games/sfcave-sdl/gates_game.cpp
+++ b/noncore/games/sfcave-sdl/gates_game.cpp
@@ -1,201 +1,201 @@
1#include "SDL_gfxPrimitives.h" 1#include <SDL/SDL_gfxPrimitives.h>
2 2
3#include "constants.h" 3#include "constants.h"
4#include "gates_game.h" 4#include "gates_game.h"
5#include "random.h" 5#include "random.h"
6 6
7GatesGame :: GatesGame( SFCave *p, int w, int h, int diff ) 7GatesGame :: GatesGame( SFCave *p, int w, int h, int diff )
8 : Game( p, w, h, diff ) 8 : Game( p, w, h, diff )
9{ 9{
10 gameName = "Gates"; 10 gameName = "Gates";
11 difficulty = MENU_DIFFICULTY_EASY; 11 difficulty = MENU_DIFFICULTY_EASY;
12 blockUpdateRate = 200; 12 blockUpdateRate = 200;
13 13
14 terrain = new Terrain( w, h ); 14 terrain = new Terrain( w, h );
15 player = new Player( w, h ); 15 player = new Player( w, h );
16 highScore = 0; 16 highScore = 0;
17} 17}
18 18
19GatesGame :: ~GatesGame() 19GatesGame :: ~GatesGame()
20{ 20{
21 // terrain and player get deleted by parent class 21 // terrain and player get deleted by parent class
22} 22}
23 23
24void GatesGame :: init() 24void GatesGame :: init()
25{ 25{
26 blockHeight = 80; 26 blockHeight = 80;
27 blockWidth = 20; 27 blockWidth = 20;
28 lastGateBottomY = 0; 28 lastGateBottomY = 0;
29 29
30 gateDistance = 75; 30 gateDistance = 75;
31 nextGate = nextInt( 50 ) + gateDistance; 31 nextGate = nextInt( 50 ) + gateDistance;
32 gapHeight = 75; 32 gapHeight = 75;
33 33
34 switch( difficulty ) 34 switch( difficulty )
35 { 35 {
36 case MENU_DIFFICULTY_EASY: 36 case MENU_DIFFICULTY_EASY:
37 gapHeight = 75; 37 gapHeight = 75;
38 player->setMovementInfo( 0.4, 0.6, 4, 5 ); 38 player->setMovementInfo( 0.4, 0.6, 4, 5 );
39 break; 39 break;
40 case MENU_DIFFICULTY_NORMAL: 40 case MENU_DIFFICULTY_NORMAL:
41 gapHeight = 50; 41 gapHeight = 50;
42 player->setMovementInfo( 0.4, 0.6, 4, 5 ); 42 player->setMovementInfo( 0.4, 0.6, 4, 5 );
43 break; 43 break;
44 case MENU_DIFFICULTY_HARD: 44 case MENU_DIFFICULTY_HARD:
45 gapHeight = 25; 45 gapHeight = 25;
46 player->setMovementInfo( 0.6, 0.8, 6, 7 ); 46 player->setMovementInfo( 0.6, 0.8, 6, 7 );
47 break; 47 break;
48 case MENU_DIFFICULTY_CUSTOM: 48 case MENU_DIFFICULTY_CUSTOM:
49 { 49 {
50 // Read custom difficulty settings for this game 50 // Read custom difficulty settings for this game
51 gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 ); 51 gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 );
52 52
53 double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 ); 53 double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 );
54 double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 ); 54 double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 );
55 double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 ); 55 double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 );
56 double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 ); 56 double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 );
57 player->setMovementInfo( thrust, gravity, maxUp, maxDown ); 57 player->setMovementInfo( thrust, gravity, maxUp, maxDown );
58 58
59 break; 59 break;
60 } 60 }
61 } 61 }
62 62
63 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 63 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
64 blocks[i].y( -1 ); 64 blocks[i].y( -1 );
65 65
66 Game :: init(); 66 Game :: init();
67} 67}
68 68
69void GatesGame :: update( int state ) 69void GatesGame :: update( int state )
70{ 70{
71 Game::update( state ); 71 Game::update( state );
72 72
73 // Game logic goes here 73 // Game logic goes here
74 if ( state == STATE_PLAYING ) 74 if ( state == STATE_PLAYING )
75 { 75 {
76 if ( nrFrames % 3 == 0 ) 76 if ( nrFrames % 3 == 0 )
77 score ++; 77 score ++;
78 78
79 if ( nrFrames % 500 == 0 ) 79 if ( nrFrames % 500 == 0 )
80 { 80 {
81 if ( gapHeight > 75 ) 81 if ( gapHeight > 75 )
82 gapHeight -= 5; 82 gapHeight -= 5;
83 } 83 }
84 84
85 // Slightly random gap distance 85 // Slightly random gap distance
86 if ( nrFrames >= nextGate ) 86 if ( nrFrames >= nextGate )
87 { 87 {
88 nextGate = nrFrames + nextInt( 50 ) + gateDistance; 88 nextGate = nrFrames + nextInt( 50 ) + gateDistance;
89 addGate(); 89 addGate();
90 } 90 }
91 91
92 if ( checkCollisions() ) 92 if ( checkCollisions() )
93 { 93 {
94 parent->changeState( STATE_CRASHING ); 94 parent->changeState( STATE_CRASHING );
95 return; 95 return;
96 } 96 }
97 97
98 terrain->moveTerrain( 5 ); 98 terrain->moveTerrain( 5 );
99 moveBlocks( 5 ); 99 moveBlocks( 5 );
100 player->move( press ); 100 player->move( press );
101 } 101 }
102} 102}
103 103
104void GatesGame :: draw( SDL_Surface *screen ) 104void GatesGame :: draw( SDL_Surface *screen )
105{ 105{
106 Game::preDraw( screen ); 106 Game::preDraw( screen );
107 107
108 if ( parent->getState() == STATE_PLAYING ) 108 if ( parent->getState() == STATE_PLAYING )
109 { 109 {
110 // Screen drawing goes here 110 // Screen drawing goes here
111 terrain->drawTerrain( screen ); 111 terrain->drawTerrain( screen );
112 112
113 player->draw( screen ); 113 player->draw( screen );
114 114
115 drawBlocks( screen ); 115 drawBlocks( screen );
116 } 116 }
117 else 117 else
118 { 118 {
119 // Screen drawing goes here 119 // Screen drawing goes here
120 terrain->drawTerrain( screen ); 120 terrain->drawTerrain( screen );
121 121
122 drawBlocks( screen ); 122 drawBlocks( screen );
123 123
124 player->draw( screen ); 124 player->draw( screen );
125 } 125 }
126 126
127 Game::draw( screen ); 127 Game::draw( screen );
128} 128}
129 129
130 130
131void GatesGame :: addGate() 131void GatesGame :: addGate()
132{ 132{
133 printf( "gapHeight = %d\n", gapHeight ); 133 printf( "gapHeight = %d\n", gapHeight );
134 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 134 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
135 { 135 {
136 if ( blocks[i].y() == -1 ) 136 if ( blocks[i].y() == -1 )
137 { 137 {
138 int x1 = sWidth; 138 int x1 = sWidth;
139 int y1 = terrain->getMapTop(50); 139 int y1 = terrain->getMapTop(50);
140 int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight); 140 int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight);
141 141
142 // See if height between last gate and this one is too big 142 // See if height between last gate and this one is too big
143 if ( b1Height - 100 > lastGateBottomY ) 143 if ( b1Height - 100 > lastGateBottomY )
144 b1Height -= 25; 144 b1Height -= 25;
145 else if ( b1Height + 100 < lastGateBottomY ) 145 else if ( b1Height + 100 < lastGateBottomY )
146 b1Height += 25; 146 b1Height += 25;
147 lastGateBottomY = b1Height; 147 lastGateBottomY = b1Height;
148 148
149 149
150 int x2 = sWidth; 150 int x2 = sWidth;
151 int y2 = y1 + b1Height + gapHeight; 151 int y2 = y1 + b1Height + gapHeight;
152 int b2Height = terrain->getMapBottom( 50 ) - y2; 152 int b2Height = terrain->getMapBottom( 50 ) - y2;
153 153
154 154
155 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 155 blocks[i].setRect( x1, y1, blockWidth, b1Height );
156 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 156 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
157 157
158 break; 158 break;
159 } 159 }
160 } 160 }
161} 161}
162 162
163void GatesGame :: moveBlocks( int amountToMove ) 163void GatesGame :: moveBlocks( int amountToMove )
164{ 164{
165 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 165 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
166 { 166 {
167 if ( blocks[i].y() != -1 ) 167 if ( blocks[i].y() != -1 )
168 { 168 {
169 blocks[i].moveBy( -amountToMove, 0 ); 169 blocks[i].moveBy( -amountToMove, 0 );
170 if ( blocks[i].x() + blocks[i].y() < 0 ) 170 if ( blocks[i].x() + blocks[i].y() < 0 )
171 blocks[i].y( -1 ); 171 blocks[i].y( -1 );
172 } 172 }
173 } 173 }
174} 174}
175 175
176void GatesGame :: drawBlocks( SDL_Surface *screen ) 176void GatesGame :: drawBlocks( SDL_Surface *screen )
177{ 177{
178 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 178 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
179 { 179 {
180 if ( blocks[i].y() != -1 ) 180 if ( blocks[i].y() != -1 )
181 { 181 {
182 SDL_Rect r = blocks[i].getRect(); 182 SDL_Rect r = blocks[i].getRect();
183 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) ); 183 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) );
184 } 184 }
185 } 185 }
186} 186}
187 187
188bool GatesGame :: checkCollisions() 188bool GatesGame :: checkCollisions()
189{ 189{
190 // Check collisions with blocks 190 // Check collisions with blocks
191 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 191 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
192 { 192 {
193 if ( blocks[i].y() != -1 ) 193 if ( blocks[i].y() != -1 )
194 { 194 {
195 if ( blocks[i].intersects( player->getPos() ) ) 195 if ( blocks[i].intersects( player->getPos() ) )
196 return true; 196 return true;
197 } 197 }
198 } 198 }
199 // Check collision with landscape 199 // Check collision with landscape
200 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() ); 200 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
201} 201}
diff --git a/noncore/games/sfcave-sdl/gates_game.h b/noncore/games/sfcave-sdl/gates_game.h
index 8499ff9..b44336a 100644
--- a/noncore/games/sfcave-sdl/gates_game.h
+++ b/noncore/games/sfcave-sdl/gates_game.h
@@ -1,45 +1,45 @@
1#ifndef __GATES_GAME_H 1#ifndef __GATES_GAME_H
2#define __GATES_GAME_H 2#define __GATES_GAME_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5 5
6#include "rect.h" 6#include "rect.h"
7 7
8#include "sfcave.h" 8#include "sfcave.h"
9#include "terrain.h" 9#include "terrain.h"
10#include "player.h" 10#include "player.h"
11#include "game.h" 11#include "game.h"
12 12
13class GatesGame : public Game 13class GatesGame : public Game
14{ 14{
15public: 15public:
16 GatesGame( SFCave *p, int w, int h, int diff ); 16 GatesGame( SFCave *p, int w, int h, int diff );
17 ~GatesGame(); 17 ~GatesGame();
18 18
19 void init(); 19 void init();
20 void update( int state ); 20 void update( int state );
21 void draw( SDL_Surface *screen ); 21 void draw( SDL_Surface *screen );
22 22
23private: 23private:
24 24
25 int gapHeight; 25 int gapHeight;
26 26
27 int gateDistance; 27 int gateDistance;
28 int nextGate; 28 int nextGate;
29 int lastGateBottomY; 29 int lastGateBottomY;
30 30
31 int blockDistance; 31 int blockDistance;
32 int blockHeight; 32 int blockHeight;
33 int blockWidth; 33 int blockWidth;
34 int blockUpdateRate; 34 int blockUpdateRate;
35 35
36 Rect blocks[BLOCKSIZE]; 36 Rect blocks[BLOCKSIZE];
37 37
38 void addGate(); 38 void addGate();
39 void moveBlocks( int amountToMove ); 39 void moveBlocks( int amountToMove );
40 void drawBlocks( SDL_Surface *screen ); 40 void drawBlocks( SDL_Surface *screen );
41 bool checkCollisions(); 41 bool checkCollisions();
42 42
43}; 43};
44 44
45#endif 45#endif
diff --git a/noncore/games/sfcave-sdl/help.cpp b/noncore/games/sfcave-sdl/help.cpp
index f1728f6..0a7924b 100644
--- a/noncore/games/sfcave-sdl/help.cpp
+++ b/noncore/games/sfcave-sdl/help.cpp
@@ -1,236 +1,236 @@
1#include "SDL.h" 1#include <SDL/SDL.h>
2#include "constants.h" 2#include "constants.h"
3 3
4#include "font.h" 4#include "font.h"
5#include "help.h" 5#include "help.h"
6#include "sfcave.h" 6#include "sfcave.h"
7#include "starfield.h" 7#include "starfield.h"
8 8
9Help :: Help( SFCave *p ) 9Help :: Help( SFCave *p )
10{ 10{
11 parent = p; 11 parent = p;
12 stars = new StarField( false, 200 ); 12 stars = new StarField( false, 200 );
13 13
14 loadText(); 14 loadText();
15 15
16 init(); 16 init();
17} 17}
18 18
19Help :: ~Help() 19Help :: ~Help()
20{ 20{
21 delete stars; 21 delete stars;
22} 22}
23 23
24void Help :: handleKeys( SDL_KeyboardEvent &key ) 24void Help :: handleKeys( SDL_KeyboardEvent &key )
25{ 25{
26 if ( key.type == SDL_KEYDOWN ) 26 if ( key.type == SDL_KEYDOWN )
27 { 27 {
28 if ( key.keysym.sym == SDLK_SPACE ) 28 if ( key.keysym.sym == SDLK_SPACE )
29 parent->changeState( STATE_MENU ); 29 parent->changeState( STATE_MENU );
30 else if ( key.keysym.sym == SDLK_DOWN ) 30 else if ( key.keysym.sym == SDLK_DOWN )
31 textSpeed = 5; 31 textSpeed = 5;
32 else if ( key.keysym.sym == SDLK_UP ) 32 else if ( key.keysym.sym == SDLK_UP )
33 { 33 {
34 if ( textSpeed > 0 ) 34 if ( textSpeed > 0 )
35 textSpeed = 0; 35 textSpeed = 0;
36 else textSpeed = 1; 36 else textSpeed = 1;
37 } 37 }
38 38
39 } 39 }
40 else if ( key.type == SDL_KEYUP ) 40 else if ( key.type == SDL_KEYUP )
41 { 41 {
42 if ( key.keysym.sym == SDLK_DOWN ) 42 if ( key.keysym.sym == SDLK_DOWN )
43 textSpeed = 1; 43 textSpeed = 1;
44 } 44 }
45} 45}
46void Help :: init() 46void Help :: init()
47{ 47{
48 startPos = 320; 48 startPos = 320;
49 currLine = 0; 49 currLine = 0;
50 textSpeed = 1; 50 textSpeed = 1;
51 51
52 // Create our coloured font 52 // Create our coloured font
53 FontHandler :: changeColor( FONT_HELP_FONT, 0, 0, 255 ); 53 FontHandler :: changeColor( FONT_HELP_FONT, 0, 0, 255 );
54} 54}
55 55
56void Help :: draw( SDL_Surface *screen ) 56void Help :: draw( SDL_Surface *screen )
57{ 57{
58 stars->draw( screen ); 58 stars->draw( screen );
59 59
60 list<string>::iterator it = textList.begin(); 60 list<string>::iterator it = textList.begin();
61 61
62 // Move to start of text 62 // Move to start of text
63 for ( int i = 0 ; i < currLine && it != textList.end() ; ++i ) 63 for ( int i = 0 ; i < currLine && it != textList.end() ; ++i )
64 it++; 64 it++;
65 65
66 int pos = startPos; 66 int pos = startPos;
67 while ( pos < 320 && it != textList.end() ) 67 while ( pos < 320 && it != textList.end() )
68 { 68 {
69 // get next line 69 // get next line
70 string text = *it; 70 string text = *it;
71 71
72 // draw text 72 // draw text
73 FontHandler::draw( screen, FONT_COLOURED_TEXT, text.c_str(), -1, pos ); 73 FontHandler::draw( screen, FONT_COLOURED_TEXT, text.c_str(), -1, pos );
74 pos += FontHandler::FontHeight( FONT_COLOURED_TEXT ); 74 pos += FontHandler::FontHeight( FONT_COLOURED_TEXT );
75 it ++; 75 it ++;
76 } 76 }
77 77
78} 78}
79 79
80void Help :: update() 80void Help :: update()
81{ 81{
82 stars->move(); 82 stars->move();
83 83
84 startPos -= textSpeed; 84 startPos -= textSpeed;
85 if ( startPos <= -FontHandler::FontHeight( FONT_COLOURED_TEXT ) ) 85 if ( startPos <= -FontHandler::FontHeight( FONT_COLOURED_TEXT ) )
86 { 86 {
87 startPos = 0; 87 startPos = 0;
88 currLine ++; 88 currLine ++;
89 89
90 if ( currLine > textList.size() ) 90 if ( currLine > textList.size() )
91 { 91 {
92 startPos = 320; 92 startPos = 320;
93 currLine = 0; 93 currLine = 0;
94 } 94 }
95 } 95 }
96 96
97} 97}
98 98
99void Help :: loadText() 99void Help :: loadText()
100{ 100{
101 textList.push_back( "SFCave" ); 101 textList.push_back( "SFCave" );
102 textList.push_back( "Written By AndyQ" ); 102 textList.push_back( "Written By AndyQ" );
103 textList.push_back( "" ); 103 textList.push_back( "" );
104 textList.push_back( "Instructions" ); 104 textList.push_back( "Instructions" );
105 textList.push_back( "To return to the menu" ); 105 textList.push_back( "To return to the menu" );
106 textList.push_back( "press the space or " ); 106 textList.push_back( "press the space or " );
107 textList.push_back( "middle button." ); 107 textList.push_back( "middle button." );
108 textList.push_back( "" ); 108 textList.push_back( "" );
109 textList.push_back( "To speed up the text" ); 109 textList.push_back( "To speed up the text" );
110 textList.push_back( "hold the down button" ); 110 textList.push_back( "hold the down button" );
111 textList.push_back( "(releasing will return" ); 111 textList.push_back( "(releasing will return" );
112 textList.push_back( "to normal speed)" ); 112 textList.push_back( "to normal speed)" );
113 textList.push_back( "" ); 113 textList.push_back( "" );
114 textList.push_back( "" ); 114 textList.push_back( "" );
115 textList.push_back( "SFCave is a flying game" ); 115 textList.push_back( "SFCave is a flying game" );
116 textList.push_back( "writtin originally for the" ); 116 textList.push_back( "writtin originally for the" );
117 textList.push_back( "Sharp Zaurus." ); 117 textList.push_back( "Sharp Zaurus." );
118 textList.push_back( "" ); 118 textList.push_back( "" );
119 textList.push_back( "The aim is to stay alive" ); 119 textList.push_back( "The aim is to stay alive" );
120 textList.push_back( "for as long as possible," ); 120 textList.push_back( "for as long as possible," );
121 textList.push_back( "and get the highest score" ); 121 textList.push_back( "and get the highest score" );
122 textList.push_back( "you can." ); 122 textList.push_back( "you can." );
123 textList.push_back( "" ); 123 textList.push_back( "" );
124 textList.push_back( "There are currently three" ); 124 textList.push_back( "There are currently three" );
125 textList.push_back( "game types - SFCave," ); 125 textList.push_back( "game types - SFCave," );
126 textList.push_back( "Gates, and Fly." ); 126 textList.push_back( "Gates, and Fly." );
127 textList.push_back( "" ); 127 textList.push_back( "" );
128 textList.push_back( "SFCave is a remake of" ); 128 textList.push_back( "SFCave is a remake of" );
129 textList.push_back( "the classic SFCave game." ); 129 textList.push_back( "the classic SFCave game." );
130 textList.push_back( "Fly through the cavern" ); 130 textList.push_back( "Fly through the cavern" );
131 textList.push_back( "avoiding all the blocks" ); 131 textList.push_back( "avoiding all the blocks" );
132 textList.push_back( "that just happen to be" ); 132 textList.push_back( "that just happen to be" );
133 textList.push_back( "hanging in mid-air" ); 133 textList.push_back( "hanging in mid-air" );
134 textList.push_back( "" ); 134 textList.push_back( "" );
135 textList.push_back( "Gates is similar to" ); 135 textList.push_back( "Gates is similar to" );
136 textList.push_back( "SFCave but instead of" ); 136 textList.push_back( "SFCave but instead of" );
137 textList.push_back( "avoiding blocks you must" ); 137 textList.push_back( "avoiding blocks you must" );
138 textList.push_back( "fly through gates without" ); 138 textList.push_back( "fly through gates without" );
139 textList.push_back( "crashing." ); 139 textList.push_back( "crashing." );
140 textList.push_back( "" ); 140 textList.push_back( "" );
141 textList.push_back( "Fly is a different kettle of" ); 141 textList.push_back( "Fly is a different kettle of" );
142 textList.push_back( "fish altogether. Instead," ); 142 textList.push_back( "fish altogether. Instead," );
143 textList.push_back( "you are flying in the " ); 143 textList.push_back( "you are flying in the " );
144 textList.push_back( "open air above a" ); 144 textList.push_back( "open air above a" );
145 textList.push_back( "scrolling landscape and" ); 145 textList.push_back( "scrolling landscape and" );
146 textList.push_back( "the aim is to fly as close" ); 146 textList.push_back( "the aim is to fly as close" );
147 textList.push_back( "to the land as possible." ); 147 textList.push_back( "to the land as possible." );
148 textList.push_back( "The closer to the land" ); 148 textList.push_back( "The closer to the land" );
149 textList.push_back( "you fly the more points" ); 149 textList.push_back( "you fly the more points" );
150 textList.push_back( "you score. But beware," ); 150 textList.push_back( "you score. But beware," );
151 textList.push_back( "fly too high above the" ); 151 textList.push_back( "fly too high above the" );
152 textList.push_back( "land and points get" ); 152 textList.push_back( "land and points get" );
153 textList.push_back( "deducted." ); 153 textList.push_back( "deducted." );
154 textList.push_back( "" ); 154 textList.push_back( "" );
155 textList.push_back( "How to play" ); 155 textList.push_back( "How to play" );
156 textList.push_back( "Press the space or middle" ); 156 textList.push_back( "Press the space or middle" );
157 textList.push_back( "button (Zaurus only) to " ); 157 textList.push_back( "button (Zaurus only) to " );
158 textList.push_back( "apply thrust (makes you" ); 158 textList.push_back( "apply thrust (makes you" );
159 textList.push_back( "go up) and release it" ); 159 textList.push_back( "go up) and release it" );
160 textList.push_back( "to go down." ); 160 textList.push_back( "to go down." );
161 textList.push_back( "" ); 161 textList.push_back( "" );
162 textList.push_back( "Have fun" ); 162 textList.push_back( "Have fun" );
163 textList.push_back( "AndyQ" ); 163 textList.push_back( "AndyQ" );
164} 164}
165 165
166// Test 166// Test
167#ifdef DEBUG_HELP 167#ifdef DEBUG_HELP
168SDL_Surface *screen; 168SDL_Surface *screen;
169Help *help; 169Help *help;
170 170
171void go() 171void go()
172{ 172{
173 FontHandler :: init(); 173 FontHandler :: init();
174 174
175 /* Initialize SDL */ 175 /* Initialize SDL */
176 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 176 if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
177 { 177 {
178 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 178 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
179 exit(1); 179 exit(1);
180 } 180 }
181 atexit(SDL_Quit); 181 atexit(SDL_Quit);
182 182
183 int videoflags = SDL_SWSURFACE ; 183 int videoflags = SDL_SWSURFACE ;
184 184
185 if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL ) 185 if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
186 { 186 {
187 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError()); 187 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
188 exit(2); 188 exit(2);
189 } 189 }
190 190
191 help = new Help(); 191 help = new Help();
192 192
193 bool done = false; 193 bool done = false;
194 while ( !done ) 194 while ( !done )
195 { 195 {
196 SDL_FillRect( screen, 0, 0 ); 196 SDL_FillRect( screen, 0, 0 );
197 help->draw( screen ); 197 help->draw( screen );
198 help->update( ); 198 help->update( );
199 199
200 SDL_Flip( screen ); 200 SDL_Flip( screen );
201 201
202 SDL_Delay( 10 ); 202 SDL_Delay( 10 );
203 203
204 SDL_Event event; 204 SDL_Event event;
205 while ( SDL_PollEvent(&event) ) 205 while ( SDL_PollEvent(&event) )
206 { 206 {
207 switch (event.type) 207 switch (event.type)
208 { 208 {
209 case SDL_KEYDOWN: 209 case SDL_KEYDOWN:
210 // Escape keypress quits the app 210 // Escape keypress quits the app
211 if ( event.key.keysym.sym != SDLK_ESCAPE ) 211 if ( event.key.keysym.sym != SDLK_ESCAPE )
212 { 212 {
213 break; 213 break;
214 } 214 }
215 case SDL_QUIT: 215 case SDL_QUIT:
216 done = 1; 216 done = 1;
217 break; 217 break;
218 default: 218 default:
219 break; 219 break;
220 } 220 }
221 } 221 }
222 } 222 }
223 } 223 }
224 224
225 225
226 226
227 227
228#ifdef __cplusplus 228#ifdef __cplusplus
229extern "C" 229extern "C"
230#endif 230#endif
231int main( int argc, char *argv[] ) 231int main( int argc, char *argv[] )
232{ 232{
233 go(); 233 go();
234} 234}
235 235
236#endif 236#endif
diff --git a/noncore/games/sfcave-sdl/help.h b/noncore/games/sfcave-sdl/help.h
index dc9e80e..2cc32cd 100644
--- a/noncore/games/sfcave-sdl/help.h
+++ b/noncore/games/sfcave-sdl/help.h
@@ -1,35 +1,35 @@
1 1
2#ifndef __HELP_H 2#ifndef __HELP_H
3#define __help_h 3#define __help_h
4 4
5#include <list> 5#include <list>
6#include <string> 6#include <string>
7using namespace std; 7using namespace std;
8 8
9class SFCave; 9class SFCave;
10class StarField; 10class StarField;
11 11
12class Help 12class Help
13{ 13{
14public: 14public:
15 Help( SFCave *p ); 15 Help( SFCave *p );
16 ~Help(); 16 ~Help();
17 17
18 void init(); 18 void init();
19 void handleKeys( SDL_KeyboardEvent &key ); 19 void handleKeys( SDL_KeyboardEvent &key );
20 void draw( SDL_Surface *screen ); 20 void draw( SDL_Surface *screen );
21 void update(); 21 void update();
22private: 22private:
23 23
24 SFCave *parent; 24 SFCave *parent;
25 StarField *stars; 25 StarField *stars;
26 26
27 int textSpeed; 27 int textSpeed;
28 list<string> textList; 28 list<string> textList;
29 int startPos; 29 int startPos;
30 int currLine; 30 int currLine;
31 31
32 void loadText(); 32 void loadText();
33}; 33};
34 34
35#endif 35#endif
diff --git a/noncore/games/sfcave-sdl/menu.cpp b/noncore/games/sfcave-sdl/menu.cpp
index a4a4216..fb2a635 100644
--- a/noncore/games/sfcave-sdl/menu.cpp
+++ b/noncore/games/sfcave-sdl/menu.cpp
@@ -1,360 +1,360 @@
1#include <SDL_image.h> 1#include <SDL/SDL_image.h>
2#include "SDL_rotozoom.h" 2#include <SDL/SDL_rotozoom.h>
3 3
4#include "constants.h" 4#include "constants.h"
5#include "sfcave.h" 5#include "sfcave.h"
6#include "game.h" 6#include "game.h"
7#include "menu.h" 7#include "menu.h"
8#include "font.h" 8#include "font.h"
9#include "starfield.h" 9#include "starfield.h"
10 10
11MenuOption :: MenuOption( string text, int id ) 11MenuOption :: MenuOption( string text, int id )
12{ 12{
13 menuText = text; 13 menuText = text;
14 menuId = id; 14 menuId = id;
15 nextMenu = 0; 15 nextMenu = 0;
16 highlighted = false; 16 highlighted = false;
17} 17}
18 18
19MenuOption :: ~MenuOption() 19MenuOption :: ~MenuOption()
20{ 20{
21} 21}
22 22
23 23
24int MenuOption :: draw( SDL_Surface *screen, int y ) 24int MenuOption :: draw( SDL_Surface *screen, int y )
25{ 25{
26 if ( highlighted ) 26 if ( highlighted )
27 { 27 {
28 int x = (240 - FontHandler::TextWidth( FONT_MENU_HIGHLIGHTED, (const char *)menuText.c_str() ))/2; 28 int x = (240 - FontHandler::TextWidth( FONT_MENU_HIGHLIGHTED, (const char *)menuText.c_str() ))/2;
29 FontHandler::draw( screen, FONT_MENU_HIGHLIGHTED, (const char *)menuText.c_str(), x, y ); 29 FontHandler::draw( screen, FONT_MENU_HIGHLIGHTED, (const char *)menuText.c_str(), x, y );
30 return FontHandler::FontHeight( FONT_MENU_HIGHLIGHTED ); 30 return FontHandler::FontHeight( FONT_MENU_HIGHLIGHTED );
31 } 31 }
32 else 32 else
33 { 33 {
34 int x = (240 - FontHandler::TextWidth( FONT_MENU_UNHIGHLIGHTED, (const char *)menuText.c_str() ))/2; 34 int x = (240 - FontHandler::TextWidth( FONT_MENU_UNHIGHLIGHTED, (const char *)menuText.c_str() ))/2;
35 FontHandler::draw( screen, FONT_MENU_UNHIGHLIGHTED, (const char *)menuText.c_str(), x, y ); 35 FontHandler::draw( screen, FONT_MENU_UNHIGHLIGHTED, (const char *)menuText.c_str(), x, y );
36 return FontHandler::FontHeight( FONT_MENU_UNHIGHLIGHTED ); 36 return FontHandler::FontHeight( FONT_MENU_UNHIGHLIGHTED );
37 } 37 }
38} 38}
39 39
40void MenuOption :: setNextMenu( Menu *item, bool down ) 40void MenuOption :: setNextMenu( Menu *item, bool down )
41{ 41{
42 nextMenu = item; 42 nextMenu = item;
43 downMenuTree = down; 43 downMenuTree = down;
44} 44}
45 45
46 46
47 47
48//----------------- Menu Class ------------- 48//----------------- Menu Class -------------
49 49
50SDL_Surface * Menu :: sfcaveTextImage; 50SDL_Surface * Menu :: sfcaveTextImage;
51Menu *Menu :: mainMenu; 51Menu *Menu :: mainMenu;
52Menu *Menu :: currentMenu; 52Menu *Menu :: currentMenu;
53 53
54// This is the Master Menu constructor 54// This is the Master Menu constructor
55Menu :: Menu( SFCave *p ) 55Menu :: Menu( SFCave *p )
56{ 56{
57 parent = p; 57 parent = p;
58 parentMenu = 0; 58 parentMenu = 0;
59 statusText = ""; 59 statusText = "";
60 60
61 //listItems.setAutoDelete( TRUE ); 61 //listItems.setAutoDelete( TRUE );
62 62
63 SDL_Surface *tmp = IMG_Load( IMAGES_PATH "sfcave_text.bmp" ); 63 SDL_Surface *tmp = IMG_Load( IMAGES_PATH "sfcave_text.bmp" );
64 sfcaveTextImage = SDL_CreateRGBSurface(SDL_SWSURFACE, tmp->w, tmp->h, 32, 64 sfcaveTextImage = SDL_CreateRGBSurface(SDL_SWSURFACE, tmp->w, tmp->h, 32,
65 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000); 65 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000);
66 SDL_BlitSurface(tmp, NULL, sfcaveTextImage, NULL); 66 SDL_BlitSurface(tmp, NULL, sfcaveTextImage, NULL);
67 SDL_FreeSurface(tmp); 67 SDL_FreeSurface(tmp);
68 68
69 // Create menu structure 69 // Create menu structure
70 // Top level menu has 5 items - Start Game, Replays, Options, Help, and Quit 70 // Top level menu has 5 items - Start Game, Replays, Options, Help, and Quit
71 // Replays, Option menu items hav submenus 71 // Replays, Option menu items hav submenus
72 MenuOption *replayMenu = 0; 72 MenuOption *replayMenu = 0;
73 MenuOption *optionsMenu = 0; 73 MenuOption *optionsMenu = 0;
74 MenuOption *item = 0; 74 MenuOption *item = 0;
75 addMenuOption( "Start Game", MENU_STARTGAME ); 75 addMenuOption( "Start Game", MENU_STARTGAME );
76 replayMenu = addMenuOption( "Replays", MENU_REPLAYS ); 76 replayMenu = addMenuOption( "Replays", MENU_REPLAYS );
77 optionsMenu = addMenuOption( "Options", MENU_OPTIONS ); 77 optionsMenu = addMenuOption( "Options", MENU_OPTIONS );
78 addMenuOption( "Help", MENU_HELP ); 78 addMenuOption( "Help", MENU_HELP );
79 addMenuOption( "Quit", MENU_QUIT ); 79 addMenuOption( "Quit", MENU_QUIT );
80 80
81 // Now deal with the Replays Menu 81 // Now deal with the Replays Menu
82 Menu *replay = new Menu( this ); 82 Menu *replay = new Menu( this );
83 replay->addMenuOption( "Play Replay", MENU_PLAY_REPLAY ); 83 replay->addMenuOption( "Play Replay", MENU_PLAY_REPLAY );
84 replay->addMenuOption( "Load Replay", MENU_LOAD_REPLAY ); 84 replay->addMenuOption( "Load Replay", MENU_LOAD_REPLAY );
85 replay->addMenuOption( "Save Replay", MENU_SAVE_REPLAY ); 85 replay->addMenuOption( "Save Replay", MENU_SAVE_REPLAY );
86 item = replay->addMenuOption( "Back", MENU_BACK ); 86 item = replay->addMenuOption( "Back", MENU_BACK );
87 item->setNextMenu( this, false ); 87 item->setNextMenu( this, false );
88 replayMenu->setNextMenu( replay ); 88 replayMenu->setNextMenu( replay );
89 89
90 // Now deal with the Options MenucurrentMenu->currentMenuOption->setHighlighted( false ); 90 // Now deal with the Options MenucurrentMenu->currentMenuOption->setHighlighted( false );
91 listItems.front()->highlight( true ); 91 listItems.front()->highlight( true );
92 92
93 Menu *options = new Menu( this ); 93 Menu *options = new Menu( this );
94 MenuOption *typeMenu = 0; 94 MenuOption *typeMenu = 0;
95 MenuOption *difficultyMenu = 0; 95 MenuOption *difficultyMenu = 0;
96 MenuOption *soundsMenu = 0; 96 MenuOption *soundsMenu = 0;
97 typeMenu = options->addMenuOption( "Game Type", MENU_GAME_TYPE ); 97 typeMenu = options->addMenuOption( "Game Type", MENU_GAME_TYPE );
98 difficultyMenu = options->addMenuOption( "Difficulty", MENU_DIFFICULTY ); 98 difficultyMenu = options->addMenuOption( "Difficulty", MENU_DIFFICULTY );
99 soundsMenu = options->addMenuOption( "Sound", MENU_SOUNDS ); 99 soundsMenu = options->addMenuOption( "Sound", MENU_SOUNDS );
100 options->addMenuOption( "Clear Scores", MENU_CLEAR_SCORES ); 100 options->addMenuOption( "Clear Scores", MENU_CLEAR_SCORES );
101 item = options->addMenuOption( "Back", MENU_BACK ); 101 item = options->addMenuOption( "Back", MENU_BACK );
102 item->setNextMenu( this, false ); 102 item->setNextMenu( this, false );
103 optionsMenu->setNextMenu( options ); 103 optionsMenu->setNextMenu( options );
104 104
105 // Game Type menu 105 // Game Type menu
106 Menu *gameType = new Menu( options ); 106 Menu *gameType = new Menu( options );
107 item = gameType->addMenuOption( "SFCave", MENU_GAME_SFCAVE ); 107 item = gameType->addMenuOption( "SFCave", MENU_GAME_SFCAVE );
108 item->setNextMenu( options ); 108 item->setNextMenu( options );
109 item = gameType->addMenuOption( "Gates", MENU_GAME_GATES ); 109 item = gameType->addMenuOption( "Gates", MENU_GAME_GATES );
110 item->setNextMenu( options ); 110 item->setNextMenu( options );
111 item = gameType->addMenuOption( "Fly", MENU_GAME_FLY ); 111 item = gameType->addMenuOption( "Fly", MENU_GAME_FLY );
112 item->setNextMenu( options ); 112 item->setNextMenu( options );
113 item = gameType->addMenuOption( "Back", MENU_BACK ); 113 item = gameType->addMenuOption( "Back", MENU_BACK );
114 item->setNextMenu( options ); 114 item->setNextMenu( options );
115 typeMenu->setNextMenu( gameType ); 115 typeMenu->setNextMenu( gameType );
116 116
117 // Game Difficulty menu 117 // Game Difficulty menu
118 MenuOption *customMenu = 0; 118 MenuOption *customMenu = 0;
119 Menu *gameDifficulty = new Menu( options ); 119 Menu *gameDifficulty = new Menu( options );
120 item = gameDifficulty->addMenuOption( "Easy", MENU_DIFFICULTY_EASY ); 120 item = gameDifficulty->addMenuOption( "Easy", MENU_DIFFICULTY_EASY );
121 item->setNextMenu( options, false ); 121 item->setNextMenu( options, false );
122 item = gameDifficulty->addMenuOption( "Normal", MENU_DIFFICULTY_NORMAL ); 122 item = gameDifficulty->addMenuOption( "Normal", MENU_DIFFICULTY_NORMAL );
123 item->setNextMenu( options, false ); 123 item->setNextMenu( options, false );
124 item = gameDifficulty->addMenuOption( "Hard", MENU_DIFFICULTY_HARD ); 124 item = gameDifficulty->addMenuOption( "Hard", MENU_DIFFICULTY_HARD );
125 item->setNextMenu( options, false ); 125 item->setNextMenu( options, false );
126 customMenu = gameDifficulty->addMenuOption( "Custom", MENU_DIFFICULTY_CUSTOM ); 126 customMenu = gameDifficulty->addMenuOption( "Custom", MENU_DIFFICULTY_CUSTOM );
127 item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); 127 item = gameDifficulty->addMenuOption( "Back", MENU_BACK );
128 item->setNextMenu( options, false ); 128 item->setNextMenu( options, false );
129 difficultyMenu->setNextMenu( gameDifficulty ); 129 difficultyMenu->setNextMenu( gameDifficulty );
130 130
131 // Sounds Menu 131 // Sounds Menu
132 Menu *sounds = new Menu( options ); 132 Menu *sounds = new Menu( options );
133 sounds->addMenuOption( "Sound On", MENU_SOUND_ON ); 133 sounds->addMenuOption( "Sound On", MENU_SOUND_ON );
134 sounds->addMenuOption( "Sound Off", MENU_SOUND_OFF ); 134 sounds->addMenuOption( "Sound Off", MENU_SOUND_OFF );
135 sounds->addMenuOption( "Music On", MENU_MUSIC_ON ); 135 sounds->addMenuOption( "Music On", MENU_MUSIC_ON );
136 sounds->addMenuOption( "Music Off", MENU_MUSIC_OFF ); 136 sounds->addMenuOption( "Music Off", MENU_MUSIC_OFF );
137 item = sounds->addMenuOption( "Back", MENU_BACK ); 137 item = sounds->addMenuOption( "Back", MENU_BACK );
138 item->setNextMenu( options, false ); 138 item->setNextMenu( options, false );
139 soundsMenu->setNextMenu( sounds ); 139 soundsMenu->setNextMenu( sounds );
140 140
141 // Custom Menu 141 // Custom Menu
142 Menu *custom = new Menu( gameDifficulty ); 142 Menu *custom = new Menu( gameDifficulty );
143 Menu *updown = new Menu( custom ); 143 Menu *updown = new Menu( custom );
144 item = custom->addMenuOption( "Thrust", MENU_CUSTOM_THRUST ); 144 item = custom->addMenuOption( "Thrust", MENU_CUSTOM_THRUST );
145 item->setNextMenu( updown ); 145 item->setNextMenu( updown );
146 item = custom->addMenuOption( "Gravity", MENU_CUSTOM_GRAVITY ); 146 item = custom->addMenuOption( "Gravity", MENU_CUSTOM_GRAVITY );
147 item->setNextMenu( updown ); 147 item->setNextMenu( updown );
148 item = custom->addMenuOption( "Max Speed Up", MENU_CUSTOM_MAXSPEEDUP ); 148 item = custom->addMenuOption( "Max Speed Up", MENU_CUSTOM_MAXSPEEDUP );
149 item->setNextMenu( updown ); 149 item->setNextMenu( updown );
150 item = custom->addMenuOption( "Max Speed Down", MENU_CUSTOM_MAXSPEEDDOWN ); 150 item = custom->addMenuOption( "Max Speed Down", MENU_CUSTOM_MAXSPEEDDOWN );
151 item->setNextMenu( updown ); 151 item->setNextMenu( updown );
152 item = custom->addMenuOption( "Back", MENU_BACK ); 152 item = custom->addMenuOption( "Back", MENU_BACK );
153 item->setNextMenu( gameDifficulty, false ); 153 item->setNextMenu( gameDifficulty, false );
154 customMenu->setNextMenu( custom ); 154 customMenu->setNextMenu( custom );
155 155
156 // Up down menu 156 // Up down menu
157 item = updown->addMenuOption( "Increase", MENU_CUSTOM_INCREASE ); 157 item = updown->addMenuOption( "Increase", MENU_CUSTOM_INCREASE );
158 item = updown->addMenuOption( "Decrease", MENU_CUSTOM_DECREASE ); 158 item = updown->addMenuOption( "Decrease", MENU_CUSTOM_DECREASE );
159 item = updown->addMenuOption( "Save", MENU_CUSTOM_SAVE ); 159 item = updown->addMenuOption( "Save", MENU_CUSTOM_SAVE );
160 item->setNextMenu( custom, false ); 160 item->setNextMenu( custom, false );
161 item = updown->addMenuOption( "Cancel", MENU_CUSTOM_CANCEL ); 161 item = updown->addMenuOption( "Cancel", MENU_CUSTOM_CANCEL );
162 item->setNextMenu( custom, false ); 162 item->setNextMenu( custom, false );
163 163
164 // Set static variables for menu selection up 164 // Set static variables for menu selection up
165 mainMenu = this; 165 mainMenu = this;
166 currentMenuOption = 0; 166 currentMenuOption = 0;
167 167
168 resetToTopMenu(); 168 resetToTopMenu();
169 169
170 angle = 0; 170 angle = 0;
171 171
172 stars = new StarField; 172 stars = new StarField;
173} 173}
174 174
175// This is a private constructor used for creating sub menus - only called by the Master Menu 175// This is a private constructor used for creating sub menus - only called by the Master Menu
176Menu :: Menu( Menu *p ) 176Menu :: Menu( Menu *p )
177{ 177{
178 parentMenu = p; 178 parentMenu = p;
179 //listItems.setAutoDelete( TRUE ); 179 //listItems.setAutoDelete( TRUE );
180 currentMenuOption = 0; 180 currentMenuOption = 0;
181} 181}
182 182
183Menu :: ~Menu() 183Menu :: ~Menu()
184{ 184{
185 if ( this == mainMenu ) 185 if ( this == mainMenu )
186 { 186 {
187 SDL_FreeSurface( sfcaveTextImage ); 187 SDL_FreeSurface( sfcaveTextImage );
188 delete stars; 188 delete stars;
189 } 189 }
190} 190}
191 191
192void Menu :: draw( SDL_Surface *screen ) 192void Menu :: draw( SDL_Surface *screen )
193{ 193{
194 // draw stafield 194 // draw stafield
195 stars->draw( screen ); 195 stars->draw( screen );
196 stars->move( ); 196 stars->move( );
197 197
198 // Draw the spinning SFCave logo 198 // Draw the spinning SFCave logo
199 SDL_Surface *rotozoom_pic; 199 SDL_Surface *rotozoom_pic;
200 SDL_Rect dest; 200 SDL_Rect dest;
201 201
202 angle += 2; 202 angle += 2;
203 if ( angle > 359 ) 203 if ( angle > 359 )
204 angle = 0; 204 angle = 0;
205 if ((rotozoom_pic=rotozoomSurface (sfcaveTextImage, angle*1, 1, SMOOTHING_ON))!=NULL) 205 if ((rotozoom_pic=rotozoomSurface (sfcaveTextImage, angle*1, 1, SMOOTHING_ON))!=NULL)
206 { 206 {
207 dest.x = (screen->w - rotozoom_pic->w)/2; 207 dest.x = (screen->w - rotozoom_pic->w)/2;
208 dest.y = 10; 208 dest.y = 10;
209 dest.w = rotozoom_pic->w; 209 dest.w = rotozoom_pic->w;
210 dest.h = rotozoom_pic->h; 210 dest.h = rotozoom_pic->h;
211 SDL_BlitSurface( rotozoom_pic, NULL, screen, &dest ); 211 SDL_BlitSurface( rotozoom_pic, NULL, screen, &dest );
212 SDL_FreeSurface(rotozoom_pic); 212 SDL_FreeSurface(rotozoom_pic);
213 } 213 }
214 214
215 // Draw what game is selected 215 // Draw what game is selected
216 char text[100]; 216 char text[100];
217 sprintf( text, "Current Game: %s", (const char *)parent->getCurrentGame()->getGameName().c_str() ); 217 sprintf( text, "Current Game: %s", (const char *)parent->getCurrentGame()->getGameName().c_str() );
218 //Menu::scoreFont.PutString( screen, (240 - Menu::scoreFont.TextWidth( (const char *)text ))/2, 120, (const char *)text ); 218 //Menu::scoreFont.PutString( screen, (240 - Menu::scoreFont.TextWidth( (const char *)text ))/2, 120, (const char *)text );
219 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)text, (240 - FontHandler::TextWidth( FONT_WHITE_TEXT,(const char *)text ))/2, 120 ); 219 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)text, (240 - FontHandler::TextWidth( FONT_WHITE_TEXT,(const char *)text ))/2, 120 );
220 sprintf( text, "Difficulty: %s", (const char *)parent->getCurrentGame()->getGameDifficultyText().c_str() ); 220 sprintf( text, "Difficulty: %s", (const char *)parent->getCurrentGame()->getGameDifficultyText().c_str() );
221 //Menu::scoreFont.PutString( screen, (240 - Menu::scoreFont.TextWidth( (const char *)text ))/2, 120 + Menu::scoreFont.FontHeight()+2, (const char *)text ); 221 //Menu::scoreFont.PutString( screen, (240 - Menu::scoreFont.TextWidth( (const char *)text ))/2, 120 + Menu::scoreFont.FontHeight()+2, (const char *)text );
222 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)text, (240 - FontHandler::TextWidth( FONT_WHITE_TEXT,(const char *)text ))/2, 120 + FontHandler::FontHeight( FONT_WHITE_TEXT ) ); 222 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)text, (240 - FontHandler::TextWidth( FONT_WHITE_TEXT,(const char *)text ))/2, 120 + FontHandler::FontHeight( FONT_WHITE_TEXT ) );
223 223
224 if ( statusText != "" ) 224 if ( statusText != "" )
225 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)statusText.c_str(), (240 - FontHandler::TextWidth( FONT_WHITE_TEXT,(const char *)statusText.c_str() ))/2, 120 + (2*FontHandler::FontHeight( FONT_WHITE_TEXT ))+6 ); 225 FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)statusText.c_str(), (240 - FontHandler::TextWidth( FONT_WHITE_TEXT,(const char *)statusText.c_str() ))/2, 120 + (2*FontHandler::FontHeight( FONT_WHITE_TEXT ))+6 );
226 // Menu::scoreFont.PutString( screen, (240 - Menu::scoreFont.TextWidth( (const char *)statusText ))/2, 120 + (Menu::scoreFont.FontHeight()*2)+6, (const char *)statusText ); 226 // Menu::scoreFont.PutString( screen, (240 - Menu::scoreFont.TextWidth( (const char *)statusText ))/2, 120 + (Menu::scoreFont.FontHeight()*2)+6, (const char *)statusText );
227 227
228 228
229 // Loop round each menu option and draw it 229 // Loop round each menu option and draw it
230 int y = 155; 230 int y = 155;
231 list<MenuOption *>::iterator it; 231 list<MenuOption *>::iterator it;
232 for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it ) 232 for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it )
233 { 233 {
234 y += (*it)->draw( screen, y ) + 2; 234 y += (*it)->draw( screen, y ) + 2;
235 } 235 }
236} 236}
237 237
238int Menu :: handleKeys( SDL_KeyboardEvent &key ) 238int Menu :: handleKeys( SDL_KeyboardEvent &key )
239{ 239{
240 if ( key.type != SDL_KEYDOWN ) 240 if ( key.type != SDL_KEYDOWN )
241 return -1; 241 return -1;
242 242
243 switch( key.keysym.sym ) 243 switch( key.keysym.sym )
244 { 244 {
245 case SDLK_DOWN: 245 case SDLK_DOWN:
246 { 246 {
247 // Move to next menu item 247 // Move to next menu item
248 currentMenu->currentMenuOption->highlight( false ); 248 currentMenu->currentMenuOption->highlight( false );
249 249
250 list<MenuOption *>::iterator it; 250 list<MenuOption *>::iterator it;
251 for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it ) 251 for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it )
252 { 252 {
253 if ( (*it) == currentMenu->currentMenuOption ) 253 if ( (*it) == currentMenu->currentMenuOption )
254 { 254 {
255 it++; 255 it++;
256 break; 256 break;
257 } 257 }
258 } 258 }
259 259
260 if ( it == currentMenu->listItems.end() ) 260 if ( it == currentMenu->listItems.end() )
261 it = currentMenu->listItems.begin(); 261 it = currentMenu->listItems.begin();
262 262
263 currentMenu->currentMenuOption = *it; 263 currentMenu->currentMenuOption = *it;
264 currentMenu->currentMenuOption->highlight( true ); 264 currentMenu->currentMenuOption->highlight( true );
265 265
266 break; 266 break;
267 } 267 }
268 case SDLK_UP: 268 case SDLK_UP:
269 { 269 {
270 // Move to previous menu item 270 // Move to previous menu item
271 currentMenu->currentMenuOption->highlight( false ); 271 currentMenu->currentMenuOption->highlight( false );
272 list<MenuOption *>::iterator it; 272 list<MenuOption *>::iterator it;
273 bool reachedBeginning = false; 273 bool reachedBeginning = false;
274 for ( it = (currentMenu->listItems).end()--; ; --it ) 274 for ( it = (currentMenu->listItems).end()--; ; --it )
275 { 275 {
276 if ( (*it) == currentMenu->currentMenuOption ) 276 if ( (*it) == currentMenu->currentMenuOption )
277 { 277 {
278 278
279 if ( it == currentMenu->listItems.begin( ) ) 279 if ( it == currentMenu->listItems.begin( ) )
280 { 280 {
281 reachedBeginning = true; 281 reachedBeginning = true;
282 break; 282 break;
283 } 283 }
284 else 284 else
285 it--; 285 it--;
286 break; 286 break;
287 } 287 }
288 288
289 } 289 }
290 290
291 if ( reachedBeginning ) 291 if ( reachedBeginning )
292 currentMenu->currentMenuOption = currentMenu->listItems.back(); 292 currentMenu->currentMenuOption = currentMenu->listItems.back();
293 else 293 else
294 currentMenu->currentMenuOption = *it; 294 currentMenu->currentMenuOption = *it;
295 295
296 currentMenu->currentMenuOption->highlight( true ); 296 currentMenu->currentMenuOption->highlight( true );
297 297
298 break; 298 break;
299 } 299 }
300 case SDLK_LEFT: 300 case SDLK_LEFT:
301 if ( currentMenu->parentMenu != 0 ) 301 if ( currentMenu->parentMenu != 0 )
302 { 302 {
303 statusText = ""; 303 statusText = "";
304 currentMenu = currentMenu->parentMenu; 304 currentMenu = currentMenu->parentMenu;
305 305
306 return -1; 306 return -1;
307 } 307 }
308 break; 308 break;
309 309
310 case SDLK_RETURN: 310 case SDLK_RETURN:
311 case SDLK_SPACE: 311 case SDLK_SPACE:
312 { 312 {
313 statusText = ""; 313 statusText = "";
314 // select menu item 314 // select menu item
315 int id = currentMenu->currentMenuOption->getMenuId(); 315 int id = currentMenu->currentMenuOption->getMenuId();
316 316
317 // if the current item has a child menu then move to that menu 317 // if the current item has a child menu then move to that menu
318 Menu *next = currentMenu->currentMenuOption->getNextMenu(); 318 Menu *next = currentMenu->currentMenuOption->getNextMenu();
319 if ( next != 0 ) 319 if ( next != 0 )
320 { 320 {
321 bool down = currentMenu->currentMenuOption->isDownMenuTree(); 321 bool down = currentMenu->currentMenuOption->isDownMenuTree();
322 currentMenu = next; 322 currentMenu = next;
323 if ( down ) 323 if ( down )
324 initCurrentMenu(); 324 initCurrentMenu();
325 } 325 }
326 326
327 return id; 327 return id;
328 328
329 break; 329 break;
330 } 330 }
331 331
332 default: 332 default:
333 break; 333 break;
334 } 334 }
335 335
336 return -1; 336 return -1;
337} 337}
338 338
339MenuOption *Menu :: addMenuOption( string text, int id ) 339MenuOption *Menu :: addMenuOption( string text, int id )
340{ 340{
341 MenuOption *item = new MenuOption( text, id ); 341 MenuOption *item = new MenuOption( text, id );
342 342
343 listItems.push_back( item ); 343 listItems.push_back( item );
344 344
345 return item; 345 return item;
346} 346}
347 347
348void Menu :: resetToTopMenu() 348void Menu :: resetToTopMenu()
349{ 349{
350 currentMenu = mainMenu; 350 currentMenu = mainMenu;
351 initCurrentMenu(); 351 initCurrentMenu();
352} 352}
353 353
354void Menu :: initCurrentMenu() 354void Menu :: initCurrentMenu()
355{ 355{
356 if ( currentMenu->currentMenuOption != 0 ) 356 if ( currentMenu->currentMenuOption != 0 )
357 currentMenu->currentMenuOption->highlight( false ); 357 currentMenu->currentMenuOption->highlight( false );
358 currentMenu->currentMenuOption = currentMenu->listItems.front(); 358 currentMenu->currentMenuOption = currentMenu->listItems.front();
359 currentMenu->currentMenuOption->highlight( true ); 359 currentMenu->currentMenuOption->highlight( true );
360} 360}
diff --git a/noncore/games/sfcave-sdl/menu.h b/noncore/games/sfcave-sdl/menu.h
index 6a5ef40..c263bcc 100644
--- a/noncore/games/sfcave-sdl/menu.h
+++ b/noncore/games/sfcave-sdl/menu.h
@@ -1,71 +1,71 @@
1#ifndef __MENU_H 1#ifndef __MENU_H
2#define __MENU_H 2#define __MENU_H
3 3
4#include <list> 4#include <list>
5using namespace std; 5using namespace std;
6 6
7#include <SDL.h> 7#include <SDL/SDL.h>
8 8
9class SFCave; 9class SFCave;
10class StarField; 10class StarField;
11class Menu; 11class Menu;
12 12
13class MenuOption 13class MenuOption
14{ 14{
15public: 15public:
16 MenuOption( string text, int id ); 16 MenuOption( string text, int id );
17 ~MenuOption(); 17 ~MenuOption();
18 18
19 void highlight( bool val ) { highlighted = val; } 19 void highlight( bool val ) { highlighted = val; }
20 int draw( SDL_Surface *screen, int y ); 20 int draw( SDL_Surface *screen, int y );
21 void setNextMenu( Menu *item, bool down = true ); 21 void setNextMenu( Menu *item, bool down = true );
22 Menu *getNextMenu() { return nextMenu; } 22 Menu *getNextMenu() { return nextMenu; }
23 int getMenuId() { return menuId; } 23 int getMenuId() { return menuId; }
24 bool isDownMenuTree() { return downMenuTree; } 24 bool isDownMenuTree() { return downMenuTree; }
25 25
26private: 26private:
27 int menuId; 27 int menuId;
28 string menuText; 28 string menuText;
29 bool highlighted; 29 bool highlighted;
30 bool downMenuTree; 30 bool downMenuTree;
31 31
32 Menu *nextMenu; 32 Menu *nextMenu;
33}; 33};
34 34
35class Menu 35class Menu
36{ 36{
37public: 37public:
38 Menu( SFCave *p ); 38 Menu( SFCave *p );
39 ~Menu(); 39 ~Menu();
40 40
41 void draw( SDL_Surface *screen ); 41 void draw( SDL_Surface *screen );
42 int handleKeys( SDL_KeyboardEvent & ); 42 int handleKeys( SDL_KeyboardEvent & );
43 MenuOption *addMenuOption( string text, int id ); 43 MenuOption *addMenuOption( string text, int id );
44 void resetToTopMenu(); 44 void resetToTopMenu();
45 void initCurrentMenu(); 45 void initCurrentMenu();
46 46
47 void setStatusText( string text ) { statusText = text; } 47 void setStatusText( string text ) { statusText = text; }
48 48
49protected: 49protected:
50 50
51private: 51private:
52 static SDL_Surface * sfcaveTextImage; 52 static SDL_Surface * sfcaveTextImage;
53 int angle; 53 int angle;
54 54
55 static Menu *mainMenu; 55 static Menu *mainMenu;
56 static Menu *currentMenu; 56 static Menu *currentMenu;
57 Menu *parentMenu; 57 Menu *parentMenu;
58 58
59 StarField *stars; 59 StarField *stars;
60 60
61 string statusText; 61 string statusText;
62 62
63 SFCave *parent; 63 SFCave *parent;
64 list<MenuOption *> listItems; 64 list<MenuOption *> listItems;
65 MenuOption *currentMenuOption; 65 MenuOption *currentMenuOption;
66 66
67 Menu( Menu* p ); 67 Menu( Menu* p );
68}; 68};
69 69
70 70
71#endif 71#endif
diff --git a/noncore/games/sfcave-sdl/player.cpp b/noncore/games/sfcave-sdl/player.cpp
index f024d6b..b491e53 100644
--- a/noncore/games/sfcave-sdl/player.cpp
+++ b/noncore/games/sfcave-sdl/player.cpp
@@ -1,284 +1,284 @@
1#include <SDL.h> 1#include <SDL/SDL.h>
2#include "SDL_gfxPrimitives.h" 2#include <SDL/SDL_gfxPrimitives.h>
3 3
4#include "constants.h" 4#include "constants.h"
5#include "player.h" 5#include "player.h"
6#include "random.h" 6#include "random.h"
7#include "animatedimage.h" 7#include "animatedimage.h"
8 8
9Player :: Player( int w, int h ) 9Player :: Player( int w, int h )
10{ 10{
11 sWidth = w; 11 sWidth = w;
12 sHeight = h; 12 sHeight = h;
13 13
14 thrust = 0.4; 14 thrust = 0.4;
15 gravity = 0.6; 15 gravity = 0.6;
16 maxUpSpeed = 4.0; 16 maxUpSpeed = 4.0;
17 maxDownSpeed = 5.0; 17 maxDownSpeed = 5.0;
18 18
19 explosion = new AnimatedImage( IMAGES_PATH "explosion.bmp", 15 ); 19 explosion = new AnimatedImage( IMAGES_PATH "explosion.bmp", 15 );
20 init(); 20 init();
21} 21}
22 22
23Player :: ~Player() 23Player :: ~Player()
24{ 24{
25 if ( explosion ) 25 if ( explosion )
26 delete explosion; 26 delete explosion;
27} 27}
28 28
29void Player :: init() 29void Player :: init()
30{ 30{
31 // Set player position 31 // Set player position
32 pos.x( 50 ); 32 pos.x( 50 );
33 pos.y( sWidth/2 ); 33 pos.y( sWidth/2 );
34 pos.h( 2 ); 34 pos.h( 2 );
35 pos.w( 4 ); 35 pos.w( 4 );
36 currentThrust = 0; 36 currentThrust = 0;
37 crashing = false; 37 crashing = false;
38 crashLineLength = 0; 38 crashLineLength = 0;
39 crashed = false; 39 crashed = false;
40 explosion->reset(); 40 explosion->reset();
41 allFaded = false; 41 allFaded = false;
42 expNextFrame = false; 42 expNextFrame = false;
43 43
44 // Reset Trail 44 // Reset Trail
45 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 45 for ( int i = 0 ; i < TRAILSIZE ; ++i )
46 { 46 {
47 trail[i].x( -1 ); 47 trail[i].x( -1 );
48 trail[i].y( 0 ); 48 trail[i].y( 0 );
49 trail[i].w( 2 ); 49 trail[i].w( 2 );
50 trail[i].h( 2 ); 50 trail[i].h( 2 );
51 } 51 }
52} 52}
53 53
54void Player :: draw( SDL_Surface *screen ) 54void Player :: draw( SDL_Surface *screen )
55{ 55{
56 if ( !crashing ) 56 if ( !crashing )
57 { 57 {
58 // Draw Player 58 // Draw Player
59 // ellipseRGBA( screen, pos.x(), pos.y(), pos.x()+ pos.width(), pos.y()+pos.height(), 0, 255, 255, 255 ); 59 // ellipseRGBA( screen, pos.x(), pos.y(), pos.x()+ pos.width(), pos.y()+pos.height(), 0, 255, 255, 255 );
60 filledEllipseRGBA( screen, pos.x() + pos.w(), pos.y(), pos.w(), pos.h(), 0, 255, 255, 255 ); 60 filledEllipseRGBA( screen, pos.x() + pos.w(), pos.y(), pos.w(), pos.h(), 0, 255, 255, 255 );
61 61
62 // Draw Trail 62 // Draw Trail
63 drawTrails( screen ); 63 drawTrails( screen );
64 } 64 }
65 else 65 else
66 { 66 {
67 drawTrails( screen ); 67 drawTrails( screen );
68 68
69 if ( !crashed ) 69 if ( !crashed )
70 explosion->draw( screen, pos.x(), pos.y() ); 70 explosion->draw( screen, pos.x(), pos.y() );
71 } 71 }
72} 72}
73 73
74void Player :: drawTrails( SDL_Surface *screen ) 74void Player :: drawTrails( SDL_Surface *screen )
75{ 75{
76 if ( allFaded && crashing ) 76 if ( allFaded && crashing )
77 return; 77 return;
78 78
79 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 79 for ( int i = 0 ; i < TRAILSIZE ; ++i )
80 { 80 {
81 if ( trail[i].x() >= 0 ) 81 if ( trail[i].x() >= 0 )
82 { 82 {
83 int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); 83 int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) ));
84 boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); 84 boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c );
85 } 85 }
86 } 86 }
87} 87}
88 88
89void Player :: move( bool up ) 89void Player :: move( bool up )
90{ 90{
91 // Find enpty trail and move others 91 // Find enpty trail and move others
92 moveTrails(); 92 moveTrails();
93 93
94 if ( up ) 94 if ( up )
95 currentThrust -= thrust; 95 currentThrust -= thrust;
96 else 96 else
97 currentThrust += gravity; 97 currentThrust += gravity;
98 98
99 if ( currentThrust > maxDownSpeed ) 99 if ( currentThrust > maxDownSpeed )
100 currentThrust = maxDownSpeed; 100 currentThrust = maxDownSpeed;
101 else if ( currentThrust < -maxUpSpeed ) 101 else if ( currentThrust < -maxUpSpeed )
102 currentThrust = -maxUpSpeed; 102 currentThrust = -maxUpSpeed;
103 103
104 pos.moveBy( 0, (int)(currentThrust) ); 104 pos.moveBy( 0, (int)(currentThrust) );
105} 105}
106 106
107void Player :: moveTrails() 107void Player :: moveTrails()
108{ 108{
109 bool done = false; 109 bool done = false;
110 bool stillVisible = false; 110 bool stillVisible = false;
111 111
112 // Dont do anything here if all faded when were crashing 112 // Dont do anything here if all faded when were crashing
113 if ( allFaded && crashing ) 113 if ( allFaded && crashing )
114 return; 114 return;
115 115
116 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 116 for ( int i = 0 ; i < TRAILSIZE ; ++i )
117 { 117 {
118 if ( trail[i].x() < 0 ) 118 if ( trail[i].x() < 0 )
119 { 119 {
120 stillVisible = true; 120 stillVisible = true;
121 if ( !crashing && !done ) 121 if ( !crashing && !done )
122 { 122 {
123 trail[i].x( pos.x() - 5 ); 123 trail[i].x( pos.x() - 5 );
124 trail[i].y( pos.y() ); 124 trail[i].y( pos.y() );
125 done = true; 125 done = true;
126 } 126 }
127 } 127 }
128 else 128 else
129 trail[i].x( trail[i].x() - 1 ); 129 trail[i].x( trail[i].x() - 1 );
130 } 130 }
131 131
132 if ( !stillVisible ) 132 if ( !stillVisible )
133 allFaded = true; 133 allFaded = true;
134} 134}
135 135
136bool Player :: updateCrashing() 136bool Player :: updateCrashing()
137{ 137{
138 crashing = true; 138 crashing = true;
139 139
140 moveTrails(); 140 moveTrails();
141 if ( expNextFrame ) 141 if ( expNextFrame )
142 { 142 {
143 expNextFrame = false; 143 expNextFrame = false;
144 crashed = !explosion->nextFrame(); 144 crashed = !explosion->nextFrame();
145 } 145 }
146 else 146 else
147 expNextFrame = true; 147 expNextFrame = true;
148 148
149 return crashed; 149 return crashed;
150} 150}
151 151
152void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown ) 152void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown )
153{ 153{
154 thrust = up; 154 thrust = up;
155 gravity = grav; 155 gravity = grav;
156 maxUpSpeed = maxUp; 156 maxUpSpeed = maxUp;
157 maxDownSpeed = maxDown; 157 maxDownSpeed = maxDown;
158} 158}
159 159
160 160
161void Player :: incValue( int valueType ) 161void Player :: incValue( int valueType )
162{ 162{
163 switch( valueType ) 163 switch( valueType )
164 { 164 {
165 case PLAYER_THRUST: 165 case PLAYER_THRUST:
166 thrust += 0.1; 166 thrust += 0.1;
167 break; 167 break;
168 case PLAYER_GRAVITY: 168 case PLAYER_GRAVITY:
169 gravity += 0.1; 169 gravity += 0.1;
170 break; 170 break;
171 case PLAYER_MAX_SPEED_UP: 171 case PLAYER_MAX_SPEED_UP:
172 maxUpSpeed += 0.1; 172 maxUpSpeed += 0.1;
173 break; 173 break;
174 case PLAYER_MAX_SPEED_DOWN: 174 case PLAYER_MAX_SPEED_DOWN:
175 maxDownSpeed += 0.1; 175 maxDownSpeed += 0.1;
176 break; 176 break;
177 } 177 }
178} 178}
179 179
180void Player :: decValue( int valueType ) 180void Player :: decValue( int valueType )
181{ 181{
182 switch( valueType ) 182 switch( valueType )
183 { 183 {
184 case PLAYER_THRUST: 184 case PLAYER_THRUST:
185 thrust -= 0.1; 185 thrust -= 0.1;
186 break; 186 break;
187 case PLAYER_GRAVITY: 187 case PLAYER_GRAVITY:
188 gravity -= 0.1; 188 gravity -= 0.1;
189 break; 189 break;
190 case PLAYER_MAX_SPEED_UP: 190 case PLAYER_MAX_SPEED_UP:
191 maxUpSpeed -= 0.1; 191 maxUpSpeed -= 0.1;
192 break; 192 break;
193 case PLAYER_MAX_SPEED_DOWN: 193 case PLAYER_MAX_SPEED_DOWN:
194 maxDownSpeed -= 0.1; 194 maxDownSpeed -= 0.1;
195 break; 195 break;
196 } 196 }
197} 197}
198 198
199void Player :: setValue( int valueType, double val ) 199void Player :: setValue( int valueType, double val )
200{ 200{
201 switch( valueType ) 201 switch( valueType )
202 { 202 {
203 case PLAYER_THRUST: 203 case PLAYER_THRUST:
204 thrust = val; 204 thrust = val;
205 break; 205 break;
206 case PLAYER_GRAVITY: 206 case PLAYER_GRAVITY:
207 gravity = val; 207 gravity = val;
208 break; 208 break;
209 case PLAYER_MAX_SPEED_UP: 209 case PLAYER_MAX_SPEED_UP:
210 maxUpSpeed = val; 210 maxUpSpeed = val;
211 break; 211 break;
212 case PLAYER_MAX_SPEED_DOWN: 212 case PLAYER_MAX_SPEED_DOWN:
213 maxDownSpeed = val; 213 maxDownSpeed = val;
214 break; 214 break;
215 } 215 }
216} 216}
217 217
218double Player :: getValue( int valueType ) 218double Player :: getValue( int valueType )
219{ 219{
220 double val; 220 double val;
221 switch( valueType ) 221 switch( valueType )
222 { 222 {
223 case PLAYER_THRUST: 223 case PLAYER_THRUST:
224 val = thrust; 224 val = thrust;
225 break; 225 break;
226 case PLAYER_GRAVITY: 226 case PLAYER_GRAVITY:
227 val = gravity; 227 val = gravity;
228 break; 228 break;
229 case PLAYER_MAX_SPEED_UP: 229 case PLAYER_MAX_SPEED_UP:
230 val = maxUpSpeed; 230 val = maxUpSpeed;
231 break; 231 break;
232 case PLAYER_MAX_SPEED_DOWN: 232 case PLAYER_MAX_SPEED_DOWN:
233 val = maxDownSpeed; 233 val = maxDownSpeed;
234 break; 234 break;
235 } 235 }
236 236
237 return val; 237 return val;
238} 238}
239 239
240string Player :: getValueTypeString( int valueType ) 240string Player :: getValueTypeString( int valueType )
241{ 241{
242 string val; 242 string val;
243 switch( valueType ) 243 switch( valueType )
244 { 244 {
245 case PLAYER_THRUST: 245 case PLAYER_THRUST:
246 val = "thrust"; 246 val = "thrust";
247 break; 247 break;
248 case PLAYER_GRAVITY: 248 case PLAYER_GRAVITY:
249 val = "gravity"; 249 val = "gravity";
250 break; 250 break;
251 case PLAYER_MAX_SPEED_UP: 251 case PLAYER_MAX_SPEED_UP:
252 val = "maxupspeed"; 252 val = "maxupspeed";
253 break; 253 break;
254 case PLAYER_MAX_SPEED_DOWN: 254 case PLAYER_MAX_SPEED_DOWN:
255 val = "maxdownspeed"; 255 val = "maxdownspeed";
256 break; 256 break;
257 } 257 }
258 258
259 return val; 259 return val;
260} 260}
261 261
262string Player :: getValueString( int valueType ) 262string Player :: getValueString( int valueType )
263{ 263{
264 char val[50]; 264 char val[50];
265 switch( valueType ) 265 switch( valueType )
266 { 266 {
267 case PLAYER_THRUST: 267 case PLAYER_THRUST:
268 sprintf( val, "Thrust - %lf", thrust ); 268 sprintf( val, "Thrust - %lf", thrust );
269 break; 269 break;
270 case PLAYER_GRAVITY: 270 case PLAYER_GRAVITY:
271 sprintf( val, "Gravity - %lf", gravity ); 271 sprintf( val, "Gravity - %lf", gravity );
272 break; 272 break;
273 case PLAYER_MAX_SPEED_UP: 273 case PLAYER_MAX_SPEED_UP:
274 sprintf( val, "Max Speed Up - %lf", maxUpSpeed ); 274 sprintf( val, "Max Speed Up - %lf", maxUpSpeed );
275 break; 275 break;
276 case PLAYER_MAX_SPEED_DOWN: 276 case PLAYER_MAX_SPEED_DOWN:
277 sprintf( val, "Max Speed Down - %lf", maxDownSpeed ); 277 sprintf( val, "Max Speed Down - %lf", maxDownSpeed );
278 break; 278 break;
279 } 279 }
280 280
281 string ret = val; 281 string ret = val;
282 return ret; 282 return ret;
283} 283}
284 284
diff --git a/noncore/games/sfcave-sdl/rect.h b/noncore/games/sfcave-sdl/rect.h
index dc9c9d5..30f082c 100644
--- a/noncore/games/sfcave-sdl/rect.h
+++ b/noncore/games/sfcave-sdl/rect.h
@@ -1,61 +1,61 @@
1#ifndef __RECT_H 1#ifndef __RECT_H
2#define __RECT_H 2#define __RECT_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5 5
6class Rect 6class Rect
7{ 7{
8public: 8public:
9 Rect() { r.x = r.y = r.w = r.h = 0; } 9 Rect() { r.x = r.y = r.w = r.h = 0; }
10 Rect( int x, int y, int w, int h ) { setRect( x, y, w, h ); } 10 Rect( int x, int y, int w, int h ) { setRect( x, y, w, h ); }
11 ~Rect() {} 11 ~Rect() {}
12 12
13 void setRect( int x, int y, int w, int h ) { r.x = x; r.y = y; r.w = w; r.h = h; } 13 void setRect( int x, int y, int w, int h ) { r.x = x; r.y = y; r.w = w; r.h = h; }
14 SDL_Rect getRect() { return r; } 14 SDL_Rect getRect() { return r; }
15 int x() { return r.x; } 15 int x() { return r.x; }
16 int y() { return r.y; } 16 int y() { return r.y; }
17 int w() { return r.w; } 17 int w() { return r.w; }
18 int h() { return r.h; } 18 int h() { return r.h; }
19 19
20 void x( int x) { r.x = x; } 20 void x( int x) { r.x = x; }
21 void y( int y) { r.y = y; } 21 void y( int y) { r.y = y; }
22 void w( int w) { r.w = w; } 22 void w( int w) { r.w = w; }
23 void h( int h) { r.h = h; } 23 void h( int h) { r.h = h; }
24 24
25 void moveBy( int x, int y ) 25 void moveBy( int x, int y )
26 { 26 {
27 r.x += x; 27 r.x += x;
28 r.y += y; 28 r.y += y;
29 } 29 }
30 30
31 bool intersects( Rect r2 ) 31 bool intersects( Rect r2 )
32 { 32 {
33 int tw = r.w; 33 int tw = r.w;
34 int th = r.h; 34 int th = r.h;
35 int rw = r2.w(); 35 int rw = r2.w();
36 int rh = r2.h(); 36 int rh = r2.h();
37 if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { 37 if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
38 return false; 38 return false;
39 } 39 }
40 int tx = r.x; 40 int tx = r.x;
41 int ty = r.y; 41 int ty = r.y;
42 int rx = r2.x(); 42 int rx = r2.x();
43 int ry = r2.y(); 43 int ry = r2.y();
44 rw += rx; 44 rw += rx;
45 rh += ry; 45 rh += ry;
46 tw += tx; 46 tw += tx;
47 th += ty; 47 th += ty;
48 48
49 // overflow || intersect 49 // overflow || intersect
50 return ((rw < rx || rw > tx) && 50 return ((rw < rx || rw > tx) &&
51 (rh < ry || rh > ty) && 51 (rh < ry || rh > ty) &&
52 (tw < tx || tw > rx) && 52 (tw < tx || tw > rx) &&
53 (th < ty || th > ry)); 53 (th < ty || th > ry));
54 } 54 }
55 55
56private: 56private:
57 SDL_Rect r; 57 SDL_Rect r;
58}; 58};
59 59
60#endif 60#endif
61 61
diff --git a/noncore/games/sfcave-sdl/sfcave-sdl.pro b/noncore/games/sfcave-sdl/sfcave-sdl.pro
index a4eb918..a02eeb3 100644
--- a/noncore/games/sfcave-sdl/sfcave-sdl.pro
+++ b/noncore/games/sfcave-sdl/sfcave-sdl.pro
@@ -1,55 +1,55 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG += qt warn_on release 2 CONFIG += qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 TARGET = sfcave-sdl 4 TARGET = sfcave-sdl
5 5
6DEFINES = _REENTRANT main=SDL_main 6DEFINES = _REENTRANT main=SDL_main
7 7
8INCLUDEPATH += $(OPIEDIR)/include 8INCLUDEPATH += $(OPIEDIR)/include
9INCLUDEPATH += $(OPIEDIR)/include/SDL 9INCLUDEPATH += $(OPIEDIR)/include/SDL
10DEPENDPATH += $(OPIEDIR)/include 10DEPENDPATH += $(OPIEDIR)/include
11 11
12LIBS += -lqpe -L${SDLDIR}/lib -lSDL -lSDLmain -lSDL_gfx -lSDL_image -lSDL_mixer -lstdc++ 12LIBS += -lqpe -L${SDLDIR}/lib -lSDL -lSDLmain -lSDL_gfx -lSDL_image -lSDL_mixer -lstdc++
13 13
14 SOURCES = animatedimage.cpp \ 14 SOURCES = animatedimage.cpp \
15 bfont.cpp \ 15 bfont.cpp \
16 font.cpp \ 16 font.cpp \
17 game.cpp \ 17 game.cpp \
18 menu.cpp \ 18 menu.cpp \
19 help.cpp \ 19 help.cpp \
20 player.cpp \ 20 player.cpp \
21 random.cpp \ 21 random.cpp \
22 sfcave.cpp \ 22 sfcave.cpp \
23 sfcave_game.cpp \ 23 sfcave_game.cpp \
24 gates_game.cpp \ 24 gates_game.cpp \
25 fly_game.cpp \ 25 fly_game.cpp \
26 flyterrain.cpp \ 26 flyterrain.cpp \
27 sound.cpp \ 27 sound.cpp \
28 terrain.cpp \ 28 terrain.cpp \
29 settings.cpp \ 29 settings.cpp \
30 starfield.cpp \ 30 starfield.cpp \
31 util.cpp 31 util.cpp
32 32
33 HEADERS = animatedimage.h \ 33 HEADERS = animatedimage.h \
34 bfont.h \ 34 bfont.h \
35 constants.h \ 35 constants.h \
36 font.h \ 36 font.h \
37 game.h \ 37 game.h \
38 menu.h \ 38 menu.h \
39 player.h \ 39 player.h \
40 random.h \ 40 random.h \
41 rect.h \ 41 rect.h \
42 sfcave.h \ 42 sfcave.h \
43 help.h \ 43 help.h \
44 sfcave_game.h \ 44 sfcave_game.h \
45 gates_game.h \ 45 gates_game.h \
46 fly_game.h \ 46 fly_game.h \
47 flyterrain.h \ 47 flyterrain.h \
48 sound.h \ 48 sound.h \
49 terrain.h \ 49 terrain.h \
50 stringtokenizer.h \ 50 stringtokenizer.h \
51 settings.h \ 51 settings.h \
52 starfield.h \ 52 starfield.h \
53 util.h 53 util.h
54 54
55include ( $(OPIEDIR)/include.pro ) \ No newline at end of file 55include ( $(OPIEDIR)/include.pro ) \ No newline at end of file
diff --git a/noncore/games/sfcave-sdl/sfcave.cpp b/noncore/games/sfcave-sdl/sfcave.cpp
index dbd788c..5d1cdd5 100644
--- a/noncore/games/sfcave-sdl/sfcave.cpp
+++ b/noncore/games/sfcave-sdl/sfcave.cpp
@@ -1,633 +1,633 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include <time.h> 4#include <time.h>
5#include <sys/timeb.h> 5#include <sys/timeb.h>
6 6
7#include "SDL.h" 7#include <SDL/SDL.h>
8#include "SDL_gfxPrimitives.h" 8#include <SDL/SDL_gfxPrimitives.h>
9 9
10#include "constants.h" 10#include "constants.h"
11 11
12#include "sound.h" 12#include "sound.h"
13#include "menu.h" 13#include "menu.h"
14#include "help.h" 14#include "help.h"
15#include "game.h" 15#include "game.h"
16#include "terrain.h" 16#include "terrain.h"
17#include "random.h" 17#include "random.h"
18#include "sfcave.h" 18#include "sfcave.h"
19#include "font.h" 19#include "font.h"
20#include "settings.h" 20#include "settings.h"
21#include "util.h" 21#include "util.h"
22 22
23#include "sfcave_game.h" 23#include "sfcave_game.h"
24#include "gates_game.h" 24#include "gates_game.h"
25#include "fly_game.h" 25#include "fly_game.h"
26 26
27void start( int argc, char *argv[] ) 27void start( int argc, char *argv[] )
28{ 28{
29 SFCave *app = new SFCave( argc, argv ); 29 SFCave *app = new SFCave( argc, argv );
30 app->mainEventLoop(); 30 app->mainEventLoop();
31 delete app; 31 delete app;
32} 32}
33 33
34#ifdef __cplusplus 34#ifdef __cplusplus
35extern "C" 35extern "C"
36#endif 36#endif
37int main(int argc, char *argv[]) 37int main(int argc, char *argv[])
38{ 38{
39 start( argc, argv ); 39 start( argc, argv );
40 return 0; 40 return 0;
41} 41}
42 42
43 43
44SFCave :: SFCave( int argc, char *argv[] ) 44SFCave :: SFCave( int argc, char *argv[] )
45{ 45{
46 setupOK = false; 46 setupOK = false;
47 47
48 // Load settings 48 // Load settings
49 string diff = loadSetting( "GameDifficulty", "Easy" ); 49 string diff = loadSetting( "GameDifficulty", "Easy" );
50 string game = loadSetting( "GameType", "SFCave" ); 50 string game = loadSetting( "GameType", "SFCave" );
51 musicPath = loadSetting( "MusicPath", SOUND_PATH ); 51 musicPath = loadSetting( "MusicPath", SOUND_PATH );
52 musicType = loadSetting( "MusicType", "mod,ogg" ); 52 musicType = loadSetting( "MusicType", "mod,ogg" );
53 bool soundOn = loadBoolSetting( "SoundOn", true ); 53 bool soundOn = loadBoolSetting( "SoundOn", true );
54 bool musicOn = loadBoolSetting( "MusicOn", true ); 54 bool musicOn = loadBoolSetting( "MusicOn", true );
55 if ( musicPath[musicPath.size()-1] != '/' ) 55 if ( musicPath[musicPath.size()-1] != '/' )
56 musicPath += "/"; 56 musicPath += "/";
57 printf( "musicPath %s\n", musicPath.c_str() ); 57 printf( "musicPath %s\n", musicPath.c_str() );
58 58
59 // Init main SDL Library 59 // Init main SDL Library
60 initSDL( argc, argv ); 60 initSDL( argc, argv );
61 61
62 // Init font handler 62 // Init font handler
63 if ( !FontHandler::init() ) 63 if ( !FontHandler::init() )
64 { 64 {
65 printf( "Unable to initialise fonts!\n" ); 65 printf( "Unable to initialise fonts!\n" );
66 return; 66 return;
67 } 67 }
68 68
69 // Init SoundHandler 69 // Init SoundHandler
70 if ( !SoundHandler :: init() ) 70 if ( !SoundHandler :: init() )
71 printf("Unable to open audio!\n"); 71 printf("Unable to open audio!\n");
72 72
73 SoundHandler :: setSoundsOn( soundOn ); 73 SoundHandler :: setSoundsOn( soundOn );
74 SoundHandler :: setMusicOn( musicOn ); 74 SoundHandler :: setMusicOn( musicOn );
75 75
76 currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff ); 76 currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff );
77 if ( !currentGame ) 77 if ( !currentGame )
78 currentGame = new SFCaveGame( this, WIDTH, HEIGHT, 0 ); 78 currentGame = new SFCaveGame( this, WIDTH, HEIGHT, 0 );
79 currentGame->setSeed(-1); 79 currentGame->setSeed(-1);
80 80
81 // Create menu 81 // Create menu
82 menu = new Menu( this ); 82 menu = new Menu( this );
83 83
84 // Create help screen 84 // Create help screen
85 help = new Help( this ); 85 help = new Help( this );
86 86
87 maxFPS = 50; 87 maxFPS = 50;
88 showFps = false; 88 showFps = false;
89 89
90 setupOK = true; 90 setupOK = true;
91} 91}
92 92
93SFCave :: ~SFCave() 93SFCave :: ~SFCave()
94{ 94{
95 if ( currentGame ) 95 if ( currentGame )
96 delete currentGame; 96 delete currentGame;
97 97
98 if ( menu ) 98 if ( menu )
99 delete menu; 99 delete menu;
100 100
101 if ( help ) 101 if ( help )
102 delete help; 102 delete help;
103 103
104 SDL_FreeSurface( screen ); 104 SDL_FreeSurface( screen );
105 FontHandler::cleanUp(); 105 FontHandler::cleanUp();
106 SoundHandler :: cleanUp(); 106 SoundHandler :: cleanUp();
107 107
108 SDL_Quit(); 108 SDL_Quit();
109} 109}
110 110
111 111
112void SFCave :: initSDL( int argc, char *argv[] ) 112void SFCave :: initSDL( int argc, char *argv[] )
113{ 113{
114 const SDL_VideoInfo *info; 114 const SDL_VideoInfo *info;
115 Uint8 video_bpp; 115 Uint8 video_bpp;
116 Uint32 videoflags; 116 Uint32 videoflags;
117 117
118 // Initialize SDL 118 // Initialize SDL
119 if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { 119 if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) {
120 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 120 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
121 exit(1); 121 exit(1);
122 } 122 }
123 123
124 video_bpp = 16; 124 video_bpp = 16;
125 125
126 if ( !SDL_VideoModeOK(WIDTH, HEIGHT, video_bpp, SDL_DOUBLEBUF) ) 126 if ( !SDL_VideoModeOK(WIDTH, HEIGHT, video_bpp, SDL_DOUBLEBUF) )
127 printf( "No double buffering\n" ); 127 printf( "No double buffering\n" );
128 128
129 videoflags = SDL_HWSURFACE | SDL_SRCALPHA; 129 videoflags = SDL_HWSURFACE | SDL_SRCALPHA;
130 while ( argc > 1 ) 130 while ( argc > 1 )
131 { 131 {
132 --argc; 132 --argc;
133 if ( strcmp(argv[argc-1], "-bpp") == 0 ) 133 if ( strcmp(argv[argc-1], "-bpp") == 0 )
134 { 134 {
135 video_bpp = atoi(argv[argc]); 135 video_bpp = atoi(argv[argc]);
136 --argc; 136 --argc;
137 } 137 }
138 else if ( strcmp(argv[argc], "-hw") == 0 ) 138 else if ( strcmp(argv[argc], "-hw") == 0 )
139 { 139 {
140 videoflags |= SDL_HWSURFACE; 140 videoflags |= SDL_HWSURFACE;
141 } 141 }
142 else if ( strcmp(argv[argc], "-warp") == 0 ) 142 else if ( strcmp(argv[argc], "-warp") == 0 )
143 { 143 {
144 videoflags |= SDL_HWPALETTE; 144 videoflags |= SDL_HWPALETTE;
145 } 145 }
146 else if ( strcmp(argv[argc], "-fullscreen") == 0 ) 146 else if ( strcmp(argv[argc], "-fullscreen") == 0 )
147 { 147 {
148 videoflags |= SDL_FULLSCREEN; 148 videoflags |= SDL_FULLSCREEN;
149 } 149 }
150 else if ( strcmp(argv[argc], "-h") == 0 ) 150 else if ( strcmp(argv[argc], "-h") == 0 )
151 { 151 {
152 fprintf(stderr, 152 fprintf(stderr,
153 "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n", 153 "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n",
154 argv[0]); 154 argv[0]);
155 exit(1); 155 exit(1);
156 } 156 }
157 } 157 }
158 158
159 // Set 240x320 video mode 159 // Set 240x320 video mode
160 if ( (screen = SDL_SetVideoMode( WIDTH,HEIGHT,video_bpp,videoflags )) == NULL ) 160 if ( (screen = SDL_SetVideoMode( WIDTH,HEIGHT,video_bpp,videoflags )) == NULL )
161 { 161 {
162 printf( "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError() ); 162 printf( "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError() );
163 exit(2); 163 exit(2);
164 } 164 }
165 165
166 // Use alpha blending 166 // Use alpha blending
167 //SDL_SetAlpha(screen, SDL_RLEACCEL, 0); 167 //SDL_SetAlpha(screen, SDL_RLEACCEL, 0);
168 168
169 // Set title for window 169 // Set title for window
170 SDL_WM_SetCaption("SFCave","SFCave"); 170 SDL_WM_SetCaption("SFCave","SFCave");
171} 171}
172 172
173void SFCave :: mainEventLoop() 173void SFCave :: mainEventLoop()
174{ 174{
175 if ( !setupOK ) 175 if ( !setupOK )
176 return; 176 return;
177 177
178 // Wait for a keystroke 178 // Wait for a keystroke
179 finish = false; 179 finish = false;
180 state = 0; 180 state = 0;
181 state = STATE_CRASHED; 181 state = STATE_CRASHED;
182 changeState( STATE_MENU ); 182 changeState( STATE_MENU );
183 183
184 FPS = 0; 184 FPS = 0;
185 actualFPS = 0; 185 actualFPS = 0;
186 time1 = 0; 186 time1 = 0;
187 187
188 limitFPS = true; 188 limitFPS = true;
189 while ( !finish ) 189 while ( !finish )
190 { 190 {
191 // calc FPS 191 // calc FPS
192 calcFPS(); 192 calcFPS();
193 193
194 SDL_FillRect( screen, 0, 0 ); 194 SDL_FillRect( screen, 0, 0 );
195 195
196 handleGameState( ); 196 handleGameState( );
197 197
198 SDL_Flip( screen ); 198 SDL_Flip( screen );
199 199
200 if ( limitFPS ) 200 if ( limitFPS )
201 FPSDelay(); 201 FPSDelay();
202 else 202 else
203 SDL_Delay( 5 ); 203 SDL_Delay( 5 );
204 204
205 handleEvents(); 205 handleEvents();
206 } 206 }
207} 207}
208 208
209 209
210void SFCave :: handleGameState() 210void SFCave :: handleGameState()
211{ 211{
212 switch( state ) 212 switch( state )
213 { 213 {
214 case STATE_MENU: 214 case STATE_MENU:
215 SDL_FillRect( screen, 0, 0 ); 215 SDL_FillRect( screen, 0, 0 );
216 menu->draw( screen ); 216 menu->draw( screen );
217 break; 217 break;
218 case STATE_HELP: 218 case STATE_HELP:
219 SDL_FillRect( screen, 0, 0 ); 219 SDL_FillRect( screen, 0, 0 );
220 help->update(); 220 help->update();
221 help->draw( screen ); 221 help->draw( screen );
222 break; 222 break;
223 case STATE_NEWGAME: 223 case STATE_NEWGAME:
224 currentGame->setReplay( false ); 224 currentGame->setReplay( false );
225 currentGame->init(); 225 currentGame->init();
226 changeState( STATE_PLAYING ); 226 changeState( STATE_PLAYING );
227 break; 227 break;
228 228
229 case STATE_REPLAY: 229 case STATE_REPLAY:
230 currentGame->setReplay( true ); 230 currentGame->setReplay( true );
231 currentGame->init(); 231 currentGame->init();
232 changeState( STATE_PLAYING ); 232 changeState( STATE_PLAYING );
233 break; 233 break;
234 234
235 case STATE_PLAYING: 235 case STATE_PLAYING:
236 case STATE_CRASHING: 236 case STATE_CRASHING:
237 case STATE_CRASHED: 237 case STATE_CRASHED:
238 currentGame->update( state ); 238 currentGame->update( state );
239 currentGame->draw( screen ); 239 currentGame->draw( screen );
240 break; 240 break;
241 241
242 case STATE_QUIT: 242 case STATE_QUIT:
243 finish = true; 243 finish = true;
244 break; 244 break;
245 } 245 }
246} 246}
247 247
248void SFCave :: handleEvents() 248void SFCave :: handleEvents()
249{ 249{
250 SDL_Event event; 250 SDL_Event event;
251 251
252 // Check for events 252 // Check for events
253 while ( SDL_PollEvent(&event) ) 253 while ( SDL_PollEvent(&event) )
254 { 254 {
255 switch (event.type) 255 switch (event.type)
256 { 256 {
257 case SDL_KEYDOWN: 257 case SDL_KEYDOWN:
258 case SDL_KEYUP: 258 case SDL_KEYUP:
259 { 259 {
260 // Escape keypress quits the app 260 // Escape keypress quits the app
261 if ( event.key.keysym.sym == SDLK_ESCAPE ) 261 if ( event.key.keysym.sym == SDLK_ESCAPE )
262 { 262 {
263 finish = true; 263 finish = true;
264 break; 264 break;
265 } 265 }
266 266
267 if ( state == STATE_MENU ) 267 if ( state == STATE_MENU )
268 { 268 {
269 int rc = menu->handleKeys( event.key ); 269 int rc = menu->handleKeys( event.key );
270 if ( rc != -1 ) 270 if ( rc != -1 )
271 handleMenuSelect( rc ); 271 handleMenuSelect( rc );
272 } 272 }
273 else if ( state == STATE_HELP ) 273 else if ( state == STATE_HELP )
274 { 274 {
275 help->handleKeys( event.key ); 275 help->handleKeys( event.key );
276 } 276 }
277 else if ( state == STATE_CRASHED ) 277 else if ( state == STATE_CRASHED )
278 { 278 {
279 if ( event.type == SDL_KEYDOWN ) 279 if ( event.type == SDL_KEYDOWN )
280 { 280 {
281 if ( event.key.keysym.sym == SDLK_UP || 281 if ( event.key.keysym.sym == SDLK_UP ||
282 event.key.keysym.sym == SDLK_DOWN || 282 event.key.keysym.sym == SDLK_DOWN ||
283 event.key.keysym.sym == SDLK_SPACE ) 283 event.key.keysym.sym == SDLK_SPACE )
284 changeState( STATE_NEWGAME ); 284 changeState( STATE_NEWGAME );
285 else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == 0 ) 285 else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == 0 )
286 { 286 {
287 changeState( STATE_MENU ); 287 changeState( STATE_MENU );
288 menu->resetToTopMenu(); 288 menu->resetToTopMenu();
289 } 289 }
290 else if ( event.key.keysym.sym == SDLK_r ) 290 else if ( event.key.keysym.sym == SDLK_r )
291 { 291 {
292 changeState( STATE_REPLAY ); 292 changeState( STATE_REPLAY );
293 } 293 }
294 else if ( event.key.keysym.sym == SDLK_s ) 294 else if ( event.key.keysym.sym == SDLK_s )
295 { 295 {
296 SoundHandler :: playSound( SND_EXPLOSION ); 296 SoundHandler :: playSound( SND_EXPLOSION );
297 } 297 }
298 } 298 }
299 } 299 }
300 else 300 else
301 { 301 {
302 switch ( event.key.keysym.sym ) 302 switch ( event.key.keysym.sym )
303 { 303 {
304 case SDLK_f: 304 case SDLK_f:
305 if ( event.type == SDL_KEYDOWN ) 305 if ( event.type == SDL_KEYDOWN )
306 showFps = !showFps; 306 showFps = !showFps;
307 break; 307 break;
308 case SDLK_l: 308 case SDLK_l:
309 if ( event.type == SDL_KEYDOWN ) 309 if ( event.type == SDL_KEYDOWN )
310 limitFPS = !limitFPS; 310 limitFPS = !limitFPS;
311 break; 311 break;
312 312
313 default: 313 default:
314 currentGame->handleKeys( event.key ); 314 currentGame->handleKeys( event.key );
315 break; 315 break;
316 } 316 }
317 } 317 }
318 318
319 break; 319 break;
320 } 320 }
321 321
322 case SDL_QUIT: 322 case SDL_QUIT:
323 finish = true; 323 finish = true;
324 break; 324 break;
325 default: 325 default:
326 break; 326 break;
327 } 327 }
328 } 328 }
329} 329}
330 330
331void SFCave :: changeState( int s ) 331void SFCave :: changeState( int s )
332{ 332{
333 if ( state != s ) 333 if ( state != s )
334 currentGame->stateChanged( state, s ); 334 currentGame->stateChanged( state, s );
335 335
336 if ( state == STATE_MENU && s == STATE_HELP ) 336 if ( state == STATE_MENU && s == STATE_HELP )
337 help->init(); 337 help->init();
338 if ( state == STATE_CRASHED && s == STATE_MENU ) 338 if ( state == STATE_CRASHED && s == STATE_MENU )
339 { 339 {
340 SoundHandler :: stopMusic( true ); 340 SoundHandler :: stopMusic( true );
341 341
342 string musicFile = chooseRandomFile( musicPath, musicType ); 342 string musicFile = chooseRandomFile( musicPath, musicType );
343 SoundHandler :: setMusicVolume( 128 ); 343 SoundHandler :: setMusicVolume( 128 );
344 SoundHandler :: playMusic( musicFile ); 344 SoundHandler :: playMusic( musicFile );
345 } 345 }
346 else if ( state == STATE_MENU && (s == STATE_NEWGAME || s == STATE_REPLAY) ) 346 else if ( state == STATE_MENU && (s == STATE_NEWGAME || s == STATE_REPLAY) )
347 { 347 {
348 SoundHandler :: stopMusic( ); 348 SoundHandler :: stopMusic( );
349 349
350 // Start the in game music 350 // Start the in game music
351 string musicFile = INGAME_MUSIC; 351 string musicFile = INGAME_MUSIC;
352 SoundHandler :: playMusic( musicFile ); 352 SoundHandler :: playMusic( musicFile );
353 SoundHandler :: setMusicVolume( 25 ); 353 SoundHandler :: setMusicVolume( 25 );
354 } 354 }
355 355
356 state = s; 356 state = s;
357} 357}
358 358
359 359
360void SFCave :: handleMenuSelect( int menuId ) 360void SFCave :: handleMenuSelect( int menuId )
361{ 361{
362 switch( menuId ) 362 switch( menuId )
363 { 363 {
364 case MENU_STARTGAME: 364 case MENU_STARTGAME:
365 changeState( STATE_NEWGAME ); 365 changeState( STATE_NEWGAME );
366 break; 366 break;
367 367
368 case MENU_HELP: 368 case MENU_HELP:
369 changeState( STATE_HELP ); 369 changeState( STATE_HELP );
370 break; 370 break;
371 371
372 case MENU_QUIT: 372 case MENU_QUIT:
373 changeState( STATE_QUIT ); 373 changeState( STATE_QUIT );
374 break; 374 break;
375 375
376 case MENU_PLAY_REPLAY: 376 case MENU_PLAY_REPLAY:
377 if ( currentGame->isReplayAvailable() ) 377 if ( currentGame->isReplayAvailable() )
378 changeState( STATE_REPLAY ); 378 changeState( STATE_REPLAY );
379 else 379 else
380 setMenuStatusText( "No replay available yet" ); 380 setMenuStatusText( "No replay available yet" );
381 break; 381 break;
382 382
383 case MENU_LOAD_REPLAY: 383 case MENU_LOAD_REPLAY:
384 { 384 {
385 string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; 385 string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay";
386 386
387 currentGame->loadReplay( replayFile ); 387 currentGame->loadReplay( replayFile );
388 388
389 break; 389 break;
390 } 390 }
391 391
392 case MENU_SAVE_REPLAY: 392 case MENU_SAVE_REPLAY:
393 { 393 {
394 394
395 if ( currentGame->isReplayAvailable() ) 395 if ( currentGame->isReplayAvailable() )
396 { 396 {
397 string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; 397 string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay";
398 398
399 currentGame->saveReplay( replayFile ); 399 currentGame->saveReplay( replayFile );
400 } 400 }
401 else 401 else
402 setMenuStatusText( "No replay available yet" ); 402 setMenuStatusText( "No replay available yet" );
403 403
404 break; 404 break;
405 } 405 }
406 case MENU_CLEAR_SCORES: 406 case MENU_CLEAR_SCORES:
407 break; 407 break;
408 408
409 case MENU_GAME_SFCAVE: 409 case MENU_GAME_SFCAVE:
410 if ( currentGame->getGameName() != "SFCave" ) 410 if ( currentGame->getGameName() != "SFCave" )
411 { 411 {
412 int diff = currentGame->getDifficulty(); 412 int diff = currentGame->getDifficulty();
413 delete currentGame; 413 delete currentGame;
414 currentGame = new SFCaveGame( this, WIDTH, HEIGHT, 0 ); 414 currentGame = new SFCaveGame( this, WIDTH, HEIGHT, 0 );
415 currentGame->setDifficulty( diff ); 415 currentGame->setDifficulty( diff );
416 416
417 saveSetting( "GameType", "SFCave" ); 417 saveSetting( "GameType", "SFCave" );
418 } 418 }
419 break; 419 break;
420 420
421 case MENU_GAME_GATES: 421 case MENU_GAME_GATES:
422 if ( currentGame->getGameName() != "Gates" ) 422 if ( currentGame->getGameName() != "Gates" )
423 { 423 {
424 int diff = currentGame->getDifficulty(); 424 int diff = currentGame->getDifficulty();
425 delete currentGame; 425 delete currentGame;
426 currentGame = new GatesGame( this, WIDTH, HEIGHT, 0 ); 426 currentGame = new GatesGame( this, WIDTH, HEIGHT, 0 );
427 currentGame->setDifficulty( diff ); 427 currentGame->setDifficulty( diff );
428 428
429 saveSetting( "GameType", "Gates" ); 429 saveSetting( "GameType", "Gates" );
430 } 430 }
431 break; 431 break;
432 break; 432 break;
433 433
434 case MENU_GAME_FLY: 434 case MENU_GAME_FLY:
435 if ( currentGame->getGameName() != "Fly" ) 435 if ( currentGame->getGameName() != "Fly" )
436 { 436 {
437 int diff = currentGame->getDifficulty(); 437 int diff = currentGame->getDifficulty();
438 delete currentGame; 438 delete currentGame;
439 currentGame = new FlyGame( this, WIDTH, HEIGHT, 0 ); 439 currentGame = new FlyGame( this, WIDTH, HEIGHT, 0 );
440 currentGame->setDifficulty( diff ); 440 currentGame->setDifficulty( diff );
441 441
442 saveSetting( "GameType", "Fly" ); 442 saveSetting( "GameType", "Fly" );
443 } 443 }
444 break; 444 break;
445 445
446 case MENU_DIFFICULTY_EASY: 446 case MENU_DIFFICULTY_EASY:
447 currentGame->setDifficulty( MENU_DIFFICULTY_EASY ); 447 currentGame->setDifficulty( MENU_DIFFICULTY_EASY );
448 saveSetting( "GameDifficulty", "Easy" ); 448 saveSetting( "GameDifficulty", "Easy" );
449 break; 449 break;
450 450
451 case MENU_DIFFICULTY_NORMAL: 451 case MENU_DIFFICULTY_NORMAL:
452 currentGame->setDifficulty( MENU_DIFFICULTY_NORMAL ); 452 currentGame->setDifficulty( MENU_DIFFICULTY_NORMAL );
453 saveSetting( "GameDifficulty", "Medium" ); 453 saveSetting( "GameDifficulty", "Medium" );
454 break; 454 break;
455 455
456 case MENU_DIFFICULTY_HARD: 456 case MENU_DIFFICULTY_HARD:
457 currentGame->setDifficulty( MENU_DIFFICULTY_HARD ); 457 currentGame->setDifficulty( MENU_DIFFICULTY_HARD );
458 saveSetting( "GameDifficulty", "Hard" ); 458 saveSetting( "GameDifficulty", "Hard" );
459 break; 459 break;
460 460
461 case MENU_DIFFICULTY_CUSTOM: 461 case MENU_DIFFICULTY_CUSTOM:
462 currentGame->setDifficulty( MENU_DIFFICULTY_CUSTOM ); 462 currentGame->setDifficulty( MENU_DIFFICULTY_CUSTOM );
463 saveSetting( "GameDifficulty", "Custom" ); 463 saveSetting( "GameDifficulty", "Custom" );
464 break; 464 break;
465 465
466 case MENU_SOUND_ON: 466 case MENU_SOUND_ON:
467 SoundHandler :: setSoundsOn( true ); 467 SoundHandler :: setSoundsOn( true );
468 saveSetting( "SoundOn", "true" ); 468 saveSetting( "SoundOn", "true" );
469 break; 469 break;
470 470
471 case MENU_SOUND_OFF: 471 case MENU_SOUND_OFF:
472 SoundHandler :: setSoundsOn( false ); 472 SoundHandler :: setSoundsOn( false );
473 saveSetting( "SoundOn", "false" ); 473 saveSetting( "SoundOn", "false" );
474 break; 474 break;
475 475
476 case MENU_MUSIC_ON: 476 case MENU_MUSIC_ON:
477 SoundHandler :: setMusicOn( true ); 477 SoundHandler :: setMusicOn( true );
478 saveSetting( "MusicOn", "true" ); 478 saveSetting( "MusicOn", "true" );
479 break; 479 break;
480 480
481 case MENU_MUSIC_OFF: 481 case MENU_MUSIC_OFF:
482 SoundHandler :: setMusicOn( false ); 482 SoundHandler :: setMusicOn( false );
483 saveSetting( "MusicOn", "false" ); 483 saveSetting( "MusicOn", "false" );
484 break; 484 break;
485 485
486 case MENU_CUSTOM_THRUST: 486 case MENU_CUSTOM_THRUST:
487 customPlayerMenuVal = PLAYER_THRUST; 487 customPlayerMenuVal = PLAYER_THRUST;
488 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); 488 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal );
489 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); 489 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) );
490 break; 490 break;
491 case MENU_CUSTOM_GRAVITY: 491 case MENU_CUSTOM_GRAVITY:
492 customPlayerMenuVal = PLAYER_GRAVITY; 492 customPlayerMenuVal = PLAYER_GRAVITY;
493 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); 493 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal );
494 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); 494 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) );
495 break; 495 break;
496 case MENU_CUSTOM_MAXSPEEDUP: 496 case MENU_CUSTOM_MAXSPEEDUP:
497 customPlayerMenuVal = PLAYER_MAX_SPEED_UP; 497 customPlayerMenuVal = PLAYER_MAX_SPEED_UP;
498 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); 498 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal );
499 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); 499 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) );
500 break; 500 break;
501 case MENU_CUSTOM_MAXSPEEDDOWN: 501 case MENU_CUSTOM_MAXSPEEDDOWN:
502 customPlayerMenuVal = PLAYER_MAX_SPEED_DOWN; 502 customPlayerMenuVal = PLAYER_MAX_SPEED_DOWN;
503 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); 503 origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal );
504 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); 504 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) );
505 break; 505 break;
506 case MENU_CUSTOM_INCREASE: 506 case MENU_CUSTOM_INCREASE:
507 currentGame->getPlayer()->incValue( customPlayerMenuVal ); 507 currentGame->getPlayer()->incValue( customPlayerMenuVal );
508 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); 508 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) );
509 break; 509 break;
510 case MENU_CUSTOM_DECREASE: 510 case MENU_CUSTOM_DECREASE:
511 currentGame->getPlayer()->decValue( customPlayerMenuVal ); 511 currentGame->getPlayer()->decValue( customPlayerMenuVal );
512 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); 512 setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) );
513 break; 513 break;
514 case MENU_CUSTOM_SAVE: 514 case MENU_CUSTOM_SAVE:
515 { 515 {
516 // save settings 516 // save settings
517 string key = currentGame->getGameName() + "_custom_player_" + currentGame->getPlayer()->getValueTypeString( customPlayerMenuVal ); 517 string key = currentGame->getGameName() + "_custom_player_" + currentGame->getPlayer()->getValueTypeString( customPlayerMenuVal );
518 saveSetting( key, currentGame->getPlayer()->getValue( customPlayerMenuVal ) ); 518 saveSetting( key, currentGame->getPlayer()->getValue( customPlayerMenuVal ) );
519 519
520 break; 520 break;
521 } 521 }
522 case MENU_CUSTOM_CANCEL: 522 case MENU_CUSTOM_CANCEL:
523 currentGame->getPlayer()->setValue( customPlayerMenuVal, origValue ); 523 currentGame->getPlayer()->setValue( customPlayerMenuVal, origValue );
524 break; 524 break;
525 525
526 default: 526 default:
527 break; 527 break;
528 } 528 }
529} 529}
530 530
531void SFCave :: setMenuStatusText( string statusText ) 531void SFCave :: setMenuStatusText( string statusText )
532{ 532{
533 menu->setStatusText( statusText ); 533 menu->setStatusText( statusText );
534} 534}
535 535
536 536
537void SFCave :: saveSetting( string key, string val ) 537void SFCave :: saveSetting( string key, string val )
538{ 538{
539 Settings cfg( "sfcave-sdl" ); 539 Settings cfg( "sfcave-sdl" );
540 cfg.writeSetting( key, val ); 540 cfg.writeSetting( key, val );
541} 541}
542 542
543void SFCave :: saveSetting( string key, int val ) 543void SFCave :: saveSetting( string key, int val )
544{ 544{
545 Settings cfg( "sfcave-sdl" ); 545 Settings cfg( "sfcave-sdl" );
546 cfg.writeSetting( key, val ); 546 cfg.writeSetting( key, val );
547} 547}
548 548
549void SFCave :: saveSetting( string key, long val ) 549void SFCave :: saveSetting( string key, long val )
550{ 550{
551 Settings cfg( "sfcave-sdl" ); 551 Settings cfg( "sfcave-sdl" );
552 cfg.writeSetting( key, val ); 552 cfg.writeSetting( key, val );
553} 553}
554 554
555void SFCave :: saveSetting( string key, double val ) 555void SFCave :: saveSetting( string key, double val )
556{ 556{
557 Settings cfg( "sfcave-sdl" ); 557 Settings cfg( "sfcave-sdl" );
558 cfg.writeSetting( key, val ); 558 cfg.writeSetting( key, val );
559} 559}
560 560
561string SFCave :: loadSetting( string key, string defaultVal ) 561string SFCave :: loadSetting( string key, string defaultVal )
562{ 562{
563 string val; 563 string val;
564 Settings cfg( "sfcave-sdl" ); 564 Settings cfg( "sfcave-sdl" );
565 cfg.readSetting( key, val ); 565 cfg.readSetting( key, val );
566 566
567 if ( val == "" ) 567 if ( val == "" )
568 val = defaultVal; 568 val = defaultVal;
569 569
570 return val; 570 return val;
571} 571}
572 572
573bool SFCave :: loadBoolSetting( string key, bool defaultVal ) 573bool SFCave :: loadBoolSetting( string key, bool defaultVal )
574{ 574{
575 bool val = defaultVal; 575 bool val = defaultVal;
576 Settings cfg( "sfcave-sdl" ); 576 Settings cfg( "sfcave-sdl" );
577 cfg.readSetting( key, val ); 577 cfg.readSetting( key, val );
578 578
579 return val; 579 return val;
580} 580}
581 581
582int SFCave :: loadIntSetting( string key, int defaultVal ) 582int SFCave :: loadIntSetting( string key, int defaultVal )
583{ 583{
584 int val = defaultVal; 584 int val = defaultVal;
585 Settings cfg( "sfcave-sdl" ); 585 Settings cfg( "sfcave-sdl" );
586 cfg.readSetting( key, val ); 586 cfg.readSetting( key, val );
587 587
588 return val; 588 return val;
589} 589}
590 590
591double SFCave :: loadDoubleSetting( string key, double defaultVal ) 591double SFCave :: loadDoubleSetting( string key, double defaultVal )
592{ 592{
593 double val = defaultVal; 593 double val = defaultVal;
594 Settings cfg( "sfcave-sdl" ); 594 Settings cfg( "sfcave-sdl" );
595 cfg.readSetting( key, val ); 595 cfg.readSetting( key, val );
596 596
597 return val; 597 return val;
598} 598}
599 599
600 600
601void SFCave :: calcFPS() 601void SFCave :: calcFPS()
602{ 602{
603 struct timeb tp; 603 struct timeb tp;
604 ftime( &tp ); 604 ftime( &tp );
605 start =(tp.time%10000)*10000 + tp.millitm; 605 start =(tp.time%10000)*10000 + tp.millitm;
606 if ( start - time1 >= 1000 ) 606 if ( start - time1 >= 1000 )
607 { 607 {
608 actualFPS = FPS; 608 actualFPS = FPS;
609 FPS = 0; 609 FPS = 0;
610 time1 = start; 610 time1 = start;
611 } 611 }
612 else 612 else
613 FPS ++; 613 FPS ++;
614} 614}
615 615
616void SFCave :: FPSDelay() 616void SFCave :: FPSDelay()
617{ 617{
618 struct timeb tp; 618 struct timeb tp;
619 // Slow down polling - limit to x FPS 619 // Slow down polling - limit to x FPS
620 ftime( &tp ); 620 ftime( &tp );
621 end = abs((tp.time%10000)*10000 + tp.millitm); 621 end = abs((tp.time%10000)*10000 + tp.millitm);
622 if ( end-start < (1000/maxFPS) ) 622 if ( end-start < (1000/maxFPS) )
623 { 623 {
624 if ( (1000/maxFPS)-(end-start) > 500 ) 624 if ( (1000/maxFPS)-(end-start) > 500 )
625 { 625 {
626 // Should never happen but in case it does sleep for 5 seconds 626 // Should never happen but in case it does sleep for 5 seconds
627 printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); 627 printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end );
628 SDL_Delay( 5 ); 628 SDL_Delay( 5 );
629 } 629 }
630 else 630 else
631 SDL_Delay((1000/maxFPS)-(end-start) ); 631 SDL_Delay((1000/maxFPS)-(end-start) );
632 } 632 }
633} 633}
diff --git a/noncore/games/sfcave-sdl/sfcave.h b/noncore/games/sfcave-sdl/sfcave.h
index c707919..4e45ec2 100644
--- a/noncore/games/sfcave-sdl/sfcave.h
+++ b/noncore/games/sfcave-sdl/sfcave.h
@@ -1,72 +1,72 @@
1#ifndef __SFCAVE_H 1#ifndef __SFCAVE_H
2#define __SFCAVE_H 2#define __SFCAVE_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5 5
6#include "terrain.h" 6#include "terrain.h"
7 7
8class Game; 8class Game;
9class Menu; 9class Menu;
10class Help; 10class Help;
11 11
12class SFCave 12class SFCave
13{ 13{
14public: 14public:
15 SFCave( int argc, char *argv[] ); 15 SFCave( int argc, char *argv[] );
16 ~SFCave(); 16 ~SFCave();
17 17
18 void initSDL( int argc, char *argv[] ); 18 void initSDL( int argc, char *argv[] );
19 void mainEventLoop(); 19 void mainEventLoop();
20 20
21 void setCrashed( bool val ); 21 void setCrashed( bool val );
22 void changeState( int s ); 22 void changeState( int s );
23 int getState() { return state; } 23 int getState() { return state; }
24 Game *getCurrentGame() { return currentGame; } 24 Game *getCurrentGame() { return currentGame; }
25 int getFPS() { return actualFPS; } 25 int getFPS() { return actualFPS; }
26 bool showFPS() { return showFps; } 26 bool showFPS() { return showFps; }
27 27
28 void setMenuStatusText( string statusText ); 28 void setMenuStatusText( string statusText );
29 29
30 void saveSetting( string key, string val ); 30 void saveSetting( string key, string val );
31 void saveSetting( string key, int val ); 31 void saveSetting( string key, int val );
32 void saveSetting( string key, long val ); 32 void saveSetting( string key, long val );
33 void saveSetting( string key, double val ); 33 void saveSetting( string key, double val );
34 string loadSetting( string key, string defaultVal = "" ); 34 string loadSetting( string key, string defaultVal = "" );
35 bool loadBoolSetting( string key, bool defaultVal); 35 bool loadBoolSetting( string key, bool defaultVal);
36 int loadIntSetting( string key, int defaultVal ); 36 int loadIntSetting( string key, int defaultVal );
37 double loadDoubleSetting( string key, double defaultVal ); 37 double loadDoubleSetting( string key, double defaultVal );
38 38
39private: 39private:
40 SDL_Surface *screen; 40 SDL_Surface *screen;
41 bool setupOK; 41 bool setupOK;
42 42
43 Game *currentGame; 43 Game *currentGame;
44 Menu *menu; 44 Menu *menu;
45 Help *help; 45 Help *help;
46 int state; 46 int state;
47 bool showFps; 47 bool showFps;
48 string musicPath; 48 string musicPath;
49 string musicType; 49 string musicType;
50 bool finish; 50 bool finish;
51 51
52 bool limitFPS; 52 bool limitFPS;
53 int maxFPS; 53 int maxFPS;
54 int actualFPS; 54 int actualFPS;
55 int FPS; 55 int FPS;
56 long time1; 56 long time1;
57 long start; 57 long start;
58 long end; 58 long end;
59 59
60 // This is used when the user is setting the custom 60 // This is used when the user is setting the custom
61 // values in the menu 61 // values in the menu
62 int customPlayerMenuVal; 62 int customPlayerMenuVal;
63 double origValue; 63 double origValue;
64 64
65 void handleMenuSelect( int menuId ); 65 void handleMenuSelect( int menuId );
66 void handleGameState(); 66 void handleGameState();
67 void handleEvents(); 67 void handleEvents();
68 void calcFPS(); 68 void calcFPS();
69 void FPSDelay(); 69 void FPSDelay();
70}; 70};
71 71
72#endif 72#endif
diff --git a/noncore/games/sfcave-sdl/sfcave_game.cpp b/noncore/games/sfcave-sdl/sfcave_game.cpp
index 8fdbbe5..ccdd625 100644
--- a/noncore/games/sfcave-sdl/sfcave_game.cpp
+++ b/noncore/games/sfcave-sdl/sfcave_game.cpp
@@ -1,179 +1,179 @@
1#include "SDL_gfxPrimitives.h" 1#include <SDL/SDL_gfxPrimitives.h>
2 2
3#include "constants.h" 3#include "constants.h"
4#include "sfcave_game.h" 4#include "sfcave_game.h"
5#include "random.h" 5#include "random.h"
6 6
7SFCaveGame :: SFCaveGame( SFCave *p, int w, int h, int diff ) 7SFCaveGame :: SFCaveGame( SFCave *p, int w, int h, int diff )
8 : Game( p, w, h, diff ) 8 : Game( p, w, h, diff )
9{ 9{
10 gameName = "SFCave"; 10 gameName = "SFCave";
11 difficulty = MENU_DIFFICULTY_EASY; 11 difficulty = MENU_DIFFICULTY_EASY;
12 blockUpdateRate = 200; 12 blockUpdateRate = 200;
13 13
14 terrain = new Terrain( w, h ); 14 terrain = new Terrain( w, h );
15 player = new Player( w, h ); 15 player = new Player( w, h );
16 highScore = 0; 16 highScore = 0;
17} 17}
18 18
19SFCaveGame :: ~SFCaveGame() 19SFCaveGame :: ~SFCaveGame()
20{ 20{
21} 21}
22 22
23void SFCaveGame :: init() 23void SFCaveGame :: init()
24{ 24{
25 blockDistance = 50; 25 blockDistance = 50;
26 blockHeight = 80; 26 blockHeight = 80;
27 blockWidth = 20; 27 blockWidth = 20;
28 28
29 switch( difficulty ) 29 switch( difficulty )
30 { 30 {
31 case MENU_DIFFICULTY_EASY: 31 case MENU_DIFFICULTY_EASY:
32 blockDistance = 50; 32 blockDistance = 50;
33 break; 33 break;
34 case MENU_DIFFICULTY_NORMAL: 34 case MENU_DIFFICULTY_NORMAL:
35 blockDistance = 40; 35 blockDistance = 40;
36 break; 36 break;
37 case MENU_DIFFICULTY_HARD: 37 case MENU_DIFFICULTY_HARD:
38 blockDistance = 30; 38 blockDistance = 30;
39 break; 39 break;
40 case MENU_DIFFICULTY_CUSTOM: 40 case MENU_DIFFICULTY_CUSTOM:
41 { 41 {
42 // Read custom difficulty settings for this game 42 // Read custom difficulty settings for this game
43 blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 ); 43 blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 );
44 44
45 double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 ); 45 double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 );
46 double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 ); 46 double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 );
47 double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 ); 47 double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 );
48 double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 ); 48 double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 );
49 player->setMovementInfo( thrust, gravity, maxUp, maxDown ); 49 player->setMovementInfo( thrust, gravity, maxUp, maxDown );
50 50
51 break; 51 break;
52 } 52 }
53 } 53 }
54 54
55 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 55 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
56 blocks[i].y( -1 ); 56 blocks[i].y( -1 );
57 57
58 Game :: init(); 58 Game :: init();
59} 59}
60 60
61void SFCaveGame :: update( int state ) 61void SFCaveGame :: update( int state )
62{ 62{
63 Game::update( state ); 63 Game::update( state );
64 64
65 if ( state == STATE_PLAYING ) 65 if ( state == STATE_PLAYING )
66 { 66 {
67 if ( nrFrames % 3 == 0 ) 67 if ( nrFrames % 3 == 0 )
68 score ++; 68 score ++;
69 69
70 if ( nrFrames % 200 == 0 ) 70 if ( nrFrames % 200 == 0 )
71 { 71 {
72 if ( terrain->getMaxHeight() < sHeight - 100 ) 72 if ( terrain->getMaxHeight() < sHeight - 100 )
73 { 73 {
74 terrain->increaseMaxHeight( 10 ); 74 terrain->increaseMaxHeight( 10 );
75 75
76 // Reduce block height 76 // Reduce block height
77 if ( terrain->getMaxHeight() > sHeight - 150 ) 77 if ( terrain->getMaxHeight() > sHeight - 150 )
78 blockHeight -= 5; 78 blockHeight -= 5;
79 } 79 }
80 } 80 }
81 81
82 if ( checkCollisions() ) 82 if ( checkCollisions() )
83 { 83 {
84 parent->changeState( STATE_CRASHING ); 84 parent->changeState( STATE_CRASHING );
85 return; 85 return;
86 } 86 }
87 87
88 if ( nrFrames % blockDistance == 0 ) 88 if ( nrFrames % blockDistance == 0 )
89 addBlock(); 89 addBlock();
90 90
91 // Game logic goes here 91 // Game logic goes here
92 terrain->moveTerrain( 5 ); 92 terrain->moveTerrain( 5 );
93 moveBlocks( 5 ); 93 moveBlocks( 5 );
94 player->move( press ); 94 player->move( press );
95 } 95 }
96} 96}
97 97
98void SFCaveGame :: draw( SDL_Surface *screen ) 98void SFCaveGame :: draw( SDL_Surface *screen )
99{ 99{
100 Game::preDraw( screen ); 100 Game::preDraw( screen );
101 101
102 if ( parent->getState() == STATE_PLAYING ) 102 if ( parent->getState() == STATE_PLAYING )
103 { 103 {
104 // Screen drawing goes here 104 // Screen drawing goes here
105 terrain->drawTerrain( screen ); 105 terrain->drawTerrain( screen );
106 106
107 player->draw( screen ); 107 player->draw( screen );
108 108
109 drawBlocks( screen ); 109 drawBlocks( screen );
110 } 110 }
111 else 111 else
112 { 112 {
113 // Screen drawing goes here 113 // Screen drawing goes here
114 terrain->drawTerrain( screen ); 114 terrain->drawTerrain( screen );
115 115
116 drawBlocks( screen ); 116 drawBlocks( screen );
117 117
118 player->draw( screen ); 118 player->draw( screen );
119 } 119 }
120 120
121 Game::draw( screen ); 121 Game::draw( screen );
122} 122}
123 123
124void SFCaveGame :: addBlock() 124void SFCaveGame :: addBlock()
125{ 125{
126 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 126 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
127 { 127 {
128 if ( blocks[i].y() == -1 ) 128 if ( blocks[i].y() == -1 )
129 { 129 {
130 int x = sWidth; 130 int x = sWidth;
131 131
132 int y = terrain->getMapTop( MAPSIZE-1 ) + (int)(nextInt(terrain->getMapBottom( MAPSIZE-1 ) - terrain->getMapTop( MAPSIZE-1 ) - blockHeight)); 132 int y = terrain->getMapTop( MAPSIZE-1 ) + (int)(nextInt(terrain->getMapBottom( MAPSIZE-1 ) - terrain->getMapTop( MAPSIZE-1 ) - blockHeight));
133 133
134 blocks[i].setRect( x, y, blockWidth, blockHeight ); 134 blocks[i].setRect( x, y, blockWidth, blockHeight );
135 135
136 break; 136 break;
137 } 137 }
138 } 138 }
139} 139}
140 140
141void SFCaveGame :: moveBlocks( int amountToMove ) 141void SFCaveGame :: moveBlocks( int amountToMove )
142{ 142{
143 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 143 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
144 { 144 {
145 if ( blocks[i].y() != -1 ) 145 if ( blocks[i].y() != -1 )
146 { 146 {
147 blocks[i].moveBy( -amountToMove, 0 ); 147 blocks[i].moveBy( -amountToMove, 0 );
148 if ( blocks[i].x() + blocks[i].y() < 0 ) 148 if ( blocks[i].x() + blocks[i].y() < 0 )
149 blocks[i].y( -1 ); 149 blocks[i].y( -1 );
150 } 150 }
151 } 151 }
152} 152}
153 153
154void SFCaveGame :: drawBlocks( SDL_Surface *screen ) 154void SFCaveGame :: drawBlocks( SDL_Surface *screen )
155{ 155{
156 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 156 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
157 { 157 {
158 if ( blocks[i].y() != -1 ) 158 if ( blocks[i].y() != -1 )
159 { 159 {
160 SDL_Rect r = blocks[i].getRect(); 160 SDL_Rect r = blocks[i].getRect();
161 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) ); 161 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) );
162 } 162 }
163 } 163 }
164} 164}
165 165
166bool SFCaveGame :: checkCollisions() 166bool SFCaveGame :: checkCollisions()
167{ 167{
168 // Check collisions with blocks 168 // Check collisions with blocks
169 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 169 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
170 { 170 {
171 if ( blocks[i].y() != -1 ) 171 if ( blocks[i].y() != -1 )
172 { 172 {
173 if ( blocks[i].intersects( player->getPos() ) ) 173 if ( blocks[i].intersects( player->getPos() ) )
174 return true; 174 return true;
175 } 175 }
176 } 176 }
177 // Check collision with landscape 177 // Check collision with landscape
178 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() ); 178 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
179} 179}
diff --git a/noncore/games/sfcave-sdl/sfcave_game.h b/noncore/games/sfcave-sdl/sfcave_game.h
index 92a0f5d..6dddf5e 100644
--- a/noncore/games/sfcave-sdl/sfcave_game.h
+++ b/noncore/games/sfcave-sdl/sfcave_game.h
@@ -1,39 +1,39 @@
1#ifndef __SFCAVE_GAME_H 1#ifndef __SFCAVE_GAME_H
2#define __SFCAVE_GAME_H 2#define __SFCAVE_GAME_H
3 3
4#include "SDL.h" 4#include <SDL/SDL.h>
5 5
6#include "rect.h" 6#include "rect.h"
7 7
8#include "sfcave.h" 8#include "sfcave.h"
9#include "terrain.h" 9#include "terrain.h"
10#include "player.h" 10#include "player.h"
11#include "game.h" 11#include "game.h"
12 12
13class SFCaveGame : public Game 13class SFCaveGame : public Game
14{ 14{
15public: 15public:
16 SFCaveGame( SFCave *p, int w, int h, int diff ); 16 SFCaveGame( SFCave *p, int w, int h, int diff );
17 ~SFCaveGame(); 17 ~SFCaveGame();
18 18
19 void init(); 19 void init();
20 void update( int state ); 20 void update( int state );
21 void draw( SDL_Surface *screen ); 21 void draw( SDL_Surface *screen );
22 22
23private: 23private:
24 24
25 int blockDistance; 25 int blockDistance;
26 int blockHeight; 26 int blockHeight;
27 int blockWidth; 27 int blockWidth;
28 int blockUpdateRate; 28 int blockUpdateRate;
29 29
30 Rect blocks[BLOCKSIZE]; 30 Rect blocks[BLOCKSIZE];
31 31
32 void addBlock(); 32 void addBlock();
33 void moveBlocks( int amountToMove ); 33 void moveBlocks( int amountToMove );
34 void drawBlocks( SDL_Surface *screen ); 34 void drawBlocks( SDL_Surface *screen );
35 bool checkCollisions(); 35 bool checkCollisions();
36 36
37}; 37};
38 38
39#endif 39#endif
diff --git a/noncore/games/sfcave-sdl/sound.cpp b/noncore/games/sfcave-sdl/sound.cpp
index 855f2e6..0be1abf 100644
--- a/noncore/games/sfcave-sdl/sound.cpp
+++ b/noncore/games/sfcave-sdl/sound.cpp
@@ -1,157 +1,157 @@
1#include "constants.h" 1#include "constants.h"
2#include "sound.h" 2#include "sound.h"
3 3
4Mix_Chunk *SoundHandler :: sounds[NR_SOUNDS]; 4Mix_Chunk *SoundHandler :: sounds[NR_SOUNDS];
5Mix_Music *SoundHandler :: music; 5Mix_Music *SoundHandler :: music;
6int SoundHandler :: soundChannels[NR_SOUNDS]; 6int SoundHandler :: soundChannels[NR_SOUNDS];
7bool SoundHandler :: soundOn; 7bool SoundHandler :: soundOn;
8bool SoundHandler :: musicOn; 8bool SoundHandler :: musicOn;
9 9
10bool SoundHandler :: init( ) 10bool SoundHandler :: init( )
11{ 11{
12 // We're going to be requesting certain things from our audio 12 // We're going to be requesting certain things from our audio
13 // device, so we set them up beforehand 13 // device, so we set them up beforehand
14 int audio_rate = 22050; 14 int audio_rate = 22050;
15 Uint16 audio_format = AUDIO_S16; //AUDIO_S16; /* 16-bit stereo */ 15 Uint16 audio_format = AUDIO_S16; //AUDIO_S16; /* 16-bit stereo */
16 int audio_channels = 2; 16 int audio_channels = 2;
17 int audio_buffers = 1024;//4096; 17 int audio_buffers = 1024;//4096;
18 18
19 // This is where we open up our audio device. Mix_OpenAudio takes 19 // This is where we open up our audio device. Mix_OpenAudio takes
20 // as its parameters the audio format we'd /like/ to have. 20 // as its parameters the audio format we'd /like/ to have.
21 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) 21 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
22 { 22 {
23 printf("Unable to open audio!\n"); 23 printf("Unable to open audio!\n");
24 return false; 24 return false;
25 } 25 }
26 26
27 // We're going to pre-load the sound effects that we need right here 27 // We're going to pre-load the sound effects that we need right here
28 sounds[SND_EXPLOSION] = Mix_LoadWAV( SOUND_PATH "explosion.wav"); 28 sounds[SND_EXPLOSION] = Mix_LoadWAV( SOUND_PATH "explosion.wav");
29 sounds[SND_THRUST] = Mix_LoadWAV( SOUND_PATH "thrust.wav"); 29 sounds[SND_THRUST] = Mix_LoadWAV( SOUND_PATH "thrust.wav");
30 30
31 music = 0; 31 music = 0;
32 32
33 soundOn = true; 33 soundOn = true;
34 musicOn = true; 34 musicOn = true;
35 35
36 return true; 36 return true;
37} 37}
38 38
39void SoundHandler :: cleanUp() 39void SoundHandler :: cleanUp()
40{ 40{
41 // Free audio sounds 41 // Free audio sounds
42 if ( sounds[SND_EXPLOSION] ) 42 if ( sounds[SND_EXPLOSION] )
43 Mix_FreeChunk( sounds[SND_EXPLOSION] ); 43 Mix_FreeChunk( sounds[SND_EXPLOSION] );
44 if ( sounds[SND_THRUST] ) 44 if ( sounds[SND_THRUST] )
45 Mix_FreeChunk( sounds[SND_THRUST] ); 45 Mix_FreeChunk( sounds[SND_THRUST] );
46 46
47 if ( music ) 47 if ( music )
48 Mix_FreeMusic( music ); 48 Mix_FreeMusic( music );
49 49
50 Mix_CloseAudio(); 50 Mix_CloseAudio();
51} 51}
52 52
53int SoundHandler :: playSound( int soundNr, int channel, int nrLoops, int playBeforeFinished ) 53int SoundHandler :: playSound( int soundNr, int channel, int nrLoops, int playBeforeFinished )
54{ 54{
55 if ( !soundOn ) 55 if ( !soundOn )
56 return -1; 56 return -1;
57 57
58 if ( soundNr >= NR_SOUNDS || !sounds[soundNr] ) 58 if ( soundNr >= NR_SOUNDS || !sounds[soundNr] )
59 return -1; 59 return -1;
60 60
61 Mix_Chunk *chunk = sounds[soundNr]; 61 Mix_Chunk *chunk = sounds[soundNr];
62 if( channel == -1 || !Mix_Playing( channel ) ) 62 if( channel == -1 || !Mix_Playing( channel ) )
63 channel = Mix_PlayChannel(-1, sounds[soundNr], nrLoops); 63 channel = Mix_PlayChannel(-1, sounds[soundNr], nrLoops);
64 64
65 Mix_Volume( channel, MIX_MAX_VOLUME ); 65 Mix_Volume( channel, MIX_MAX_VOLUME );
66 return channel; 66 return channel;
67} 67}
68 68
69void SoundHandler :: stopSound( int channel, bool fadeOut, int nrMilliSecs ) 69void SoundHandler :: stopSound( int channel, bool fadeOut, int nrMilliSecs )
70{ 70{
71 if ( !soundOn ) 71 if ( !soundOn )
72 return; 72 return;
73 73
74 if ( !fadeOut ) 74 if ( !fadeOut )
75 Mix_HaltChannel( channel ); 75 Mix_HaltChannel( channel );
76 else 76 else
77 { 77 {
78 Mix_FadeOutChannel( channel, nrMilliSecs ); 78 Mix_FadeOutChannel( channel, nrMilliSecs );
79 } 79 }
80} 80}
81 81
82void SoundHandler :: playMusic( string musicFile ) 82void SoundHandler :: playMusic( string musicFile )
83{ 83{
84 if ( !soundOn ) 84 if ( !soundOn )
85 return; 85 return;
86 86
87 // If music already exists - stop it playing if necessary and free it up 87 // If music already exists - stop it playing if necessary and free it up
88 if ( music ) 88 if ( music )
89 { 89 {
90 stopMusic(); 90 stopMusic();
91 Mix_FreeMusic( music ); 91 Mix_FreeMusic( music );
92 } 92 }
93 93
94 // Load music 94 // Load music
95 music = Mix_LoadMUS( musicFile.c_str() ); 95 music = Mix_LoadMUS( musicFile.c_str() );
96 if(!music) 96 if(!music)
97 { 97 {
98 printf("Mix_LoadMUS(%s): %s\n", musicFile.c_str(), Mix_GetError()); 98 printf("Mix_LoadMUS(%s): %s\n", musicFile.c_str(), Mix_GetError());
99 // this might be a critical error... 99 // this might be a critical error...
100 } 100 }
101 101
102 playMusic(); 102 playMusic();
103} 103}
104 104
105void SoundHandler :: playMusic( bool fade ) 105void SoundHandler :: playMusic( bool fade )
106{ 106{
107 if ( !musicOn ) 107 if ( !musicOn )
108 return; 108 return;
109 109
110 if ( music ) 110 if ( music )
111 { 111 {
112 Mix_VolumeMusic( MIX_MAX_VOLUME ); 112 Mix_VolumeMusic( MIX_MAX_VOLUME );
113 Mix_RewindMusic(); 113 Mix_RewindMusic();
114 114
115 if ( fade ) 115 if ( fade )
116 Mix_FadeInMusic( music, -1, 1000 ); 116 Mix_FadeInMusic( music, -1, 1000 );
117 else 117 else
118 Mix_PlayMusic( music, -1 ); 118 Mix_PlayMusic( music, -1 );
119 119
120 } 120 }
121} 121}
122 122
123void SoundHandler :: stopMusic( bool fadeOut ) 123void SoundHandler :: stopMusic( bool fadeOut )
124{ 124{
125 if ( !music || !Mix_PlayingMusic() ) 125 if ( !music || !Mix_PlayingMusic() )
126 return; 126 return;
127 127
128 if ( fadeOut && Mix_FadingMusic() == MIX_NO_FADING ) 128 if ( fadeOut && Mix_FadingMusic() == MIX_NO_FADING )
129 { 129 {
130 Mix_FadeOutMusic( 1000 ); 130 Mix_FadeOutMusic( 1000 );
131 } 131 }
132 else 132 else
133 { 133 {
134 Mix_HaltMusic(); 134 Mix_HaltMusic();
135 } 135 }
136 136
137} 137}
138 138
139void SoundHandler :: setMusicVolume( int vol ) 139void SoundHandler :: setMusicVolume( int vol )
140{ 140{
141 Mix_VolumeMusic( vol ); 141 Mix_VolumeMusic( vol );
142} 142}
143 143
144void SoundHandler :: setSoundsOn( bool val ) 144void SoundHandler :: setSoundsOn( bool val )
145{ 145{
146 soundOn = val; 146 soundOn = val;
147} 147}
148 148
149void SoundHandler :: setMusicOn( bool val ) 149void SoundHandler :: setMusicOn( bool val )
150{ 150{
151 musicOn = val; 151 musicOn = val;
152 152
153 if ( !musicOn ) 153 if ( !musicOn )
154 stopMusic(); 154 stopMusic();
155 else 155 else
156 playMusic( true ); 156 playMusic( true );
157} 157}
diff --git a/noncore/games/sfcave-sdl/sound.h b/noncore/games/sfcave-sdl/sound.h
index d46b5bc..180429a 100644
--- a/noncore/games/sfcave-sdl/sound.h
+++ b/noncore/games/sfcave-sdl/sound.h
@@ -1,35 +1,35 @@
1#ifndef __SOUND_H 1#ifndef __SOUND_H
2#define __SOUND_H 2#define __SOUND_H
3 3
4#include <SDL.h> 4#include <SDL/SDL.h>
5#include "SDL_mixer.h" 5#include <SDL/SDL_mixer.h>
6 6
7#define NR_SOUNDS 3 7#define NR_SOUNDS 3
8 8
9class SoundHandler 9class SoundHandler
10{ 10{
11public: 11public:
12 static bool init(); 12 static bool init();
13 static void cleanUp(); 13 static void cleanUp();
14 14
15 static int playSound( int soundNr, int channel = -1, int nrLoops = 0, int playBeforeFinished = false ); 15 static int playSound( int soundNr, int channel = -1, int nrLoops = 0, int playBeforeFinished = false );
16 static void stopSound( int channel, bool fadeOut, int nrMilliSecs = 1000 ); 16 static void stopSound( int channel, bool fadeOut, int nrMilliSecs = 1000 );
17 static void setSoundsOn( bool val ); 17 static void setSoundsOn( bool val );
18 static void setMusicOn( bool val ); 18 static void setMusicOn( bool val );
19 static void playMusic( string musicFile ); 19 static void playMusic( string musicFile );
20 static void playMusic( bool fadeIn = false ); 20 static void playMusic( bool fadeIn = false );
21 static void stopMusic( bool fadeOut = false ); 21 static void stopMusic( bool fadeOut = false );
22 static void setMusicVolume( int vol ); 22 static void setMusicVolume( int vol );
23 23
24 24
25private: 25private:
26 static Mix_Music *music; 26 static Mix_Music *music;
27 static Mix_Chunk *sounds[NR_SOUNDS]; 27 static Mix_Chunk *sounds[NR_SOUNDS];
28 static int soundChannels[NR_SOUNDS]; 28 static int soundChannels[NR_SOUNDS];
29 static bool soundOn; 29 static bool soundOn;
30 static bool musicOn; 30 static bool musicOn;
31 31
32 SoundHandler() {} 32 SoundHandler() {}
33}; 33};
34 34
35#endif 35#endif
diff --git a/noncore/games/sfcave-sdl/starfield.cpp b/noncore/games/sfcave-sdl/starfield.cpp
index 82edfc1..3b26895 100644
--- a/noncore/games/sfcave-sdl/starfield.cpp
+++ b/noncore/games/sfcave-sdl/starfield.cpp
@@ -1,295 +1,295 @@
1#include "SDL.h" 1#include <SDL/SDL.h>
2#include "SDL_gfxPrimitives.h" 2#include <SDL/SDL_gfxPrimitives.h>
3 3
4#include <stdlib.h> 4#include <stdlib.h>
5 5
6#include "starfield.h" 6#include "starfield.h"
7#include "random.h" 7#include "random.h"
8#include "util.h" 8#include "util.h"
9 9
10#define VERTICAL_VELOCITY 0 10#define VERTICAL_VELOCITY 0
11 11
12StarField :: StarField( bool side, int nStars, int mx, int my, int minz, int maxz ) 12StarField :: StarField( bool side, int nStars, int mx, int my, int minz, int maxz )
13{ 13{
14 nrStars = nStars; 14 nrStars = nStars;
15 maxX = mx; 15 maxX = mx;
16 maxY = my; 16 maxY = my;
17 minZ = minz; 17 minZ = minz;
18 maxZ = maxz; 18 maxZ = maxz;
19 19
20 min_brightness = 50; 20 min_brightness = 50;
21 top_star_speed = 6; 21 top_star_speed = 6;
22 22
23 sideways = side; 23 sideways = side;
24 24
25 if ( !sideways ) 25 if ( !sideways )
26 { 26 {
27 x = new int[nrStars]; 27 x = new int[nrStars];
28 y = new int[nrStars]; 28 y = new int[nrStars];
29 z = new int[nrStars]; 29 z = new int[nrStars];
30 30
31 star_color = 0; 31 star_color = 0;
32 vel_x = 0; 32 vel_x = 0;
33 vel_y = 0; 33 vel_y = 0;
34 pos_x = 0; 34 pos_x = 0;
35 pos_y = 0; 35 pos_y = 0;
36 } 36 }
37 else 37 else
38 { 38 {
39 star_color = new int[nrStars]; 39 star_color = new int[nrStars];
40 vel_x = new int[nrStars]; 40 vel_x = new int[nrStars];
41 vel_y = new int[nrStars]; 41 vel_y = new int[nrStars];
42 pos_x = new int[nrStars]; 42 pos_x = new int[nrStars];
43 pos_y = new int[nrStars]; 43 pos_y = new int[nrStars];
44 44
45 x = 0; 45 x = 0;
46 y = 0; 46 y = 0;
47 z = 0; 47 z = 0;
48 } 48 }
49 49
50 init(); 50 init();
51} 51}
52 52
53StarField :: ~StarField() 53StarField :: ~StarField()
54{ 54{
55 if ( star_color ) 55 if ( star_color )
56 delete []star_color; 56 delete []star_color;
57 if ( vel_x ) 57 if ( vel_x )
58 delete []vel_x; 58 delete []vel_x;
59 if ( vel_y ) 59 if ( vel_y )
60 delete []vel_y; 60 delete []vel_y;
61 if ( pos_x ) 61 if ( pos_x )
62 delete []pos_x; 62 delete []pos_x;
63 if ( pos_y ) 63 if ( pos_y )
64 delete []pos_y; 64 delete []pos_y;
65 65
66 if ( x ) 66 if ( x )
67 delete []x; 67 delete []x;
68 if ( y ) 68 if ( y )
69 delete []y; 69 delete []y;
70 if ( z ) 70 if ( z )
71 delete []z; 71 delete []z;
72} 72}
73 73
74void StarField :: init() 74void StarField :: init()
75{ 75{
76 if ( !sideways ) 76 if ( !sideways )
77 { 77 {
78 for ( int i = 0 ; i < nrStars ; ++i ) 78 for ( int i = 0 ; i < nrStars ; ++i )
79 { 79 {
80 newStar( i ); 80 newStar( i );
81 z[i] = (int)(Random() * (double)(maxZ - minZ)) + minZ; 81 z[i] = (int)(Random() * (double)(maxZ - minZ)) + minZ;
82 } 82 }
83 } 83 }
84 else 84 else
85 { 85 {
86 int brightness; 86 int brightness;
87 87
88 //Initialise each star 88 //Initialise each star
89 for(int i = 0; i < nrStars ; i++) 89 for(int i = 0; i < nrStars ; i++)
90 { 90 {
91 //Inialise velocities 91 //Inialise velocities
92 vel_x[i] = -(int)floor( (Random() * top_star_speed)+1 ); 92 vel_x[i] = -(int)floor( (Random() * top_star_speed)+1 );
93 vel_y[i] = VERTICAL_VELOCITY; 93 vel_y[i] = VERTICAL_VELOCITY;
94 94
95 //Initialise positions randomly 95 //Initialise positions randomly
96 pos_x[i] = (int)floor((Random() * 240)); 96 pos_x[i] = (int)floor((Random() * 240));
97 pos_y[i] = (int)floor((Random() * 320)); 97 pos_y[i] = (int)floor((Random() * 320));
98 98
99 //The Faster it goes, the Dimmer it is 99 //The Faster it goes, the Dimmer it is
100 if (vel_x[i] != 0) 100 if (vel_x[i] != 0)
101 { 101 {
102 brightness = (int)(255 / fabs(vel_x[i]) ); 102 brightness = (int)(255 / fabs(vel_x[i]) );
103 if (brightness < min_brightness) 103 if (brightness < min_brightness)
104 brightness = min_brightness; 104 brightness = min_brightness;
105 } 105 }
106 else 106 else
107 brightness = 255; 107 brightness = 255;
108 108
109 star_color[i] = brightness; 109 star_color[i] = brightness;
110 } 110 }
111 } 111 }
112} 112}
113 113
114void StarField :: newStar( int starNr ) 114void StarField :: newStar( int starNr )
115{ 115{
116 if ( !sideways ) 116 if ( !sideways )
117 { 117 {
118 x[starNr] = (int)(Random() * (double)maxX) + 1; 118 x[starNr] = (int)(Random() * (double)maxX) + 1;
119 y[starNr] = (int)(Random() * (double)maxY) + 1; 119 y[starNr] = (int)(Random() * (double)maxY) + 1;
120 z[starNr] = maxZ; 120 z[starNr] = maxZ;
121 121
122 int i = (int)(Random() * 4.0); 122 int i = (int)(Random() * 4.0);
123 if(i < 2) 123 if(i < 2)
124 x[starNr] = -x[starNr]; 124 x[starNr] = -x[starNr];
125 if(i == 0 || i == 2) 125 if(i == 0 || i == 2)
126 y[starNr] = -y[starNr]; 126 y[starNr] = -y[starNr];
127 } 127 }
128} 128}
129 129
130void StarField :: move( ) 130void StarField :: move( )
131{ 131{
132 if ( !sideways ) 132 if ( !sideways )
133 { 133 {
134 int amountToMove = 16; 134 int amountToMove = 16;
135 for(int i = 0; i < nrStars; i++) 135 for(int i = 0; i < nrStars; i++)
136 { 136 {
137 // Rotate star 137 // Rotate star
138 z[i] = z[i] - amountToMove; 138 z[i] = z[i] - amountToMove;
139 if(z[i] < minZ) 139 if(z[i] < minZ)
140 newStar(i); 140 newStar(i);
141 } 141 }
142 } 142 }
143 else 143 else
144 { 144 {
145 for(int i = 0; i < nrStars ; i++) 145 for(int i = 0; i < nrStars ; i++)
146 { 146 {
147 //Check speed limits x 147 //Check speed limits x
148 if (vel_x[i] > top_star_speed) 148 if (vel_x[i] > top_star_speed)
149 vel_x[i] = top_star_speed; 149 vel_x[i] = top_star_speed;
150 else if (vel_x[i] < -top_star_speed) 150 else if (vel_x[i] < -top_star_speed)
151 vel_x[i] = -top_star_speed; 151 vel_x[i] = -top_star_speed;
152 152
153 //Check speed limits y 153 //Check speed limits y
154 if (vel_y[i] > top_star_speed) 154 if (vel_y[i] > top_star_speed)
155 vel_y[i] = top_star_speed; 155 vel_y[i] = top_star_speed;
156 else if (vel_y[i] < -top_star_speed) 156 else if (vel_y[i] < -top_star_speed)
157 vel_y[i] = -top_star_speed; 157 vel_y[i] = -top_star_speed;
158 158
159 159
160 160
161 //Move Star 161 //Move Star
162 pos_x[i] += vel_x[i]; 162 pos_x[i] += vel_x[i];
163 pos_y[i] += vel_y[i]; 163 pos_y[i] += vel_y[i];
164 164
165 if (pos_x[i] < 0) 165 if (pos_x[i] < 0)
166 pos_x[i] = pos_x[i] + 240; 166 pos_x[i] = pos_x[i] + 240;
167 167
168 if (pos_x[i] > 240) 168 if (pos_x[i] > 240)
169 pos_x[i] = pos_x[i] - 240; 169 pos_x[i] = pos_x[i] - 240;
170 if (pos_y[i] < 0) 170 if (pos_y[i] < 0)
171 pos_y[i] = pos_y[i] + 320; 171 pos_y[i] = pos_y[i] + 320;
172 172
173 if (pos_y[i] > 320) 173 if (pos_y[i] > 320)
174 pos_y[i] = pos_y[i] - 320; 174 pos_y[i] = pos_y[i] - 320;
175 } 175 }
176 } 176 }
177} 177}
178 178
179void StarField :: draw( SDL_Surface *screen, int w, int h ) 179void StarField :: draw( SDL_Surface *screen, int w, int h )
180{ 180{
181 if ( !sideways ) 181 if ( !sideways )
182 { 182 {
183 int scrW = w / 2; 183 int scrW = w / 2;
184 int scrH = h / 2; 184 int scrH = h / 2;
185 for(int i = 0; i < nrStars; i++) 185 for(int i = 0; i < nrStars; i++)
186 { 186 {
187 int sx = (x[i] * 256) / z[i] + scrW; 187 int sx = (x[i] * 256) / z[i] + scrW;
188 int sy = (y[i] * 256) / z[i] + scrH; 188 int sy = (y[i] * 256) / z[i] + scrH;
189 if(sx < 0 || sx > w || sy < 0 || sy > h) 189 if(sx < 0 || sx > w || sy < 0 || sy > h)
190 { 190 {
191 newStar(i); 191 newStar(i);
192 } 192 }
193 else 193 else
194 { 194 {
195 int size = (z[i] * 3) / maxZ; 195 int size = (z[i] * 3) / maxZ;
196 196
197 SDL_Rect r; 197 SDL_Rect r;
198 r.x = sx; 198 r.x = sx;
199 r.y = sy; 199 r.y = sy;
200 r.w = 3 - size; 200 r.w = 3 - size;
201 r.h = 3 - size; 201 r.h = 3 - size;
202 202
203 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 255, 255, 255 ) ); 203 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 255, 255, 255 ) );
204 } 204 }
205 } 205 }
206 } 206 }
207 else 207 else
208 { 208 {
209 SDL_LockSurface( screen ); 209 SDL_LockSurface( screen );
210 for(int i = 0; i < nrStars ; i++) 210 for(int i = 0; i < nrStars ; i++)
211 { 211 {
212 212
213 Uint32 c = getpixel( screen, pos_x[i], pos_y[i] ); 213 Uint32 c = getpixel( screen, pos_x[i], pos_y[i] );
214 214
215 215
216 if ( c == 0 ) 216 if ( c == 0 )
217 lineRGBA( screen, pos_x[i], pos_y[i], pos_x [i]+ vel_x[i], pos_y[i] + vel_y[i], star_color[i], star_color[i], star_color[i], 255 ); 217 lineRGBA( screen, pos_x[i], pos_y[i], pos_x [i]+ vel_x[i], pos_y[i] + vel_y[i], star_color[i], star_color[i], star_color[i], 255 );
218 218
219 //*** NOTE : if the velocity of the stars never changes then the values such as 'pos_x[i] + vel_x[i]' could be precalculated for each star *** 219 //*** NOTE : if the velocity of the stars never changes then the values such as 'pos_x[i] + vel_x[i]' could be precalculated for each star ***
220 } 220 }
221 SDL_UnlockSurface( screen ); 221 SDL_UnlockSurface( screen );
222 } 222 }
223} 223}
224 224
225 225
226 226
227// Test 227// Test
228#ifdef DEBUG_STARS 228#ifdef DEBUG_STARS
229SDL_Surface *screen; 229SDL_Surface *screen;
230StarField *stars; 230StarField *stars;
231 231
232void go() 232void go()
233{ 233{
234 /* Initialize SDL */ 234 /* Initialize SDL */
235 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 235 if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
236 { 236 {
237 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 237 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
238 exit(1); 238 exit(1);
239 } 239 }
240 atexit(SDL_Quit); 240 atexit(SDL_Quit);
241 241
242 int videoflags = SDL_SWSURFACE ; 242 int videoflags = SDL_SWSURFACE ;
243 243
244 if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL ) 244 if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
245 { 245 {
246 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError()); 246 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
247 exit(2); 247 exit(2);
248 } 248 }
249 249
250 stars = new StarField( false, 200 ); 250 stars = new StarField( false, 200 );
251 251
252 bool done = false; 252 bool done = false;
253 while ( !done ) 253 while ( !done )
254 { 254 {
255 SDL_FillRect( screen, 0, 0 ); 255 SDL_FillRect( screen, 0, 0 );
256 stars->draw( screen ); 256 stars->draw( screen );
257 stars->move( ); 257 stars->move( );
258 258
259 SDL_Flip( screen ); 259 SDL_Flip( screen );
260 260
261 SDL_Delay( 10 ); 261 SDL_Delay( 10 );
262 262
263 SDL_Event event; 263 SDL_Event event;
264 while ( SDL_PollEvent(&event) ) 264 while ( SDL_PollEvent(&event) )
265 { 265 {
266 switch (event.type) 266 switch (event.type)
267 { 267 {
268 case SDL_KEYDOWN: 268 case SDL_KEYDOWN:
269 // Escape keypress quits the app 269 // Escape keypress quits the app
270 if ( event.key.keysym.sym != SDLK_ESCAPE ) 270 if ( event.key.keysym.sym != SDLK_ESCAPE )
271 { 271 {
272 break; 272 break;
273 } 273 }
274 case SDL_QUIT: 274 case SDL_QUIT:
275 done = 1; 275 done = 1;
276 break; 276 break;
277 default: 277 default:
278 break; 278 break;
279 } 279 }
280 } 280 }
281 } 281 }
282 } 282 }
283 283
284 284
285 285
286 286
287#ifdef __cplusplus 287#ifdef __cplusplus
288extern "C" 288extern "C"
289#endif 289#endif
290int main( int argc, char *argv[] ) 290int main( int argc, char *argv[] )
291{ 291{
292 go(); 292 go();
293} 293}
294 294
295#endif 295#endif
diff --git a/noncore/games/sfcave-sdl/starfield.h b/noncore/games/sfcave-sdl/starfield.h
index ae9bd34..133cb54 100644
--- a/noncore/games/sfcave-sdl/starfield.h
+++ b/noncore/games/sfcave-sdl/starfield.h
@@ -1,41 +1,41 @@
1#ifndef __STARFIELD_H 1#ifndef __STARFIELD_H
2#define __STARFIELD_H 2#define __STARFIELD_H
3 3
4class StarField 4class StarField
5{ 5{
6public: 6public:
7 StarField( bool side = false, int nrStars = 100, int mx = 240, int my = 320, int minz = 32, int maxz = 725 ); 7 StarField( bool side = false, int nrStars = 100, int mx = 240, int my = 320, int minz = 32, int maxz = 725 );
8 ~StarField(); 8 ~StarField();
9 9
10 void init(); 10 void init();
11 void move( ); 11 void move( );
12 void draw( SDL_Surface *screen, int w = 240, int h = 320 ); 12 void draw( SDL_Surface *screen, int w = 240, int h = 320 );
13 13
14private: 14private:
15 // 3d effect 15 // 3d effect
16 int *x; 16 int *x;
17 int *y; 17 int *y;
18 int *z; 18 int *z;
19 19
20 int maxX; 20 int maxX;
21 int maxY; 21 int maxY;
22 int minZ; 22 int minZ;
23 int maxZ; 23 int maxZ;
24 24
25 // Sideways 25 // Sideways
26 int *star_color; 26 int *star_color;
27 int *vel_x; 27 int *vel_x;
28 int *vel_y; 28 int *vel_y;
29 int *pos_x; 29 int *pos_x;
30 int *pos_y; 30 int *pos_y;
31 int min_brightness; 31 int min_brightness;
32 int top_star_speed; 32 int top_star_speed;
33 33
34 bool sideways; 34 bool sideways;
35 int nrStars; 35 int nrStars;
36 36
37 void newStar( int i ); 37 void newStar( int i );
38}; 38};
39 39
40 40
41#endif 41#endif
diff --git a/noncore/games/sfcave-sdl/stringtokenizer.h b/noncore/games/sfcave-sdl/stringtokenizer.h
index 3f299a6..51daa42 100644
--- a/noncore/games/sfcave-sdl/stringtokenizer.h
+++ b/noncore/games/sfcave-sdl/stringtokenizer.h
@@ -1,23 +1,23 @@
1#ifndef __STRINGTOKENIZER_H 1#ifndef __STRINGTOKENIZER_H
2#define __STRINGTOKENIZER_H 2#define __STRINGTOKENIZER_H
3 3
4#include <vector> 4#include <vector>
5using namespace std; 5using namespace std;
6 6
7class StringTokenizer : public vector<string> 7class StringTokenizer : public vector<string>
8{ 8{
9 public: 9 public:
10 StringTokenizer(const string &rStr, const string &rDelimiters = " ,\n") 10 StringTokenizer(const string &rStr, const string &rDelimiters = " ,\n")
11 { 11 {
12 string::size_type lastPos(rStr.find_first_not_of(rDelimiters, 0)); 12 string::size_type lastPos(rStr.find_first_not_of(rDelimiters, 0));
13 string::size_type pos(rStr.find_first_of(rDelimiters, lastPos)); 13 string::size_type pos(rStr.find_first_of(rDelimiters, lastPos));
14 while (string::npos != pos || string::npos != lastPos) 14 while (string::npos != pos || string::npos != lastPos)
15 { 15 {
16 push_back(rStr.substr(lastPos, pos - lastPos)); 16 push_back(rStr.substr(lastPos, pos - lastPos));
17 lastPos = rStr.find_first_not_of(rDelimiters, pos); 17 lastPos = rStr.find_first_not_of(rDelimiters, pos);
18 pos = rStr.find_first_of(rDelimiters, lastPos); 18 pos = rStr.find_first_of(rDelimiters, lastPos);
19 } 19 }
20 } 20 }
21}; 21};
22 22
23#endif 23#endif
diff --git a/noncore/games/sfcave-sdl/terrain.cpp b/noncore/games/sfcave-sdl/terrain.cpp
index b243f45..5943275 100644
--- a/noncore/games/sfcave-sdl/terrain.cpp
+++ b/noncore/games/sfcave-sdl/terrain.cpp
@@ -1,297 +1,297 @@
1#include "SDL.h" 1#include <SDL/SDL.h>
2#include "SDL_rotozoom.h" 2#include <SDL/SDL_rotozoom.h>
3#include "SDL_gfxPrimitives.h" 3#include <SDL/SDL_gfxPrimitives.h>
4 4
5#include "constants.h" 5#include "constants.h"
6#include "terrain.h" 6#include "terrain.h"
7#include "random.h" 7#include "random.h"
8#include "util.h" 8#include "util.h"
9#include "starfield.h" 9#include "starfield.h"
10 10
11Terrain :: Terrain( int w, int h, bool drawTop, bool drawBottom ) 11Terrain :: Terrain( int w, int h, bool drawTop, bool drawBottom )
12{ 12{
13 sWidth = w; 13 sWidth = w;
14 sHeight = h; 14 sHeight = h;
15 speed = 1; 15 speed = 1;
16 segSize = sWidth/(MAPSIZE-2)+1; 16 segSize = sWidth/(MAPSIZE-2)+1;
17 this->drawTop = drawTop; 17 this->drawTop = drawTop;
18 this->drawBottom = drawBottom; 18 this->drawBottom = drawBottom;
19 19
20 stars = new StarField( true ); 20 stars = new StarField( true );
21 21
22 SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, sWidth + 20, sHeight, 32, 22 SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, sWidth + 20, sHeight, 32,
23 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000); 23 0x000000ff,0x0000ff00, 0x00ff0000, 0xff000000);
24 terrainSurface = SDL_DisplayFormat( tmp ); 24 terrainSurface = SDL_DisplayFormat( tmp );
25 SDL_FreeSurface( tmp ); 25 SDL_FreeSurface( tmp );
26 26
27 initTerrain(); 27 initTerrain();
28 28
29} 29}
30 30
31Terrain :: ~Terrain() 31Terrain :: ~Terrain()
32{ 32{
33 SDL_FreeSurface( terrainSurface ); 33 SDL_FreeSurface( terrainSurface );
34 delete stars; 34 delete stars;
35} 35}
36 36
37void Terrain :: initTerrain() 37void Terrain :: initTerrain()
38{ 38{
39 dir = 1; 39 dir = 1;
40 offset = 0; 40 offset = 0;
41 41
42 maxHeight = 50; 42 maxHeight = 50;
43 43
44 mapTop[0] = (int)(nextInt(50)) + 5; 44 mapTop[0] = (int)(nextInt(50)) + 5;
45 mapBottom[0] = sHeight - (maxHeight - mapTop[0]); 45 mapBottom[0] = sHeight - (maxHeight - mapTop[0]);
46 for ( int i = 1 ; i < MAPSIZE ; ++i ) 46 for ( int i = 1 ; i < MAPSIZE ; ++i )
47 setPoint( i ); 47 setPoint( i );
48 48
49 SDL_FillRect( terrainSurface, 0, 0 ); 49 SDL_FillRect( terrainSurface, 0, 0 );
50 50
51 // Draw Terrain into surface 51 // Draw Terrain into surface
52 Sint16 px[5]; 52 Sint16 px[5];
53 Sint16 py[5]; 53 Sint16 py[5];
54 54
55 for ( int i = 0 ; i < MAPSIZE ; ++i ) 55 for ( int i = 0 ; i < MAPSIZE ; ++i )
56 { 56 {
57 int left = (i*segSize); 57 int left = (i*segSize);
58 int right = ((i+1)*segSize); 58 int right = ((i+1)*segSize);
59 px[0] = left; 59 px[0] = left;
60 py[0] = mapTop[i]; 60 py[0] = mapTop[i];
61 px[1] = right; 61 px[1] = right;
62 py[1] = mapTop[i+1]; 62 py[1] = mapTop[i+1];
63 px[2] = right; 63 px[2] = right;
64 py[2] = 0; 64 py[2] = 0;
65 px[3] = left; 65 px[3] = left;
66 py[3] = 0; 66 py[3] = 0;
67 67
68 if ( drawTop ) 68 if ( drawTop )
69 { 69 {
70 // Only display top landscape if not running FLY_GAME 70 // Only display top landscape if not running FLY_GAME
71 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 ); 71 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 );
72 } 72 }
73 73
74 if ( drawBottom ) 74 if ( drawBottom )
75 { 75 {
76 py[0] = mapBottom[i]; 76 py[0] = mapBottom[i];
77 py[1] = mapBottom[i+1]; 77 py[1] = mapBottom[i+1];
78 py[2] = sHeight; 78 py[2] = sHeight;
79 py[3] = sHeight; 79 py[3] = sHeight;
80 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 ); 80 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 );
81 } 81 }
82 82
83 } 83 }
84 84
85 85
86} 86}
87 87
88void Terrain :: moveTerrain( int amountToMove ) 88void Terrain :: moveTerrain( int amountToMove )
89{ 89{
90 stars->move(); 90 stars->move();
91 91
92 offset += amountToMove; 92 offset += amountToMove;
93 speed = offset/segSize; 93 speed = offset/segSize;
94 94
95 if ( offset >= segSize ) 95 if ( offset >= segSize )
96 { 96 {
97 for ( int i = 0 ; i < (MAPSIZE)-speed ; ++i ) 97 for ( int i = 0 ; i < (MAPSIZE)-speed ; ++i )
98 { 98 {
99 mapTop[i] = mapTop[i+speed]; 99 mapTop[i] = mapTop[i+speed];
100 mapBottom[i] = mapBottom[i+speed]; 100 mapBottom[i] = mapBottom[i+speed];
101 } 101 }
102 102
103 for ( int i = (MAPSIZE)-speed ; i < MAPSIZE ; ++i ) 103 for ( int i = (MAPSIZE)-speed ; i < MAPSIZE ; ++i )
104 { 104 {
105 setPoint( i ); 105 setPoint( i );
106 } 106 }
107 107
108 SDL_Rect dst; 108 SDL_Rect dst;
109 dst.x = offset; 109 dst.x = offset;
110 dst.y = 0; 110 dst.y = 0;
111 dst.w = sWidth; 111 dst.w = sWidth;
112 dst.h = sHeight; 112 dst.h = sHeight;
113 113
114 SDL_Rect dst2; 114 SDL_Rect dst2;
115 dst2.x = 0; 115 dst2.x = 0;
116 dst2.y = 0; 116 dst2.y = 0;
117 117
118 SDL_BlitSurface(terrainSurface, &dst, terrainSurface, &dst2 ); 118 SDL_BlitSurface(terrainSurface, &dst, terrainSurface, &dst2 );
119 119
120 dst.x = sWidth-5; 120 dst.x = sWidth-5;
121 dst.y = 0; 121 dst.y = 0;
122 dst.w = offset; 122 dst.w = offset;
123 dst.h = sHeight; 123 dst.h = sHeight;
124 SDL_FillRect( terrainSurface, &dst, 0 ); 124 SDL_FillRect( terrainSurface, &dst, 0 );
125 for ( int i = (MAPSIZE-1) - speed -1; i < MAPSIZE-1 ; ++i ) 125 for ( int i = (MAPSIZE-1) - speed -1; i < MAPSIZE-1 ; ++i )
126 { 126 {
127 Sint16 px[4]; 127 Sint16 px[4];
128 Sint16 py[5]; 128 Sint16 py[5];
129 int left = ((i-1)*segSize); 129 int left = ((i-1)*segSize);
130 int right = ((i)*segSize); 130 int right = ((i)*segSize);
131 // printf( "left = %d, right = %d\n", left, right ); 131 // printf( "left = %d, right = %d\n", left, right );
132 132
133 px[0] = left; 133 px[0] = left;
134 py[0] = mapTop[i]; 134 py[0] = mapTop[i];
135 px[1] = right; 135 px[1] = right;
136 py[1] = mapTop[i+1]; 136 py[1] = mapTop[i+1];
137 px[2] = right; 137 px[2] = right;
138 py[2] = 0; 138 py[2] = 0;
139 px[3] = left; 139 px[3] = left;
140 py[3] = 0; 140 py[3] = 0;
141 141
142 if ( drawTop ) 142 if ( drawTop )
143 { 143 {
144 // Only display top landscape if not running FLY_GAME 144 // Only display top landscape if not running FLY_GAME
145 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 ); 145 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 );
146 } 146 }
147 147
148 if ( drawBottom ) 148 if ( drawBottom )
149 { 149 {
150 py[0] = mapBottom[i]; 150 py[0] = mapBottom[i];
151 py[1] = mapBottom[i+1]; 151 py[1] = mapBottom[i+1];
152 py[2] = sHeight; 152 py[2] = sHeight;
153 py[3] = sHeight; 153 py[3] = sHeight;
154 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 ); 154 filledPolygonRGBA( terrainSurface, px, py, 4, 0, 190, 0, 255 );
155 } 155 }
156 } 156 }
157 157
158 offset -= speed*segSize; 158 offset -= speed*segSize;
159 159
160 } 160 }
161 161
162} 162}
163 163
164void Terrain :: setPoint( int point ) 164void Terrain :: setPoint( int point )
165{ 165{
166 if ( nextInt( 100 ) >= 80 ) 166 if ( nextInt( 100 ) >= 80 )
167 dir *= -1; 167 dir *= -1;
168 168
169 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 )); 169 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ));
170 if ( mapTop[point] < 0 ) 170 if ( mapTop[point] < 0 )
171 { 171 {
172 mapTop[point] = 0; 172 mapTop[point] = 0;
173 dir *= -1; 173 dir *= -1;
174 } 174 }
175 else if ( mapTop[point] >= maxHeight ) 175 else if ( mapTop[point] >= maxHeight )
176 { 176 {
177 mapTop[point] = maxHeight; 177 mapTop[point] = maxHeight;
178 dir *= -1; 178 dir *= -1;
179 } 179 }
180 180
181 mapBottom[point] = sHeight - (maxHeight - mapTop[point]); 181 mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
182} 182}
183 183
184void Terrain :: increaseMaxHeight( int amount ) 184void Terrain :: increaseMaxHeight( int amount )
185{ 185{
186 maxHeight += amount; 186 maxHeight += amount;
187} 187}
188 188
189void Terrain :: drawTerrain( SDL_Surface *screen ) 189void Terrain :: drawTerrain( SDL_Surface *screen )
190{ 190{
191 // Blit terrain surface onto screen 191 // Blit terrain surface onto screen
192 192
193 SDL_Rect dst; 193 SDL_Rect dst;
194 dst.x = offset; 194 dst.x = offset;
195 dst.y = 0; 195 dst.y = 0;
196 dst.w = sWidth; 196 dst.w = sWidth;
197 dst.h = sHeight; 197 dst.h = sHeight;
198 198
199 SDL_Rect dst2; 199 SDL_Rect dst2;
200 dst2.x = 0; 200 dst2.x = 0;
201 dst2.y = 0; 201 dst2.y = 0;
202 202
203 SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 ); 203 SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 );
204 204
205 stars->draw( screen ); 205 stars->draw( screen );
206} 206}
207 207
208bool Terrain :: checkCollision( int x, int y, int h ) 208bool Terrain :: checkCollision( int x, int y, int h )
209{ 209{
210 if ( y < 0 || y > sHeight ) 210 if ( y < 0 || y > sHeight )
211 return true; 211 return true;
212 212
213 // First get segment that matches x 213 // First get segment that matches x
214 SDL_LockSurface( terrainSurface ); 214 SDL_LockSurface( terrainSurface );
215 215
216 Uint32 c = getpixel( terrainSurface, x, y ); 216 Uint32 c = getpixel( terrainSurface, x, y );
217 217
218 SDL_UnlockSurface( terrainSurface ); 218 SDL_UnlockSurface( terrainSurface );
219 219
220 if ( c == 0 ) 220 if ( c == 0 )
221 return false; 221 return false;
222 else 222 else
223 return true; 223 return true;
224} 224}
225 225
226 226
227// Test 227// Test
228#ifdef DEBUG_TERRAIN 228#ifdef DEBUG_TERRAIN
229SDL_Surface *screen; 229SDL_Surface *screen;
230Terrain *terrain; 230Terrain *terrain;
231 231
232void go() 232void go()
233{ 233{
234 // Initialize SDL 234 // Initialize SDL
235 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 235 if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
236 { 236 {
237 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 237 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
238 exit(1); 238 exit(1);
239 } 239 }
240 atexit(SDL_Quit); 240 atexit(SDL_Quit);
241 241
242 int videoflags = SDL_SWSURFACE ; 242 int videoflags = SDL_SWSURFACE ;
243 243
244 if ( (screen=SDL_SetVideoMode(280, 320,32,videoflags)) == NULL ) 244 if ( (screen=SDL_SetVideoMode(280, 320,32,videoflags)) == NULL )
245 { 245 {
246 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError()); 246 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError());
247 exit(2); 247 exit(2);
248 } 248 }
249 249
250 terrain = new Terrain( 240, 320 ); 250 terrain = new Terrain( 240, 320 );
251 251
252 bool done = false; 252 bool done = false;
253 while ( !done ) 253 while ( !done )
254 { 254 {
255 SDL_FillRect( screen, 0, 0 ); 255 SDL_FillRect( screen, 0, 0 );
256 terrain->drawTerrain( screen ); 256 terrain->drawTerrain( screen );
257 terrain->moveTerrain( 5 ); 257 terrain->moveTerrain( 5 );
258 258
259 SDL_Flip( screen ); 259 SDL_Flip( screen );
260 260
261 SDL_Delay( 5 ); 261 SDL_Delay( 5 );
262 262
263 SDL_Event event; 263 SDL_Event event;
264 while ( SDL_PollEvent(&event) ) 264 while ( SDL_PollEvent(&event) )
265 { 265 {
266 switch (event.type) 266 switch (event.type)
267 { 267 {
268 case SDL_KEYDOWN: 268 case SDL_KEYDOWN:
269 // Escape keypress quits the app 269 // Escape keypress quits the app
270 if ( event.key.keysym.sym != SDLK_ESCAPE ) 270 if ( event.key.keysym.sym != SDLK_ESCAPE )
271 { 271 {
272 terrain->moveTerrain( 5 ); 272 terrain->moveTerrain( 5 );
273 break; 273 break;
274 } 274 }
275 case SDL_QUIT: 275 case SDL_QUIT:
276 done = 1; 276 done = 1;
277 break; 277 break;
278 default: 278 default:
279 break; 279 break;
280 } 280 }
281 } 281 }
282 } 282 }
283 } 283 }
284 284
285 285
286 286
287 287
288#ifdef __cplusplus 288#ifdef __cplusplus
289extern "C" 289extern "C"
290#endif 290#endif
291int main( int argc, char *argv[] ) 291int main( int argc, char *argv[] )
292{ 292{
293 go(); 293 go();
294} 294}
295 295
296#endif 296#endif
297 297
diff --git a/noncore/games/sfcave-sdl/terrain.h b/noncore/games/sfcave-sdl/terrain.h
index 4070318..3cc9691 100644
--- a/noncore/games/sfcave-sdl/terrain.h
+++ b/noncore/games/sfcave-sdl/terrain.h
@@ -1,50 +1,50 @@
1#ifndef __TERRAIN_H 1#ifndef __TERRAIN_H
2#define __TERRAIN_H 2#define __TERRAIN_H
3 3
4#include <SDL.h> 4#include <SDL/SDL.h>
5 5
6class StarField; 6class StarField;
7class Terrain 7class Terrain
8{ 8{
9public: 9public:
10 Terrain( int w, int h, bool drawTop = true, bool drawBottom = true ); 10 Terrain( int w, int h, bool drawTop = true, bool drawBottom = true );
11 virtual ~Terrain(); 11 virtual ~Terrain();
12 12
13 virtual void initTerrain(); 13 virtual void initTerrain();
14 virtual void moveTerrain( int amountToMove ); 14 virtual void moveTerrain( int amountToMove );
15 virtual bool checkCollision( int x, int y, int h ); 15 virtual bool checkCollision( int x, int y, int h );
16 virtual void drawTerrain( SDL_Surface *screen ); 16 virtual void drawTerrain( SDL_Surface *screen );
17 17
18 int getMapTop( int pos ) { return mapTop[pos]; } 18 int getMapTop( int pos ) { return mapTop[pos]; }
19 int getMapBottom( int pos ) { return mapBottom[pos]; } 19 int getMapBottom( int pos ) { return mapBottom[pos]; }
20 int getMaxHeight() { return maxHeight; } 20 int getMaxHeight() { return maxHeight; }
21 void increaseMaxHeight( int amount ); 21 void increaseMaxHeight( int amount );
22 22
23 int offset; 23 int offset;
24protected: 24protected:
25 25
26 int sWidth; 26 int sWidth;
27 int sHeight; 27 int sHeight;
28 28
29 int drawTop; 29 int drawTop;
30 int drawBottom; 30 int drawBottom;
31 31
32 int mapTop[MAPSIZE]; 32 int mapTop[MAPSIZE];
33 int mapBottom[MAPSIZE]; 33 int mapBottom[MAPSIZE];
34 int maxTop; 34 int maxTop;
35 int maxBottom; 35 int maxBottom;
36 36
37 int maxHeight; 37 int maxHeight;
38 int dir; 38 int dir;
39 int speed; 39 int speed;
40 int segSize; 40 int segSize;
41 41
42 SDL_Surface *terrainSurface; 42 SDL_Surface *terrainSurface;
43 StarField *stars; 43 StarField *stars;
44 44
45 void setPoint( int point ); 45 void setPoint( int point );
46}; 46};
47 47
48 48
49#endif 49#endif
50 50
diff --git a/noncore/games/sfcave-sdl/util.cpp b/noncore/games/sfcave-sdl/util.cpp
index f73e256..743f16e 100644
--- a/noncore/games/sfcave-sdl/util.cpp
+++ b/noncore/games/sfcave-sdl/util.cpp
@@ -1,75 +1,75 @@
1#include "SDL.h" 1#include <SDL/SDL.h>
2 2
3#include <dirent.h> 3#include <dirent.h>
4 4
5#include <vector> 5#include <vector>
6using namespace std; 6using namespace std;
7 7
8#include "util.h" 8#include "util.h"
9#include "random.h" 9#include "random.h"
10 10
11Uint32 getpixel(SDL_Surface *surface, int x, int y) 11Uint32 getpixel(SDL_Surface *surface, int x, int y)
12{ 12{
13 int bpp = surface->format->BytesPerPixel; 13 int bpp = surface->format->BytesPerPixel;
14 /* Here p is the address to the pixel we want to retrieve */ 14 /* Here p is the address to the pixel we want to retrieve */
15 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; 15 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
16 16
17 switch(bpp) { 17 switch(bpp) {
18 case 1: 18 case 1:
19 return *p; 19 return *p;
20 20
21 case 2: 21 case 2:
22 return *(Uint16 *)p; 22 return *(Uint16 *)p;
23 23
24 case 3: 24 case 3:
25 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 25 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
26 return p[0] << 16 | p[1] << 8 | p[2]; 26 return p[0] << 16 | p[1] << 8 | p[2];
27 else 27 else
28 return p[0] | p[1] << 8 | p[2] << 16; 28 return p[0] | p[1] << 8 | p[2] << 16;
29 29
30 case 4: 30 case 4:
31 return *(Uint32 *)p; 31 return *(Uint32 *)p;
32 32
33 default: 33 default:
34 return 0; /* shouldn't happen, but avoids warnings */ 34 return 0; /* shouldn't happen, but avoids warnings */
35 } 35 }
36} 36}
37 37
38string chooseRandomFile( string path, string fileType ) 38string chooseRandomFile( string path, string fileType )
39{ 39{
40 vector<string> files; 40 vector<string> files;
41 DIR *d = opendir( path.c_str() ); 41 DIR *d = opendir( path.c_str() );
42 if ( !d ) 42 if ( !d )
43 return ""; 43 return "";
44 44
45 struct dirent *item = readdir( d ); 45 struct dirent *item = readdir( d );
46 while ( item ) 46 while ( item )
47 { 47 {
48 string file = string( path ) + item->d_name; 48 string file = string( path ) + item->d_name;
49 49
50 // Rip extension from file 50 // Rip extension from file
51 int pos = file.find( ".", 1 ) + 1; 51 int pos = file.find( ".", 1 ) + 1;
52 string tmp = file.substr( pos ); 52 string tmp = file.substr( pos );
53 if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) 53 if ( tmp.size() > 0 && fileType.find( tmp ) != -1 )
54 { 54 {
55 files.push_back( file ); 55 files.push_back( file );
56 } 56 }
57 item = readdir( d ); 57 item = readdir( d );
58 } 58 }
59 59
60 closedir( d ); 60 closedir( d );
61 return files[nextInt( files.size() )]; 61 return files[nextInt( files.size() )];
62} 62}
63 63
64 64
65string getHomeDir() 65string getHomeDir()
66{ 66{
67 string home; 67 string home;
68#ifdef QWS 68#ifdef QWS
69 home = getenv( "HOME" ); 69 home = getenv( "HOME" );
70#else 70#else
71 home = "."; 71 home = ".";
72#endif 72#endif
73 73
74 return home; 74 return home;
75} 75}
diff --git a/noncore/games/sfcave-sdl/util.h b/noncore/games/sfcave-sdl/util.h
index e3aa31a..a67707b 100644
--- a/noncore/games/sfcave-sdl/util.h
+++ b/noncore/games/sfcave-sdl/util.h
@@ -1,10 +1,10 @@
1#ifndef __UTIL_H 1#ifndef __UTIL_H
2#define __UTIL_H 2#define __UTIL_H
3 3
4#include <string> 4#include <string>
5using namespace std; 5using namespace std;
6 6
7Uint32 getpixel(SDL_Surface *surface, int x, int y); 7Uint32 getpixel(SDL_Surface *surface, int x, int y);
8string chooseRandomFile( string path, string fileType ); 8string chooseRandomFile( string path, string fileType );
9string getHomeDir(); 9string getHomeDir();
10#endif 10#endif