SBSPSS/source/enemy/nsshark.cpp

224 lines
3.9 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
#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__
#include <ACTOR_SHARKSUB_ANIM.h>
#endif
2001-02-27 22:25:22 +01:00
void CNpcEnemy::processSubSharkMovement( 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;
m_animNo = ANIM_SHARKSUB_SHARKSUBSWIPE;
m_frame = 0;
}
else
{
m_animPlaying = true;
m_animNo = ANIM_SHARKSUB_SHARKSUBSWIM;
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;
projectile = new( "test projectile" ) CProjectile;
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-03-13 18:01:35 +01:00
if ( m_extendDir == EXTEND_RIGHT )
{
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 )
{
processGenericGotoTarget( _frames, xDist, yDist, m_data[m_type].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 )
{
processGenericGotoTarget( _frames, xDist, yDist, m_data[m_type].speed );
}
else
{
m_extendDir = EXTEND_RIGHT;
if ( m_movementTimer <= 0 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
}
}
2001-01-25 18:19:08 +01:00
}
}
2001-02-27 22:25:22 +01:00
void CNpcEnemy::processCloseSubSharkAttack( 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-03-13 18:01:35 +01:00
processGenericGotoTarget( _frames, playerXDist, 0, m_data[m_type].speed );
if ( 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;
m_animNo = ANIM_SHARKSUB_SHARKSUBSPRINTOPEN;
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 );
if ( playerXDistSqr < 10000 )
2001-01-25 18:19:08 +01:00
{
2001-03-13 18:01:35 +01:00
m_animPlaying = true;
m_animNo = ANIM_SHARKSUB_SHARKSUBCHOMP;
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-03-13 18:01:35 +01:00
if ( m_extendDir == EXTEND_RIGHT )
2001-01-25 18:19:08 +01:00
{
2001-03-13 20:46:15 +01:00
s32 xDist = 600 - Pos.vx;
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-03-13 20:46:15 +01:00
s32 xDist = 100 - Pos.vx;
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;
m_animNo = ANIM_SHARKSUB_SHARKSUBSWIM;
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;
}
}
}