SBSPSS/source/enemy/nclam.cpp
Charles cb014a96f2
2001-04-20 14:48:15 +00:00

140 lines
2.3 KiB
C++

/*=========================================================================
nclam.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __ENEMY_NCLAM_H__
#include "enemy\nclam.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __ANIM_CLAM_HEADER__
#include <ACTOR_CLAM_ANIM.h>
#endif
bool CNpcClamEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr + playerYDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
m_movementTimer = GameState::getOneSecondInFrames() >> 3;
m_velocity = ( getRnd() % 6 ) + 1;
return( true );
}
else
{
return( false );
}
}
}
}
void CNpcJumpingClamEnemy::processClose( int _frames )
{
s32 velocity;
if ( m_extendDir == EXTEND_UP )
{
m_movementTimer -= _frames;
if ( m_movementTimer > 0 )
{
// extend
velocity = m_velocity * _frames;
m_extension += velocity;
Pos.vx += ( velocity * rcos( m_heading ) ) >> 12;
Pos.vy += ( velocity * rsin( m_heading ) ) >> 12;
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_CLAM_SIDESNAP;
m_frame = 0;
}
}
else
{
m_extendDir = EXTEND_DOWN;
}
}
else if ( m_extendDir == EXTEND_DOWN )
{
// retract
if ( m_extension > 0 )
{
velocity = -_frames;
if ( m_extension < _frames )
{
velocity = m_extension - _frames;
}
m_extension += velocity;
Pos.vx += ( velocity * rcos( m_heading ) ) >> 12;
Pos.vy += ( velocity * rsin( m_heading ) ) >> 12;
}
else
{
if ( !m_animPlaying )
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}
}
}
}
void CNpcStaticClamEnemy::processClose( int _frames )
{
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_CLAM_SIDESNAP;
m_frame = 0;
}
m_controlFunc = NPC_CONTROL_MOVEMENT;
}