2001-04-24 16:00:16 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
hpendulm.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __HAZARD_HPENDULM_H__
|
|
|
|
#include "hazard\hpendulm.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-01 15:28:11 +02:00
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-24 16:00:16 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcPendulumHazard::init()
|
|
|
|
{
|
|
|
|
CNpcHazard::init();
|
|
|
|
|
|
|
|
m_extendDir = EXTEND_LEFT;
|
|
|
|
m_extension = 0;
|
|
|
|
m_heading = 1024;
|
2001-04-24 21:14:52 +02:00
|
|
|
m_length = 200;
|
2001-04-24 16:00:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-05-01 15:28:11 +02:00
|
|
|
void CNpcPendulumHazard::setWaypoints( sThingHazard *ThisHazard )
|
|
|
|
{
|
|
|
|
int pointNum;
|
|
|
|
|
|
|
|
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
|
|
|
|
|
|
|
|
u16 newXPos, newYPos;
|
|
|
|
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
|
|
|
DVECTOR startPos;
|
|
|
|
startPos.vx = newXPos << 4;
|
|
|
|
startPos.vy = newYPos << 4;
|
|
|
|
|
|
|
|
if ( ThisHazard->PointCount > 1 )
|
|
|
|
{
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
|
|
|
DVECTOR pivotPos;
|
|
|
|
pivotPos.vx = newXPos << 4;
|
|
|
|
pivotPos.vy = newYPos << 4;
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
Pos = pivotPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pos = startPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_base = Pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-04-24 16:00:16 +02:00
|
|
|
void CNpcPendulumHazard::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
if ( m_extendDir == EXTEND_LEFT )
|
|
|
|
{
|
2001-05-01 15:28:11 +02:00
|
|
|
if ( m_extension > m_maxExtension )
|
2001-04-24 16:00:16 +02:00
|
|
|
{
|
|
|
|
m_extendDir = EXTEND_RIGHT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_extension += _frames << 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-01 15:28:11 +02:00
|
|
|
if ( m_extension < -m_maxExtension )
|
2001-04-24 16:00:16 +02:00
|
|
|
{
|
|
|
|
m_extendDir = EXTEND_LEFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_extension -= _frames << 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-24 21:14:52 +02:00
|
|
|
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 );
|
2001-04-24 16:00:16 +02:00
|
|
|
}
|