139 lines
2.6 KiB
C++
139 lines
2.6 KiB
C++
/*=========================================================================
|
|
|
|
nbblob.cpp
|
|
|
|
Author: CRB
|
|
Created:
|
|
Project: Spongebob
|
|
Purpose:
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
===========================================================================*/
|
|
|
|
#ifndef __ENEMY_NPC_H__
|
|
#include "enemy\npc.h"
|
|
#endif
|
|
|
|
#ifndef __GAME_GAME_H__
|
|
#include "game\game.h"
|
|
#endif
|
|
|
|
#ifndef __ANIM_BALLBLOB_HEADER__
|
|
#include <ACTOR_BALLBLOB_ANIM.h>
|
|
#endif
|
|
|
|
void CNpcEnemy::processBallBlobMovement( int _frames, s32 *moveX, s32 *moveY )
|
|
{
|
|
s32 waypointXDist;
|
|
s32 waypointYDist;
|
|
s32 waypointHeading;
|
|
|
|
if ( !m_animPlaying && m_frame != 0 )
|
|
{
|
|
m_animNo = ANIM_BALLBLOB_WOBBLE;
|
|
m_frame = 0;
|
|
}
|
|
else if ( m_animNo == ANIM_BALLBLOB_BOUNCE )
|
|
{
|
|
*moveX = 0;
|
|
*moveY = 0;
|
|
|
|
return;
|
|
}
|
|
|
|
// deal with horizontal
|
|
|
|
if ( m_npcPath.thinkFlat( Pos, &waypointXDist, &waypointYDist, &waypointHeading ) )
|
|
{
|
|
// increment waypoint
|
|
|
|
if ( waypointHeading == 0 )
|
|
{
|
|
// head right
|
|
|
|
if ( m_heading >= 1024 && m_heading <= 3072 )
|
|
{
|
|
// currently heading in the wrong direction, reverse horizontal
|
|
|
|
s32 headingDiff = m_heading - 2048;
|
|
|
|
headingDiff = -headingDiff;
|
|
|
|
headingDiff += 4096;
|
|
|
|
m_heading = headingDiff % 4096;
|
|
|
|
m_animPlaying = true;
|
|
m_animNo = ANIM_BALLBLOB_WOBBLE;
|
|
m_frame = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// head left
|
|
|
|
if ( m_heading < 1024 || m_heading > 3072 )
|
|
{
|
|
// currently heading in the wrong direction, reverse horizontal
|
|
|
|
s32 headingDiff = m_heading;
|
|
|
|
headingDiff = -headingDiff;
|
|
|
|
headingDiff += 6144;
|
|
|
|
m_heading = headingDiff % 4096;
|
|
|
|
m_animPlaying = true;
|
|
m_animNo = ANIM_BALLBLOB_WOBBLE;
|
|
m_frame = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
s32 preShiftX = _frames * m_data[m_type].speed * rcos( m_heading );
|
|
s32 preShiftY = _frames * m_data[m_type].speed * rsin( m_heading );
|
|
|
|
*moveX = preShiftX >> 12;
|
|
if ( !(*moveX) && preShiftX )
|
|
{
|
|
*moveX = preShiftX / abs( preShiftX );
|
|
}
|
|
|
|
*moveY = preShiftY >> 12;
|
|
if ( !(*moveY) && preShiftY )
|
|
{
|
|
*moveY = preShiftY / abs( preShiftY );
|
|
}
|
|
|
|
// deal with vertical
|
|
|
|
if ( Pos.vy < 0 || m_layerCollision->Get( ( Pos.vx + *moveX ) >> 4, ( Pos.vy + *moveY ) >> 4 ) )
|
|
{
|
|
// reflect heading in vertical
|
|
|
|
m_heading = 4096 - m_heading;
|
|
|
|
m_animPlaying = true;
|
|
m_animNo = ANIM_BALLBLOB_BOUNCE;
|
|
m_frame = 0;
|
|
|
|
// get new movement values
|
|
|
|
preShiftX = _frames * m_data[m_type].speed * rcos( m_heading );
|
|
preShiftY = _frames * m_data[m_type].speed * rsin( m_heading );
|
|
|
|
*moveX = preShiftX >> 12;
|
|
if ( !(*moveX) && preShiftX )
|
|
{
|
|
*moveX = preShiftX / abs( preShiftX );
|
|
}
|
|
|
|
*moveY = preShiftY >> 12;
|
|
if ( !(*moveY) && preShiftY )
|
|
{
|
|
*moveY = preShiftY / abs( preShiftY );
|
|
}
|
|
}
|
|
} |