diff --git a/source/hazard/hrweight.cpp b/source/hazard/hrweight.cpp new file mode 100644 index 000000000..09ce5e031 --- /dev/null +++ b/source/hazard/hrweight.cpp @@ -0,0 +1,100 @@ +/*========================================================================= + + hrweight.cpp + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HRWEIGHT_H__ +#include "hazard\hrweight.h" +#endif + +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightHazard::init() +{ + CNpcHazard::init(); + + m_triggered = false; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightHazard::setWaypoints( sThingHazard *ThisHazard ) +{ + ASSERT( ThisHazard->PointCount == 3 ); + + u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard)); + + u16 newXPos, newYPos; + + // get master hazard init pos + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + DVECTOR startPos; + startPos.vx = newXPos << 4; + startPos.vy = newYPos << 4; + + Pos = startPos; + m_base = Pos; + + // get master hazard max vertical extension + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + m_maxExtension = abs( ( newYPos << 4 ) - startPos.vy ) << 8; + + // get slave trigger position + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + m_wheelPos.vx = newXPos; + m_wheelPos.vy = newYPos; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightHazard::processMovement( int _frames ) +{ + if ( m_triggered ) + { + m_triggered = false; + m_extension += ( 3 * _frames ) << 8; + if ( m_extension > m_maxExtension ) + { + m_extension = m_maxExtension; + } + } + else + { + m_extension -= 64 * _frames; + + if ( m_extension < 0 ) + { + m_extension = 0; + } + } + + Pos.vy = m_base.vy - ( m_extension >> 8 ); +} diff --git a/source/hazard/hrweight.h b/source/hazard/hrweight.h new file mode 100644 index 000000000..db01925c6 --- /dev/null +++ b/source/hazard/hrweight.h @@ -0,0 +1,36 @@ +/*========================================================================= + + hrweight.h + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HRWEIGHT_H__ +#define __HAZARD_HRWEIGHT_H__ + +#ifndef __HAZARD_HAZARD_H__ +#include "hazard\hazard.h" +#endif + +class CNpcRisingWeightHazard : public CNpcHazard +{ +public: + void init(); + DVECTOR const &getWheelPos() {return( m_wheelPos );} + void setTriggered() {m_triggered = true;} +protected: + virtual void setWaypoints( sThingHazard *ThisHazard ); + virtual void processMovement( int _frames ); + + s32 m_maxExtension; + DVECTOR m_wheelPos; + u8 m_triggered; +}; + +#endif \ No newline at end of file diff --git a/source/hazard/hrwheel.cpp b/source/hazard/hrwheel.cpp new file mode 100644 index 000000000..8053e0968 --- /dev/null +++ b/source/hazard/hrwheel.cpp @@ -0,0 +1,116 @@ +/*========================================================================= + + hrwheel.cpp + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HRWHEEL_H__ +#include "hazard\hrwheel.h" +#endif + +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightWheelHazard::init() +{ + CNpcHazard::init(); + + m_rotation = 0; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightWheelHazard::setWaypoints( sThingHazard *ThisHazard ) +{ + u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard)); + + u16 newXPos, newYPos; + + // get init pos + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + DVECTOR startPos; + startPos.vx = newXPos << 4; + startPos.vy = newYPos << 4; + + Pos = startPos; + m_base = Pos; + + m_wheelPos.vx = newXPos; + m_wheelPos.vy = newYPos; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightWheelHazard::collidedWith( CThing *_thisThing ) +{ + if ( m_isActive ) + { + switch(_thisThing->getThingType()) + { + case TYPE_PLAYER: + { + CPlayer *player = (CPlayer *) _thisThing; + + ATTACK_STATE playerState = player->getAttackState(); + + if ( playerState == ATTACK_STATE__BUTT_BOUNCE ) + { + m_weight->setTriggered(); + + m_rotation += 128; + m_rotation &= 4095; + } + + break; + } + + default: + ASSERT(0); + break; + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcRisingWeightWheelHazard::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); + } +} diff --git a/source/hazard/hrwheel.h b/source/hazard/hrwheel.h new file mode 100644 index 000000000..64f2b4a97 --- /dev/null +++ b/source/hazard/hrwheel.h @@ -0,0 +1,41 @@ +/*========================================================================= + + hrwheel.h + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __HAZARD_HRWHEEL_H__ +#define __HAZARD_HRWHEEL_H__ + +#ifndef __HAZARD_HAZARD_H__ +#include "hazard\hazard.h" +#endif + +#ifndef __HAZARD_HRWEIGHT_H__ +#include "hazard\hrweight.h" +#endif + +class CNpcRisingWeightWheelHazard : public CNpcHazard +{ +public: + void init(); + DVECTOR const &getWheelPos() {return( m_wheelPos );} + void linkToWeight( CNpcRisingWeightHazard *weight ) {m_weight = weight;} + virtual void render(); +protected: + virtual void setWaypoints( sThingHazard *ThisHazard ); + virtual void collidedWith(CThing *_thisThing); + + DVECTOR m_wheelPos; + CNpcRisingWeightHazard *m_weight; + s16 m_rotation; +}; + +#endif \ No newline at end of file