SBSPSS/source/enemy/nsshark.cpp

404 lines
7.2 KiB
C++
Raw Normal View History

2001-01-25 18:19:08 +01:00
/*=========================================================================
nsshark.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_NSSHARK_H__
#include "enemy\nsshark.h"
#endif
2001-01-25 18:19:08 +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-02-28 22:05:39 +01:00
#ifndef __ANIM_SHARKSUB_HEADER__
2001-05-03 23:39:27 +02:00
#include <ACTOR_SHARKSUB_ANIM.h>
2001-02-28 22:05:39 +01:00
#endif
2001-06-11 23:49:49 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-28 22:05:39 +01:00
2001-04-20 22:22:16 +02:00
void CNpcSubSharkEnemy::postInit()
{
m_state = SUB_SHARK_MINE_1;
m_extendDir = EXTEND_RIGHT;
2001-05-03 23:39:27 +02:00
m_npcPath.setPathType( CNpcPath::PONG_PATH );
2001-05-16 21:04:40 +02:00
m_salvoCount = 0;
2001-04-20 22:22:16 +02:00
}
2001-06-11 23:49:49 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcSubSharkEnemy::processMovement( int _frames )
2001-01-25 18:19:08 +01:00
{
2001-02-28 22:05:39 +01:00
if ( !m_animPlaying )
{
2001-03-13 18:01:35 +01:00
if ( playerXDistSqr + playerYDistSqr < 100 && !m_salvoCount )
{
m_animPlaying = true;
2001-05-03 23:39:27 +02:00
m_animNo = ANIM_SHARKSUB_SWIPE;
2001-03-13 18:01:35 +01:00
m_frame = 0;
}
else
{
m_animPlaying = true;
2001-05-03 23:39:27 +02:00
m_animNo = ANIM_SHARKSUB_SWIM;
2001-03-13 18:01:35 +01:00
m_frame = 0;
}
2001-02-28 22:05:39 +01:00
}
2001-01-25 18:19:08 +01:00
if ( m_timerTimer <= 0 )
{
if ( m_salvoCount > 0 )
{
// drop mine
CProjectile *projectile;
2001-06-14 18:07:48 +02:00
projectile = CProjectile::Create();
2001-01-25 18:19:08 +01:00
projectile->init( Pos, 1024 );
m_salvoCount--;
m_timerTimer = GameState::getOneSecondInFrames() * 1;
}
}
if ( m_movementTimer > 0 )
{
m_movementTimer -= _frames;
2001-03-13 18:01:35 +01:00
}
2001-01-25 18:19:08 +01:00
2001-05-03 23:39:27 +02:00
s32 moveX = 0, moveY = 0;
s32 moveVel = 0;
s32 moveDist = 0;
processGenericFixedPathMove( _frames, &moveX, &moveY, &moveVel, &moveDist );
if ( moveX > 0 )
{
m_extendDir = EXTEND_RIGHT;
}
else
{
m_extendDir = EXTEND_LEFT;
}
Pos.vx += moveX;
Pos.vy += moveY;
if ( m_movementTimer <= 0 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
}
/*if ( m_extendDir == EXTEND_RIGHT )
2001-03-13 18:01:35 +01:00
{
s32 xDist = 600 - Pos.vx;
s32 xDistSqr = xDist * xDist;
s32 yDist = m_base.vy - Pos.vy;
s32 yDistSqr = yDist * yDist;
2001-01-25 18:19:08 +01:00
2001-03-13 18:01:35 +01:00
if ( ( xDistSqr + yDistSqr ) > 100 )
{
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, xDist, yDist, m_speed );
2001-01-25 18:19:08 +01:00
}
else
{
2001-03-13 18:01:35 +01:00
m_extendDir = EXTEND_LEFT;
2001-01-25 18:19:08 +01:00
2001-03-13 18:01:35 +01:00
if ( m_movementTimer <= 0 )
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
m_controlFunc = NPC_CONTROL_CLOSE;
2001-01-25 18:19:08 +01:00
}
}
}
else
{
2001-03-13 18:01:35 +01:00
s32 xDist = 100 - Pos.vx;
s32 xDistSqr = xDist * xDist;
s32 yDist = m_base.vy - Pos.vy;
s32 yDistSqr = yDist * yDist;
if ( ( xDistSqr + yDistSqr ) > 100 )
{
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, xDist, yDist, m_speed );
2001-03-13 18:01:35 +01:00
}
else
{
m_extendDir = EXTEND_RIGHT;
if ( m_movementTimer <= 0 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
}
}
2001-05-03 23:39:27 +02:00
}*/
2001-01-25 18:19:08 +01:00
}
2001-06-11 23:49:49 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcSubSharkEnemy::processClose( int _frames )
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
if ( m_state != SUB_SHARK_SWALLOW )
2001-01-25 20:57:29 +01:00
{
2001-03-13 18:01:35 +01:00
if ( playerXDist > 0 )
{
m_extendDir = EXTEND_RIGHT;
}
else
{
m_extendDir = EXTEND_LEFT;
}
2001-01-25 20:57:29 +01:00
}
2001-01-25 18:19:08 +01:00
switch( m_state )
{
case SUB_SHARK_MINE_1:
2001-03-13 18:01:35 +01:00
case SUB_SHARK_MINE_2:
2001-01-25 18:19:08 +01:00
{
2001-05-03 23:39:27 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_SHARKSUB_SWIM;
m_frame = 0;
}
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, playerXDist, 0, m_speed );
2001-03-13 18:01:35 +01:00
2001-06-05 16:54:56 +02:00
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( Pos.vx < minX || Pos.vx > maxX || playerXDistSqr < 100 )
2001-01-25 18:19:08 +01:00
{
// fire at player
m_salvoCount = 5;
2001-03-13 18:01:35 +01:00
m_state++;
2001-01-25 18:19:08 +01:00
m_movementTimer = GameState::getOneSecondInFrames() * 8;
m_controlFunc = NPC_CONTROL_MOVEMENT;
}
break;
}
2001-03-13 18:01:35 +01:00
case SUB_SHARK_CYCLE:
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
// charge player
if ( !m_animPlaying )
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
m_animPlaying = true;
2001-05-03 23:39:27 +02:00
m_animNo = ANIM_SHARKSUB_SPRINTOPEN;
2001-03-13 18:01:35 +01:00
m_frame = 0;
2001-01-25 18:19:08 +01:00
}
2001-03-13 18:01:35 +01:00
processGenericGotoTarget( _frames, playerXDist, 0, NPC_SUB_SHARK_HIGH_SPEED );
2001-06-05 16:54:56 +02:00
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( Pos.vx < minX || Pos.vx > maxX || playerXDistSqr < 10000 )
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
m_animPlaying = true;
2001-05-03 23:39:27 +02:00
m_animNo = ANIM_SHARKSUB_CHOMP;
2001-03-13 18:01:35 +01:00
m_frame = 0;
2001-01-25 18:19:08 +01:00
2001-03-13 18:01:35 +01:00
m_state = SUB_SHARK_SWALLOW;
2001-01-25 18:19:08 +01:00
}
break;
}
2001-03-13 18:01:35 +01:00
case SUB_SHARK_SWALLOW:
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
// if ( collision )
// else
2001-01-25 18:19:08 +01:00
2001-06-05 16:54:56 +02:00
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
2001-03-13 18:01:35 +01:00
if ( m_extendDir == EXTEND_RIGHT )
2001-01-25 18:19:08 +01:00
{
2001-06-05 16:54:56 +02:00
//s32 xDist = 600 - Pos.vx;
s32 xDist = maxX - Pos.vx;
2001-03-13 20:46:15 +01:00
s32 xDistSqr = xDist * xDist;
if ( xDistSqr > 100 )
{
processGenericGotoTarget( _frames, xDist, 0, NPC_SUB_SHARK_HIGH_SPEED );
}
else
{
m_extendDir = EXTEND_LEFT;
}
2001-01-25 18:19:08 +01:00
}
else
{
2001-06-05 16:54:56 +02:00
//s32 xDist = 100 - Pos.vx;
s32 xDist = minX - Pos.vx;
2001-03-13 20:46:15 +01:00
s32 xDistSqr = xDist * xDist;
if ( xDistSqr > 100 )
{
processGenericGotoTarget( _frames, xDist, 0, NPC_SUB_SHARK_HIGH_SPEED );
}
else
{
m_extendDir = EXTEND_RIGHT;
}
2001-03-13 18:01:35 +01:00
}
if ( !m_animPlaying )
{
m_animPlaying = true;
2001-05-03 23:39:27 +02:00
m_animNo = ANIM_SHARKSUB_SWIM;
2001-03-13 18:01:35 +01:00
m_frame = 0;
2001-01-25 18:19:08 +01:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_movementTimer = GameState::getOneSecondInFrames() * 8;
m_state = SUB_SHARK_MINE_1;
}
break;
}
}
2001-06-11 23:49:49 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSubSharkEnemy::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 )
{
CSoundMediator::playSfx( m_data[m_type].deathSfx );
}
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;
}
}
}