2001-01-22 15:21:37 +01:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2001-01-25 16:45:15 +01:00
|
|
|
void CNpc::processGenericGotoTarget( int _frames, s32 xDist, s32 yDist, s32 speed )
|
|
|
|
{
|
|
|
|
s16 decDir, incDir, moveDist;
|
|
|
|
s32 moveX, moveY;
|
|
|
|
s16 headingToTarget = ratan2( yDist, xDist );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
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 * speed * rcos( m_heading );
|
|
|
|
s32 preShiftY = _frames * 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;
|
|
|
|
}
|
|
|
|
|
2001-02-06 20:29:35 +01:00
|
|
|
void CNpc::processGenericGetUserDist( int _frames, s32 *distX, s32 *distY )
|
2001-01-22 15:21:37 +01:00
|
|
|
{
|
|
|
|
s32 moveX = 0, moveY = 0;
|
|
|
|
|
|
|
|
s16 moveDist = 0;
|
|
|
|
|
|
|
|
s32 moveVel = 0;
|
|
|
|
|
|
|
|
CPlayer *player = GameScene.getPlayer();
|
|
|
|
|
|
|
|
DVECTOR playerPos = player->getPos();
|
|
|
|
|
2001-02-06 20:29:35 +01:00
|
|
|
*distX = playerPos.vx - this->Pos.vx;
|
|
|
|
*distY = playerPos.vy - this->Pos.vy;
|
2001-01-22 15:21:37 +01:00
|
|
|
}
|
2001-02-12 18:52:04 +01:00
|
|
|
|
|
|
|
bool CNpc::isCollisionWithGround()
|
|
|
|
{
|
|
|
|
ASSERT(m_layerCollision);
|
2001-02-12 21:03:44 +01:00
|
|
|
return m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + 1 ) >>4 );
|
2001-02-12 18:52:04 +01:00
|
|
|
}
|