This commit is contained in:
Charles 2001-01-22 17:44:58 +00:00
parent 8a530eec6f
commit b512e83b0b
3 changed files with 123 additions and 7 deletions

View File

@ -23,6 +23,110 @@
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
void CNpc::processCloseAnemone1Attack( int _frames )
{
s32 moveX, moveY;
s16 decDir, incDir, moveDist;
CPlayer *player = GameScene.getPlayer();
DVECTOR playerPos = player->getPos();
s32 xDist, yDist;
s16 maxTurnRate = m_data[m_type].turnSpeed;
bool withinRange = false;
xDist = playerPos.vx - this->Pos.vx;
yDist = playerPos.vy - this->Pos.vy;
s16 headingToPlayer = ratan2( yDist, xDist );
decDir = m_baseHeading - headingToPlayer;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToPlayer - m_baseHeading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
// check user is within 45 degrees either way
if ( moveDist < 512 )
{
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;
}
else
{
withinRange = true;
}
m_heading += moveDist;
m_heading = m_heading % ONE;
if ( withinRange )
{
// can fire
if ( m_timerTimer <= 0 )
{
CProjectile *projectile;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos, m_heading );
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerTimer = GameState::getOneSecondInFrames();
}
}
}
}
void CNpc::processCloseAnemone2Attack( int _frames )
{

View File

@ -106,10 +106,10 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] =
{ // NPC_ANEMONE_1
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_SENSOR_ANEMONE_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_CLOSE_ANEMONE_1_ATTACK,
NPC_TIMER_NONE,
false,
0,
@ -383,9 +383,9 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] =
void CNpc::init()
{
m_type = NPC_ANEMONE_2;
m_type = NPC_ANEMONE_1;
m_heading = m_baseHeading = 3072;
m_heading = m_baseHeading = 0;
m_movementTimer = 0;
m_timerTimer = 0;
m_velocity = 0;
@ -700,7 +700,7 @@ bool CNpc::processSensor()
case NPC_SENSOR_ANEMONE_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
if ( xDistSqr + yDistSqr < 40000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
@ -897,9 +897,16 @@ void CNpc::processClose(int _frames)
break;
case NPC_CLOSE_ANEMONE_1_ATTACK:
processCloseAnemone1Attack( _frames );
break;
case NPC_CLOSE_ANEMONE_2_ATTACK:
processCloseAnemone2Attack( _frames );
break;
default:
break;
}
@ -911,6 +918,11 @@ void CNpc::processCollision()
void CNpc::processTimer(int _frames)
{
if ( m_timerTimer > 0 )
{
this->m_timerTimer -= _frames;
}
switch( m_timerFunc )
{
case NPC_TIMER_NONE:
@ -921,8 +933,6 @@ void CNpc::processTimer(int _frames)
case NPC_TIMER_EVADE_DONE:
case NPC_TIMER_ATTACK_DONE:
{
this->m_timerTimer -= _frames;
if ( m_timerTimer <= 0 )
{
this->m_timerFunc = NPC_TIMER_NONE;

View File

@ -107,6 +107,7 @@ protected:
NPC_CLOSE_GHOST_PIRATE_ATTACK,
NPC_CLOSE_SHARK_MAN_ATTACK,
NPC_CLOSE_GENERIC_USER_SEEK,
NPC_CLOSE_ANEMONE_1_ATTACK,
NPC_CLOSE_ANEMONE_2_ATTACK,
};
@ -192,6 +193,7 @@ protected:
// anemone functions
void processCloseAnemone1Attack( int _frames );
void processCloseAnemone2Attack( int _frames );
// data