SBSPSS/source/hazard/hfirebal.cpp

144 lines
2.9 KiB
C++
Raw Normal View History

2001-04-24 16:13:32 +02:00
/*=========================================================================
hfirebal.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HFIREBAL_H__
#include "hazard\hfirebal.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-18 14:55:34 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-04-24 16:13:32 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFireballHazard::init()
{
CNpcHazard::init();
2001-05-18 14:55:34 +02:00
m_extension = 0;
m_velocity = 40;
2001-05-23 21:11:51 +02:00
m_height = 50;
2001-04-24 16:13:32 +02:00
2001-05-18 14:55:34 +02:00
m_respawnRate = 4;
}
2001-04-24 16:13:32 +02:00
2001-05-18 14:55:34 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 16:13:32 +02:00
2001-05-18 14:55:34 +02:00
void CNpcFireballHazard::setWaypoints( sThingHazard *ThisHazard )
{
int pointNum;
2001-04-24 16:13:32 +02:00
2001-05-18 14:55:34 +02:00
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
2001-05-10 21:27:57 +02:00
2001-05-18 14:55:34 +02:00
u16 newXPos, newYPos;
2001-05-30 00:07:28 +02:00
m_npcPath.setWaypointCount( ThisHazard->PointCount - 1 );
2001-05-18 14:55:34 +02:00
newXPos = (u16) *PntList;
2001-05-30 00:07:28 +02:00
setWaypointPtr( PntList );
2001-05-18 14:55:34 +02:00
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
2001-05-31 18:24:48 +02:00
startPos.vx = ( newXPos << 4 ) + 8;
startPos.vy = ( newYPos << 4 ) + 16;
2001-05-18 14:55:34 +02:00
Pos = startPos;
m_base = Pos;
2001-05-23 21:11:51 +02:00
s32 minX, maxX, minY, maxY;
m_npcPath.getPathXExtents( &minX, &maxX );
m_width = maxX - minX;
m_npcPath.getPathYExtents( &minY, &maxY );
m_height = maxY - minY;
2001-06-14 23:27:25 +02:00
if ( ThisHazard->PointCount > 1 )
{
newXPos = (u16) *PntList;
if ( ( ( newXPos << 4 ) + 8 ) < startPos.vx )
{
m_width = -m_width;
}
}
2001-06-19 22:07:57 +02:00
m_thinkArea.x1 = minX;
m_thinkArea.x2 = maxX;
m_thinkArea.y1 = minY;
m_thinkArea.y2 = maxY;
2001-04-24 16:13:32 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFireballHazard::processMovement( int _frames )
{
s32 velocity;
if ( m_extension < 4096 )
{
velocity = m_velocity * _frames;
if ( 4096 - m_extension < velocity )
{
velocity = 4096 - m_extension;
}
m_extension += velocity;
}
else
{
// move complete
Pos = m_base;
m_extension = 0;
m_isActive = false;
m_timerActive = true;
2001-05-10 21:27:57 +02:00
m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames();
2001-06-18 21:06:43 +02:00
if ( m_soundId == NOT_PLAYING )
{
2001-07-18 23:13:54 +02:00
m_soundId = CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FIREBALL_LAND, true, true );
2001-06-18 21:06:43 +02:00
}
2001-04-24 16:13:32 +02:00
return;
}
2001-05-23 21:11:51 +02:00
Pos.vx = m_base.vx + ( ( m_width * m_extension ) >> 12 );
Pos.vy = m_base.vy - ( m_height * rsin( m_extension >> 1 ) >> 12 );
2001-04-24 16:13:32 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFireballHazard::processTimer( int _frames )
{
m_timer -= _frames;
if ( m_timer < 0 )
{
m_timerActive = false;
m_isActive = true;
2001-06-01 18:30:37 +02:00
2001-06-18 21:06:43 +02:00
if ( m_soundId == NOT_PLAYING )
{
2001-07-18 23:13:54 +02:00
m_soundId = CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FIREBALL_LAUNCH, true, true );
2001-06-18 21:06:43 +02:00
}
2001-04-24 16:13:32 +02:00
}
}