2001-04-02 17:51:25 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
nhcrab.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __ENEMY_NPC_H__
|
|
|
|
#include "enemy\npc.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-20 00:09:59 +02:00
|
|
|
#ifndef __ENEMY_NHCRAB_H__
|
|
|
|
#include "enemy\nhcrab.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-02 17:51:25 +02:00
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __ANIM_HERMITCRAB_HEADER__
|
|
|
|
#include <ACTOR_HERMITCRAB_ANIM.h>
|
|
|
|
#endif
|
|
|
|
|
2001-04-20 22:22:16 +02:00
|
|
|
void CNpcHermitCrabEnemy::postInit()
|
|
|
|
{
|
|
|
|
m_npcPath.setPathType( CNpcPath::PONG_PATH );
|
|
|
|
|
|
|
|
m_state = HERMIT_CRAB_NO_ATTACK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 00:09:59 +02:00
|
|
|
bool CNpcHermitCrabEnemy::processSensor()
|
|
|
|
{
|
|
|
|
switch( m_sensorFunc )
|
|
|
|
{
|
|
|
|
case NPC_SENSOR_NONE:
|
|
|
|
return( false );
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2001-05-10 01:14:35 +02:00
|
|
|
if ( playerXDistSqr + playerYDistSqr < 4000 )
|
2001-04-20 00:09:59 +02:00
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_CLOSE;
|
|
|
|
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNpcHermitCrabEnemy::processClose( int _frames )
|
2001-04-02 17:51:25 +02:00
|
|
|
{
|
|
|
|
if ( m_state == HERMIT_CRAB_NO_ATTACK )
|
|
|
|
{
|
2001-05-14 21:48:27 +02:00
|
|
|
//m_state = ( getRnd() % 2 ) + 1;
|
|
|
|
m_state = HERMIT_CRAB_ROLL_ATTACK_JUMP1;
|
|
|
|
m_movementTimer = 0;
|
|
|
|
m_jumpBase = Pos.vy;
|
|
|
|
|
|
|
|
if ( playerXDist > 0 )
|
|
|
|
{
|
|
|
|
m_extendDir = EXTEND_RIGHT;
|
|
|
|
m_heading = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_extendDir = EXTEND_LEFT;
|
|
|
|
m_heading = 2048;
|
|
|
|
}
|
2001-04-02 17:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( m_state )
|
|
|
|
{
|
|
|
|
case HERMIT_CRAB_PUNCH_ATTACK:
|
|
|
|
{
|
|
|
|
if ( m_animNo != ANIM_HERMITCRAB_PUNCH )
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_HERMITCRAB_PUNCH;
|
|
|
|
m_frame = 0;
|
|
|
|
}
|
|
|
|
else if ( !m_animPlaying )
|
|
|
|
{
|
|
|
|
m_state = HERMIT_CRAB_NO_ATTACK;
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-05-14 21:48:27 +02:00
|
|
|
case HERMIT_CRAB_ROLL_ATTACK_JUMP1:
|
|
|
|
case HERMIT_CRAB_ROLL_ATTACK_JUMP2:
|
|
|
|
{
|
|
|
|
s16 sineVal = ( m_movementTimer << 11 ) / ( GameState::getOneSecondInFrames() >> 3 );
|
|
|
|
Pos.vy = m_jumpBase - ( ( 10 * rsin( sineVal ) ) >> 12 );
|
|
|
|
|
|
|
|
if ( m_movementTimer < ( GameState::getOneSecondInFrames() >> 3 ) )
|
|
|
|
{
|
|
|
|
m_movementTimer++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_state++;
|
|
|
|
m_movementTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HERMIT_CRAB_ROLL_ATTACK_ROLL:
|
2001-04-02 17:51:25 +02:00
|
|
|
{
|
2001-04-04 20:35:07 +02:00
|
|
|
if ( !m_animPlaying || m_animNo == m_data[m_type].moveAnim )
|
2001-04-02 17:51:25 +02:00
|
|
|
{
|
|
|
|
switch( m_animNo )
|
|
|
|
{
|
|
|
|
case ANIM_HERMITCRAB_ROLLATTACKSTART:
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_HERMITCRAB_ROLLATTACK;
|
|
|
|
m_frame = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ANIM_HERMITCRAB_ROLLATTACK:
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_HERMITCRAB_ROLLATTACKEND;
|
|
|
|
m_frame = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ANIM_HERMITCRAB_ROLLATTACKEND:
|
|
|
|
{
|
|
|
|
m_state = HERMIT_CRAB_NO_ATTACK;
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_HERMITCRAB_ROLLATTACKSTART;
|
|
|
|
m_frame = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_animNo == ANIM_HERMITCRAB_ROLLATTACK )
|
|
|
|
{
|
|
|
|
// check for vertical movement
|
|
|
|
|
|
|
|
s32 moveX = 0, moveY = 0;
|
|
|
|
s32 groundHeight;
|
2001-04-04 21:55:49 +02:00
|
|
|
s32 fallSpeed = 3;
|
2001-04-02 17:51:25 +02:00
|
|
|
s8 yMovement = fallSpeed * _frames;
|
|
|
|
|
|
|
|
moveX = 6 * _frames;
|
|
|
|
|
2001-04-02 21:21:46 +02:00
|
|
|
m_heading = 0;
|
|
|
|
|
2001-04-02 17:51:25 +02:00
|
|
|
if ( m_extendDir == EXTEND_LEFT )
|
|
|
|
{
|
|
|
|
moveX = -moveX;
|
2001-04-02 21:21:46 +02:00
|
|
|
m_heading = 2048;
|
2001-04-02 17:51:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-04 20:35:07 +02:00
|
|
|
s32 minX, maxX, newX;
|
|
|
|
|
|
|
|
m_npcPath.getPathXExtents( &minX, &maxX );
|
|
|
|
|
|
|
|
newX = Pos.vx + moveX;
|
2001-04-02 17:51:25 +02:00
|
|
|
|
2001-04-04 20:35:07 +02:00
|
|
|
if ( newX < minX || newX > maxX )
|
2001-04-02 17:51:25 +02:00
|
|
|
{
|
2001-04-04 20:35:07 +02:00
|
|
|
// moving outside path constraints, abort
|
2001-04-02 17:51:25 +02:00
|
|
|
|
2001-04-04 20:35:07 +02:00
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_HERMITCRAB_ROLLATTACKEND;
|
|
|
|
m_frame = 0;
|
2001-04-02 17:51:25 +02:00
|
|
|
}
|
2001-04-04 20:35:07 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
groundHeight = m_layerCollision->getHeightFromGround( newX, Pos.vy, yMovement + 16 );
|
|
|
|
|
|
|
|
if ( groundHeight <= yMovement )
|
|
|
|
{
|
|
|
|
// groundHeight <= yMovement indicates either just above ground or on or below ground
|
2001-04-02 17:51:25 +02:00
|
|
|
|
2001-04-04 20:35:07 +02:00
|
|
|
moveY = groundHeight;
|
|
|
|
}
|
2001-04-04 21:55:49 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// fall
|
|
|
|
|
|
|
|
moveY = yMovement;
|
|
|
|
}
|
2001-04-04 20:35:07 +02:00
|
|
|
|
|
|
|
Pos.vx = newX;
|
|
|
|
Pos.vy += moveY;
|
|
|
|
}
|
2001-04-02 17:51:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-04-26 17:20:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNpcHermitCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 distY, s32 dist, s16 headingChange )
|
|
|
|
{
|
|
|
|
Pos.vx += distX;
|
|
|
|
Pos.vy += distY;
|
|
|
|
|
|
|
|
// sort out draw rotation
|
|
|
|
|
|
|
|
DVECTOR testPos1, testPos2;
|
|
|
|
|
|
|
|
testPos1 = testPos2 = Pos;
|
|
|
|
testPos1.vx -= 10;
|
|
|
|
testPos2.vx += 10;
|
|
|
|
|
|
|
|
testPos1.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 );
|
2001-05-08 20:57:00 +02:00
|
|
|
testPos2.vy += m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, 16 );
|
2001-04-26 17:20:21 +02:00
|
|
|
|
|
|
|
s32 xDist = testPos2.vx - testPos1.vx;
|
|
|
|
s32 yDist = testPos2.vy - testPos1.vy;
|
|
|
|
|
|
|
|
s16 heading = ratan2( yDist, xDist );
|
|
|
|
|
|
|
|
m_drawRotation = heading;
|
|
|
|
}
|