summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore 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,130 +1,130 @@
#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 );
}
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,100 +1,100 @@
#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;
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,122 +1,122 @@
#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 );
}