SBSPSS/source/hazard/hfalling.cpp

203 lines
3.9 KiB
C++
Raw Normal View History

2001-04-24 15:46:16 +02:00
/*=========================================================================
hfalling.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HFALLING_H__
#include "hazard\hfalling.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-10 23:30:17 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-04-24 15:46:16 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::init()
{
CNpcHazard::init();
2001-05-10 21:27:57 +02:00
m_movementTimer = 2 * GameState::getOneSecondInFrames();
m_respawnRate = 4;
2001-05-10 23:30:17 +02:00
m_bounceFinish = false;
2001-04-24 15:46:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::processMovement( int _frames )
{
s8 groundHeight;
s8 yMovement;
2001-05-10 23:30:17 +02:00
if ( m_bounceFinish )
2001-04-24 15:46:16 +02:00
{
2001-05-10 23:30:17 +02:00
if ( m_bounceDir )
2001-04-24 15:46:16 +02:00
{
2001-05-10 23:30:17 +02:00
Pos.vx += 2 * _frames;
2001-04-24 15:46:16 +02:00
}
else
{
2001-05-10 23:30:17 +02:00
Pos.vx -= 2 * _frames;
2001-04-24 15:46:16 +02:00
}
2001-05-10 23:30:17 +02:00
Pos.vy += m_speed * _frames;
2001-04-24 15:46:16 +02:00
2001-05-14 22:07:52 +02:00
if ( Pos.vy > ( m_bouncePos.vy + 32 ) )
2001-04-24 15:46:16 +02:00
{
2001-05-14 22:07:52 +02:00
m_bounceFinish = false;
2001-05-10 23:30:17 +02:00
}
2001-05-14 22:07:52 +02:00
else
2001-05-10 23:30:17 +02:00
{
2001-05-14 22:07:52 +02:00
if ( m_speed < 3 )
{
m_speed++;
}
2001-04-24 15:46:16 +02:00
}
2001-05-10 23:30:17 +02:00
}
else
{
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-04-24 15:46:16 +02:00
else
{
2001-05-10 23:30:17 +02:00
yMovement = 3 * _frames;
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight < yMovement )
{
// colliding with ground
Pos.vy += groundHeight;
m_bounceFinish = true;
m_speed = -5;
m_bounceDir = getRnd() % 2;
2001-05-14 22:07:52 +02:00
m_bouncePos = Pos;
2001-05-10 23:30:17 +02:00
}
else
{
// drop down
2001-04-24 15:46:16 +02:00
2001-05-10 23:30:17 +02:00
Pos.vy += yMovement;
}
2001-04-24 15:46:16 +02:00
}
}
2001-05-14 22:07:52 +02:00
DVECTOR offset = CLevel::getCameraPos();
s32 yPos = Pos.vy - offset.vy;
if ( yPos > VidGetScrH() )
{
m_isActive = false;
m_timerActive = true;
m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames();
}
2001-04-24 15:46:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::processTimer( int _frames )
{
m_timer -= _frames;
if ( m_timer < 0 )
{
m_timerActive = false;
m_isActive = true;
Pos = m_base;
2001-05-10 21:27:57 +02:00
m_movementTimer = 2 * GameState::getOneSecondInFrames();
2001-05-10 23:30:17 +02:00
m_bounceFinish = false;
2001-04-24 15:46:16 +02:00
}
}
2001-05-12 19:24:44 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-14 22:07:52 +02:00
2001-05-12 19:24:44 +02:00
void CNpcFallingHazard::collidedWith( CThing *_thisThing )
{
2001-05-14 23:08:03 +02:00
if (m_movementTimer<=0) CNpcHazard::collidedWith(_thisThing);
2001-05-12 19:24:44 +02:00
}
2001-05-14 22:07:52 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CRECT *CNpcFallingHazard::getThinkBBox()
{
CRECT objThinkBox = getCollisionArea();
sBBox &thinkBBox = CThingManager::getThinkBBox();
objThinkBox.y2 = thinkBBox.YMin + 1;
return &objThinkBox;
2001-05-14 23:08:03 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::setWaypoints( sThingHazard *ThisHazard )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
u16 newXPos, newYPos;
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
startPos.vx = newXPos << 4;
//startPos.vy = newYPos << 4;
startPos.vy = -10;
Pos = startPos;
m_base = Pos;
addWaypoint( newXPos, newYPos );
if ( ThisHazard->PointCount > 1 )
{
for ( pointNum = 1 ; pointNum < ThisHazard->PointCount ; pointNum++ )
{
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
addWaypoint( newXPos, newYPos );
}
}
}