Commit 2f520f95 authored by Gerhard Stein's avatar Gerhard Stein

New more original Physics for the Galaxy Engine. I think Keen behaves nearly...

New more original Physics for the Galaxy Engine. I think Keen behaves nearly perfect now. Enemies nevertheless need some revision
parent 7f50510e
......@@ -7,7 +7,8 @@
#include "CPhysicsSettings.h"
CPhysicsSettings::CPhysicsSettings() {
CPhysicsSettings::CPhysicsSettings()
{
// used for jumping
player.maxjumpspeed = 120;
player.defaultjumpupdecreasespeed = 4;
......@@ -18,11 +19,9 @@ CPhysicsSettings::CPhysicsSettings() {
player.impossiblepogospeed = 175;
player.max_x_speed = 68;
//player.max_x_speed = 75;
player.pogostickonstart = false;
// when falling keen's Y inertia increases up to maximum
//max_fallspeed = 140;
// NOTE: The commented value was the old one
max_fallspeed = 104;
fallspeed_increase = 4;
......@@ -41,44 +40,59 @@ CPhysicsSettings::CPhysicsSettings() {
*/
void CPhysicsSettings::loadGameConstants(int episode, byte* data)
{
if(episode == 1)
{ // Code for Episode 1.
// player
byte pogo = *(data+0x900E);
player.pogostickonstart = pogo;
player.start_with_shots = *(data+0x9008);
// vorticon
vorticon.default_hp = *(data+0x180D)+1;
vorticon.commander_hp = *(data+0x1819)+1;
// tank bot
tankbot.shot_height_from_top = *(data+0x4900);
misc.ctspace_ammo = GETWORD(data+0xE03);
misc.ctspace_keys = GETWORD(data+0xE11);
misc.one_eyed_tile = GETWORD(data+0x4547);
misc.joy_tile = GETWORD(data+0x992A);
misc.bat_tile = GETWORD(data+0x995D);
misc.vac_tile = GETWORD(data+0x9990);
misc.wsk_tile = GETWORD(data+0x99C3);
misc.raygun_tile = GETWORD(data+0x1166);
misc.pogo_tile = GETWORD(data+0x11A7);
misc.changestoneblock = GETWORD(data+0x2414);
// TODO: ... More stuff will come here
}
else if(episode == 2)
{ // Code for Episode 2.
player.pogostickonstart = true;
player.start_with_shots = *(data+0x8AA2);
// TODO: ... More stuff will come here
if(episode >= 4 && episode <= 6 )
{
// Galaxy Engine
fallspeed_increase = 7;
max_fallspeed = 175; // Factor 2.5 to the original assembly it is
}
else if(episode == 3)
{ // Code for Episode 3.
player.pogostickonstart = true;
player.start_with_shots = 5;
// TODO: ... More stuff will come here
else
{
// Vorticon Engine
fallspeed_increase = 4;
max_fallspeed = 104;
if(episode == 1)
{ // Code for Episode 1.
// player
byte pogo = *(data+0x900E);
player.pogostickonstart = pogo;
player.start_with_shots = *(data+0x9008);
// vorticon
vorticon.default_hp = *(data+0x180D)+1;
vorticon.commander_hp = *(data+0x1819)+1;
// tank bot
tankbot.shot_height_from_top = *(data+0x4900);
misc.ctspace_ammo = GETWORD(data+0xE03);
misc.ctspace_keys = GETWORD(data+0xE11);
misc.one_eyed_tile = GETWORD(data+0x4547);
misc.joy_tile = GETWORD(data+0x992A);
misc.bat_tile = GETWORD(data+0x995D);
misc.vac_tile = GETWORD(data+0x9990);
misc.wsk_tile = GETWORD(data+0x99C3);
misc.raygun_tile = GETWORD(data+0x1166);
misc.pogo_tile = GETWORD(data+0x11A7);
misc.changestoneblock = GETWORD(data+0x2414);
// TODO: ... More stuff will come here
}
else if(episode == 2)
{ // Code for Episode 2.
player.pogostickonstart = true;
player.start_with_shots = *(data+0x8AA2);
// TODO: ... More stuff will come here
}
else if(episode == 3)
{ // Code for Episode 3.
player.pogostickonstart = true;
player.start_with_shots = 5;
// TODO: ... More stuff will come here
}
}
}
......@@ -19,6 +19,7 @@
class CPhysicsSettings {
public:
CPhysicsSettings();
void loadGameConstants(int episode, byte* data);
struct playersettings{
......
......@@ -277,6 +277,43 @@ Uint32 CSpriteObject::getYMidPos()
{ return m_Pos.y+(m_BBox.y2-m_BBox.y1)/2; }
void CSpriteObject::processFallPhysics(const int boost)
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
// In this case foe is jumping?
// Not sure here. We should use another variable...
if(yinertia<0 && !blockedu)
{
moveUp(-yinertia);
yinertia += boost;
}
else if( yinertia>=0 && !blockedd )
{
moveDown(yinertia);
// gradually increase the fall speed up to maximum rate
if (yinertia>Physics.max_fallspeed)
yinertia = Physics.max_fallspeed;
else if (yinertia<Physics.max_fallspeed)
yinertia += boost;
}
// hit floor or ceiling? set inertia to zero
if( (blockedd && yinertia>0) || (blockedu && yinertia<0) )
yinertia = 0;
// If object is not falling (yinertia >= 0) and blocked he cannot be falling
if(blockedd && yinertia>=0)
falling = false;
}
void CSpriteObject::processFallPhysics()
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
processFallPhysics(Physics.fallspeed_increase);
}
/**
* processes falling of an object. Can be player or any other foe
*/
......@@ -287,33 +324,7 @@ void CSpriteObject::processFalling()
// So it reaches the maximum of fallspeed
if(!inhibitfall)
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
// In this case foe is jumping?
// Not sure here. We should use another variable...
if(yinertia<0 && !blockedu)
{
moveUp(-yinertia);
yinertia += Physics.fallspeed_increase;
}
else if( yinertia>=0 && !blockedd )
{
moveDown(yinertia);
// gradually increase the fall speed up to maximum rate
if (yinertia>Physics.max_fallspeed)
yinertia = Physics.max_fallspeed;
else if (yinertia<Physics.max_fallspeed)
yinertia += Physics.fallspeed_increase;
}
// hit floor or ceiling? set inertia to zero
if( (blockedd && yinertia>0) || (blockedu && yinertia<0) )
yinertia = 0;
// If object is not falling (yinertia >= 0) and blocked he cannot be falling
if(blockedd && yinertia>=0)
falling = false;
processFallPhysics();
}
else
{
......
......@@ -221,6 +221,8 @@ public:
Uint32 getYDownPos();
Uint32 getYMidPos();
void processFallPhysics(const int boost);
void processFallPhysics();
virtual void processFalling();
virtual void getTouchedBy(CSpriteObject &theObject) {};
virtual bool isNearby(CSpriteObject &theObject) { return true; }
......
......@@ -177,8 +177,12 @@ bool CGameLauncherMenu::loadResources( const std::string& DataDirectory, const i
// Load the sound data
g_pSound->loadSoundData();
}
g_pBehaviorEngine->getPhysicsSettings().loadGameConstants(Episode, p_exedata);
return true;
}
return true;
return false;
}
......
......@@ -16,6 +16,10 @@ next(0,0),
m_ActionBaseOffset(0x0),
nextX(0),
nextY(0),
topTI(0),
bottomTI(0),
leftTI(0),
rightTI(0),
user1(0),
user2(0),
user3(0),
......@@ -46,6 +50,70 @@ void CGalaxySpriteObject::setupGalaxyObjectOnMap(const size_t ActionBaseOffset,
exists = false;
}
/**
* Some Physics
*/
void CGalaxySpriteObject::performPhysAccelHor( const int accX, const int velLimit )
{
bool isNegative = (xinertia < 0);
xinertia += accX;
if( xinertia != isNegative )
{
isNegative = (xinertia < 0);
xDirection = isNegative?-1:1;
}
if(xinertia < 0)
{
if( xinertia < -velLimit )
xinertia = -velLimit;
}
else
{
if( xinertia > velLimit )
xinertia = velLimit;
}
}
void CGalaxySpriteObject::performPhysDampHorz()
{
if (xinertia < 0)
{
xinertia++;
}
else if (xinertia > 0)
{
xinertia--;
}
}
void CGalaxySpriteObject::performGravityLow()
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
processFallPhysics(Physics.fallspeed_increase/4);
}
void CGalaxySpriteObject::performGravityMid()
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
processFallPhysics(3*Physics.fallspeed_increase/4);
}
void CGalaxySpriteObject::performGravityHigh()
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
processFallPhysics(Physics.fallspeed_increase);
}
/**
* processes falling of an object. Can be player or any other foe
*/
......
......@@ -18,6 +18,12 @@ public:
void setupGalaxyObjectOnMap(const size_t ActionBaseOffset = 0x0,
const size_t ActionNumber = 0x0 );
void performPhysAccelHor( const int accX, const int velLimit );
void performPhysDampHorz();
void performGravityLow();
void performGravityMid();
void performGravityHigh();
void processFalling();
int checkSolidU(int x1, int x2, int y1, const bool push_mode=false );
......@@ -41,6 +47,10 @@ public:
int nextX;
int nextY;
//TileInfo for surrounding tiles.
int topTI, bottomTI, leftTI, rightTI;
int user1;
int user2;
int user3;
......
This diff is collapsed.
......@@ -77,6 +77,7 @@ public:
CInventory &l_Inventory, stCheat &Cheatmode);
void prepareToShoot();
/**
* \brief handles the input when keen standing on ground.
*/
......@@ -99,6 +100,11 @@ public:
*/
void centerView();
/**
* Input handles
*/
/**
* \description This is the main process cycle
*/
......@@ -170,6 +176,13 @@ public:
/**
* \brief Checks if Keen must fall.
*/
void verifyFalling();
/**
* \description Simple process called while Keen is falling down
*/
......@@ -188,8 +201,14 @@ public:
*/
void shootInAir();
void verifyJumpAndFall();
void processJumping();
void processPogoCommon();
void processPogoBounce();
void processPogo();
void processLooking();
......@@ -215,12 +234,19 @@ public:
/**
* This function will ensure that Keen keeps ducking
*/
void processPressDucking();
void processLookingDown();
/**
* This function will do the cycle when Keen is on the pole
*/
void processPoleClimbing();
void performPoleHandleInput();
void processPoleClimbingSit();
void processPoleClimbingUp();
void processPoleClimbingDown();
void processExiting();
......
......@@ -14,8 +14,8 @@ namespace galaxy
const int A_MUSHROOM_BOUNCE = 0;
const int MUSHROOM_LOW_INERTIA = 60;
const int MUSHROOM_HIGH_INERTIA = 150;
const int MUSHROOM_LOW_INERTIA = 85;
const int MUSHROOM_HIGH_INERTIA = 212;
CMadMushroom::CMadMushroom(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y) :
CGalaxySpriteObject(pmap, foeID, x, y),
......@@ -68,7 +68,7 @@ void CMadMushroom::getTouchedBy(CSpriteObject &theObject)
void CMadMushroom::process()
{
processFalling();
performGravityMid();
performCollisions();
......
......@@ -231,6 +231,18 @@ void CTimer::TimeToDelay( void )
}
}
int CTimer::getTicksPerFrame()
{
int ratio = m_LogicRate/m_FrameRate;
if(ratio < 1)
ratio = 1;
return ratio;
}
//////////////////////////////////////////////////////////
// Those are for measuring the time in the game itself. //
//////////////////////////////////////////////////////////
......
......@@ -52,6 +52,9 @@ public:
int getLogicPerSec( void ) { return m_LPS; }
int getFramesPerSec( void ) { return m_FPS; }
int getTicksPerFrame();
Uint32 getTicks() { return timerTicks(); }
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment