SBSPSS/source/enemy/ngpirate.cpp

137 lines
2.3 KiB
C++
Raw Normal View History

2001-01-19 21:18:54 +01:00
/*=========================================================================
ngpirate.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 16:48:15 +02:00
#ifndef __ENEMY_NGPIRATE_H__
#include "enemy\ngpirate.h"
#endif
2001-01-19 21:18:54 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-01-22 20:48:57 +01:00
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-01-19 21:18:54 +01:00
2001-04-20 22:22:16 +02:00
void CNpcGhostPirateEnemy::postInit()
{
m_heading = m_fireHeading = 3072;
}
2001-04-20 16:48:15 +02:00
bool CNpcGhostPirateEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr + playerYDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
m_movementTimer = GameState::getOneSecondInFrames() >> 1;
m_velocity = 4;
return( true );
}
else
{
return( false );
}
}
}
}
void CNpcGhostPirateEnemy::processClose( int _frames )
2001-01-19 21:18:54 +01:00
{
s32 velocity;
if ( m_extendDir == EXTEND_UP )
{
m_movementTimer -= _frames;
if ( m_movementTimer > 0 )
{
// extend
velocity = m_velocity * _frames;
m_extension += velocity;
Pos.vx += ( velocity * rcos( m_heading ) ) >> 12;
Pos.vy += ( velocity * rsin( m_heading ) ) >> 12;
}
else
{
m_extendDir = EXTEND_DOWN;
2001-01-22 20:48:57 +01:00
// fire
s16 heading;
2001-02-07 17:42:13 +01:00
if ( playerXDist > 0 )
2001-01-22 20:48:57 +01:00
{
heading = 0;
}
else
{
heading = 2048;
}
CProjectile *projectile;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos, heading );
2001-04-12 16:55:55 +02:00
projectile->setLayerCollision( m_layerCollision );
2001-01-19 21:18:54 +01:00
}
}
else if ( m_extendDir == EXTEND_DOWN )
{
// retract
if ( m_extension > 0 )
{
velocity = - ( m_velocity * _frames );
if ( m_extension < _frames )
{
velocity = m_extension - _frames;
}
m_extension += velocity;
Pos.vx += ( velocity * rcos( m_heading ) ) >> 12;
Pos.vy += ( velocity * rsin( m_heading ) ) >> 12;
}
else
{
this->m_controlFunc = NPC_CONTROL_MOVEMENT;
this->m_timerFunc = NPC_TIMER_ATTACK_DONE;
this->m_timerTimer = GameState::getOneSecondInFrames();
this->m_sensorFunc = NPC_SENSOR_NONE;
}
}
}