diff --git a/source/hazard/hboat.cpp b/source/hazard/hboat.cpp new file mode 100644 index 000000000..b3a816559 --- /dev/null +++ b/source/hazard/hboat.cpp @@ -0,0 +1,121 @@ +/*========================================================================= + + hboat.cpp + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HBOAT_H__ +#include "hazard\hboat.h" +#endif + +#ifndef __LAYER_COLLISION_H__ +#include "level\layercollision.h" +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBoatHazard::init() +{ + CNpcHazard::init(); + + DVECTOR newPos; + + Pos.vx = 100; + Pos.vy = 100; + m_base = Pos; + + newPos.vx = 600; + newPos.vy = 100; + + m_npcPath.addWaypoint( newPos ); + + newPos.vx = 50; + newPos.vy = 100; + + m_npcPath.addWaypoint( newPos ); + + m_npcPath.setPathType( CNpcPath::PONG_PATH ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBoatHazard::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; + + if ( m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading ) ) + { + // path has finished, waypoint has changed, or there are no waypoints - do not move horizontally + + // 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 ); + + if ( groundHeight <= yMovement ) + { + // groundHeight <= yMovement indicates either just above ground or on or below ground + + moveX = distX * 3 * _frames; + moveY = groundHeight; + } + else + { + // fall + + moveY = yMovement; + } + } + } + + Pos.vx += moveX; + Pos.vy += moveY; +} \ No newline at end of file diff --git a/source/hazard/hboat.h b/source/hazard/hboat.h new file mode 100644 index 000000000..fb514ebf0 --- /dev/null +++ b/source/hazard/hboat.h @@ -0,0 +1,29 @@ +/*========================================================================= + + hboat.h + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HBOAT_H__ +#define __HAZARD_HBOAT_H__ + +#ifndef __HAZARD_HAZARD_H__ +#include "hazard\hazard.h" +#endif + +class CNpcBoatHazard : public CNpcHazard +{ +public: + void init(); +protected: + void processMovement( int _frames ); +}; + +#endif \ No newline at end of file