SBSPSS/source/enemy/nsshark.cpp

269 lines
4.5 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-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
}
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;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos, 1024 );
2001-04-12 16:55:55 +02:00
projectile->setLayerCollision( m_layerCollision );
2001-01-25 18:19:08 +01:00
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-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
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;
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 );
if ( 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-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;
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;
}
}
}