This commit is contained in:
Charles 2001-05-09 16:52:22 +00:00
parent 5239cda7b0
commit 5bd31594fd
2 changed files with 70 additions and 38 deletions

View file

@ -33,6 +33,7 @@ void CNpcRaftPlatform::postInit()
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH ); m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
m_isActivated = false; m_isActivated = false;
m_isSinking = false;
sBBox boundingBox = m_modelGfx->GetBBox(); sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) ); setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
@ -43,70 +44,100 @@ void CNpcRaftPlatform::postInit()
void CNpcRaftPlatform::processMovement( int _frames ) void CNpcRaftPlatform::processMovement( int _frames )
{ {
s32 groundHeight;
s32 maxHeight = 20;
s32 distX, distY;
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
s32 moveX = 0;
s32 moveY = 0;
if ( m_isActivated ) if ( m_isActivated )
{ {
s32 maxHeight = 20; if ( m_isSinking )
s32 distX, distY;
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
s32 groundHeight;
s32 moveX = 0;
s32 moveY = 0;
// ignore y component of waypoint, since we are stuck to the ground
bool pathComplete;
m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading );
if ( pathComplete )
{ {
m_isActive = false; Pos.vy += _frames;
m_timer = getRnd() % ( 4 * GameState::getOneSecondInFrames() );
m_timerType = NPC_PLATFORM_TIMER_RESPAWN; groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy - 32 );
m_isActivated = false;
m_npcPath.resetPath(); if ( groundHeight <= 0 )
{
m_isActive = false;
m_timer = getRnd() % ( 2 * GameState::getOneSecondInFrames() );
m_timerType = NPC_PLATFORM_TIMER_RESPAWN;
m_isActivated = false;
m_npcPath.resetPath();
m_isSinking = false;
}
} }
else else
{ {
// check for collision // ignore y component of waypoint, since we are stuck to the ground
distX = distX / abs( distX ); bool pathComplete;
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( distX * m_data[m_type].speed * _frames ), Pos.vy ) < -maxHeight ) m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading );
if ( pathComplete )
{ {
// there is an obstacle in the way, increment the path point (hopefully this will resolve the problem) m_isSinking = true;
m_npcPath.incPath();
} }
else else
{ {
// check for vertical movement // check for collision
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 ); distX = distX / abs( distX );
if ( groundHeight <= yMovement ) if ( m_layerCollision->getHeightFromGround( Pos.vx + ( distX * m_data[m_type].speed * _frames ), Pos.vy ) < -maxHeight )
{ {
// groundHeight <= yMovement indicates either just above ground or on or below ground // there is an obstacle in the way, increment the path point (hopefully this will resolve the problem)
moveX = distX * m_data[m_type].speed * _frames; m_npcPath.incPath();
moveY = groundHeight;
} }
else else
{ {
// fall // check for vertical movement
moveY = yMovement; groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveX = distX * m_data[m_type].speed * _frames;
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
} }
} }
}
Pos.vx += moveX; Pos.vx += moveX;
Pos.vy += moveY; Pos.vy += moveY;
}
} }
else else
{ {
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
Pos.vy += moveY;
if ( m_contact ) if ( m_contact )
{ {
m_isActivated = true; m_isActivated = true;

View file

@ -26,6 +26,7 @@ protected:
virtual void processMovement( int _frames ); virtual void processMovement( int _frames );
u8 m_isActivated; u8 m_isActivated;
u8 m_isSinking;
}; };
#endif #endif