2001-04-23 18:29:19 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
plinear.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PLINEAR_H__
|
|
|
|
#include "platform\plinear.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcLinearPlatform::postInit()
|
|
|
|
{
|
|
|
|
m_npcPath.setPathType( CNpcPath::PONG_PATH );
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcLinearPlatform::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
s32 moveX = 0, moveY = 0;
|
|
|
|
s32 moveDist = 0;
|
|
|
|
|
|
|
|
bool pathComplete;
|
|
|
|
bool waypointChange;
|
|
|
|
|
|
|
|
s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange );
|
|
|
|
|
|
|
|
if ( !pathComplete )
|
|
|
|
{
|
|
|
|
s16 decDir, incDir;
|
|
|
|
s16 maxTurnRate = m_data[m_type].turnSpeed;
|
|
|
|
|
|
|
|
decDir = m_heading - headingToTarget;
|
|
|
|
|
|
|
|
if ( decDir < 0 )
|
|
|
|
{
|
|
|
|
decDir += ONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
incDir = headingToTarget - m_heading;
|
|
|
|
|
|
|
|
if ( incDir < 0 )
|
|
|
|
{
|
|
|
|
incDir += ONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( decDir < incDir )
|
|
|
|
{
|
2001-04-23 22:40:13 +02:00
|
|
|
moveDist = -decDir;
|
2001-04-23 18:29:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-23 22:40:13 +02:00
|
|
|
moveDist = incDir;
|
2001-04-23 18:29:19 +02:00
|
|
|
}
|
|
|
|
|
2001-04-23 22:40:13 +02:00
|
|
|
if ( moveDist < -maxTurnRate )
|
2001-04-23 18:29:19 +02:00
|
|
|
{
|
2001-04-23 22:40:13 +02:00
|
|
|
moveDist = -maxTurnRate;
|
2001-04-23 18:29:19 +02:00
|
|
|
}
|
2001-04-23 22:40:13 +02:00
|
|
|
else if ( moveDist > maxTurnRate )
|
2001-04-23 18:29:19 +02:00
|
|
|
{
|
2001-04-23 22:40:13 +02:00
|
|
|
moveDist = maxTurnRate;
|
2001-04-23 18:29:19 +02:00
|
|
|
}
|
|
|
|
|
2001-04-23 22:40:13 +02:00
|
|
|
m_heading += moveDist;
|
2001-04-23 18:29:19 +02:00
|
|
|
m_heading &= 4095;
|
|
|
|
|
|
|
|
s32 preShiftX = _frames * m_data[m_type].speed * rcos( m_heading );
|
|
|
|
s32 preShiftY = _frames * m_data[m_type].speed * rsin( m_heading );
|
|
|
|
|
2001-04-23 22:40:13 +02:00
|
|
|
moveX = preShiftX >> 12;
|
|
|
|
if ( !moveX && preShiftX )
|
2001-04-23 18:29:19 +02:00
|
|
|
{
|
2001-04-23 22:40:13 +02:00
|
|
|
moveX = preShiftX / abs( preShiftX );
|
2001-04-23 18:29:19 +02:00
|
|
|
}
|
|
|
|
|
2001-04-23 22:40:13 +02:00
|
|
|
moveY = preShiftY >> 12;
|
|
|
|
if ( !moveY && preShiftY )
|
2001-04-23 18:29:19 +02:00
|
|
|
{
|
2001-04-23 22:40:13 +02:00
|
|
|
moveY = preShiftY / abs( preShiftY );
|
2001-04-23 18:29:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//processGroundCollisionReverse( moveX, moveY );
|
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
|
|
|
}
|