SBSPSS/source/enemy/ndogfish.cpp

298 lines
4.9 KiB
C++
Raw Normal View History

2001-01-25 20:54:20 +01:00
/*=========================================================================
ndogfish.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 22:22:16 +02:00
#ifndef __ENEMY_NDOGFISH_H__
#include "enemy\ndogfish.h"
#endif
2001-01-25 20:54:20 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-04-02 17:52:09 +02:00
#ifndef __ANIM_IRONDOGFISH_HEADER__
#include <ACTOR_IRONDOGFISH_ANIM.h>
#endif
2001-04-20 22:22:16 +02:00
void CNpcIronDogfishEnemy::postInit()
{
m_state = IRON_DOGFISH_THUMP_1;
m_extendDir = EXTEND_RIGHT;
2001-05-04 00:49:57 +02:00
m_npcPath.setPathType( CNpcPath::PONG_PATH );
2001-04-20 22:22:16 +02:00
}
bool CNpcIronDogfishEnemy::processSensor()
{
2001-05-04 00:49:57 +02:00
/*switch( m_sensorFunc )
2001-04-20 22:22:16 +02:00
{
case NPC_SENSOR_NONE:
return( false );
default:
{
2001-05-04 00:49:57 +02:00
if ( playerXDistSqr + playerYDistSqr < 5000 )
2001-04-20 22:22:16 +02:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
return( true );
}
else
{
return( false );
}
}
2001-05-04 00:49:57 +02:00
}*/
return( false );
2001-04-20 22:22:16 +02:00
}
void CNpcIronDogfishEnemy::processMovement( int _frames )
2001-01-25 20:54:20 +01:00
{
2001-05-04 00:49:57 +02:00
s32 moveX = 0, moveY = 0;
s32 moveVel = 0;
s32 moveDist = 0;
2001-01-25 20:54:20 +01:00
if ( m_movementTimer > 0 )
{
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_WALK;
m_frame = 0;
}
2001-05-04 00:49:57 +02:00
processGenericFixedPathWalk( _frames, &moveX, &moveY );
Pos.vx += moveX;
Pos.vy += moveY;
2001-01-25 20:54:20 +01:00
m_movementTimer -= _frames;
2001-05-04 00:49:57 +02:00
}
else
{
processStandardIronDogfishAttack( _frames );
}
}
void CNpcIronDogfishEnemy::processWalkToUser( int _frames, int speed )
{
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( playerXDist > 0 )
{
m_heading = 0;
2001-01-25 20:54:20 +01:00
2001-05-04 00:49:57 +02:00
if ( Pos.vx + playerXDist > maxX )
2001-01-25 20:54:20 +01:00
{
2001-05-04 00:49:57 +02:00
// abort
2001-01-25 20:54:20 +01:00
2001-05-04 00:49:57 +02:00
m_movementTimer = GameState::getOneSecondInFrames() * 3;
2001-01-25 20:54:20 +01:00
}
else
{
2001-05-04 00:49:57 +02:00
Pos.vx += _frames * speed;
}
}
else
{
m_heading = 2048;
2001-01-25 20:54:20 +01:00
2001-05-04 00:49:57 +02:00
if ( Pos.vx + playerXDist < minX )
{
// abort
m_movementTimer = GameState::getOneSecondInFrames() * 3;
}
else
{
Pos.vx -= _frames * speed;
2001-01-25 20:54:20 +01:00
}
}
2001-05-04 00:49:57 +02:00
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
s32 groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
// move to ground level
Pos.vx += groundHeight;
}
2001-01-25 20:54:20 +01:00
else
{
2001-05-04 00:49:57 +02:00
// fall
Pos.vx += yMovement;
2001-01-25 20:54:20 +01:00
}
}
2001-04-20 22:22:16 +02:00
void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames )
2001-01-25 20:54:20 +01:00
{
2001-02-07 17:42:13 +01:00
if ( playerXDist > 0 )
2001-01-25 20:54:20 +01:00
{
m_extendDir = EXTEND_RIGHT;
}
else
{
m_extendDir = EXTEND_LEFT;
}
switch( m_state )
{
case IRON_DOGFISH_THUMP_1:
case IRON_DOGFISH_THUMP_2:
{
2001-02-07 17:42:13 +01:00
if ( playerXDistSqr > 100 )
2001-01-25 20:54:20 +01:00
{
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_WALK;
m_frame = 0;
}
2001-05-09 23:27:23 +02:00
processWalkToUser( _frames, m_speed );
2001-01-25 20:54:20 +01:00
}
else
{
// thump player
2001-04-02 17:52:09 +02:00
if ( m_animNo != ANIM_IRONDOGFISH_PUNCH )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_PUNCH;
m_frame = 0;
}
else if ( !m_animPlaying )
{
m_state++;
m_movementTimer = GameState::getOneSecondInFrames() * 3;
}
2001-01-25 20:54:20 +01:00
}
break;
}
case IRON_DOGFISH_LASER_EYE_1:
case IRON_DOGFISH_LASER_EYE_2:
{
// fire at user
2001-02-07 17:42:13 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-01-25 21:12:19 +01:00
CProjectile *projectile;
projectile = new( "test projectile" ) CProjectile;
2001-05-04 00:49:57 +02:00
DVECTOR startPos = Pos;
startPos.vy -= 20;
projectile->init( startPos, headingToPlayer );
2001-04-12 16:55:55 +02:00
projectile->setLayerCollision( m_layerCollision );
2001-01-25 21:12:19 +01:00
2001-01-25 20:54:20 +01:00
m_state++;
if ( m_state > IRON_DOGFISH_LASER_EYE_2 )
{
// return to first state
m_state = IRON_DOGFISH_THUMP_1;
}
break;
}
case IRON_DOGFISH_ROLL:
{
// charge user
2001-02-07 17:42:13 +01:00
if ( playerXDistSqr > 100 )
2001-01-25 20:54:20 +01:00
{
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_WALK;
m_frame = 0;
}
2001-05-09 23:27:23 +02:00
processWalkToUser( _frames, m_speed );
2001-01-25 20:54:20 +01:00
}
else
{
2001-05-04 00:49:57 +02:00
if ( m_animNo != ANIM_IRONDOGFISH_TAILSMASH )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_TAILSMASH;
m_frame = 0;
}
else if ( !m_animPlaying )
{
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_state++;
}
2001-01-25 20:54:20 +01:00
}
break;
}
}
}
2001-04-20 22:22:16 +02:00
void CNpcIronDogfishEnemy::processClose( int _frames )
2001-01-25 20:54:20 +01:00
{
// swipe at player
2001-05-04 00:49:57 +02:00
if ( m_animNo != ANIM_IRONDOGFISH_PUNCH )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_PUNCH;
m_frame = 0;
}
else if ( !m_animPlaying )
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}
}
2001-05-04 20:54:27 +02:00
void CNpcIronDogfishEnemy::processAttackCollision()
2001-05-04 00:49:57 +02:00
{
2001-05-04 20:54:27 +02:00
switch( m_animNo )
2001-05-04 00:49:57 +02:00
{
2001-05-04 20:54:27 +02:00
case ANIM_IRONDOGFISH_PUNCH:
case ANIM_IRONDOGFISH_TAILSMASH:
2001-05-04 00:49:57 +02:00
{
2001-05-04 20:54:27 +02:00
// only detect collision if in attack mode
2001-05-04 00:49:57 +02:00
2001-05-04 20:54:27 +02:00
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
2001-05-04 00:49:57 +02:00
2001-05-04 20:54:27 +02:00
break;
2001-05-04 00:49:57 +02:00
}
2001-05-04 20:54:27 +02:00
default:
break;
2001-05-04 00:49:57 +02:00
}
}