SBSPSS/source/platform/ppendulm.cpp

107 lines
2.2 KiB
C++
Raw Normal View History

2001-04-24 23:48:20 +02:00
/*=========================================================================
ppendulm.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PPENDULM_H__
#include "platform\ppendulm.h"
#endif
2001-04-25 00:05:29 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 23:48:20 +02:00
void CNpcPendulumPlatform::postInit()
{
m_extendDir = EXTEND_LEFT;
m_extension = 0;
m_heading = 1024;
}
2001-04-25 00:05:29 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcPendulumPlatform::setWaypoints( sThingPlatform *ThisPlatform )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisPlatform,sizeof(sThingPlatform));
2001-04-25 00:58:43 +02:00
u16 newXPos, newYPos;
2001-04-25 00:05:29 +02:00
newXPos = (u16) *PntList;
PntList++;
2001-04-25 00:58:43 +02:00
newYPos = (u16) *PntList;
2001-04-25 00:05:29 +02:00
PntList++;
2001-04-25 21:22:15 +02:00
DVECTOR startPos;
2001-04-25 00:05:29 +02:00
startPos.vx = newXPos << 4;
startPos.vy = newYPos << 4;
if ( ThisPlatform->PointCount > 1 )
{
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
2001-04-25 21:22:15 +02:00
DVECTOR pivotPos;
2001-04-25 00:58:43 +02:00
pivotPos.vx = newXPos << 4;
pivotPos.vy = newYPos << 4;
2001-04-26 18:07:25 +02:00
s32 xDist = startPos.vx - pivotPos.vx;
s32 yDist = startPos.vy - pivotPos.vy;
m_maxExtension = 1024 - ratan2( abs( yDist ), abs( xDist ) );
m_length = isqrt2( ( xDist * xDist ) + ( yDist * yDist ) );
2001-04-25 00:58:43 +02:00
init( pivotPos );
}
else
{
init( startPos );
2001-04-25 00:05:29 +02:00
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 23:48:20 +02:00
void CNpcPendulumPlatform::processMovement( int _frames )
{
if ( m_extendDir == EXTEND_LEFT )
{
2001-04-26 18:07:25 +02:00
if ( m_extension > m_maxExtension )
2001-04-24 23:48:20 +02:00
{
m_extendDir = EXTEND_RIGHT;
}
else
{
m_extension += _frames << 3;
}
}
else
{
2001-04-26 18:07:25 +02:00
if ( m_extension < -m_maxExtension )
2001-04-24 23:48:20 +02:00
{
m_extendDir = EXTEND_LEFT;
}
else
{
m_extension -= _frames << 3;
}
}
Pos.vx = m_base.vx + ( ( m_length * rcos( m_heading + m_extension ) ) >> 12 );
Pos.vy = m_base.vy + ( ( m_length * rsin( m_heading + m_extension ) ) >> 12 );
}