SBSPSS/source/enemy/nshrkman.cpp

117 lines
2.1 KiB
C++
Raw Normal View History

2001-01-19 21:51:24 +01:00
/*=========================================================================
nshrkman.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
void CNpc::processCloseSharkManAttack( int _frames )
{
2001-02-22 17:56:27 +01:00
s32 moveX = 0, moveY = 0;
s32 groundHeight;
2001-01-19 21:51:24 +01:00
s16 decDir, incDir, moveDist;
2001-02-22 17:56:27 +01:00
s32 direction;
s32 maxHeight = 10;
s32 fallSpeed = 2;
s8 yMovement = fallSpeed * _frames;
2001-01-19 21:51:24 +01:00
2001-02-07 17:42:13 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-01-19 21:51:24 +01:00
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;
}
2001-01-19 22:46:30 +01:00
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
2001-02-07 17:42:13 +01:00
if ( abs( moveDist ) < 1024 && abs( xDistWaypoint ) >= abs( playerXDist ) )
2001-01-19 21:51:24 +01:00
{
// continue charge
2001-02-22 17:56:27 +01:00
if ( playerXDist != 0 )
2001-01-19 21:51:24 +01:00
{
2001-02-22 17:56:27 +01:00
direction = playerXDist / abs( playerXDist );
2001-01-19 21:51:24 +01:00
}
else
{
2001-02-22 17:56:27 +01:00
direction = 1;
2001-01-19 21:51:24 +01:00
}
2001-02-22 17:56:27 +01:00
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( _frames * m_velocity * direction ), Pos.vy ) < -maxHeight )
2001-01-19 21:51:24 +01:00
{
2001-02-22 17:56:27 +01:00
// there is an obstacle in the way, abort
2001-01-19 21:51:24 +01:00
2001-02-22 17:56:27 +01:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
2001-01-19 21:51:24 +01:00
}
2001-02-22 17:56:27 +01:00
else
{
// check for vertical movement
2001-01-19 21:51:24 +01:00
2001-02-22 17:56:27 +01:00
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveX = _frames * m_velocity * direction;
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
Pos.vx += moveX;
Pos.vy += moveY;
}
2001-01-19 21:51:24 +01:00
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
}
}