SBSPSS/source/platform/pfallnor.cpp

173 lines
3.3 KiB
C++
Raw Normal View History

2001-05-03 21:01:23 +02:00
/*=========================================================================
pfallnor.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PFALLNOR_H__
#include "platform\pfallnor.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-30 20:31:57 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-03 21:01:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingNoRespawnPlatform::postInit()
{
2001-05-05 15:54:34 +02:00
CNpcPlatform::postInit();
2001-05-03 21:01:23 +02:00
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
2001-05-30 20:31:57 +02:00
m_spinFinish = false;
m_rotation = 0;
2001-05-03 21:01:23 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingNoRespawnPlatform::processMovement( int _frames )
{
2001-05-30 20:31:57 +02:00
s32 moveX = 0, moveY = 0;
2001-05-03 21:01:23 +02:00
s32 distX, distY, heading;
bool pathComplete;
2001-07-23 21:26:37 +02:00
DVECTOR const &offset = CLevel::getCameraPos();
2001-06-19 22:21:26 +02:00
2001-05-30 20:31:57 +02:00
if ( m_spinFinish )
2001-05-03 21:01:23 +02:00
{
2001-05-30 20:31:57 +02:00
m_rotation += 64 * _frames;
m_rotation &= 4095;
if ( m_bounceDir )
{
Pos.vx += 2 * _frames;
}
else
{
Pos.vx -= 2 * _frames;
}
Pos.vy += m_speed * _frames;
2001-06-04 22:12:28 +02:00
if ( m_speed < 12 )
2001-05-30 20:31:57 +02:00
{
m_speed++;
}
s32 yPos = Pos.vy - offset.vy;
2001-05-30 21:20:38 +02:00
if ( yPos < 0 || yPos > VidGetScrH() )
2001-05-30 20:31:57 +02:00
{
setToShutdown();
}
2001-05-03 21:01:23 +02:00
}
else
{
2001-05-30 20:31:57 +02:00
m_npcPath.thinkVertical( Pos, &pathComplete, &distX, &distY, &heading );
2001-05-03 21:01:23 +02:00
2001-05-30 20:31:57 +02:00
if ( pathComplete )
2001-05-03 21:01:23 +02:00
{
2001-05-30 20:31:57 +02:00
m_spinFinish = true;
m_speed = -5;
m_bounceDir = getRnd() % 2;
2001-07-12 22:44:52 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__ACORN_LAND, true );
2001-05-03 21:01:23 +02:00
}
2001-05-30 20:31:57 +02:00
else
{
moveX = 0;
moveY = m_speed * _frames;
if ( heading == 3072 )
{
moveY = -moveY;
}
2001-05-03 21:01:23 +02:00
2001-05-30 20:31:57 +02:00
s32 groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx + moveX, Pos.vy + moveY, 16 );
2001-05-03 21:01:23 +02:00
2001-05-30 20:31:57 +02:00
if ( groundHeight < moveY )
2001-05-08 17:35:37 +02:00
{
2001-05-30 20:31:57 +02:00
if ( ( CGameScene::getCollision()->getCollisionBlock( Pos.vx, Pos.vy + groundHeight + 8 ) & COLLISION_TYPE_MASK ) != COLLISION_TYPE_FLAG_DEATH_FALL )
{
moveY = groundHeight;
moveX = 2 * _frames;
}
2001-05-08 17:35:37 +02:00
}
2001-05-03 21:01:23 +02:00
}
2001-06-19 22:21:26 +02:00
s32 yPos = Pos.vy - offset.vy;
if ( yPos > VidGetScrH() + 100 )
{
setToShutdown();
}
2001-05-03 21:01:23 +02:00
}
2001-05-30 20:31:57 +02:00
Pos.vx += moveX;
Pos.vy += moveY;
2001-05-22 23:42:39 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-30 20:31:57 +02:00
void CNpcFallingNoRespawnPlatform::render()
{
if ( m_isActive )
{
CPlatformThing::render();
// Render
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = m_rotation;
VECTOR scale;
scale.vx = ONE;
scale.vy = ONE;
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int CNpcFallingNoRespawnPlatform::checkCollisionAgainst(CThing *_thisThing, int _frames)
{
if ( m_spinFinish )
{
return( false );
}
else
{
return( CNpcPlatform::checkCollisionAgainst( _thisThing, _frames ) );
}
}