SBSPSS/source/platform/pretract.cpp

175 lines
3.3 KiB
C++
Raw Normal View History

2001-04-23 21:18:06 +02:00
/*=========================================================================
pretract.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PRETRACT_H__
#include "platform\pretract.h"
#endif
2001-04-23 22:40:13 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-08 22:23:16 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-07-11 17:36:46 +02:00
#include "fx\fx.h"
2001-04-23 21:18:06 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRetractingPlatform::postInit()
{
2001-05-05 15:54:34 +02:00
CNpcPlatform::postInit();
2001-04-23 21:18:06 +02:00
m_timer = NPC_PLATFORM_TIMER_RETRACT;
2001-05-08 22:23:16 +02:00
m_extension = ONE;
2001-07-10 19:08:34 +02:00
m_initDelay = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRetractingPlatform::setSpeed( s16 newSpeed )
{
m_speed = newSpeed;
m_initDelay = ( m_speed * GameState::getOneSecondInFrames() ) >> 2;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRetractingPlatform::reinit()
{
CNpcPlatform::reinit();
m_initDelay = ( m_speed * GameState::getOneSecondInFrames() ) >> 2;
2001-04-23 21:18:06 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRetractingPlatform::processTimer( int _frames )
{
2001-07-10 19:08:34 +02:00
if ( m_initDelay > 0 )
{
m_initDelay -= _frames;
return;
}
2001-04-23 21:18:06 +02:00
switch( m_timerType )
{
case NPC_PLATFORM_TIMER_RETRACT:
{
if ( m_timer > 0 )
{
m_timer -= _frames;
2001-07-24 21:17:11 +02:00
if ( m_timer <= 0 )
{
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_RETRACTING_PLATFORM, true, true );
}
}
2001-04-23 21:18:06 +02:00
}
else
{
2001-05-08 22:23:16 +02:00
if ( m_extension > 1 )
{
m_extension -= 128 * _frames;
if ( m_extension <= 1 )
{
m_extension = 1;
m_timer = 4 * GameState::getOneSecondInFrames();
m_timerType = NPC_PLATFORM_TIMER_EXTEND;
m_detectCollision = false;
}
}
2001-04-23 21:18:06 +02:00
}
break;
}
case NPC_PLATFORM_TIMER_EXTEND:
{
if ( m_timer > 0 )
{
m_timer -= _frames;
2001-07-24 21:17:11 +02:00
if ( m_timer <= 0 )
{
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_RETRACTING_PLATFORM, true, true );
}
}
2001-04-23 21:18:06 +02:00
}
else
{
2001-05-08 22:23:16 +02:00
if ( m_extension < ONE )
{
m_extension += 128 * _frames;
if ( m_extension >= ONE )
{
m_extension = ONE;
m_timer = 4 * GameState::getOneSecondInFrames();
m_timerType = NPC_PLATFORM_TIMER_RETRACT;
m_detectCollision = true;
}
}
2001-04-23 21:18:06 +02:00
}
break;
}
}
2001-05-08 22:23:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRetractingPlatform::render()
{
if ( m_isActive )
{
CPlatformThing::render();
// Render
2001-05-10 18:16:57 +02:00
CPlatformThing::render();
2001-05-08 22:23:16 +02:00
2001-05-10 18:16:57 +02:00
if (canRender())
2001-05-08 22:23:16 +02:00
{
2001-05-10 18:16:57 +02:00
DVECTOR &renderPos=getRenderPos();
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = 0;
2001-05-08 22:23:16 +02:00
2001-05-10 18:16:57 +02:00
VECTOR scale;
scale.vx = ONE;
2001-07-11 17:36:46 +02:00
scale.vy = ( ONE >> 1 ) + ( ( m_extension * ( ONE >> 1 ) ) / ONE );
2001-05-10 18:16:57 +02:00
scale.vz = m_extension;
2001-05-08 22:23:16 +02:00
2001-05-10 18:16:57 +02:00
m_modelGfx->Render(renderPos,&rotation,&scale);
2001-05-08 22:23:16 +02:00
}
}
}