SBSPSS/source/enemy/nfdutch.cpp

360 lines
6.3 KiB
C++
Raw Normal View History

2001-01-25 16:30:11 +01:00
/*=========================================================================
nfdutch.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 22:22:16 +02:00
#ifndef __ENEMY_NFDUTCH_H__
#include "enemy\nfdutch.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
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-06-12 20:12:34 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-04-04 21:55:49 +02:00
#ifndef __ANIM_FLYINGDUTCHMAN_HEADER__
#include <ACTOR_FLYINGDUTCHMAN_ANIM.h>
#endif
2001-01-25 16:30:11 +01:00
2001-06-12 22:40:08 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
#endif
2001-06-12 20:12:34 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcFlyingDutchmanEnemy::postInit()
{
m_state = FLYING_DUTCHMAN_ATTACK_PLAYER_1;
m_extendDir = EXTEND_UP;
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
2001-05-04 00:15:13 +02:00
m_npcPath.getPathYExtents( &m_minY, &m_maxY );
2001-04-20 22:22:16 +02:00
m_extension = minX;
}
2001-06-12 20:12:34 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcFlyingDutchmanEnemy::processMovement( int _frames )
2001-01-25 16:30:11 +01:00
{
2001-04-04 21:55:49 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
}
2001-01-25 16:30:11 +01:00
if ( m_movementTimer > 0 )
{
m_movementTimer -= _frames;
2001-03-13 21:45:51 +01:00
s32 xDist = m_extension - Pos.vx;
s32 xDistSqr = xDist * xDist;
2001-01-25 16:30:11 +01:00
2001-03-13 21:45:51 +01:00
if ( xDistSqr > 100 )
{
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, xDist, 0, m_speed );
2001-01-25 16:30:11 +01:00
}
else
{
2001-03-13 21:45:51 +01:00
if ( m_extendDir == EXTEND_UP )
2001-01-25 16:30:11 +01:00
{
2001-05-04 00:15:13 +02:00
s32 yDist = m_minY - Pos.vy;
2001-03-13 21:45:51 +01:00
s32 yDistSqr = yDist * yDist;
if ( yDistSqr > 100 )
{
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, 0, yDist, m_speed );
2001-03-13 21:45:51 +01:00
}
else
{
m_extendDir = EXTEND_DOWN;
}
2001-01-25 16:30:11 +01:00
}
else
{
2001-05-04 00:15:13 +02:00
s32 yDist = m_maxY - Pos.vy;
2001-03-13 21:45:51 +01:00
s32 yDistSqr = yDist * yDist;
if ( yDistSqr > 100 )
{
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, 0, yDist, m_speed );
2001-03-13 21:45:51 +01:00
}
else
{
m_extendDir = EXTEND_UP;
}
2001-01-25 16:30:11 +01:00
}
}
}
else
{
m_controlFunc = NPC_CONTROL_CLOSE;
}
2001-04-04 21:55:49 +02:00
if ( playerXDist > 0 )
{
m_heading = 0;
}
else
{
m_heading = 2048;
}
2001-01-25 16:30:11 +01:00
}
2001-06-12 20:12:34 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcFlyingDutchmanEnemy::processClose( int _frames )
2001-01-25 16:30:11 +01:00
{
2001-02-07 17:42:13 +01:00
if ( playerYDist > 0 )
2001-01-25 16:30:11 +01:00
{
m_extendDir = EXTEND_DOWN;
}
else
{
m_extendDir = EXTEND_UP;
}
2001-02-07 17:42:13 +01:00
if ( playerYDistSqr > 100 )
2001-01-25 16:30:11 +01:00
{
2001-04-04 21:55:49 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
}
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, 0, playerYDist, m_speed );
2001-01-25 16:30:11 +01:00
}
else
{
switch( m_state )
{
case FLYING_DUTCHMAN_ATTACK_PLAYER_1:
case FLYING_DUTCHMAN_ATTACK_PLAYER_2:
{
2001-04-04 21:55:49 +02:00
if ( m_animNo != ANIM_FLYINGDUTCHMAN_FIREATTACK )
2001-01-25 16:30:11 +01:00
{
2001-04-04 21:55:49 +02:00
m_animNo = ANIM_FLYINGDUTCHMAN_FIREATTACK;
m_animPlaying = true;
m_frame = 0;
2001-01-25 16:30:11 +01:00
}
2001-04-04 21:55:49 +02:00
else if ( !m_animPlaying )
2001-01-25 16:30:11 +01:00
{
2001-04-04 21:55:49 +02:00
// fire at player
s16 heading;
2001-01-25 16:30:11 +01:00
2001-04-04 21:55:49 +02:00
if ( playerXDist > 0 )
{
heading = 0;
}
else
{
heading = 2048;
}
2001-01-25 16:30:11 +01:00
2001-04-04 21:55:49 +02:00
CProjectile *projectile;
2001-06-14 18:07:48 +02:00
projectile = CProjectile::Create();
2001-06-12 22:40:08 +02:00
DVECTOR newPos = Pos;
newPos.vy -= 50;
projectile->init( newPos, heading );
projectile->setGraphic( FRM__LIGHTNING2 );
2001-01-25 16:30:11 +01:00
2001-04-04 21:55:49 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_state++;
}
2001-01-25 16:30:11 +01:00
break;
}
default:
{
2001-04-04 21:55:49 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
}
2001-01-25 16:30:11 +01:00
// charge player
2001-02-07 17:42:13 +01:00
if ( playerXDistSqr + playerYDistSqr > 100 )
2001-01-25 16:30:11 +01:00
{
2001-02-07 17:42:13 +01:00
processGenericGotoTarget( _frames, playerXDist, playerYDist, 6 );
2001-01-25 16:30:11 +01:00
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_state = FLYING_DUTCHMAN_ATTACK_PLAYER_1;
2001-03-13 21:45:51 +01:00
2001-04-06 15:43:03 +02:00
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( m_extension == minX )
2001-03-13 21:45:51 +01:00
{
2001-04-06 15:43:03 +02:00
m_extension = maxX;
2001-03-13 21:45:51 +01:00
}
else
{
2001-04-06 15:43:03 +02:00
m_extension = minX;
2001-03-13 21:45:51 +01:00
}
2001-01-25 16:30:11 +01:00
}
break;
}
}
}
2001-04-04 21:55:49 +02:00
if ( playerXDist > 0 )
{
m_heading = 0;
}
else
{
m_heading = 2048;
}
2001-06-12 20:12:34 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFlyingDutchmanEnemy::processShot( int _frames )
{
switch( m_data[m_type].shotFunc )
{
case NPC_SHOT_NONE:
{
// do nothing
break;
}
case NPC_SHOT_GENERIC:
{
switch ( m_state )
{
case NPC_GENERIC_HIT_CHECK_HEALTH:
{
m_health -= 5;
if ( m_health < 0 )
{
m_state = NPC_GENERIC_HIT_DEATH_START;
m_isDying = true;
}
else
{
m_state = NPC_GENERIC_HIT_RECOIL;
m_animPlaying = true;
m_animNo = m_data[m_type].recoilAnim;
m_frame = 0;
}
break;
}
case NPC_GENERIC_HIT_RECOIL:
{
if ( !m_animPlaying )
{
m_state = 0;
m_controlFunc = NPC_CONTROL_MOVEMENT;
}
break;
}
case NPC_GENERIC_HIT_DEATH_START:
{
m_animPlaying = true;
m_animNo = m_data[m_type].dieAnim;
m_frame = 0;
m_state = NPC_GENERIC_HIT_DEATH_END;
m_isDying = true;
if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS )
{
CSoundMediator::playSfx( m_data[m_type].deathSfx );
}
m_speed = -5;
if (m_data[m_type].skelType)
{
m_actorGfx->SetOtPos( 0 );
}
break;
}
case NPC_GENERIC_HIT_DEATH_END:
{
if ( !m_animPlaying )
{
m_drawRotation += 64 * _frames;
m_drawRotation &= 4095;
Pos.vy += m_speed * _frames;
if ( m_speed < 5 )
{
m_speed++;
}
DVECTOR offset = CLevel::getCameraPos();
if ( Pos.vy - offset.vy > VidGetScrH() )
{
if ( m_data[m_type].respawning )
{
m_isActive = false;
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 4 * GameState::getOneSecondInFrames();
}
else
{
setToShutdown();
CGameScene::setBossHasBeenKilled();
}
}
}
break;
}
}
break;
}
}
}