SBSPSS/source/platform/praft.cpp

247 lines
4.6 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-06-25 15:53:02 +02:00
moveX = distX * m_speed * _frames;
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
2001-08-02 20:54:55 +02:00
2001-06-08 18:08:18 +02:00
DVECTOR testPos1, testPos2;
testPos1 = testPos2 = Pos;
2001-08-02 20:54:55 +02:00
testPos1.vx -= 10;
testPos2.vx += 10;
2001-06-08 18:08:18 +02:00
2001-06-09 16:42:12 +02:00
s16 heightDiff;
2001-08-02 20:54:55 +02:00
bool levelOff = false;
2001-06-09 16:42:12 +02:00
2001-08-02 20:54:55 +02:00
heightDiff = CGameScene::getCollision()->getHeightFromGround( testPos1.vx, testPos1.vy, 16 );
2001-06-09 16:42:12 +02:00
2001-08-02 20:54:55 +02:00
if ( heightDiff == 16 )
2001-06-09 16:42:12 +02:00
{
2001-08-02 20:54:55 +02:00
levelOff = true;
2001-06-09 16:42:12 +02:00
}
testPos1.vy += heightDiff;
2001-08-02 20:54:55 +02:00
heightDiff = CGameScene::getCollision()->getHeightFromGround( testPos2.vx, testPos2.vy, 16 );
2001-06-09 16:42:12 +02:00
2001-08-02 20:54:55 +02:00
if ( heightDiff == 16 )
2001-06-09 16:42:12 +02:00
{
2001-08-02 20:54:55 +02:00
levelOff = true;
2001-06-09 16:42:12 +02:00
}
testPos2.vy += heightDiff;
2001-06-08 18:08:18 +02:00
2001-08-02 20:54:55 +02:00
s16 heading;
if ( levelOff )
{
heading = getCollisionAngle();
if ( heading )
{
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, 56 );
if ( groundHeight < 32 && groundHeight > 4 )
{
int reverseAngle = -heading;
int maxRotate = 32 * _frames;
2001-06-08 18:08:18 +02:00
2001-08-02 20:54:55 +02:00
if ( reverseAngle > maxRotate )
{
reverseAngle = maxRotate;
}
else if ( reverseAngle < -maxRotate )
{
reverseAngle = -maxRotate;
}
heading += reverseAngle;
}
}
}
else
{
s32 xDist = testPos2.vx - testPos1.vx;
s32 yDist = testPos2.vy - testPos1.vy;
heading = ratan2( yDist, xDist );
}
2001-06-08 18:08:18 +02:00
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);
}
}
}