SBSPSS/source/platform/ppendulm.cpp

199 lines
4.3 KiB
C++
Raw Normal View History

2001-04-24 23:48:20 +02:00
/*=========================================================================
ppendulm.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PPENDULM_H__
#include "platform\ppendulm.h"
#endif
2001-04-25 00:05:29 +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
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-04-25 00:05:29 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 23:48:20 +02:00
void CNpcPendulumPlatform::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-24 23:48:20 +02:00
m_extendDir = EXTEND_LEFT;
m_extension = 0;
m_heading = 1024;
2001-05-09 15:22:04 +02:00
m_lineBase.vx = Pos.vx;
m_lineBase.vy = 0;
2001-04-24 23:48:20 +02:00
}
2001-04-25 00:05:29 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcPendulumPlatform::setWaypoints( sThingPlatform *ThisPlatform )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisPlatform,sizeof(sThingPlatform));
2001-04-25 00:58:43 +02:00
u16 newXPos, newYPos;
2001-04-25 00:05:29 +02:00
newXPos = (u16) *PntList;
PntList++;
2001-04-25 00:58:43 +02:00
newYPos = (u16) *PntList;
2001-04-25 00:05:29 +02:00
PntList++;
2001-04-25 21:22:15 +02:00
DVECTOR startPos;
2001-05-31 18:24:48 +02:00
startPos.vx = ( newXPos << 4 ) + 8;
startPos.vy = ( newYPos << 4 ) + 16;
2001-04-25 00:05:29 +02:00
if ( ThisPlatform->PointCount > 1 )
{
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
2001-04-25 21:22:15 +02:00
DVECTOR pivotPos;
2001-05-31 18:24:48 +02:00
pivotPos.vx = ( newXPos << 4 ) + 8;
pivotPos.vy = ( newYPos << 4 ) + 16;
2001-04-25 00:58:43 +02:00
2001-04-26 18:07:25 +02:00
s32 xDist = startPos.vx - pivotPos.vx;
s32 yDist = startPos.vy - pivotPos.vy;
m_maxExtension = 1024 - ratan2( abs( yDist ), abs( xDist ) );
m_length = isqrt2( ( xDist * xDist ) + ( yDist * yDist ) );
2001-04-25 00:58:43 +02:00
init( pivotPos );
}
else
{
init( startPos );
2001-06-19 22:07:57 +02:00
m_length = 200;
2001-04-25 00:05:29 +02:00
}
2001-06-19 22:07:57 +02:00
m_thinkArea.x1 = Pos.vx - m_length;
m_thinkArea.x2 = Pos.vx + m_length;
m_thinkArea.y1 = Pos.vy - m_length;
m_thinkArea.y2 = Pos.vy + m_length;
2001-04-25 00:05:29 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 23:48:20 +02:00
void CNpcPendulumPlatform::processMovement( int _frames )
{
if ( m_extendDir == EXTEND_LEFT )
{
2001-04-26 18:07:25 +02:00
if ( m_extension > m_maxExtension )
2001-04-24 23:48:20 +02:00
{
m_extendDir = EXTEND_RIGHT;
}
else
{
2001-05-10 18:47:35 +02:00
m_extension += m_speed * _frames;
2001-04-24 23:48:20 +02:00
}
}
else
{
2001-04-26 18:07:25 +02:00
if ( m_extension < -m_maxExtension )
2001-04-24 23:48:20 +02:00
{
m_extendDir = EXTEND_LEFT;
}
else
{
2001-05-10 18:47:35 +02:00
m_extension -= m_speed * _frames;
2001-04-24 23:48:20 +02:00
}
}
Pos.vx = m_base.vx + ( ( m_length * rcos( m_heading + m_extension ) ) >> 12 );
Pos.vy = m_base.vy + ( ( m_length * rsin( m_heading + m_extension ) ) >> 12 );
}
2001-05-09 15:22:04 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcPendulumPlatform::render()
{
int x1,y1,x2,y2;
int x1Boundary,y1Boundary,x2Boundary,y2Boundary;
2001-05-10 18:47:35 +02:00
DVECTOR offset = CLevel::getCameraPos();
2001-05-09 15:22:04 +02:00
if ( m_isActive )
{
CPlatformThing::render();
2001-05-10 18:16:57 +02:00
if (canRender())
2001-05-09 15:22:04 +02:00
{
2001-05-10 18:16:57 +02:00
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
2001-05-10 18:47:35 +02:00
}
2001-05-09 15:22:04 +02:00
2001-05-10 18:47:35 +02:00
x1 = x1Boundary = Pos.vx - offset.vx;
x2 = x2Boundary = m_lineBase.vx - offset.vx;
2001-05-09 15:22:04 +02:00
2001-05-10 18:47:35 +02:00
y1 = y1Boundary = Pos.vy - offset.vy;
y2 = y2Boundary = m_lineBase.vy - offset.vy;
2001-05-09 15:22:04 +02:00
2001-05-10 18:47:35 +02:00
int angle = ratan2( x1 - x2, y1 - y2 );
2001-05-09 15:22:04 +02:00
2001-05-10 18:47:35 +02:00
if ( y2 < 0 )
{
int yDiff = -y2;
y2 = y2Boundary = 0;
int hyp = ( yDiff << 12 ) / rcos( angle );
x2 += ( hyp * rsin( angle ) ) >> 12;
}
if ( y1 > VidGetScrH() )
{
int yDiff = y1 - VidGetScrH();
y1 = y1Boundary = VidGetScrH();
int hyp = ( yDiff << 12 ) / rcos( angle );
x1 -= ( hyp * rsin( angle ) ) >> 12;
}
2001-05-09 15:22:04 +02:00
2001-05-10 18:47:35 +02:00
if ( x1Boundary > x2Boundary )
{
int tempX = x1Boundary;
x1Boundary = x2Boundary;
x2Boundary = tempX;
}
2001-05-09 15:22:04 +02:00
2001-05-10 18:47:35 +02:00
if ( y1Boundary > y2Boundary )
{
int tempY = y1Boundary;
y1Boundary = y2Boundary;
y2Boundary = tempY;
}
if ( x2Boundary >= 0 && x1Boundary <= VidGetScrW() )
{
if ( y2Boundary >= 0 && y1Boundary <= VidGetScrH() )
2001-05-09 15:22:04 +02:00
{
2001-07-11 18:17:05 +02:00
DrawLine( x1, y1, x2, y2, 0, 0, 0, 8 );
2001-05-09 15:22:04 +02:00
}
}
}
}