summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/fly_game.cpp3
-rw-r--r--noncore/games/sfcave-sdl/gates_game.cpp4
-rw-r--r--noncore/games/sfcave-sdl/player.cpp2
-rw-r--r--noncore/games/sfcave-sdl/sfcave_game.cpp4
4 files changed, 6 insertions, 7 deletions
diff --git a/noncore/games/sfcave-sdl/fly_game.cpp b/noncore/games/sfcave-sdl/fly_game.cpp
index 7605c3f..8b05d8f 100644
--- a/noncore/games/sfcave-sdl/fly_game.cpp
+++ b/noncore/games/sfcave-sdl/fly_game.cpp
@@ -1,112 +1,111 @@
#include "SDL_gfxPrimitives.h"
#include "constants.h"
#include "fly_game.h"
#include "random.h"
FlyGame :: FlyGame( SFCave *p, int w, int h, int diff )
: Game( p, w, h, diff )
{
gameName = "Fly";
difficulty = MENU_DIFFICULTY_EASY;
terrain = new FlyTerrain( w, h );
player = new Player( w, h );
highScore = 0;
}
FlyGame :: ~FlyGame()
{
// terrain and player get deleted by parent class
}
void FlyGame :: init()
{
- Game :: init();
-
switch( difficulty )
{
case MENU_DIFFICULTY_EASY:
player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 );
break;
case MENU_DIFFICULTY_NORMAL:
player->setMovementInfo( 0.35, 0.4, 2.5, 3 );
break;
case MENU_DIFFICULTY_HARD:
player->setMovementInfo( 0.4, 0.6, 4, 5 );
break;
case MENU_DIFFICULTY_CUSTOM:
{
double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 );
double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 );
double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 );
double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 );
player->setMovementInfo( thrust, gravity, maxUp, maxDown );
break;
}
}
startScoring = false;
+ Game :: init();
}
void FlyGame :: update( int state )
{
Game::update( state );
if ( state == STATE_PLAYING )
{
if ( nrFrames % 3 == 0 )
{
int diff = terrain->getMapBottom( 10 ) - player->getY();
int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff );
if ( !startScoring )
{
if ( tmpScore > 0 )
startScoring = true;
}
if ( startScoring )
{
// Update score
// get distance between landscape and ship
// the closer the difference is to 0 means more points
score += tmpScore;
}
}
if ( checkCollisions() )
{
parent->changeState( STATE_CRASHING );
return;
}
// Game logic goes here
terrain->moveTerrain( 5 );
player->move( press );
}
}
void FlyGame :: draw( SDL_Surface *screen )
{
Game::preDraw( screen );
// Screen drawing goes here
terrain->drawTerrain( screen );
player->draw( screen );
Game::draw( screen );
}
bool FlyGame :: checkCollisions()
{
bool ret = false;
// Check collision with landscape
return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
}
diff --git a/noncore/games/sfcave-sdl/gates_game.cpp b/noncore/games/sfcave-sdl/gates_game.cpp
index 762801d..700a6ec 100644
--- a/noncore/games/sfcave-sdl/gates_game.cpp
+++ b/noncore/games/sfcave-sdl/gates_game.cpp
@@ -1,201 +1,201 @@
#include "SDL_gfxPrimitives.h"
#include "constants.h"
#include "gates_game.h"
#include "random.h"
GatesGame :: GatesGame( SFCave *p, int w, int h, int diff )
: Game( p, w, h, diff )
{
gameName = "Gates";
difficulty = MENU_DIFFICULTY_EASY;
blockUpdateRate = 200;
terrain = new Terrain( w, h );
player = new Player( w, h );
highScore = 0;
}
GatesGame :: ~GatesGame()
{
// terrain and player get deleted by parent class
}
void GatesGame :: init()
{
- Game :: init();
-
blockHeight = 80;
blockWidth = 20;
lastGateBottomY = 0;
gateDistance = 75;
nextGate = nextInt( 50 ) + gateDistance;
gapHeight = 75;
switch( difficulty )
{
case MENU_DIFFICULTY_EASY:
gapHeight = 75;
player->setMovementInfo( 0.4, 0.6, 4, 5 );
break;
case MENU_DIFFICULTY_NORMAL:
gapHeight = 50;
player->setMovementInfo( 0.4, 0.6, 4, 5 );
break;
case MENU_DIFFICULTY_HARD:
gapHeight = 25;
player->setMovementInfo( 0.6, 0.8, 6, 7 );
break;
case MENU_DIFFICULTY_CUSTOM:
{
// Read custom difficulty settings for this game
gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 );
double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 );
double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 );
double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 );
double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 );
player->setMovementInfo( thrust, gravity, maxUp, maxDown );
break;
}
}
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
blocks[i].y( -1 );
+
+ Game :: init();
}
void GatesGame :: update( int state )
{
Game::update( state );
// Game logic goes here
if ( state == STATE_PLAYING )
{
if ( nrFrames % 3 == 0 )
score ++;
if ( nrFrames % 500 == 0 )
{
if ( gapHeight > 75 )
gapHeight -= 5;
}
// Slightly random gap distance
if ( nrFrames >= nextGate )
{
nextGate = nrFrames + nextInt( 50 ) + gateDistance;
addGate();
}
if ( checkCollisions() )
{
parent->changeState( STATE_CRASHING );
return;
}
terrain->moveTerrain( 5 );
moveBlocks( 5 );
player->move( press );
}
}
void GatesGame :: draw( SDL_Surface *screen )
{
Game::preDraw( screen );
if ( parent->getState() == STATE_PLAYING )
{
// Screen drawing goes here
terrain->drawTerrain( screen );
player->draw( screen );
drawBlocks( screen );
}
else
{
// Screen drawing goes here
terrain->drawTerrain( screen );
drawBlocks( screen );
player->draw( screen );
}
Game::draw( screen );
}
void GatesGame :: addGate()
{
printf( "gapHeight = %d\n", gapHeight );
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() == -1 )
{
int x1 = sWidth;
int y1 = terrain->getMapTop(50);
int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight);
// See if height between last gate and this one is too big
if ( b1Height - 100 > lastGateBottomY )
b1Height -= 25;
else if ( b1Height + 100 < lastGateBottomY )
b1Height += 25;
lastGateBottomY = b1Height;
int x2 = sWidth;
int y2 = y1 + b1Height + gapHeight;
int b2Height = terrain->getMapBottom( 50 ) - y2;
blocks[i].setRect( x1, y1, blockWidth, b1Height );
blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
break;
}
}
}
void GatesGame :: moveBlocks( int amountToMove )
{
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() != -1 )
{
blocks[i].moveBy( -amountToMove, 0 );
if ( blocks[i].x() + blocks[i].y() < 0 )
blocks[i].y( -1 );
}
}
}
void GatesGame :: drawBlocks( SDL_Surface *screen )
{
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() != -1 )
{
SDL_Rect r = blocks[i].getRect();
SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) );
}
}
}
bool GatesGame :: checkCollisions()
{
// Check collisions with blocks
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() != -1 )
{
if ( blocks[i].intersects( player->getPos() ) )
return true;
}
}
// Check collision with landscape
return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
}
diff --git a/noncore/games/sfcave-sdl/player.cpp b/noncore/games/sfcave-sdl/player.cpp
index 2d52ae2..f024d6b 100644
--- a/noncore/games/sfcave-sdl/player.cpp
+++ b/noncore/games/sfcave-sdl/player.cpp
@@ -1,284 +1,284 @@
#include <SDL.h>
#include "SDL_gfxPrimitives.h"
#include "constants.h"
#include "player.h"
#include "random.h"
#include "animatedimage.h"
Player :: Player( int w, int h )
{
sWidth = w;
sHeight = h;
thrust = 0.4;
gravity = 0.6;
maxUpSpeed = 4.0;
maxDownSpeed = 5.0;
explosion = new AnimatedImage( IMAGES_PATH "explosion.bmp", 15 );
init();
}
Player :: ~Player()
{
if ( explosion )
delete explosion;
}
void Player :: init()
{
// Set player position
pos.x( 50 );
pos.y( sWidth/2 );
pos.h( 2 );
pos.w( 4 );
- thrust = 0;
+ currentThrust = 0;
crashing = false;
crashLineLength = 0;
crashed = false;
explosion->reset();
allFaded = false;
expNextFrame = false;
// Reset Trail
for ( int i = 0 ; i < TRAILSIZE ; ++i )
{
trail[i].x( -1 );
trail[i].y( 0 );
trail[i].w( 2 );
trail[i].h( 2 );
}
}
void Player :: draw( SDL_Surface *screen )
{
if ( !crashing )
{
// Draw Player
// ellipseRGBA( screen, pos.x(), pos.y(), pos.x()+ pos.width(), pos.y()+pos.height(), 0, 255, 255, 255 );
filledEllipseRGBA( screen, pos.x() + pos.w(), pos.y(), pos.w(), pos.h(), 0, 255, 255, 255 );
// Draw Trail
drawTrails( screen );
}
else
{
drawTrails( screen );
if ( !crashed )
explosion->draw( screen, pos.x(), pos.y() );
}
}
void Player :: drawTrails( SDL_Surface *screen )
{
if ( allFaded && crashing )
return;
for ( int i = 0 ; i < TRAILSIZE ; ++i )
{
if ( trail[i].x() >= 0 )
{
int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) ));
boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c );
}
}
}
void Player :: move( bool up )
{
// Find enpty trail and move others
moveTrails();
if ( up )
currentThrust -= thrust;
else
currentThrust += gravity;
if ( currentThrust > maxDownSpeed )
currentThrust = maxDownSpeed;
else if ( currentThrust < -maxUpSpeed )
currentThrust = -maxUpSpeed;
pos.moveBy( 0, (int)(currentThrust) );
}
void Player :: moveTrails()
{
bool done = false;
bool stillVisible = false;
// Dont do anything here if all faded when were crashing
if ( allFaded && crashing )
return;
for ( int i = 0 ; i < TRAILSIZE ; ++i )
{
if ( trail[i].x() < 0 )
{
stillVisible = true;
if ( !crashing && !done )
{
trail[i].x( pos.x() - 5 );
trail[i].y( pos.y() );
done = true;
}
}
else
trail[i].x( trail[i].x() - 1 );
}
if ( !stillVisible )
allFaded = true;
}
bool Player :: updateCrashing()
{
crashing = true;
moveTrails();
if ( expNextFrame )
{
expNextFrame = false;
crashed = !explosion->nextFrame();
}
else
expNextFrame = true;
return crashed;
}
void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown )
{
thrust = up;
gravity = grav;
maxUpSpeed = maxUp;
maxDownSpeed = maxDown;
}
void Player :: incValue( int valueType )
{
switch( valueType )
{
case PLAYER_THRUST:
thrust += 0.1;
break;
case PLAYER_GRAVITY:
gravity += 0.1;
break;
case PLAYER_MAX_SPEED_UP:
maxUpSpeed += 0.1;
break;
case PLAYER_MAX_SPEED_DOWN:
maxDownSpeed += 0.1;
break;
}
}
void Player :: decValue( int valueType )
{
switch( valueType )
{
case PLAYER_THRUST:
thrust -= 0.1;
break;
case PLAYER_GRAVITY:
gravity -= 0.1;
break;
case PLAYER_MAX_SPEED_UP:
maxUpSpeed -= 0.1;
break;
case PLAYER_MAX_SPEED_DOWN:
maxDownSpeed -= 0.1;
break;
}
}
void Player :: setValue( int valueType, double val )
{
switch( valueType )
{
case PLAYER_THRUST:
thrust = val;
break;
case PLAYER_GRAVITY:
gravity = val;
break;
case PLAYER_MAX_SPEED_UP:
maxUpSpeed = val;
break;
case PLAYER_MAX_SPEED_DOWN:
maxDownSpeed = val;
break;
}
}
double Player :: getValue( int valueType )
{
double val;
switch( valueType )
{
case PLAYER_THRUST:
val = thrust;
break;
case PLAYER_GRAVITY:
val = gravity;
break;
case PLAYER_MAX_SPEED_UP:
val = maxUpSpeed;
break;
case PLAYER_MAX_SPEED_DOWN:
val = maxDownSpeed;
break;
}
return val;
}
string Player :: getValueTypeString( int valueType )
{
string val;
switch( valueType )
{
case PLAYER_THRUST:
val = "thrust";
break;
case PLAYER_GRAVITY:
val = "gravity";
break;
case PLAYER_MAX_SPEED_UP:
val = "maxupspeed";
break;
case PLAYER_MAX_SPEED_DOWN:
val = "maxdownspeed";
break;
}
return val;
}
string Player :: getValueString( int valueType )
{
char val[50];
switch( valueType )
{
case PLAYER_THRUST:
sprintf( val, "Thrust - %lf", thrust );
break;
case PLAYER_GRAVITY:
sprintf( val, "Gravity - %lf", gravity );
break;
case PLAYER_MAX_SPEED_UP:
sprintf( val, "Max Speed Up - %lf", maxUpSpeed );
break;
case PLAYER_MAX_SPEED_DOWN:
sprintf( val, "Max Speed Down - %lf", maxDownSpeed );
break;
}
string ret = val;
return ret;
}
diff --git a/noncore/games/sfcave-sdl/sfcave_game.cpp b/noncore/games/sfcave-sdl/sfcave_game.cpp
index 1b00e14..8fdbbe5 100644
--- a/noncore/games/sfcave-sdl/sfcave_game.cpp
+++ b/noncore/games/sfcave-sdl/sfcave_game.cpp
@@ -1,179 +1,179 @@
#include "SDL_gfxPrimitives.h"
#include "constants.h"
#include "sfcave_game.h"
#include "random.h"
SFCaveGame :: SFCaveGame( SFCave *p, int w, int h, int diff )
: Game( p, w, h, diff )
{
gameName = "SFCave";
difficulty = MENU_DIFFICULTY_EASY;
blockUpdateRate = 200;
terrain = new Terrain( w, h );
player = new Player( w, h );
highScore = 0;
}
SFCaveGame :: ~SFCaveGame()
{
}
void SFCaveGame :: init()
{
- Game :: init();
-
blockDistance = 50;
blockHeight = 80;
blockWidth = 20;
switch( difficulty )
{
case MENU_DIFFICULTY_EASY:
blockDistance = 50;
break;
case MENU_DIFFICULTY_NORMAL:
blockDistance = 40;
break;
case MENU_DIFFICULTY_HARD:
blockDistance = 30;
break;
case MENU_DIFFICULTY_CUSTOM:
{
// Read custom difficulty settings for this game
blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 );
double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 );
double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 );
double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 );
double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 );
player->setMovementInfo( thrust, gravity, maxUp, maxDown );
break;
}
}
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
blocks[i].y( -1 );
+
+ Game :: init();
}
void SFCaveGame :: update( int state )
{
Game::update( state );
if ( state == STATE_PLAYING )
{
if ( nrFrames % 3 == 0 )
score ++;
if ( nrFrames % 200 == 0 )
{
if ( terrain->getMaxHeight() < sHeight - 100 )
{
terrain->increaseMaxHeight( 10 );
// Reduce block height
if ( terrain->getMaxHeight() > sHeight - 150 )
blockHeight -= 5;
}
}
if ( checkCollisions() )
{
parent->changeState( STATE_CRASHING );
return;
}
if ( nrFrames % blockDistance == 0 )
addBlock();
// Game logic goes here
terrain->moveTerrain( 5 );
moveBlocks( 5 );
player->move( press );
}
}
void SFCaveGame :: draw( SDL_Surface *screen )
{
Game::preDraw( screen );
if ( parent->getState() == STATE_PLAYING )
{
// Screen drawing goes here
terrain->drawTerrain( screen );
player->draw( screen );
drawBlocks( screen );
}
else
{
// Screen drawing goes here
terrain->drawTerrain( screen );
drawBlocks( screen );
player->draw( screen );
}
Game::draw( screen );
}
void SFCaveGame :: addBlock()
{
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() == -1 )
{
int x = sWidth;
int y = terrain->getMapTop( MAPSIZE-1 ) + (int)(nextInt(terrain->getMapBottom( MAPSIZE-1 ) - terrain->getMapTop( MAPSIZE-1 ) - blockHeight));
blocks[i].setRect( x, y, blockWidth, blockHeight );
break;
}
}
}
void SFCaveGame :: moveBlocks( int amountToMove )
{
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() != -1 )
{
blocks[i].moveBy( -amountToMove, 0 );
if ( blocks[i].x() + blocks[i].y() < 0 )
blocks[i].y( -1 );
}
}
}
void SFCaveGame :: drawBlocks( SDL_Surface *screen )
{
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() != -1 )
{
SDL_Rect r = blocks[i].getRect();
SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) );
}
}
}
bool SFCaveGame :: checkCollisions()
{
// Check collisions with blocks
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
{
if ( blocks[i].y() != -1 )
{
if ( blocks[i].intersects( player->getPos() ) )
return true;
}
}
// Check collision with landscape
return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
}