SBSPSS/source/platform/pfishhk.cpp

179 lines
3.5 KiB
C++
Raw Normal View History

2001-04-23 20:18:19 +02:00
/*=========================================================================
pfishhk.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PFISHHK_H__
#include "platform\pfishhk.h"
#endif
2001-05-04 18:34:57 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-09 15:22:04 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-04 18:34:57 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-07-26 21:12:49 +02:00
#ifndef __GFX_OTPOS_H__
#include "gfx\otpos.h"
#endif
2001-05-04 18:34:57 +02:00
2001-04-23 20:18:19 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-25 22:04:25 +02:00
void CNpcFishHookPlatform::postInit()
{
2001-05-23 16:46:23 +02:00
sBBox boundingBox = m_modelGfx->GetBBox();
boundingBox.YMin += 18;
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
2001-05-05 15:54:34 +02:00
2001-05-23 17:10:45 +02:00
calculateNonRotatedCollisionData();
setCollisionAngle( m_tiltAngle >> 8 );
2001-04-25 22:04:25 +02:00
m_isMoving = false;
2001-05-14 17:14:39 +02:00
m_isResetting = false;
2001-05-09 15:22:04 +02:00
m_lineBase.vx = Pos.vx;
m_lineBase.vy = 0;
2001-05-25 18:44:30 +02:00
m_bobTimer = 0;
2001-04-25 22:04:25 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-23 20:18:19 +02:00
void CNpcFishHookPlatform::processLifetime( int _frames )
{
if ( m_contact )
{
m_isMoving = true;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFishHookPlatform::processMovement( int _frames )
{
2001-04-23 22:40:13 +02:00
if ( m_isMoving )
2001-04-23 20:18:19 +02:00
{
2001-06-18 21:06:43 +02:00
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_FISH_HOOK_MOVE, true );
}
2001-05-21 23:16:42 +02:00
2001-05-14 17:14:39 +02:00
if ( m_isResetting )
{
Pos.vy += 2 * _frames;
if ( Pos.vy > m_base.vy )
{
Pos.vy = m_base.vy;
2001-04-23 22:40:13 +02:00
2001-05-14 17:14:39 +02:00
m_isResetting = false;
m_isMoving = false;
}
}
else
2001-04-23 22:40:13 +02:00
{
2001-05-14 17:14:39 +02:00
Pos.vy -= m_speed * _frames;
if ( Pos.vy < 0 )
{
m_isResetting = true;
}
2001-04-23 22:40:13 +02:00
}
2001-04-23 20:18:19 +02:00
}
2001-05-25 18:44:30 +02:00
else
{
int second = GameState::getOneSecondInFrames();
m_bobTimer += _frames;
if ( m_bobTimer > ( 3 * second ) )
{
m_bobTimer -= 3 * second;
}
s16 sineVal = ( m_bobTimer << 12 ) / ( 3 * second );
Pos.vy = m_base.vy + ( ( 5 * rsin( sineVal ) ) >> 12 );
}
2001-05-09 15:22:04 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFishHookPlatform::render()
{
int x1,y1,x2,y2;
if ( m_isActive )
{
CPlatformThing::render();
2001-05-10 18:16:57 +02:00
DVECTOR &renderPos=getRenderPos();
if (canRender())
2001-05-09 15:22:04 +02:00
{
2001-05-10 18:16:57 +02:00
m_modelGfx->Render(renderPos);
2001-05-09 15:22:04 +02:00
}
2001-05-10 18:16:57 +02:00
// draw Line (Literally!!)
2001-06-21 21:19:15 +02:00
if (renderPos.vx>0 && renderPos.vx<INGAME_SCREENW)
2001-05-10 18:16:57 +02:00
{
DVECTOR const &CamPos=CLevel::getCameraPos();
x1 = renderPos.vx;
x2 = m_lineBase.vx - CamPos.vx;
2001-05-09 15:22:04 +02:00
2001-05-10 18:16:57 +02:00
if ( x1 > x2 )
{
int tempX = x1;
x1 = x2;
x2 = tempX;
}
2001-05-09 15:22:04 +02:00
2001-05-10 18:16:57 +02:00
y1 = renderPos.vy;
y2 = m_lineBase.vy - CamPos.vy;
2001-05-09 15:22:04 +02:00
2001-05-10 18:16:57 +02:00
if ( y1 > y2 )
{
int tempY = y1;
y1 = y2;
y2 = tempY;
}
2001-05-09 15:22:04 +02:00
2001-05-10 18:16:57 +02:00
if ( y1 < 0 )
2001-05-09 15:22:04 +02:00
{
2001-05-10 18:16:57 +02:00
y1 = 0;
2001-05-09 15:22:04 +02:00
}
2001-05-10 18:16:57 +02:00
if ( y2 > VidGetScrH() )
{
y2 = VidGetScrH();
}
2001-07-26 21:12:49 +02:00
DrawLine( x1, y1, x2, y2, 0, 0, 0, OTPOS__ACTOR_POS+1 );
2001-05-09 15:22:04 +02:00
}
}
2001-05-10 18:16:57 +02:00
2001-05-09 15:22:04 +02:00
}
2001-05-14 20:48:54 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CRECT *CNpcFishHookPlatform::getThinkBBox()
{
CRECT objThinkBox = getCollisionArea();
sBBox &thinkBBox = CThingManager::getThinkBBox();
objThinkBox.y2 = thinkBBox.YMin + 1;
return &objThinkBox;
}