SBSPSS/source/enemy/nsklfish.cpp

158 lines
2.9 KiB
C++
Raw Normal View History

2001-02-12 16:37:31 +01:00
/*=========================================================================
nsklfish.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
2001-04-20 16:48:15 +02:00
#ifndef __ENEMY_NSKLFISH_H__
#include "enemy\nsklfish.h"
#endif
2001-02-12 16:37:31 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-04-02 17:52:09 +02:00
#ifndef __ANIM_SKELETALFISH_HEADER__
#include <ACTOR_SKELETALFISH_ANIM.h>
#endif
2001-02-12 16:37:31 +01:00
2001-05-22 17:15:08 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CNpcSkeletalFishEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr + playerYDistSqr < 10000 )
{
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
if ( abs( xDistWaypoint ) >= abs( playerXDist ) )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_velocity = 0;
m_chargeTime = 0;
m_sensorFunc = NPC_SENSOR_NONE;
return( true );
}
else
{
return( false );
}
}
else
{
return( false );
}
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 16:48:15 +02:00
void CNpcSkeletalFishEnemy::processClose( int _frames )
2001-02-12 16:37:31 +01:00
{
s32 moveX, moveY;
s16 decDir, incDir, moveDist;
2001-05-22 17:15:08 +02:00
if ( m_chargeTime > GameState::getOneSecondInFrames() )
{
if ( m_velocity < SKELETAL_FISH_CHARGE_VELOCITY )
{
m_velocity++;
}
}
else
{
m_chargeTime += _frames;
}
2001-02-12 16:37:31 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_SKELETALFISH_SWIM;
m_frame = 0;
}
2001-02-12 16:37:31 +01:00
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;
}
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
2001-05-22 17:15:08 +02:00
if ( ( playerXDistSqr + playerYDistSqr > 100 ) && abs( xDistWaypoint ) >= abs( playerXDist ) )
2001-02-12 16:37:31 +01:00
{
// continue charge
processGenericGotoTarget( _frames, playerXDist, playerYDist, m_velocity );
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
2001-05-22 17:15:08 +02:00
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_chargeTime = m_timerTimer = GameState::getOneSecondInFrames();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
s32 CNpcSkeletalFishEnemy::getFrameShift( int _frames )
{
if ( m_chargeTime < GameState::getOneSecondInFrames() )
{
return( _frames << 8 );
}
else
{
return( ( _frames << 8 ) >> 2 );
2001-02-12 16:37:31 +01:00
}
}