SBSPSS/source/platform/praft.cpp

228 lines
4.4 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 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-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->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-25 20:43:47 +02:00
if ( CGameScene::getCollision()->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
2001-05-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-05-09 18:52:22 +02:00
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-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-05-09 18:52:22 +02:00
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;
}
}
2001-06-08 18:08:18 +02:00
// sort out rotation
DVECTOR testPos1, testPos2;
testPos1 = testPos2 = Pos;
2001-06-09 16:42:12 +02:00
testPos1.vx -= 20;
testPos2.vx += 20;
2001-06-08 18:08:18 +02:00
2001-06-09 16:42:12 +02:00
s16 heightDiff;
heightDiff = CGameScene::getCollision()->getHeightFromGround( testPos1.vx, testPos1.vy, 16 );
if ( heightDiff == 16 )
{
return;
}
testPos1.vy += heightDiff;
heightDiff = CGameScene::getCollision()->getHeightFromGround( testPos2.vx, testPos2.vy, 16 );
if ( heightDiff == 16 )
{
return;
}
testPos2.vy += heightDiff;
2001-06-08 18:08:18 +02:00
s32 xDist = testPos2.vx - testPos1.vx;
s32 yDist = testPos2.vy - testPos1.vy;
s16 heading = ratan2( yDist, xDist );
2001-06-09 16:42:12 +02:00
/*if ( heading > 512 )
{
heading = 512;
}
else if ( heading < -512 )
{
heading = -512;
}*/
2001-06-08 18:08:18 +02:00
setCollisionAngle( heading );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRaftPlatform::render()
{
if ( m_isActive )
{
CPlatformThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = getCollisionAngle();
VECTOR scale;
scale.vx = ONE;
scale.vy = ONE;
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
}
}
}
2001-06-09 16:42:12 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-19 22:07:57 +02:00
/*const CRECT *CNpcRaftPlatform::getThinkBBox()
2001-06-09 16:42:12 +02:00
{
CRECT objThinkBox = getCollisionArea();
sBBox &thinkBBox = CThingManager::getThinkBBox();
objThinkBox.x1 = thinkBBox.XMin;
objThinkBox.x2 = thinkBBox.XMax;
objThinkBox.y1 = thinkBBox.YMin;
objThinkBox.y2 = thinkBBox.YMax;
return &objThinkBox;
2001-06-19 22:07:57 +02:00
}*/