SBSPSS/source/hazard/hflytrap.cpp

193 lines
3.5 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();
2001-07-18 23:30:45 +02:00
m_rotation = -1024;
2001-05-23 00:01:06 +02:00
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;
2001-07-20 22:30:13 +02:00
if ( m_rotation > -256 )
2001-05-30 16:08:36 +02:00
{
2001-07-20 22:30:13 +02:00
m_rotation = -256;
2001-05-30 16:08:36 +02:00
m_shut = false;
m_contact = false;
m_timer = GameState::getOneSecondInFrames();
2001-07-12 18:53:21 +02:00
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK, true );
}
2001-05-30 16:08:36 +02:00
}
}
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-07-18 23:30:45 +02:00
if ( m_rotation < -1024 )
2001-05-30 16:08:36 +02:00
{
2001-07-18 23:30:45 +02:00
m_rotation = -1024;
2001-05-30 16:08:36 +02:00
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;
2001-07-23 21:26:37 +02:00
m_modelGfx->RenderClip(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();
}
}
}
2001-07-18 23:30:45 +02:00
if ( m_rotation > -512 )
2001-05-30 16:08:36 +02:00
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
}
break;
}
2001-07-09 23:43:13 +02:00
case TYPE_NPC:
break;
2001-05-30 16:08:36 +02:00
default:
ASSERT(0);
break;
}
2001-05-23 00:01:06 +02:00
}
}