This commit is contained in:
parent
895fbfd27b
commit
dedfdcf295
7 changed files with 114 additions and 6 deletions
|
@ -99,6 +99,75 @@ void CNpc::processGenericGetUserDist( int _frames, s32 *distX, s32 *distY )
|
|||
*distY = playerPos.vy - this->Pos.vy;
|
||||
}
|
||||
|
||||
void CNpc::processGenericFixedPathWalk( int _frames, s32 *moveX, s32 *moveY )
|
||||
{
|
||||
s32 maxHeight = 10;
|
||||
s32 distX, distY;
|
||||
s32 fallSpeed = 5;
|
||||
s8 yMovement = fallSpeed * _frames;
|
||||
s32 groundHeight;
|
||||
|
||||
*moveX = 0;
|
||||
*moveY = 0;
|
||||
|
||||
// ignore y component of waypoint, since we are stuck to the ground
|
||||
|
||||
if ( m_npcPath.think2D( Pos, &distX, &distY ) )
|
||||
{
|
||||
// path has finished, waypoint has changed, or there are no waypoints - do not move horizontally
|
||||
|
||||
// check for vertical movement
|
||||
|
||||
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
|
||||
|
||||
*moveY = groundHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
// fall
|
||||
|
||||
*moveY = yMovement;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// check for collision
|
||||
|
||||
distX = distX / abs( distX );
|
||||
|
||||
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( distX * m_data[m_type].speed * _frames ), Pos.vy ) < -maxHeight )
|
||||
{
|
||||
// there is an obstacle in the way, increment the path point (hopefully this will resolve the problem)
|
||||
|
||||
m_npcPath.incPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
// check for vertical movement
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CNpc::isCollisionWithGround()
|
||||
{
|
||||
ASSERT(m_layerCollision);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue