This commit is contained in:
Charles 2001-05-22 19:59:14 +00:00
parent 9e6fae82c4
commit 5298e61a8a
2 changed files with 313 additions and 0 deletions

278
source/hazard/hrrock.cpp Normal file
View File

@ -0,0 +1,278 @@
/*=========================================================================
hrrock.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HRROCK_H__
#include "hazard\hrrock.h"
#endif
#ifndef __LAYER_COLLISION_H__
#include "level\layercollision.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRollingRockHazard::init()
{
CNpcHazard::init();
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
m_rotation = 0;
m_jump = false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRollingRockHazard::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;
bool waypointChange;
m_npcPath.think( Pos, &pathComplete, &waypointChange, &distX, &distY );
if ( pathComplete )
{
// reset
Pos = m_base;
m_npcPath.resetPath();
m_jump = false;
return;
}
else
{
if ( distX )
{
// move along ground
s32 groundSpeed = 3 * _frames;
moveX = distX;
if ( moveX > groundSpeed )
{
moveX = groundSpeed;
}
else if ( moveX < -groundSpeed )
{
moveX = -groundSpeed;
}
if ( m_jump )
{
// process jump movement
if ( m_jumpVel < ( 16 << 8 ) )
{
m_jumpVel += 128 * _frames;
}
moveY += m_jumpVel >> 8;
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx + moveX, Pos.vy + moveY, 16 );
if ( groundHeight < 16 )
{
// have hit ground
m_jump = false;
moveY += groundHeight;
}
}
else
{
// check for vertical movement
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx + moveX, Pos.vy, 64 );
if ( groundHeight < 64 )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveY = groundHeight;
}
else
{
// cannot find ground immediately below
m_jump = true;
m_jumpVel = 0;
moveY = 0;
}
}
}
else
{
// drop vertically
// check for vertical movement
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveY = groundHeight;
// increment path if we hit the ground at this stage
m_npcPath.incPath();
m_jump = false;
}
else
{
// fall
moveY = yMovement;
}
}
}
/*if ( m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading ) )
{
if ( pathComplete )
{
// reset
Pos = m_base;
m_npcPath.resetPath();
return;
}
else
{
// check for vertical movement
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
}
}
else
{
// check for collision
distX = distX / abs( distX );
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( distX * 3 * _frames ), Pos.vy ) < -maxHeight )
{
// 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
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
moveX = distX * 3 * _frames;
if ( groundHeight <= yMovement )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
}
}*/
if ( moveX < 0 )
{
m_rotation -= 64 * _frames;
m_rotation &= 4095;
}
else if ( moveX > 0 )
{
m_rotation += 64 * _frames;
m_rotation &= 4095;
}
Pos.vx += moveX;
Pos.vy += moveY;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcRollingRockHazard::render()
{
CHazardThing::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);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CRECT *CNpcRollingRockHazard::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;
}

35
source/hazard/hrrock.h Normal file
View File

@ -0,0 +1,35 @@
/*=========================================================================
hrrock.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HRROCK_H__
#define __HAZARD_HRROCK_H__
#ifndef __HAZARD_HAZARD_H__
#include "hazard\hazard.h"
#endif
class CNpcRollingRockHazard : public CNpcHazard
{
public:
void init();
void render();
virtual CRECT const *getThinkBBox();
protected:
void processMovement( int _frames );
s16 m_rotation;
u8 m_jump;
s32 m_jumpVel;
};
#endif