SBSPSS/source/hazard/hmasher.cpp

103 lines
2.1 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-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:
{
s8 yMovement = 3 * _frames;
s8 groundHeight;
2001-05-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-05-04 22:46:43 +02:00
if ( groundHeight < yMovement )
{
// colliding with ground
Pos.vy += groundHeight;
// pause and change direction
m_state = MASHER_RISING;
}
else
{
// drop down
Pos.vy += yMovement;
}
break;
}
case MASHER_RISING:
{
if ( m_base.vx - Pos.vx == 0 && m_base.vy - Pos.vy == 0 )
{
m_state = MASHER_DROPPING;
}
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 );
}