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,50 +1,50 @@ | |||
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 | ||
7 | AnimatedImage :: AnimatedImage( string file, int nFrames ) | 7 | AnimatedImage :: 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 | ||
26 | AnimatedImage :: ~AnimatedImage() | 26 | AnimatedImage :: ~AnimatedImage() |
27 | { | 27 | { |
28 | if ( image != 0 ) | 28 | if ( image != 0 ) |
29 | SDL_FreeSurface( image ); | 29 | SDL_FreeSurface( image ); |
30 | } | 30 | } |
31 | 31 | ||
32 | bool AnimatedImage :: nextFrame() | 32 | bool 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 | ||
45 | void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) | 45 | void 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; |
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 | ||
6 | class AnimatedImage | 6 | class AnimatedImage |
7 | { | 7 | { |
8 | public: | 8 | public: |
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; } |
16 | private: | 16 | private: |
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,60 +1,60 @@ | |||
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" |
7 | using namespace std; | 7 | using 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 | ||
15 | void BFont::InitFont() | 15 | void 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 */ |
51 | void BFont::LoadFont (const char *filename) | 51 | void 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 | { |
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,60 +1,60 @@ | |||
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 | ||
14 | class BFont | 14 | class 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); |
25 | public: | 25 | public: |
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, ...); |
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,49 +1,49 @@ | |||
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 | ||
7 | FlyGame :: FlyGame( SFCave *p, int w, int h, int diff ) | 7 | FlyGame :: 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 | ||
18 | FlyGame :: ~FlyGame() | 18 | FlyGame :: ~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 | ||
23 | void FlyGame :: init() | 23 | void 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 | } |
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 | ||
10 | class FlyGame : public Game | 10 | class FlyGame : public Game |
11 | { | 11 | { |
12 | public: | 12 | public: |
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 | ||
20 | private: | 20 | private: |
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,50 +1,49 @@ | |||
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 | ||
16 | FlyTerrain :: FlyTerrain( int w, int h ) | 15 | FlyTerrain :: 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 | ||
22 | FlyTerrain :: ~FlyTerrain() | 21 | FlyTerrain :: ~FlyTerrain() |
23 | { | 22 | { |
24 | } | 23 | } |
25 | 24 | ||
26 | void FlyTerrain :: setPoint( int point ) | 25 | void 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 | ||
50 | void FlyTerrain :: drawTerrain( SDL_Surface *screen ) | 49 | void FlyTerrain :: drawTerrain( SDL_Surface *screen ) |
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 | ||
8 | class FlyTerrain : public Terrain | 8 | class FlyTerrain : public Terrain |
9 | { | 9 | { |
10 | public: | 10 | public: |
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 | ||
19 | protected: | 19 | protected: |
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 | ||
13 | class FontHandler | 13 | class FontHandler |
14 | { | 14 | { |
15 | public: | 15 | public: |
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 ); |
25 | private: | 25 | private: |
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,53 +1,53 @@ | |||
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 | ||
21 | Game :: Game( SFCave *p, int w, int h, int diff ) | 21 | Game :: 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 | ||
34 | Game :: ~Game() | 34 | Game :: ~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 | ||
45 | void Game :: init() | 45 | void 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 | { |
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,49 +1,49 @@ | |||
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 | ||
7 | GatesGame :: GatesGame( SFCave *p, int w, int h, int diff ) | 7 | GatesGame :: 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 | ||
19 | GatesGame :: ~GatesGame() | 19 | GatesGame :: ~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 | ||
24 | void GatesGame :: init() | 24 | void 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 | { |
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 | ||
13 | class GatesGame : public Game | 13 | class GatesGame : public Game |
14 | { | 14 | { |
15 | public: | 15 | public: |
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 | ||
23 | private: | 23 | private: |
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 | ||
9 | Help :: Help( SFCave *p ) | 9 | Help :: 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 | ||
19 | Help :: ~Help() | 19 | Help :: ~Help() |
20 | { | 20 | { |
21 | delete stars; | 21 | delete stars; |
22 | } | 22 | } |
23 | 23 | ||
24 | void Help :: handleKeys( SDL_KeyboardEvent &key ) | 24 | void 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 | } |
46 | void Help :: init() | 46 | void 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 | ||
56 | void Help :: draw( SDL_Surface *screen ) | 56 | void 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 | ||
80 | void Help :: update() | 80 | void 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 | ||
99 | void Help :: loadText() | 99 | void 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 |
168 | SDL_Surface *screen; | 168 | SDL_Surface *screen; |
169 | Help *help; | 169 | Help *help; |
170 | 170 | ||
171 | void go() | 171 | void 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 |
229 | extern "C" | 229 | extern "C" |
230 | #endif | 230 | #endif |
231 | int main( int argc, char *argv[] ) | 231 | int 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> |
7 | using namespace std; | 7 | using namespace std; |
8 | 8 | ||
9 | class SFCave; | 9 | class SFCave; |
10 | class StarField; | 10 | class StarField; |
11 | 11 | ||
12 | class Help | 12 | class Help |
13 | { | 13 | { |
14 | public: | 14 | public: |
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(); |
22 | private: | 22 | private: |
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,50 +1,50 @@ | |||
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 | ||
11 | MenuOption :: MenuOption( string text, int id ) | 11 | MenuOption :: 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 | ||
19 | MenuOption :: ~MenuOption() | 19 | MenuOption :: ~MenuOption() |
20 | { | 20 | { |
21 | } | 21 | } |
22 | 22 | ||
23 | 23 | ||
24 | int MenuOption :: draw( SDL_Surface *screen, int y ) | 24 | int 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 | ||
40 | void MenuOption :: setNextMenu( Menu *item, bool down ) | 40 | void 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 | ||
50 | SDL_Surface * Menu :: sfcaveTextImage; | 50 | SDL_Surface * Menu :: sfcaveTextImage; |
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,55 +1,55 @@ | |||
1 | #ifndef __MENU_H | 1 | #ifndef __MENU_H |
2 | #define __MENU_H | 2 | #define __MENU_H |
3 | 3 | ||
4 | #include <list> | 4 | #include <list> |
5 | using namespace std; | 5 | using namespace std; |
6 | 6 | ||
7 | #include <SDL.h> | 7 | #include <SDL/SDL.h> |
8 | 8 | ||
9 | class SFCave; | 9 | class SFCave; |
10 | class StarField; | 10 | class StarField; |
11 | class Menu; | 11 | class Menu; |
12 | 12 | ||
13 | class MenuOption | 13 | class MenuOption |
14 | { | 14 | { |
15 | public: | 15 | public: |
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 | ||
26 | private: | 26 | private: |
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 | ||
35 | class Menu | 35 | class Menu |
36 | { | 36 | { |
37 | public: | 37 | public: |
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 | ||
49 | protected: | 49 | protected: |
50 | 50 | ||
51 | private: | 51 | private: |
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; |
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,50 +1,50 @@ | |||
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 | ||
9 | Player :: Player( int w, int h ) | 9 | Player :: 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 | ||
23 | Player :: ~Player() | 23 | Player :: ~Player() |
24 | { | 24 | { |
25 | if ( explosion ) | 25 | if ( explosion ) |
26 | delete explosion; | 26 | delete explosion; |
27 | } | 27 | } |
28 | 28 | ||
29 | void Player :: init() | 29 | void 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 ); |
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 | ||
6 | class Rect | 6 | class Rect |
7 | { | 7 | { |
8 | public: | 8 | public: |
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 | ||
56 | private: | 56 | private: |
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 | ||
6 | DEFINES = _REENTRANT main=SDL_main | 6 | DEFINES = _REENTRANT main=SDL_main |
7 | 7 | ||
8 | INCLUDEPATH += $(OPIEDIR)/include | 8 | INCLUDEPATH += $(OPIEDIR)/include |
9 | INCLUDEPATH += $(OPIEDIR)/include/SDL | 9 | INCLUDEPATH += $(OPIEDIR)/include/SDL |
10 | DEPENDPATH += $(OPIEDIR)/include | 10 | DEPENDPATH += $(OPIEDIR)/include |
11 | 11 | ||
12 | LIBS += -lqpe -L${SDLDIR}/lib -lSDL -lSDLmain -lSDL_gfx -lSDL_image -lSDL_mixer -lstdc++ | 12 | LIBS += -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 | ||
55 | include ( $(OPIEDIR)/include.pro ) \ No newline at end of file | 55 | include ( $(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,56 +1,56 @@ | |||
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 | ||
27 | void start( int argc, char *argv[] ) | 27 | void 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 |
35 | extern "C" | 35 | extern "C" |
36 | #endif | 36 | #endif |
37 | int main(int argc, char *argv[]) | 37 | int 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 | ||
44 | SFCave :: SFCave( int argc, char *argv[] ) | 44 | SFCave :: 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 += "/"; |
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,52 +1,52 @@ | |||
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 | ||
8 | class Game; | 8 | class Game; |
9 | class Menu; | 9 | class Menu; |
10 | class Help; | 10 | class Help; |
11 | 11 | ||
12 | class SFCave | 12 | class SFCave |
13 | { | 13 | { |
14 | public: | 14 | public: |
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 | ||
39 | private: | 39 | private: |
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; |
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,49 +1,49 @@ | |||
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 | ||
7 | SFCaveGame :: SFCaveGame( SFCave *p, int w, int h, int diff ) | 7 | SFCaveGame :: 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 | ||
19 | SFCaveGame :: ~SFCaveGame() | 19 | SFCaveGame :: ~SFCaveGame() |
20 | { | 20 | { |
21 | } | 21 | } |
22 | 22 | ||
23 | void SFCaveGame :: init() | 23 | void 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 ); |
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 | ||
13 | class SFCaveGame : public Game | 13 | class SFCaveGame : public Game |
14 | { | 14 | { |
15 | public: | 15 | public: |
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 | ||
23 | private: | 23 | private: |
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 | ||
4 | Mix_Chunk *SoundHandler :: sounds[NR_SOUNDS]; | 4 | Mix_Chunk *SoundHandler :: sounds[NR_SOUNDS]; |
5 | Mix_Music *SoundHandler :: music; | 5 | Mix_Music *SoundHandler :: music; |
6 | int SoundHandler :: soundChannels[NR_SOUNDS]; | 6 | int SoundHandler :: soundChannels[NR_SOUNDS]; |
7 | bool SoundHandler :: soundOn; | 7 | bool SoundHandler :: soundOn; |
8 | bool SoundHandler :: musicOn; | 8 | bool SoundHandler :: musicOn; |
9 | 9 | ||
10 | bool SoundHandler :: init( ) | 10 | bool 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 | ||
39 | void SoundHandler :: cleanUp() | 39 | void 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 | ||
53 | int SoundHandler :: playSound( int soundNr, int channel, int nrLoops, int playBeforeFinished ) | 53 | int 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 | ||
69 | void SoundHandler :: stopSound( int channel, bool fadeOut, int nrMilliSecs ) | 69 | void 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 | ||
82 | void SoundHandler :: playMusic( string musicFile ) | 82 | void 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 | ||
105 | void SoundHandler :: playMusic( bool fade ) | 105 | void 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 | ||
123 | void SoundHandler :: stopMusic( bool fadeOut ) | 123 | void 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 | ||
139 | void SoundHandler :: setMusicVolume( int vol ) | 139 | void SoundHandler :: setMusicVolume( int vol ) |
140 | { | 140 | { |
141 | Mix_VolumeMusic( vol ); | 141 | Mix_VolumeMusic( vol ); |
142 | } | 142 | } |
143 | 143 | ||
144 | void SoundHandler :: setSoundsOn( bool val ) | 144 | void SoundHandler :: setSoundsOn( bool val ) |
145 | { | 145 | { |
146 | soundOn = val; | 146 | soundOn = val; |
147 | } | 147 | } |
148 | 148 | ||
149 | void SoundHandler :: setMusicOn( bool val ) | 149 | void 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 | ||
9 | class SoundHandler | 9 | class SoundHandler |
10 | { | 10 | { |
11 | public: | 11 | public: |
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 | ||
25 | private: | 25 | private: |
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 | ||
12 | StarField :: StarField( bool side, int nStars, int mx, int my, int minz, int maxz ) | 12 | StarField :: 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 | ||
53 | StarField :: ~StarField() | 53 | StarField :: ~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 | ||
74 | void StarField :: init() | 74 | void 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 | ||
114 | void StarField :: newStar( int starNr ) | 114 | void 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 | ||
130 | void StarField :: move( ) | 130 | void 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 | ||
179 | void StarField :: draw( SDL_Surface *screen, int w, int h ) | 179 | void 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 |
229 | SDL_Surface *screen; | 229 | SDL_Surface *screen; |
230 | StarField *stars; | 230 | StarField *stars; |
231 | 231 | ||
232 | void go() | 232 | void 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 |
288 | extern "C" | 288 | extern "C" |
289 | #endif | 289 | #endif |
290 | int main( int argc, char *argv[] ) | 290 | int 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 | ||
4 | class StarField | 4 | class StarField |
5 | { | 5 | { |
6 | public: | 6 | public: |
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 | ||
14 | private: | 14 | private: |
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> |
5 | using namespace std; | 5 | using namespace std; |
6 | 6 | ||
7 | class StringTokenizer : public vector<string> | 7 | class 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,51 +1,51 @@ | |||
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 | ||
11 | Terrain :: Terrain( int w, int h, bool drawTop, bool drawBottom ) | 11 | Terrain :: 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 | ||
31 | Terrain :: ~Terrain() | 31 | Terrain :: ~Terrain() |
32 | { | 32 | { |
33 | SDL_FreeSurface( terrainSurface ); | 33 | SDL_FreeSurface( terrainSurface ); |
34 | delete stars; | 34 | delete stars; |
35 | } | 35 | } |
36 | 36 | ||
37 | void Terrain :: initTerrain() | 37 | void 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 |
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 | ||
6 | class StarField; | 6 | class StarField; |
7 | class Terrain | 7 | class Terrain |
8 | { | 8 | { |
9 | public: | 9 | public: |
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; |
24 | protected: | 24 | protected: |
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> |
6 | using namespace std; | 6 | using namespace std; |
7 | 7 | ||
8 | #include "util.h" | 8 | #include "util.h" |
9 | #include "random.h" | 9 | #include "random.h" |
10 | 10 | ||
11 | Uint32 getpixel(SDL_Surface *surface, int x, int y) | 11 | Uint32 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 | ||
38 | string chooseRandomFile( string path, string fileType ) | 38 | string 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 | ||
65 | string getHomeDir() | 65 | string 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> |
5 | using namespace std; | 5 | using namespace std; |
6 | 6 | ||
7 | Uint32 getpixel(SDL_Surface *surface, int x, int y); | 7 | Uint32 getpixel(SDL_Surface *surface, int x, int y); |
8 | string chooseRandomFile( string path, string fileType ); | 8 | string chooseRandomFile( string path, string fileType ); |
9 | string getHomeDir(); | 9 | string getHomeDir(); |
10 | #endif | 10 | #endif |