2001-04-23 20:58:30 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
pcart.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PCART_H__
|
|
|
|
#include "platform\pcart.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-23 22:40:13 +02:00
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-08 20:57:00 +02:00
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-23 20:58:30 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcCartPlatform::postInit()
|
|
|
|
{
|
2001-05-05 15:54:34 +02:00
|
|
|
CNpcPlatform::postInit();
|
|
|
|
|
2001-05-04 18:20:10 +02:00
|
|
|
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
|
|
|
|
|
|
|
|
m_carSpeed = m_data[m_type].speed << 8;
|
2001-04-23 20:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcCartPlatform::processMovement( int _frames )
|
|
|
|
{
|
2001-05-04 18:20:10 +02:00
|
|
|
s32 fallSpeed = 2;
|
2001-04-23 20:58:30 +02:00
|
|
|
s8 yMovement = fallSpeed * _frames;
|
|
|
|
s32 distX, distY, heading;
|
|
|
|
s32 groundHeight;
|
|
|
|
s32 moveX = 0;
|
|
|
|
s32 moveY = 0;
|
|
|
|
|
|
|
|
bool pathComplete;
|
|
|
|
|
|
|
|
m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &heading );
|
|
|
|
|
2001-05-04 18:20:10 +02:00
|
|
|
if ( !pathComplete )
|
2001-04-23 20:58:30 +02:00
|
|
|
{
|
2001-05-04 18:20:10 +02:00
|
|
|
moveX = ( m_carSpeed >> 8 ) * _frames;
|
|
|
|
|
|
|
|
if ( heading == 2048 )
|
|
|
|
{
|
|
|
|
moveX = -moveX;
|
|
|
|
}
|
2001-04-23 20:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for vertical movement
|
|
|
|
|
2001-05-04 18:20:10 +02:00
|
|
|
s32 checkDist = yMovement + 50;
|
2001-04-23 20:58:30 +02:00
|
|
|
|
2001-05-04 18:20:10 +02:00
|
|
|
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx + moveX, Pos.vy, checkDist );
|
|
|
|
|
|
|
|
if ( groundHeight < checkDist )
|
2001-04-23 20:58:30 +02:00
|
|
|
{
|
|
|
|
// groundHeight <= yMovement indicates either just above ground or on or below ground
|
|
|
|
|
|
|
|
moveY = groundHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// fall
|
|
|
|
|
|
|
|
moveY = yMovement;
|
|
|
|
}
|
|
|
|
|
2001-05-04 18:20:10 +02:00
|
|
|
if ( moveY < 0 )
|
|
|
|
{
|
|
|
|
m_carSpeed -= 20;
|
|
|
|
|
|
|
|
if ( m_carSpeed < ( 2 << 8 ) )
|
|
|
|
{
|
|
|
|
m_carSpeed = ( 2 << 8 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( moveY > 0 )
|
|
|
|
{
|
|
|
|
m_carSpeed += 20;
|
|
|
|
|
|
|
|
if ( m_carSpeed > ( 6 << 8 ) )
|
|
|
|
{
|
|
|
|
m_carSpeed = ( 6 << 8 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-23 20:58:30 +02:00
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
2001-05-08 20:57:00 +02:00
|
|
|
|
|
|
|
// sort out draw rotation
|
|
|
|
|
|
|
|
DVECTOR testPos1, testPos2;
|
|
|
|
|
|
|
|
testPos1 = testPos2 = Pos;
|
|
|
|
testPos1.vx -= 10;
|
|
|
|
testPos2.vx += 10;
|
|
|
|
|
|
|
|
u8 sensorDist = 16;
|
|
|
|
|
|
|
|
s32 yDiff;
|
|
|
|
|
|
|
|
yDiff = m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, sensorDist + 1 );
|
|
|
|
|
|
|
|
if ( yDiff <= sensorDist )
|
|
|
|
{
|
|
|
|
// only use if there is ground present
|
|
|
|
|
|
|
|
testPos1.vy += yDiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
yDiff = m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, sensorDist + 1 );
|
|
|
|
|
|
|
|
if ( yDiff <= sensorDist )
|
|
|
|
{
|
|
|
|
// only use if there is ground present
|
|
|
|
|
|
|
|
testPos2.vy += yDiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 xDist = testPos2.vx - testPos1.vx;
|
|
|
|
s32 yDist = testPos2.vy - testPos1.vy;
|
|
|
|
|
|
|
|
heading = ratan2( yDist, xDist );
|
|
|
|
|
|
|
|
setCollisionAngle( heading );
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcCartPlatform::render()
|
|
|
|
{
|
|
|
|
if ( m_isActive )
|
|
|
|
{
|
|
|
|
CPlatformThing::render();
|
|
|
|
|
|
|
|
// Render
|
|
|
|
DVECTOR renderPos;
|
|
|
|
DVECTOR offset = CLevel::getCameraPos();
|
|
|
|
|
|
|
|
renderPos.vx = Pos.vx - offset.vx ;
|
|
|
|
renderPos.vy = Pos.vy - offset.vy ;
|
|
|
|
|
|
|
|
CRECT collisionRect = getCollisionArea();
|
|
|
|
collisionRect.x1 -= Pos.vx;
|
|
|
|
collisionRect.x2 -= Pos.vx;
|
|
|
|
collisionRect.y1 -= Pos.vy;
|
|
|
|
collisionRect.y2 -= Pos.vy;
|
|
|
|
|
|
|
|
if ( renderPos.vx + collisionRect.x2 >= 0 && renderPos.vx + collisionRect.x1 <= VidGetScrW() )
|
|
|
|
{
|
|
|
|
if ( renderPos.vy + collisionRect.y2 >= 0 && renderPos.vy + collisionRect.y1 <= VidGetScrH() )
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
#if defined (__USER_paul__) || defined (__USER_charles__)
|
|
|
|
DVECTOR size;
|
|
|
|
DVECTOR centre;
|
|
|
|
int halfLength;
|
|
|
|
int x1,y1,x2,y2;
|
|
|
|
|
|
|
|
centre=getCollisionCentre();
|
|
|
|
size=getCollisionSize();
|
|
|
|
halfLength=size.vx>>1;
|
|
|
|
|
|
|
|
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
|
|
|
|
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
|
|
|
|
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
|
|
|
|
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
|
|
|
|
|
|
|
|
centre.vx-=offset.vx;
|
|
|
|
centre.vy-=offset.vy;
|
|
|
|
x1+=centre.vx;
|
|
|
|
y1+=centre.vy;
|
|
|
|
x2+=centre.vx;
|
|
|
|
y2+=centre.vy;
|
|
|
|
|
|
|
|
DrawLine(x1,y1,x2,y2,0,255,0,0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|