From 432cba9e4f8b6d45c387848bc4cdba9eea19c6a3 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 5 Jun 2001 15:59:51 +0000 Subject: [PATCH] --- source/hazard/hbrock.cpp | 207 +++++++++++++++++++++++++++++++++++ source/hazard/hbrock.h | 34 ++++++ source/triggers/thazwalk.cpp | 85 ++++++++++++++ source/triggers/thazwalk.h | 55 ++++++++++ 4 files changed, 381 insertions(+) create mode 100644 source/hazard/hbrock.cpp create mode 100644 source/hazard/hbrock.h create mode 100644 source/triggers/thazwalk.cpp create mode 100644 source/triggers/thazwalk.h diff --git a/source/hazard/hbrock.cpp b/source/hazard/hbrock.cpp new file mode 100644 index 000000000..e3d4598b5 --- /dev/null +++ b/source/hazard/hbrock.cpp @@ -0,0 +1,207 @@ +/*========================================================================= + + hbrock.h + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HBROCK_H__ +#include "hazard\hbrock.h" +#endif + +#ifndef __TRIGGERS_THAZWALK_H__ +#include "triggers\thazwalk.h" +#endif + +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBouncingRockHazard::init() +{ + CNpcBouncingBarrelHazard::init(); + + m_isTriggered = false; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBouncingRockHazard::setWaypoints( sThingHazard *ThisHazard ) +{ + int pointNum; + + u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard)); + + u16 newXPos, newYPos; + + m_npcPath.setWaypointCount( ThisHazard->PointCount - 2 ); + + newXPos = (u16) *PntList; + setWaypointPtr( PntList ); + PntList++; + newYPos = (u16) *PntList; + PntList++; + + DVECTOR startPos; + startPos.vx = ( newXPos << 4 ) + 8; + startPos.vy = ( newYPos << 4 ) + 16; + + Pos = startPos; + m_base = Pos; + + for ( int i = 2 ; i < ThisHazard->PointCount ; i++ ) + { + PntList++; + PntList++; + } + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + + CHazardTrigger *trigger; + + trigger=(CHazardTrigger*)CTrigger::Create(CTrigger::TRIGGER_HAZARD_WALK); + trigger->setPositionAndSize( ( newXPos << 4 ) + 8, ( newYPos << 4 ) + 16, 100, 0 ); + trigger->setHazard( this ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBouncingRockHazard::processMovement( int _frames ) +{ + if ( m_isTriggered ) + { + s32 moveX = 0, moveY = 0; + s32 moveVel = 0; + s32 moveDist = 0; + s32 waypointXDist; + s32 waypointYDist; + s32 waypointHeading; + s32 groundHeight; + + // deal with horizontal + + bool pathComplete; + + if ( m_npcPath.thinkFlat( Pos, &pathComplete, &waypointXDist, &waypointYDist, &waypointHeading, 1 ) ) + { + if ( pathComplete ) + { + setToShutdown(); + } + + m_lastWaypoint = Pos; + } + + moveX = 3 * _frames; + + if ( moveX > abs( waypointXDist ) ) + { + moveX = abs( waypointXDist ); + } + + if ( waypointHeading == 2048 ) + { + moveX = -moveX; + m_rotation -= 256 * _frames; + m_rotation &= 4095; + } + else + { + m_rotation += 256 * _frames; + m_rotation &= 4095; + } + + if ( m_rockDir ) + { + m_rockRotation += 30 * _frames; + + if ( m_rockRotation > 256 ) + { + m_rockDir = false; + } + } + else + { + m_rockRotation -= 30 * _frames; + + if ( m_rockRotation < -256 ) + { + m_rockDir = true; + } + } + + Pos.vx += moveX; + + // deal with vertical + + DVECTOR nextWaypoint; + + nextWaypoint.vx = waypointXDist + Pos.vx; + nextWaypoint.vy = waypointYDist + Pos.vy; + + s32 waypointDist = abs( nextWaypoint.vx - m_lastWaypoint.vx ); + + if ( waypointDist < 1 ) + { + waypointDist = 1; + } + + if ( waypointYDist > 0 ) + { + s32 sineVal = ( abs( Pos.vx - nextWaypoint.vx ) * 1024 ) / waypointDist; + + Pos.vy = nextWaypoint.vy - ( ( abs( nextWaypoint.vy - m_lastWaypoint.vy ) * rsin( sineVal ) ) >> 12 ); + } + else if ( waypointYDist < 0 ) + { + s32 sineVal = ( abs( Pos.vx - m_lastWaypoint.vx ) * 1024 ) / waypointDist; + + Pos.vy = m_lastWaypoint.vy - ( ( abs( nextWaypoint.vy - m_lastWaypoint.vy ) * rsin( sineVal ) ) >> 12 ); + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBouncingRockHazard::trigger() +{ + m_isTriggered = true; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBouncingRockHazard::collidedWith( CThing *_thisThing ) +{ + if ( m_isActive ) + { + switch(_thisThing->getThingType()) + { + case TYPE_PLAYER: + { + CPlayer *player = (CPlayer *) _thisThing; + player->takeDamage( DAMAGE__KILL_OUTRIGHT ); + + break; + } + + default: + ASSERT(0); + break; + } + } +} diff --git a/source/hazard/hbrock.h b/source/hazard/hbrock.h new file mode 100644 index 000000000..1fff79971 --- /dev/null +++ b/source/hazard/hbrock.h @@ -0,0 +1,34 @@ +/*========================================================================= + + hbrock.h + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HBROCK_H__ +#define __HAZARD_HBROCK_H__ + +#ifndef __HAZARD_HBBARREL_H__ +#include "hazard\hbbarrel.h" +#endif + +class CNpcBouncingRockHazard : public CNpcBouncingBarrelHazard +{ +public: + void init(); + virtual void setWaypoints( sThingHazard *ThisHazard ); + virtual void trigger(); +protected: + void processMovement( int _frames ); + virtual void collidedWith(CThing *_thisThing); + + u8 m_isTriggered; +}; + +#endif \ No newline at end of file diff --git a/source/triggers/thazwalk.cpp b/source/triggers/thazwalk.cpp new file mode 100644 index 000000000..1d11e7b84 --- /dev/null +++ b/source/triggers/thazwalk.cpp @@ -0,0 +1,85 @@ +/*========================================================================= + + thazwalk.cpp + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "triggers\trigger.h" +#include "triggers\thazwalk.h" + +#ifndef __GAME_GAME_H__ +#include "game\game.h" +#endif + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + + +/* Std Lib + ------- */ + +/* Data + ---- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CHazardWalkTrigger::collidedWith(CThing *_thisThing) +{ + if ( m_timeout <= 0 ) + { + switch( _thisThing->getThingType() ) + { + case TYPE_PLAYER: + { + CPlayer *player = (CPlayer *) _thisThing; + + if ( m_hazard ) + { + m_hazard->trigger(); + m_hazard = NULL; + } + + break; + } + + default: + break; + } + } +} + +/*=========================================================================== +end */ diff --git a/source/triggers/thazwalk.h b/source/triggers/thazwalk.h new file mode 100644 index 000000000..7c2fb9fb6 --- /dev/null +++ b/source/triggers/thazwalk.h @@ -0,0 +1,55 @@ +/*========================================================================= + + thazwalk.h + + Author: Charles Blair + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __TRIGGERS_THAZWALK_H__ +#define __TRIGGERS_THAZWALK_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#ifndef __TRIGGERS_THAZARD_H__ +#include "triggers\thazard.h" +#endif + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class CHazardWalkTrigger : public CHazardTrigger +{ +protected: + virtual void collidedWith(CThing *_thisThing); +}; + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#endif + +/*=========================================================================== + end */