SBSPSS/source/enemy/nocto.cpp

187 lines
3.3 KiB
C++
Raw Normal View History

2001-02-06 17:12:56 +01:00
/*=========================================================================
nocto.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_NOCTO_H__
#include "enemy\nocto.h"
#endif
2001-02-06 17:12:56 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-04-03 17:14:53 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __ANIM_BABYOCTOPUS_HEADER__
#include <ACTOR_BABYOCTOPUS_ANIM.h>
#endif
2001-02-06 17:12:56 +01:00
2001-04-20 16:48:15 +02:00
bool CNpcBabyOctopusEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr + playerYDistSqr < 400 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
return( true );
}
else
{
return( false );
}
}
}
}
void CNpcBabyOctopusEnemy::processMovementModifier( int _frames, s32 distX, s32 distY, s32 dist, s16 headingChange )
2001-02-06 17:12:56 +01:00
{
s32 newX, newY;
s32 preShiftX, preShiftY;
2001-04-20 16:48:15 +02:00
s16 headingVal;
2001-02-06 17:12:56 +01:00
2001-04-03 17:14:53 +02:00
//u16 octopusData[11] = { 96, 192, 256, 256, 256, 192, 192, 192, 128, 128, 96 };
u16 octopusData[11] = { 96, 256, 96, 256, 96, 256, 96, 256, 96, 256, 96 };
2001-02-06 17:12:56 +01:00
u32 dataPoint;
m_movementTimer += _frames;
2001-04-03 17:14:53 +02:00
if ( m_movementTimer > ( 2 * GameState::getOneSecondInFrames() ) )
2001-02-06 17:12:56 +01:00
{
2001-04-03 17:14:53 +02:00
m_movementTimer -= ( 2 * GameState::getOneSecondInFrames() );
2001-02-06 17:12:56 +01:00
}
dataPoint = 10 * m_movementTimer;
if ( dataPoint != 0 )
{
2001-04-03 17:14:53 +02:00
dataPoint /= ( 2 * GameState::getOneSecondInFrames() );
2001-02-06 17:12:56 +01:00
}
s32 resistance;
s32 absVelocity = abs( m_velocity );
s32 reqVelocity = dist;
2001-04-20 22:22:16 +02:00
resistance = _frames * NPC_OCTOPUS_RESISTANCE;
2001-02-06 17:12:56 +01:00
if ( absVelocity < resistance )
{
resistance = absVelocity;
}
if ( absVelocity != 0 )
{
resistance = -( resistance * m_velocity ) / absVelocity;
}
else
{
resistance = 0;
}
m_velocity += resistance;
2001-04-20 16:48:15 +02:00
headingVal = abs( headingChange );
if ( headingVal > 128 )
{
headingVal = 128;
}
2001-02-06 17:12:56 +01:00
reqVelocity = dist * octopusData[dataPoint];
reqVelocity >>= 8;
2001-04-20 16:48:15 +02:00
reqVelocity *= 128 + ( 128 - headingVal );
2001-02-06 17:12:56 +01:00
reqVelocity >>= 8;
s32 absReqVelocity = abs( reqVelocity );
if ( absReqVelocity > absVelocity )
{
m_velocity += reqVelocity >> 1;
}
preShiftX = ( m_velocity >> 8 ) * rcos( m_heading );
preShiftY = ( m_velocity >> 8 ) * rsin( m_heading );
newX = preShiftX >> 12;
if ( !newX && preShiftX )
{
newX = preShiftX / abs( preShiftX );
}
newY = preShiftY >> 12;
if ( !newY && preShiftY )
{
newY = preShiftY / abs( preShiftY );
}
Pos.vx += newX;
Pos.vy += newY;
}
2001-04-03 17:14:53 +02:00
2001-04-20 16:48:15 +02:00
void CNpcBabyOctopusEnemy::processClose( int _frames )
2001-04-03 17:14:53 +02:00
{
2001-04-20 16:48:15 +02:00
if ( m_animNo == m_data[m_type].initAnim || m_animNo == m_data[m_type].moveAnim )
2001-04-03 17:14:53 +02:00
{
// not playing an attack anim, hence choose one
u8 newAction = getRnd() % 3;
switch( newAction )
{
case 0:
{
m_animNo = ANIM_BABYOCTOPUS_HEAD_BUTT;
break;
}
case 1:
{
m_animNo = ANIM_BABYOCTOPUS_HIT;
break;
}
case 2:
{
m_animNo = ANIM_BABYOCTOPUS_INK;
break;
}
}
m_animPlaying = true;
m_frame = 0;
2001-04-20 16:48:15 +02:00
}
else if ( !m_animPlaying )
{
2001-04-03 17:14:53 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}
}