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()
|
|
|
|
{
|
2001-05-05 15:54:34 +02:00
|
|
|
CNpcPlatform::postInit();
|
|
|
|
|
2001-04-23 18:29:19 +02:00
|
|
|
m_npcPath.setPathType( CNpcPath::PONG_PATH );
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcLinearPlatform::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
s32 moveX = 0, moveY = 0;
|
|
|
|
s32 moveDist = 0;
|
2001-04-28 19:39:24 +02:00
|
|
|
s32 xDist, yDist;
|
2001-04-23 18:29:19 +02:00
|
|
|
|
|
|
|
bool pathComplete;
|
|
|
|
bool waypointChange;
|
|
|
|
|
2001-04-28 19:39:24 +02:00
|
|
|
s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange, &xDist, &yDist );
|
2001-04-23 18:29:19 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-05-09 23:27:23 +02:00
|
|
|
s32 preShiftX = _frames * m_speed * rcos( m_heading );
|
|
|
|
s32 preShiftY = _frames * m_speed * rsin( m_heading );
|
2001-04-23 18:29:19 +02:00
|
|
|
|
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-28 19:39:24 +02:00
|
|
|
if ( xDist > 0 )
|
|
|
|
{
|
|
|
|
if ( moveX > xDist )
|
|
|
|
{
|
|
|
|
moveX = xDist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( xDist < 0 )
|
|
|
|
{
|
|
|
|
if ( moveX < xDist )
|
|
|
|
{
|
|
|
|
moveX = xDist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moveX = 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-04-28 19:39:24 +02:00
|
|
|
if ( yDist > 0 )
|
|
|
|
{
|
|
|
|
if ( moveY > yDist )
|
|
|
|
{
|
|
|
|
moveY = yDist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( yDist < 0 )
|
|
|
|
{
|
|
|
|
if ( moveY < yDist )
|
|
|
|
{
|
|
|
|
moveY = yDist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moveY = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-23 18:29:19 +02:00
|
|
|
//processGroundCollisionReverse( moveX, moveY );
|
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
|
|
|
}
|