summaryrefslogtreecommitdiff
Unidiff
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,8 +1,8 @@
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{
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,10 +1,10 @@
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();
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
@@ -6,13 +6,13 @@
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);
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
@@ -6,13 +6,13 @@
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
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,7 +1,7 @@
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 )
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
@@ -2,13 +2,13 @@
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();
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,8 +1,7 @@
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
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,10 +1,10 @@
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:
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,10 +1,10 @@
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
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,11 +1,11 @@
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"
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,7 +1,7 @@
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 )
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,10 +1,10 @@
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"
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,8 +1,8 @@
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"
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,13 +1,13 @@
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
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,8 +1,8 @@
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
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,14 +1,14 @@
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"
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,10 +1,10 @@
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;
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,7 +1,7 @@
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 )
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,10 +1,10 @@
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"
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,9 +1,9 @@
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"
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,10 +1,10 @@
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 );
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