SBSPSS/source/enemy/nmjfish.cpp

220 lines
4.4 KiB
C++
Raw Normal View History

2001-01-25 16:30:11 +01:00
/*=========================================================================
2001-04-20 22:22:16 +02:00
nmjfish.cpp
2001-01-25 16:30:11 +01:00
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_NMJFISH_H__
#include "enemy\nmjfish.h"
#endif
2001-01-25 16:30:11 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-03-12 20:14:38 +01:00
#define MJ_CYCLE_WIDTH 400
#define MJ_HALF_CYCLE_WIDTH ( MJ_CYCLE_WIDTH >> 1 )
2001-01-25 16:30:11 +01:00
2001-04-20 22:22:16 +02:00
void CNpcMotherJellyfishEnemy::postInit()
{
m_state = MOTHER_JELLYFISH_RETURN_TO_START_1;
}
void CNpcMotherJellyfishEnemy::processMovement( int _frames )
2001-01-25 16:30:11 +01:00
{
s32 xDist, yDist;
s32 xDistSqr, yDistSqr;
switch( m_state )
{
2001-03-12 20:14:38 +01:00
case MOTHER_JELLYFISH_RETURN_TO_START_1:
case MOTHER_JELLYFISH_RETURN_TO_START_2:
case MOTHER_JELLYFISH_RETURN_TO_START_3:
2001-01-25 16:30:11 +01:00
{
2001-03-12 20:14:38 +01:00
xDist = m_base.vx - this->Pos.vx - MJ_HALF_CYCLE_WIDTH;
2001-01-25 16:30:11 +01:00
xDistSqr = xDist * xDist;
yDist = m_base.vy - this->Pos.vy;
yDistSqr = yDist * yDist;
if ( xDistSqr + yDistSqr > 100 )
{
processGenericGotoTarget( _frames, xDist, yDist, m_data[m_type].speed );
}
else
{
// have arrived at base position
2001-03-12 20:14:38 +01:00
m_movementTimer = GameState::getOneSecondInFrames() * 10;
m_state++;
m_extension = -MJ_HALF_CYCLE_WIDTH;
2001-01-25 16:30:11 +01:00
m_extendDir = EXTEND_RIGHT;
}
break;
}
2001-03-12 20:14:38 +01:00
case MOTHER_JELLYFISH_CYCLE_1:
case MOTHER_JELLYFISH_CYCLE_2:
case MOTHER_JELLYFISH_CYCLE_3:
2001-01-25 16:30:11 +01:00
{
2001-03-12 20:14:38 +01:00
m_movementTimer -= _frames;
s32 xExtension;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
if ( m_extendDir == EXTEND_RIGHT )
{
if ( m_extension < MJ_HALF_CYCLE_WIDTH )
2001-01-25 16:30:11 +01:00
{
2001-03-12 20:14:38 +01:00
m_extension += 3 * _frames;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
xExtension = ( MJ_HALF_CYCLE_WIDTH * rsin( ( m_extension << 10 ) / MJ_HALF_CYCLE_WIDTH ) ) >> 12;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
Pos.vx = m_base.vx + xExtension;
Pos.vy = m_base.vy - ( ( 50 * rsin( ( xExtension << 12 ) / MJ_CYCLE_WIDTH ) ) >> 12 );
m_heading = 0;
2001-01-25 16:30:11 +01:00
}
else
{
2001-03-12 20:14:38 +01:00
m_extendDir = EXTEND_LEFT;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
if ( m_movementTimer < 0 )
2001-01-25 16:30:11 +01:00
{
2001-03-12 20:14:38 +01:00
m_controlFunc = NPC_CONTROL_CLOSE;
m_state++;
2001-01-25 16:30:11 +01:00
}
}
}
else
{
2001-03-12 20:14:38 +01:00
if ( m_extension > -MJ_HALF_CYCLE_WIDTH )
{
m_extension -= 3 * _frames;
xExtension = ( MJ_HALF_CYCLE_WIDTH * rsin( ( m_extension << 10 ) / MJ_HALF_CYCLE_WIDTH ) ) >> 12;
Pos.vx = m_base.vx + xExtension;
Pos.vy = m_base.vy + ( ( 50 * rsin( ( xExtension << 12 ) / MJ_CYCLE_WIDTH ) ) >> 12 );
m_heading = 2048;
}
else
{
m_extendDir = EXTEND_RIGHT;
if ( m_movementTimer < 0 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_state++;
}
}
2001-01-25 16:30:11 +01:00
}
break;
}
default:
break;
}
}
2001-04-20 22:22:16 +02:00
void CNpcMotherJellyfishEnemy::processClose( int _frames )
2001-01-25 16:30:11 +01:00
{
2001-03-12 20:14:38 +01:00
switch( m_state )
{
case MOTHER_JELLYFISH_ATTACK_PLAYER_SHOCK:
{
// seek position above user
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
CPlayer *player = GameScene.getPlayer();
DVECTOR playerPos = player->getPos();
DVECTOR seekPos;
s32 xDist, yDist;
s32 xDistSqr, yDistSqr;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
seekPos = playerPos;
seekPos.vy -= 100;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
xDist = seekPos.vx - this->Pos.vx;
xDistSqr = xDist * xDist;
yDist = seekPos.vy - this->Pos.vy;
yDistSqr = yDist * yDist;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
if ( xDistSqr + yDistSqr > 400 )
{
processGenericGotoTarget( _frames, xDist, yDist, m_data[m_type].speed );
}
else
{
// fire at user
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_state = MOTHER_JELLYFISH_RETURN_TO_START_1;
}
break;
}
default:
{
s32 xExtension;
if ( m_extendDir == EXTEND_RIGHT )
{
if ( m_extension < MJ_HALF_CYCLE_WIDTH )
{
m_extension += 3 * _frames;
2001-01-25 16:30:11 +01:00
2001-03-12 20:14:38 +01:00
xExtension = ( MJ_HALF_CYCLE_WIDTH * rsin( ( m_extension << 10 ) / MJ_HALF_CYCLE_WIDTH ) ) >> 12;
Pos.vx = m_base.vx + xExtension;
Pos.vy = m_base.vy - ( ( 50 * rcos( ( xExtension << 11 ) / MJ_CYCLE_WIDTH ) ) >> 12 );
m_heading = 0;
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_state++;
}
}
else
{
if ( m_extension > -MJ_HALF_CYCLE_WIDTH )
{
m_extension -= 3 * _frames;
xExtension = ( MJ_HALF_CYCLE_WIDTH * rsin( ( m_extension << 10 ) / MJ_HALF_CYCLE_WIDTH ) ) >> 12;
Pos.vx = m_base.vx + xExtension;
Pos.vy = m_base.vy + ( ( 50 * rcos( ( xExtension << 11 ) / MJ_CYCLE_WIDTH ) ) >> 12 );
m_heading = 2048;
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_state++;
}
}
break;
}
2001-01-25 16:30:11 +01:00
}
}