SBSPSS/source/hazard/hflytrap.cpp

185 lines
3.3 KiB
C++
Raw Normal View History

2001-05-23 00:01:06 +02:00
/*=========================================================================
hflytrap.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HFLYTRAP_H__
#include "hazard\hflytrap.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __LEVEL_LEVEL_H__
#include "level\level.h"
#endif
2001-05-30 16:08:36 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-05-23 00:01:06 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFlyTrapHazard::init()
{
CNpcHazard::init();
m_rotation = 0;
m_shut = true;
2001-05-30 16:08:36 +02:00
m_contact = false;
2001-05-23 00:01:06 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFlyTrapHazard::processMovement( int _frames )
{
if ( m_shut )
{
2001-05-30 16:08:36 +02:00
if ( m_contact )
2001-05-23 00:01:06 +02:00
{
2001-05-30 16:08:36 +02:00
if ( m_timer <= 0 )
{
m_rotation += 64 * _frames;
if ( m_rotation > 1024 )
{
m_rotation = 1024;
m_shut = false;
m_contact = false;
m_timer = GameState::getOneSecondInFrames();
}
}
else
{
m_timer -= _frames;
}
2001-05-23 00:01:06 +02:00
}
}
2001-05-30 16:08:36 +02:00
else if ( !m_shut )
2001-05-23 00:01:06 +02:00
{
2001-05-30 16:08:36 +02:00
if ( m_timer <= 0 )
{
m_rotation -= 64 * _frames;
2001-05-23 00:01:06 +02:00
2001-05-30 16:08:36 +02:00
if ( m_rotation < 0 )
{
m_rotation = 0;
m_shut = true;
}
}
else
2001-05-23 00:01:06 +02:00
{
2001-05-30 16:08:36 +02:00
if ( m_contact )
{
m_contact = false;
}
else
{
if ( m_timer > 0 )
{
m_timer -= _frames;
}
}
2001-05-23 00:01:06 +02:00
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFlyTrapHazard::render()
{
CHazardThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
SVECTOR rotation;
rotation.vx = m_rotation;
rotation.vy = 0;
rotation.vz = 0;
VECTOR scale;
scale.vx = ONE;
scale.vy = ONE;
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
2001-05-30 16:08:36 +02:00
sBBox boundingBox = m_modelGfx->GetBBox();
s32 vertSize = ( ( boundingBox.YMax - boundingBox.YMin ) * rsin( 1024 - m_rotation ) ) >> 12;
if ( vertSize < 20 )
{
vertSize = 20;
}
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), vertSize );
//setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, -vertSize >> 1 );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFlyTrapHazard::collidedWith( CThing *_thisThing )
{
if ( m_isActive )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
if ( !m_contact )
{
if ( m_shut )
{
m_contact = true;
2001-05-31 15:47:33 +02:00
m_timer = GameState::getOneSecondInFrames();
2001-05-30 16:08:36 +02:00
}
else
{
if ( m_timer > 0 )
{
m_contact = true;
m_timer = GameState::getOneSecondInFrames();
}
}
}
if ( m_rotation > 512 )
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
}
break;
}
default:
ASSERT(0);
break;
}
2001-05-23 00:01:06 +02:00
}
}