SBSPSS/source/enemy/ndogfish.cpp

705 lines
14 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
m_meterOn=false;
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
m_energyBar = NULL;
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 )
{
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;
}
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-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-06-18 23:18:12 +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;
startPos.vy -= 20;
2001-06-18 23:18:12 +02:00
projectile->init( startPos, headingToPlayer );*/
2001-06-19 20:13:29 +02:00
m_laserTimer = GameState::getOneSecondInFrames();
2001-06-18 23:18:12 +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-06-18 23:18:12 +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
{
m_effect->killFX();
m_state++;
if ( m_state > IRON_DOGFISH_LASER_EYE_2_WAIT )
{
// return to first state
m_state = IRON_DOGFISH_THUMP_1;
}
2001-01-25 20:54:20 +01:00
2001-06-18 23:18:12 +02:00
m_movementTimer = GameState::getOneSecondInFrames() * 3;
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;
}
else if ( !m_animPlaying )
{
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_state++;
}
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();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::processTimer(int _frames)
{
if ( m_steamTimer > 0 )
{
m_steamTimer -= _frames;
}
CNpcEnemy::processTimer( _frames );
}
2001-06-11 23:49:49 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::processShot( int _frames )
{
switch( m_data[m_type].shotFunc )
{
case NPC_SHOT_NONE:
{
// do nothing
break;
}
case NPC_SHOT_GENERIC:
{
switch ( m_state )
{
case NPC_GENERIC_HIT_CHECK_HEALTH:
{
m_health -= 5;
if ( m_health < 0 )
{
m_state = NPC_GENERIC_HIT_DEATH_START;
m_isDying = true;
}
else
{
m_state = NPC_GENERIC_HIT_RECOIL;
m_animPlaying = true;
m_animNo = m_data[m_type].recoilAnim;
m_frame = 0;
}
break;
}
case NPC_GENERIC_HIT_RECOIL:
{
if ( !m_animPlaying )
{
m_state = 0;
m_controlFunc = NPC_CONTROL_MOVEMENT;
}
break;
}
case NPC_GENERIC_HIT_DEATH_START:
{
m_animPlaying = true;
m_animNo = m_data[m_type].dieAnim;
m_frame = 0;
m_state = NPC_GENERIC_HIT_DEATH_END;
m_isDying = true;
if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS )
{
2001-06-18 21:06:43 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true );
2001-06-11 23:49:49 +02:00
}
m_speed = -5;
if (m_data[m_type].skelType)
{
m_actorGfx->SetOtPos( 0 );
}
break;
}
case NPC_GENERIC_HIT_DEATH_END:
{
if ( !m_animPlaying )
{
m_drawRotation += 64 * _frames;
m_drawRotation &= 4095;
Pos.vy += m_speed * _frames;
if ( m_speed < 5 )
{
m_speed++;
}
DVECTOR offset = CLevel::getCameraPos();
if ( Pos.vy - offset.vy > VidGetScrH() )
{
if ( m_data[m_type].respawning )
{
m_isActive = false;
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 4 * GameState::getOneSecondInFrames();
}
else
{
setToShutdown();
2001-06-12 20:12:34 +02:00
CGameScene::setBossHasBeenKilled();
2001-06-11 23:49:49 +02:00
}
}
}
break;
}
}
break;
}
}
}
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()
{
if ( m_state != NPC_GENERIC_HIT_DEATH_END )
{
CLevel::setIsBossRespawn( true );
CLevel::setBossHealth( m_health );
}
2001-06-27 20:28:21 +02:00
if ( m_energyBar )
{
m_energyBar->setToShutdown();
}
2001-06-16 19:45:30 +02:00
CNpcEnemy::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcIronDogfishEnemy::render()
{
SprFrame = NULL;
if ( m_isActive )
{
CEnemyThing::render();
if (canRender())
{
if (!m_meterOn)
{
2001-06-27 20:28:21 +02:00
m_energyBar=(CFXNRGBar*)CFX::Create(CFX::FX_TYPE_NRG_BAR,this);
m_energyBar->SetMax(m_data[m_type].initHealth);
2001-06-16 19:45:30 +02:00
m_meterOn=true;
}
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;
}