2001-05-05 21:07:25 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
hdbarrel.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __HAZARD_HDBARREL_H__
|
|
|
|
#include "hazard\hdbarrel.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __LAYER_COLLISION_H__
|
|
|
|
#include "level\layercollision.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
#ifndef __PLATFORM_PLATFORM_H__
|
|
|
|
#include "platform\platform.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-08 18:42:06 +02:00
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __LEVEL_LEVEL_H__
|
|
|
|
#include "level\level.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-25 20:43:47 +02:00
|
|
|
#include "game\game.h"
|
|
|
|
|
|
|
|
|
2001-05-05 21:07:25 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcDualPlatformBarrelHazard::init()
|
|
|
|
{
|
|
|
|
CNpcHazard::init();
|
|
|
|
|
|
|
|
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
|
2001-05-08 18:42:06 +02:00
|
|
|
|
|
|
|
m_rotation = 0;
|
|
|
|
m_rotationDir = 1;
|
2001-05-05 21:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcDualPlatformBarrelHazard::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
s32 maxHeight = 20;
|
|
|
|
s32 distX, distY;
|
|
|
|
s32 fallSpeed = 3;
|
|
|
|
s8 yMovement = fallSpeed * _frames;
|
|
|
|
s32 groundHeight;
|
|
|
|
|
|
|
|
s32 moveX = 0;
|
|
|
|
s32 moveY = 0;
|
|
|
|
|
|
|
|
// ignore y component of waypoint, since we are stuck to the ground
|
|
|
|
|
|
|
|
bool pathComplete;
|
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading );
|
2001-05-05 21:07:25 +02:00
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
if ( pathComplete )
|
|
|
|
{
|
|
|
|
// reset
|
2001-05-05 21:07:25 +02:00
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
Pos = m_base;
|
|
|
|
m_npcPath.resetPath();
|
2001-05-05 21:07:25 +02:00
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
return;
|
2001-05-05 21:07:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// check for collision
|
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
if ( distX )
|
|
|
|
{
|
|
|
|
distX = distX / abs( distX );
|
|
|
|
}
|
2001-05-05 21:07:25 +02:00
|
|
|
|
2001-05-25 20:43:47 +02:00
|
|
|
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( distX * 3 * _frames ), Pos.vy ) < -maxHeight )
|
2001-05-05 21:07:25 +02:00
|
|
|
{
|
|
|
|
// there is an obstacle in the way, increment the path point (hopefully this will resolve the problem)
|
|
|
|
|
|
|
|
m_npcPath.incPath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// check for vertical movement
|
|
|
|
|
2001-05-25 20:43:47 +02:00
|
|
|
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
|
2001-05-05 21:07:25 +02:00
|
|
|
|
|
|
|
if ( groundHeight <= yMovement )
|
|
|
|
{
|
|
|
|
// groundHeight <= yMovement indicates either just above ground or on or below ground
|
|
|
|
|
|
|
|
moveX = distX * 3 * _frames;
|
|
|
|
moveY = groundHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-08 18:25:45 +02:00
|
|
|
CNpcPlatform *platform = (CNpcPlatform *) isOnPlatform();
|
|
|
|
|
|
|
|
if ( platform )
|
|
|
|
{
|
|
|
|
// stick to platform top
|
|
|
|
|
|
|
|
moveY = platform->getHeightFromPlatformAtPosition( Pos.vx, Pos.vy + yMovement );
|
|
|
|
|
|
|
|
if ( !platform->canDrop() )
|
|
|
|
{
|
|
|
|
// if platform cannot drop any further, move in X
|
|
|
|
|
|
|
|
moveX = distX * 3 * _frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// fall
|
2001-05-05 21:07:25 +02:00
|
|
|
|
2001-05-08 18:25:45 +02:00
|
|
|
moveY = yMovement;
|
|
|
|
}
|
2001-05-05 21:07:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-08 18:42:06 +02:00
|
|
|
if ( moveX )
|
|
|
|
{
|
|
|
|
m_rotationDir = abs( moveX ) / moveX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rotationDir = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_rotation += m_rotationDir * 64 * _frames;
|
|
|
|
m_rotation &= 4095;
|
|
|
|
|
2001-05-05 21:07:25 +02:00
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
|
|
|
|
|
|
|
s32 minY, maxY;
|
|
|
|
|
|
|
|
m_npcPath.getPathYExtents( &minY, &maxY );
|
|
|
|
|
|
|
|
if ( Pos.vy > maxY )
|
|
|
|
{
|
|
|
|
Pos = m_base;
|
|
|
|
m_npcPath.resetPath();
|
|
|
|
}
|
2001-05-08 18:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcDualPlatformBarrelHazard::render()
|
|
|
|
{
|
|
|
|
CHazardThing::render();
|
|
|
|
|
2001-05-14 23:08:03 +02:00
|
|
|
if (canRender())
|
2001-05-08 18:42:06 +02:00
|
|
|
{
|
2001-05-14 23:08:03 +02:00
|
|
|
DVECTOR &renderPos=getRenderPos();
|
2001-05-08 18:42:06 +02:00
|
|
|
|
2001-05-14 23:08:03 +02:00
|
|
|
SVECTOR rotation;
|
|
|
|
rotation.vx = 0;
|
|
|
|
rotation.vy = 0;
|
|
|
|
rotation.vz = m_rotation;
|
2001-05-08 18:42:06 +02:00
|
|
|
|
2001-05-14 23:08:03 +02:00
|
|
|
VECTOR scale;
|
|
|
|
scale.vx = ONE;
|
|
|
|
scale.vy = ONE;
|
|
|
|
scale.vz = ONE;
|
|
|
|
|
|
|
|
m_modelGfx->Render(renderPos,&rotation,&scale);
|
2001-05-08 18:42:06 +02:00
|
|
|
}
|
2001-05-22 22:10:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const CRECT *CNpcDualPlatformBarrelHazard::getThinkBBox()
|
|
|
|
{
|
|
|
|
CRECT objThinkBox = getCollisionArea();
|
|
|
|
|
|
|
|
sBBox &thinkBBox = CThingManager::getThinkBBox();
|
|
|
|
objThinkBox.x1 = thinkBBox.XMin;
|
|
|
|
objThinkBox.x2 = thinkBBox.XMax;
|
|
|
|
objThinkBox.y1 = thinkBBox.YMin;
|
|
|
|
objThinkBox.y2 = thinkBBox.YMax;
|
|
|
|
|
|
|
|
return &objThinkBox;
|
2001-05-05 21:07:25 +02:00
|
|
|
}
|