SBSPSS/source/platform/praft.cpp

146 lines
3.1 KiB
C++
Raw Normal View History

2001-05-04 16:48:40 +02:00
/*=========================================================================
praft.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PRAFT_H__
#include "platform\praft.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRaftPlatform::postInit()
{
2001-05-05 15:54:34 +02:00
CNpcPlatform::postInit();
2001-05-04 16:48:40 +02:00
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
m_isActivated = false;
2001-05-09 18:52:22 +02:00
m_isSinking = false;
2001-05-04 21:26:04 +02:00
sBBox boundingBox = m_modelGfx->GetBBox();
2001-05-10 21:22:34 +02:00
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), PLATFORMCOLLISIONHEIGHT + ( boundingBox.YMax - boundingBox.YMin ) );
2001-05-04 21:26:04 +02:00
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) - 16 );
2001-05-04 16:48:40 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRaftPlatform::processMovement( int _frames )
{
2001-05-09 18:52:22 +02:00
s32 groundHeight;
s32 maxHeight = 20;
s32 distX, distY;
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
s32 moveX = 0;
s32 moveY = 0;
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
if ( m_isActivated )
{
if ( m_isSinking )
{
Pos.vy += _frames;
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy - 32 );
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
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;
}
2001-05-04 16:48:40 +02:00
}
else
{
2001-05-09 18:52:22 +02:00
// ignore y component of waypoint, since we are stuck to the ground
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
bool pathComplete;
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading );
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
if ( pathComplete )
{
m_isSinking = true;
2001-05-04 16:48:40 +02:00
}
else
{
2001-05-09 18:52:22 +02:00
// check for collision
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
distX = distX / abs( distX );
2001-05-04 16:48:40 +02:00
2001-05-09 23:27:23 +02:00
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( distX * m_speed * _frames ), Pos.vy ) < -maxHeight )
2001-05-04 16:48:40 +02:00
{
2001-05-09 18:52:22 +02:00
// there is an obstacle in the way, increment the path point (hopefully this will resolve the problem)
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
m_npcPath.incPath();
2001-05-04 16:48:40 +02:00
}
else
{
2001-05-09 18:52:22 +02:00
// 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
2001-05-09 23:27:23 +02:00
moveX = distX * m_speed * _frames;
2001-05-09 18:52:22 +02:00
moveY = groundHeight;
}
else
{
// fall
2001-05-04 16:48:40 +02:00
2001-05-09 18:52:22 +02:00
moveY = yMovement;
}
2001-05-04 16:48:40 +02:00
}
}
2001-05-09 18:52:22 +02:00
Pos.vx += moveX;
Pos.vy += moveY;
}
2001-05-04 16:48:40 +02:00
}
else
{
2001-05-09 18:52:22 +02:00
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
Pos.vy += moveY;
2001-05-04 16:48:40 +02:00
if ( m_contact )
{
m_isActivated = true;
}
}
}