SBSPSS/source/enemy/ndogfish.cpp

621 lines
12 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-06-11 23:49:49 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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-06-06 15:27:46 +02:00
m_steamTimer = 0;
2001-06-16 19:34:46 +02:00
m_vulnerableTimer = 0;
2001-06-16 19:45:30 +02:00
if ( CLevel::getIsBossRespawn() )
{
m_health = CLevel::getBossHealth();
m_speed = m_data[m_type].speed + ( ( 3 * ( m_data[m_type].initHealth - m_health ) ) / m_data[m_type].initHealth );
}
2001-06-27 20:28:21 +02:00
2001-06-30 17:39:43 +02:00
CNpcBossEnemy::postInit();
2001-04-20 22:22:16 +02:00
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
bool CNpcIronDogfishEnemy::processSensor()
{
2001-06-18 21:06:43 +02:00
switch( m_sensorFunc )
2001-04-20 22:22:16 +02:00
{
case NPC_SENSOR_NONE:
return( false );
default:
{
2001-06-18 23:18:12 +02:00
if ( m_movementTimer > 0 && playerXDistSqr + playerYDistSqr < 5000 )
2001-04-20 22:22:16 +02:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
return( true );
}
else
{
return( false );
}
}
2001-06-18 21:06:43 +02:00
}
2001-04-20 22:22:16 +02:00
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcIronDogfishEnemy::processMovement( int _frames )
2001-01-25 20:54:20 +01:00
{
2001-06-16 19:34:46 +02:00
if ( m_vulnerableTimer > 0 )
2001-01-25 20:54:20 +01:00
{
2001-06-16 19:34:46 +02:00
m_vulnerableTimer -= _frames;
if ( m_animNo != ANIM_IRONDOGFISH_IDLE )
2001-04-02 17:52:09 +02:00
{
m_animPlaying = true;
2001-06-16 19:34:46 +02:00
m_animNo = ANIM_IRONDOGFISH_IDLE;
2001-04-02 17:52:09 +02:00
m_frame = 0;
}
2001-05-04 00:49:57 +02:00
}
else
{
2001-06-16 19:34:46 +02:00
s32 moveX = 0, moveY = 0;
s32 moveVel = 0;
s32 moveDist = 0;
if ( m_movementTimer > 0 )
{
2001-07-14 00:11:49 +02:00
if ( m_soundId == NOT_PLAYING && m_data[m_type].moveSfx < CSoundMediator::NUM_SFXIDS )
{
m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].moveSfx, true );
}
2001-06-16 19:34:46 +02:00
if ( m_animNo != ANIM_IRONDOGFISH_WALK || !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_WALK;
m_frame = 0;
}
processGenericFixedPathWalk( _frames, &moveX, &moveY );
Pos.vx += moveX;
Pos.vy += moveY;
m_movementTimer -= _frames;
}
else
{
processStandardIronDogfishAttack( _frames );
}
2001-05-04 00:49:57 +02:00
}
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-04 00:49:57 +02:00
void CNpcIronDogfishEnemy::processWalkToUser( int _frames, int speed )
{
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( playerXDist > 0 )
{
m_heading = 0;
2001-06-18 23:18:12 +02:00
Pos.vx += _frames * speed;
2001-05-04 00:49:57 +02:00
}
else
{
m_heading = 2048;
2001-06-18 23:18:12 +02:00
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;
2001-05-25 20:43:47 +02:00
s32 groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-05-04 00:49:57 +02:00
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-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames )
2001-01-25 20:54:20 +01:00
{
2001-06-18 23:18:12 +02:00
if ( m_state != IRON_DOGFISH_LASER_EYE_1_WAIT && m_state != IRON_DOGFISH_LASER_EYE_2_WAIT )
2001-01-25 20:54:20 +01:00
{
2001-06-18 23:18:12 +02:00
if ( playerXDist > 0 )
{
m_extendDir = EXTEND_RIGHT;
m_heading = 0;
}
else
{
m_extendDir = EXTEND_LEFT;
m_heading = 2048;
}
2001-01-25 20:54:20 +01:00
}
switch( m_state )
{
case IRON_DOGFISH_THUMP_1:
case IRON_DOGFISH_THUMP_2:
{
2001-06-18 23:18:12 +02:00
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
u8 thump = false;
if ( playerXDist > 0 )
{
if ( Pos.vx + playerXDist > maxX )
{
thump = true;
}
}
else
{
if ( Pos.vx + playerXDist < minX )
{
thump = true;
}
}
if ( playerXDistSqr > 100 && !thump )
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;
2001-07-14 00:11:49 +02:00
CSoundMediator::playSfx( CSoundMediator::SFX_DOGFISH_THUMP );
2001-04-02 17:52:09 +02:00
}
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:
{
2001-07-25 18:47:37 +02:00
if ( playerYDistSqr > 250000 )
{
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_state = IRON_DOGFISH_THUMP_2;
break;
}
2001-06-18 23:18:12 +02:00
if ( m_animNo != ANIM_IRONDOGFISH_IDLE || !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_IDLE;
m_frame = 0;
}
2001-01-25 20:54:20 +01:00
// fire at user
2001-06-07 20:41:59 +02:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist ) & 4095;
2001-01-25 21:12:19 +01:00
2001-07-04 22:00:05 +02:00
CProjectile *projectile;
2001-06-14 18:07:48 +02:00
projectile = CProjectile::Create();
2001-05-04 00:49:57 +02:00
DVECTOR startPos = Pos;
2001-07-04 22:00:05 +02:00
if ( m_heading == 0 )
{
startPos.vx += 60;
}
else
{
startPos.vx -= 60;
}
startPos.vy -= 45;
projectile->init( startPos, headingToPlayer );
2001-07-05 16:51:53 +02:00
projectile->setSpeed( 6 );
2001-06-18 23:18:12 +02:00
2001-07-04 22:00:05 +02:00
m_laserTimer = GameState::getOneSecondInFrames() >> 1;
2001-06-18 23:18:12 +02:00
2001-07-14 00:11:49 +02:00
CSoundMediator::playSfx( CSoundMediator::SFX_DOGFISH_LASER );
2001-07-04 22:00:05 +02:00
/*m_effect = (CFXLaser*) CFX::Create( CFX::FX_TYPE_LASER, this );
2001-06-19 20:07:05 +02:00
2001-06-18 23:18:12 +02:00
DVECTOR offsetPos;
if ( m_heading == 0 )
{
2001-06-19 20:07:05 +02:00
offsetPos.vx = 60;
2001-06-18 23:18:12 +02:00
}
else
{
2001-06-19 20:07:05 +02:00
offsetPos.vx = -60;
2001-06-18 23:18:12 +02:00
}
offsetPos.vy = -45;
m_effect->setOffset( offsetPos );
2001-06-19 20:07:05 +02:00
DVECTOR targetPos = GameScene.getPlayer()->getPos();
targetPos.vy -= 45;
m_effect->setTarget( targetPos );
2001-07-04 22:00:05 +02:00
m_effect->setRGB( 255, 0, 0 );*/
2001-01-25 21:12:19 +01:00
2001-01-25 20:54:20 +01:00
m_state++;
2001-06-18 23:18:12 +02:00
break;
}
case IRON_DOGFISH_LASER_EYE_1_WAIT:
case IRON_DOGFISH_LASER_EYE_2_WAIT:
{
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_IRONDOGFISH_IDLE;
m_frame = 0;
}
if ( m_laserTimer > 0 )
2001-01-25 20:54:20 +01:00
{
2001-06-18 23:18:12 +02:00
m_laserTimer -= _frames;
}
else
{
2001-07-04 22:00:05 +02:00
//m_effect->killFX();
2001-06-18 23:18:12 +02:00
m_state++;
2001-07-04 22:00:05 +02:00
if ( m_state == IRON_DOGFISH_LASER_EYE_2_WAIT )
2001-06-18 23:18:12 +02:00
{
2001-07-04 22:00:05 +02:00
m_movementTimer = GameState::getOneSecondInFrames() * 3;
2001-06-18 23:18:12 +02:00
}
2001-01-25 20:54:20 +01:00
}
break;
}
case IRON_DOGFISH_ROLL:
{
2001-06-18 23:18:12 +02:00
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
u8 thump = false;
if ( playerXDist > 0 )
{
if ( Pos.vx + playerXDist > maxX )
{
thump = true;
}
}
else
{
if ( Pos.vx + playerXDist < minX )
{
thump = true;
}
}
2001-01-25 20:54:20 +01:00
2001-06-18 23:18:12 +02:00
if ( playerXDistSqr > 100 && !thump )
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;
2001-07-14 00:11:49 +02:00
CSoundMediator::playSfx( CSoundMediator::SFX_DOGFISH_GROWL );
2001-05-04 00:49:57 +02:00
}
else if ( !m_animPlaying )
{
m_movementTimer = GameState::getOneSecondInFrames() * 3;
2001-07-04 22:00:05 +02:00
// return to first state
m_state = IRON_DOGFISH_THUMP_1;
2001-05-04 00:49:57 +02:00
}
2001-01-25 20:54:20 +01:00
}
break;
}
}
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
}
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::hasBeenSteamed( DVECTOR &steamPos )
{
if ( m_steamTimer <= 0 )
{
2001-06-16 19:34:46 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
2001-06-18 21:06:43 +02:00
s16 second = GameState::getOneSecondInFrames();
m_vulnerableTimer = ( 2 * second ) + ( 2 * second * ( ( m_data[m_type].initHealth - m_health ) / m_data[m_type].initHealth ) );
2001-06-16 19:34:46 +02:00
//hasBeenAttacked();
2001-06-06 15:27:46 +02:00
m_steamTimer = 4 * GameState::getOneSecondInFrames();
2001-07-06 17:21:14 +02:00
//m_effect->killFX();
2001-06-06 15:27:46 +02:00
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::processTimer(int _frames)
{
if ( m_steamTimer > 0 )
{
m_steamTimer -= _frames;
}
CNpcEnemy::processTimer( _frames );
}
2001-06-11 23:49:49 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-28 22:29:14 +02:00
void CNpcIronDogfishEnemy::processShotDeathEnd( int _frames )
2001-06-11 23:49:49 +02:00
{
2001-06-28 22:29:14 +02:00
if ( !m_animPlaying )
2001-06-11 23:49:49 +02:00
{
2001-06-28 22:29:14 +02:00
CNpcEnemy::processShotDeathEnd( _frames );
2001-06-11 23:49:49 +02:00
2001-06-28 22:29:14 +02:00
if ( isSetToShutdown() )
2001-06-11 23:49:49 +02:00
{
2001-06-28 22:29:14 +02:00
CGameScene::setBossHasBeenKilled();
2001-06-11 23:49:49 +02:00
}
}
}
2001-06-16 19:34:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::collidedWith( CThing *_thisThing )
{
if ( m_isActive && !m_isCaught && !m_isDying )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
ATTACK_STATE playerState = player->getAttackState();
if(playerState==ATTACK_STATE__NONE)
{
if ( !player->isRecoveringFromHit() )
{
switch( m_data[m_type].detectCollision )
{
case DETECT_NO_COLLISION:
{
// ignore
break;
}
case DETECT_ALL_COLLISION:
{
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
break;
}
case DETECT_ATTACK_COLLISION_GENERIC:
{
processAttackCollision();
break;
}
}
}
}
else if ( m_vulnerableTimer > 0 )
{
// player is attacking, respond appropriately
if ( m_controlFunc != NPC_CONTROL_SHOT )
{
if(playerState==ATTACK_STATE__BUTT_BOUNCE)
{
player->justButtBouncedABadGuy();
}
m_controlFunc = NPC_CONTROL_SHOT;
m_state = NPC_GENERIC_HIT_CHECK_HEALTH;
drawAttackEffect();
}
}
break;
}
case TYPE_ENEMY:
{
CNpcEnemy *enemy = (CNpcEnemy *) _thisThing;
if ( canCollideWithEnemy() && enemy->canCollideWithEnemy() )
{
2001-06-18 23:18:12 +02:00
//processEnemyCollision( _thisThing );
2001-06-16 19:34:46 +02:00
}
break;
}
default:
ASSERT(0);
break;
}
}
}
2001-06-16 19:45:30 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::shutdown()
{
2001-07-06 16:55:58 +02:00
CLevel::setIsBossRespawn( true );
2001-06-16 19:45:30 +02:00
if ( m_state != NPC_GENERIC_HIT_DEATH_END )
{
CLevel::setBossHealth( m_health );
}
2001-07-06 16:55:58 +02:00
else
{
CLevel::setBossHealth( 0 );
}
2001-06-16 19:45:30 +02:00
2001-06-30 17:39:43 +02:00
CNpcBossEnemy::shutdown();
2001-06-16 19:45:30 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::render()
{
SprFrame = NULL;
if ( m_isActive )
{
CEnemyThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
SprFrame = m_actorGfx->Render(renderPos,m_animNo,( m_frame >> 8 ),m_reversed);
m_actorGfx->RotateScale( SprFrame, renderPos, 0, 4096, 4096 );
sBBox boundingBox = m_actorGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
}
}
}
2001-06-18 23:18:12 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::processCollision()
{
CPlayer *player = GameScene.getPlayer();
player->takeDamage( m_data[m_type].damageToUserType,REACT__GET_DIRECTION_FROM_THING,(CThing*)this );
m_controlFunc = m_oldControlFunc;
}