This commit is contained in:
parent
2cc37a2eab
commit
50e5b9af4d
114
source/enemy/ngeneric.cpp
Normal file
114
source/enemy/ngeneric.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
/*=========================================================================
|
||||
|
||||
ngeneric.cpp
|
||||
|
||||
Author: CRB
|
||||
Created:
|
||||
Project: Spongebob
|
||||
Purpose:
|
||||
|
||||
Copyright (c) 2000 Climax Development Ltd
|
||||
|
||||
===========================================================================*/
|
||||
|
||||
#ifndef __ENEMY_NPC_H__
|
||||
#include "enemy\npc.h"
|
||||
#endif
|
||||
|
||||
#ifndef __GAME_GAME_H__
|
||||
#include "game\game.h"
|
||||
#endif
|
||||
|
||||
#ifndef __PLAYER_PLAYER_H__
|
||||
#include "player\player.h"
|
||||
#endif
|
||||
|
||||
|
||||
void CNpc::processCloseGenericUserSeek( int _frames )
|
||||
{
|
||||
s32 moveX = 0, moveY = 0;
|
||||
|
||||
s16 moveDist = 0;
|
||||
|
||||
s32 moveVel = 0;
|
||||
|
||||
CPlayer *player = GameScene.getPlayer();
|
||||
|
||||
DVECTOR playerPos = player->getPos();
|
||||
|
||||
s32 xDist, yDist;
|
||||
s32 xDistSqr, yDistSqr;
|
||||
|
||||
xDist = playerPos.vx - this->Pos.vx;
|
||||
xDistSqr = xDist * xDist;
|
||||
|
||||
yDist = playerPos.vy - this->Pos.vy;
|
||||
yDistSqr = yDist * yDist;
|
||||
|
||||
//if ( xDistSqr + yDistSqr > 22500 )
|
||||
//{
|
||||
//this->m_controlFunc = NPC_CONTROL_MOVEMENT;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
bool pathComplete;
|
||||
|
||||
s16 headingToPlayer = ratan2( yDist, xDist );
|
||||
s16 maxTurnRate = m_data[m_type].turnSpeed;
|
||||
s16 decDir, incDir;
|
||||
|
||||
decDir = m_heading - headingToPlayer;
|
||||
|
||||
if ( decDir < 0 )
|
||||
{
|
||||
decDir += ONE;
|
||||
}
|
||||
|
||||
incDir = headingToPlayer - 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 = m_heading % ONE;
|
||||
|
||||
s32 preShiftX = _frames * m_data[m_type].speed * rcos( m_heading );
|
||||
s32 preShiftY = _frames * m_data[m_type].speed * 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user