SBSPSS/source/enemy/nanemone.cpp

248 lines
4.8 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
2001-04-02 17:52:09 +02:00
#ifndef __ANIM_ANENOMELVL1_HEADER__
#include <ACTOR_ANENOMELVL1_ANIM.h>
#endif
#ifndef __ANIM_SPIKEYANENOME_HEADER__
#include <ACTOR_SPIKEYANENOME_ANIM.h>
#endif
2001-04-04 17:53:44 +02:00
#ifndef __ANIM_ANENOMELVL3_HEADER__
#include <ACTOR_ANENOMELVL3_ANIM.h>
#endif
2001-01-22 18:44:58 +01:00
2001-02-27 22:25:22 +01:00
void CNpcEnemy::processCloseAnemone1Attack( int _frames )
2001-01-22 18:44:58 +01:00
{
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
2001-04-02 17:52:09 +02:00
if ( m_timerTimer <= 0 && !m_animPlaying )
2001-01-22 18:44:58 +01:00
{
2001-04-02 17:52:09 +02:00
if ( m_animNo != ANIM_ANENOMELVL1_FIRE )
{
m_animPlaying = true;
m_animNo = ANIM_ANENOMELVL1_FIRE;
m_frame = 0;
}
else
{
CProjectile *projectile;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos, m_heading );
2001-04-12 16:55:55 +02:00
projectile->setLayerCollision( m_layerCollision );
2001-04-02 17:52:09 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerTimer = GameState::getOneSecondInFrames();
2001-04-05 22:44:30 +02:00
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_sensorFunc = NPC_SENSOR_NONE;
2001-04-02 17:52:09 +02:00
m_animPlaying = true;
m_animNo = ANIM_ANENOMELVL1_BEND;
m_frame = 0;
}
2001-01-22 18:44:58 +01:00
}
}
}
}
2001-01-22 17:01:49 +01:00
2001-02-27 22:25:22 +01:00
void CNpcEnemy::processCloseAnemone2Attack( int _frames )
2001-01-22 17:01:49 +01:00
{
int fireLoop;
CProjectile *projectile;
s16 heading;
2001-04-02 17:52:09 +02:00
if ( m_animNo != ANIM_SPIKEYANENOME_BODY )
2001-01-22 17:01:49 +01:00
{
2001-04-02 17:52:09 +02:00
m_animPlaying = true;
m_animNo = ANIM_SPIKEYANENOME_BODY;
m_frame = 0;
2001-01-22 17:01:49 +01:00
}
2001-04-02 17:52:09 +02:00
else
{
2001-04-04 17:53:44 +02:00
CProjectile *projectile;
s16 heading;
// fire off attached spikes
CThing *nextThing = Next;
while ( nextThing )
{
CProjectile *projectile;
projectile = (CProjectile *) nextThing;
if ( projectile->getMovementType() == CProjectile::PROJECTILE_FIXED )
{
projectile->setMovementType( CProjectile::PROJECTILE_DUMBFIRE );
projectile->setLifeTime( CProjectile::PROJECTILE_FINITE_LIFE );
projectile->setState( CProjectile::PROJECTILE_ATTACK );
}
nextThing = nextThing->getNext();
}
2001-04-12 18:33:48 +02:00
removeAllChild();
2001-04-04 17:53:44 +02:00
// attach new spikes
2001-04-02 17:52:09 +02:00
for ( fireLoop = 0 ; fireLoop < 5 ; fireLoop++ )
{
2001-04-04 17:53:44 +02:00
DVECTOR spikePos;
2001-04-02 17:52:09 +02:00
heading = m_heading - 1024 + ( fireLoop * 512 );
2001-04-05 16:17:24 +02:00
heading &= 4095;
2001-01-22 17:01:49 +01:00
2001-04-04 17:53:44 +02:00
spikePos = Pos;
2001-04-09 22:20:58 +02:00
spikePos.vx += ( 40 * rcos( heading ) ) >> 12;
spikePos.vy += ( 40 * rsin( heading ) ) >> 12;
2001-04-04 17:53:44 +02:00
projectile = new( "anemone lev2 projectile" ) CProjectile;
projectile->init( spikePos, heading, CProjectile::PROJECTILE_FIXED, CProjectile::PROJECTILE_INFINITE_LIFE );
2001-04-12 16:55:55 +02:00
projectile->setLayerCollision( m_layerCollision );
2001-04-04 17:53:44 +02:00
addChild( projectile );
2001-04-02 17:52:09 +02:00
}
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}
2001-02-08 16:34:18 +01:00
}
2001-02-27 22:25:22 +01:00
void CNpcEnemy::processCloseAnemone3Attack( int _frames )
2001-02-08 16:34:18 +01:00
{
2001-04-04 17:53:44 +02:00
if ( m_animNo != ANIM_ANENOMELVL3_FIRE )
{
m_animPlaying = true;
m_animNo = ANIM_ANENOMELVL3_FIRE;
m_frame = 0;
}
else if ( !m_animPlaying )
{
CProjectile *projectile;
u8 lifetime = 8;
projectile = new( "test projectile" ) CProjectile;
projectile->init( Pos,
m_fireHeading,
CProjectile::PROJECTILE_GAS_CLOUD,
CProjectile::PROJECTILE_FINITE_LIFE,
lifetime * GameState::getOneSecondInFrames() );
2001-04-12 16:55:55 +02:00
projectile->setLayerCollision( m_layerCollision );
2001-04-04 17:53:44 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = ( lifetime + 4 ) * GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
m_animPlaying = true;
m_animNo = ANIM_ANENOMELVL3_BEND;
m_frame = 0;
}
2001-01-22 17:01:49 +01:00
}