SBSPSS/source/hazard/hmasher.cpp

115 lines
2.4 KiB
C++
Raw Normal View History

2001-05-04 22:46:43 +02:00
/*=========================================================================
hmasher.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HMASHER_H__
#include "hazard\hmasher.h"
#endif
#ifndef __LAYER_COLLISION_H__
#include "level\layercollision.h"
#endif
2001-05-25 20:43:47 +02:00
#include "game\game.h"
2001-06-06 17:26:06 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-04 22:46:43 +02:00
void CNpcMasherHazard::init()
{
CNpcHazard::init();
m_state = MASHER_DROPPING;
2001-07-18 18:09:39 +02:00
m_pauseTimer = 0;
2001-05-04 22:46:43 +02:00
}
2001-06-06 17:26:06 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-04 22:46:43 +02:00
void CNpcMasherHazard::processMovement( int _frames )
{
switch ( m_state )
{
case MASHER_DROPPING:
{
2001-07-18 18:09:39 +02:00
if ( m_pauseTimer <= 0 )
{
s8 yMovement = 3 * _frames;
2001-05-04 22:46:43 +02:00
2001-07-18 18:09:39 +02:00
s8 groundHeight;
2001-05-04 22:46:43 +02:00
2001-07-18 18:09:39 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-05-04 22:46:43 +02:00
2001-07-18 18:09:39 +02:00
if ( groundHeight < yMovement )
{
// colliding with ground
2001-05-04 22:46:43 +02:00
2001-07-18 18:09:39 +02:00
Pos.vy += groundHeight;
2001-05-04 22:46:43 +02:00
2001-07-18 18:09:39 +02:00
// pause and change direction
2001-05-04 22:46:43 +02:00
2001-07-18 18:09:39 +02:00
m_state = MASHER_RISING;
2001-07-19 17:55:47 +02:00
2001-07-24 21:21:44 +02:00
CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FALLING_ROCK_LAND, false, true );
2001-07-18 18:09:39 +02:00
}
else
{
// drop down
Pos.vy += yMovement;
}
2001-05-04 22:46:43 +02:00
}
else
{
2001-07-18 18:09:39 +02:00
m_pauseTimer -= _frames;
2001-05-04 22:46:43 +02:00
}
break;
}
case MASHER_RISING:
{
if ( m_base.vx - Pos.vx == 0 && m_base.vy - Pos.vy == 0 )
{
m_state = MASHER_DROPPING;
2001-07-18 18:09:39 +02:00
m_pauseTimer = GameState::getOneSecondInFrames();
2001-05-04 22:46:43 +02:00
}
else
{
// return to original position
Pos.vy -= 3 * _frames;
if ( Pos.vy < m_base.vy )
{
Pos.vy = m_base.vy;
}
}
break;
}
}
}
2001-06-06 17:26:06 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcMasherHazard::setGraphic( sThingHazard *ThisHazard )
{
m_modelGfx = new ("ModelGfx") CModelGfx;
m_modelGfx->SetModel( ThisHazard->Gfx );
sBBox boundingBox = m_modelGfx->GetBBox();
boundingBox.YMin = boundingBox.YMax - 18;
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
}