SBSPSS/source/hazard/hsaw.cpp

115 lines
2.0 KiB
C++
Raw Normal View History

2001-04-24 16:27:23 +02:00
/*=========================================================================
hsaw.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HSAW_H__
#include "hazard\hsaw.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSawbladeHazard::init()
{
CNpcHazard::init();
DVECTOR newPos;
Pos.vx = 100;
Pos.vy = 100;
m_base = Pos;
newPos.vx = 300;
newPos.vy = 100;
2001-05-30 00:07:28 +02:00
//m_npcPath.addWaypoint( newPos );
2001-04-24 16:27:23 +02:00
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSawbladeHazard::processMovement( int _frames )
{
bool pathComplete;
bool waypointChange;
2001-04-28 19:39:24 +02:00
s32 xDist, yDist;
2001-04-24 16:27:23 +02:00
2001-04-28 19:39:24 +02:00
s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange, &xDist, &yDist );
2001-04-24 16:27:23 +02:00
if ( !pathComplete )
{
s16 decDir, incDir, moveDist;
s16 maxTurnRate = 2048;
s32 moveX, moveY;
decDir = m_heading - headingToTarget;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToTarget - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = -decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist < -maxTurnRate )
{
moveDist = -maxTurnRate;
}
else if ( moveDist > maxTurnRate )
{
moveDist = maxTurnRate;
}
m_heading += moveDist;
m_heading &= 4095;
s32 preShiftX = _frames * 3 * rcos( m_heading );
s32 preShiftY = _frames * 3 * rsin( m_heading );
moveX = preShiftX >> 12;
if ( !moveX && preShiftX )
{
moveX = preShiftX / abs( preShiftX );
}
moveY = preShiftY >> 12;
if ( !moveY && preShiftY )
{
moveY = preShiftY / abs( preShiftY );
}
Pos.vx += moveX;
Pos.vy += moveY;
}
else
{
m_npcPath.resetPath();
Pos = m_base;
}
}