SBSPSS/source/hazard/hrckshrd.cpp

135 lines
2.8 KiB
C++
Raw Normal View History

2001-05-24 16:39:30 +02:00
/*=========================================================================
hrckshrd.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HRCKSHRD_H__
#include "hazard\hrckshrd.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-24 17:39:12 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-24 16:39:30 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRockShardHazard::init()
{
CNpcHazard::init();
m_movementTimer = 2 * GameState::getOneSecondInFrames();
m_respawnRate = 4;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRockShardHazard::processMovement( int _frames )
{
s8 groundHeight;
s8 yMovement;
if ( m_movementTimer > 0 )
{
m_movementTimer -= _frames;
if ( m_movementTimer <= 0 )
{
Pos = m_base;
}
else
{
Pos.vx = m_base.vx + ( -3 + ( getRnd() % 7 ) );
Pos.vy = m_base.vy + ( -3 + ( getRnd() % 7 ) );
2001-06-18 21:06:43 +02:00
2001-08-09 16:13:25 +02:00
if ( canRender() && m_soundId == NOT_PLAYING )
2001-06-18 21:06:43 +02:00
{
2001-07-18 23:13:54 +02:00
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_RATTLE, true, true );
2001-06-18 21:06:43 +02:00
}
2001-05-24 16:39:30 +02:00
}
}
else
{
yMovement = 6 * _frames;
2001-05-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-05-24 16:39:30 +02:00
if ( groundHeight < yMovement )
{
// colliding with ground
Pos.vy += groundHeight;
m_isActive = false;
m_timerActive = true;
m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames();
2001-06-18 21:06:43 +02:00
2001-08-09 16:13:25 +02:00
if ( canRender() && m_soundId == NOT_PLAYING )
2001-06-18 21:06:43 +02:00
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_LAND, true );
}
2001-05-24 16:39:30 +02:00
}
else
{
// drop down
Pos.vy += yMovement;
}
2001-05-24 17:39:12 +02:00
2001-07-23 21:26:37 +02:00
DVECTOR const &offset = CLevel::getCameraPos();
2001-05-24 17:39:12 +02:00
s32 yPos = Pos.vy - offset.vy;
if ( yPos > VidGetScrH() )
{
m_isActive = false;
m_timerActive = true;
m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames();
}
2001-05-24 16:39:30 +02:00
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRockShardHazard::processTimer( int _frames )
{
m_timer -= _frames;
if ( m_timer < 0 )
{
m_timerActive = false;
m_isActive = true;
Pos = m_base;
m_movementTimer = 2 * GameState::getOneSecondInFrames();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CRECT *CNpcRockShardHazard::getThinkBBox()
{
CRECT objThinkBox = getCollisionArea();
sBBox &thinkBBox = CThingManager::getThinkBBox();
objThinkBox.y2 = thinkBBox.YMin + 1;
return &objThinkBox;
}