SBSPSS/source/enemy/nanemone.cpp

143 lines
2.3 KiB
C++
Raw Normal View History

2001-01-22 17:01:49 +01:00
/*=========================================================================
nanemone.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-01-22 18:44:58 +01:00
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
void CNpc::processCloseAnemone1Attack( int _frames )
{
s32 moveX, moveY;
s16 decDir, incDir, moveDist;
s16 maxTurnRate = m_data[m_type].turnSpeed;
bool withinRange = false;
2001-02-07 17:42:13 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-01-22 18:44:58 +01:00
2001-01-22 20:14:00 +01:00
decDir = m_fireHeading - headingToPlayer;
2001-01-22 18:44:58 +01:00
if ( decDir < 0 )
{
decDir += ONE;
}
2001-01-22 20:14:00 +01:00
incDir = headingToPlayer - m_fireHeading;
2001-01-22 18:44:58 +01:00
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
// check user is within 45 degrees either way
if ( moveDist < 512 )
{
decDir = m_heading - headingToPlayer;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToPlayer - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist < -maxTurnRate )
{
moveDist = -maxTurnRate;
}
else if ( moveDist > maxTurnRate )
{
moveDist = maxTurnRate;
}
else
{
withinRange = true;
}
m_heading += moveDist;
m_heading = m_heading % ONE;
if ( withinRange )
{
// can fire
if ( m_timerTimer <= 0 )
{
CProjectile *projectile;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos, m_heading );
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerTimer = GameState::getOneSecondInFrames();
}
}
}
}
2001-01-22 17:01:49 +01:00
void CNpc::processCloseAnemone2Attack( int _frames )
{
int fireLoop;
CProjectile *projectile;
s16 heading;
for ( fireLoop = 0 ; fireLoop < 5 ; fireLoop++ )
{
2001-01-22 20:14:00 +01:00
heading = m_heading - 1024 + ( fireLoop * 512 );
2001-01-22 17:01:49 +01:00
heading %= 4096;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos, heading );
}
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}