diff --git a/source/enemy/nanemone.cpp b/source/enemy/nanemone.cpp index 8d43a919f..663b7ffe4 100644 --- a/source/enemy/nanemone.cpp +++ b/source/enemy/nanemone.cpp @@ -23,6 +23,110 @@ #include "game\game.h" #endif +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + + +void CNpc::processCloseAnemone1Attack( int _frames ) +{ + s32 moveX, moveY; + s16 decDir, incDir, moveDist; + CPlayer *player = GameScene.getPlayer(); + DVECTOR playerPos = player->getPos(); + s32 xDist, yDist; + s16 maxTurnRate = m_data[m_type].turnSpeed; + bool withinRange = false; + + xDist = playerPos.vx - this->Pos.vx; + + yDist = playerPos.vy - this->Pos.vy; + + s16 headingToPlayer = ratan2( yDist, xDist ); + + decDir = m_baseHeading - headingToPlayer; + + if ( decDir < 0 ) + { + decDir += ONE; + } + + incDir = headingToPlayer - m_baseHeading; + + 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(); + } + } + } +} void CNpc::processCloseAnemone2Attack( int _frames ) { diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index 4b042e7b3..6cd550c06 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -106,10 +106,10 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] = { // NPC_ANEMONE_1 NPC_INIT_DEFAULT, - NPC_SENSOR_NONE, + NPC_SENSOR_ANEMONE_USER_CLOSE, NPC_MOVEMENT_STATIC, NPC_MOVEMENT_MODIFIER_NONE, - NPC_CLOSE_NONE, + NPC_CLOSE_ANEMONE_1_ATTACK, NPC_TIMER_NONE, false, 0, @@ -383,9 +383,9 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] = void CNpc::init() { - m_type = NPC_ANEMONE_2; + m_type = NPC_ANEMONE_1; - m_heading = m_baseHeading = 3072; + m_heading = m_baseHeading = 0; m_movementTimer = 0; m_timerTimer = 0; m_velocity = 0; @@ -700,7 +700,7 @@ bool CNpc::processSensor() case NPC_SENSOR_ANEMONE_USER_CLOSE: { - if ( xDistSqr + yDistSqr < 10000 ) + if ( xDistSqr + yDistSqr < 40000 ) { m_controlFunc = NPC_CONTROL_CLOSE; @@ -897,9 +897,16 @@ void CNpc::processClose(int _frames) break; + case NPC_CLOSE_ANEMONE_1_ATTACK: + processCloseAnemone1Attack( _frames ); + + break; + case NPC_CLOSE_ANEMONE_2_ATTACK: processCloseAnemone2Attack( _frames ); + break; + default: break; } @@ -911,6 +918,11 @@ void CNpc::processCollision() void CNpc::processTimer(int _frames) { + if ( m_timerTimer > 0 ) + { + this->m_timerTimer -= _frames; + } + switch( m_timerFunc ) { case NPC_TIMER_NONE: @@ -921,8 +933,6 @@ void CNpc::processTimer(int _frames) case NPC_TIMER_EVADE_DONE: case NPC_TIMER_ATTACK_DONE: { - this->m_timerTimer -= _frames; - if ( m_timerTimer <= 0 ) { this->m_timerFunc = NPC_TIMER_NONE; diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 139365cdd..aa87a8126 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -107,6 +107,7 @@ protected: NPC_CLOSE_GHOST_PIRATE_ATTACK, NPC_CLOSE_SHARK_MAN_ATTACK, NPC_CLOSE_GENERIC_USER_SEEK, + NPC_CLOSE_ANEMONE_1_ATTACK, NPC_CLOSE_ANEMONE_2_ATTACK, }; @@ -192,6 +193,7 @@ protected: // anemone functions + void processCloseAnemone1Attack( int _frames ); void processCloseAnemone2Attack( int _frames ); // data