SBSPSS/source/hazard/hpendulm.cpp

176 lines
3.3 KiB
C++
Raw Normal View History

2001-04-24 16:00:16 +02:00
/*=========================================================================
hpendulm.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HPENDULM_H__
#include "hazard\hpendulm.h"
#endif
2001-05-01 15:28:11 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-06-06 17:04:20 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-04-24 16:00:16 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcPendulumHazard::init()
{
CNpcHazard::init();
m_extendDir = EXTEND_LEFT;
m_extension = 0;
m_heading = 1024;
2001-04-24 21:14:52 +02:00
m_length = 200;
2001-04-24 16:00:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-01 15:28:11 +02:00
void CNpcPendulumHazard::setWaypoints( sThingHazard *ThisHazard )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
u16 newXPos, newYPos;
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
2001-05-31 18:24:48 +02:00
startPos.vx = ( newXPos << 4 ) + 8;
startPos.vy = ( newYPos << 4 ) + 16;
2001-05-01 15:28:11 +02:00
if ( ThisHazard->PointCount > 1 )
{
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR pivotPos;
2001-05-31 18:24:48 +02:00
pivotPos.vx = ( newXPos << 4 ) + 8;
pivotPos.vy = ( newYPos << 4 ) + 16;
2001-05-01 15:28:11 +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 ) );
Pos = pivotPos;
2001-06-19 22:48:45 +02:00
m_base = pivotPos;
2001-05-01 15:28:11 +02:00
}
else
{
Pos = startPos;
2001-06-19 22:48:45 +02:00
m_base = Pos;
2001-05-01 15:28:11 +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-05-01 15:28:11 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 16:00:16 +02:00
void CNpcPendulumHazard::processMovement( int _frames )
{
if ( m_extendDir == EXTEND_LEFT )
{
2001-05-01 15:28:11 +02:00
if ( m_extension > m_maxExtension )
2001-04-24 16:00:16 +02:00
{
m_extendDir = EXTEND_RIGHT;
}
else
{
m_extension += _frames << 3;
}
}
else
{
2001-05-01 15:28:11 +02:00
if ( m_extension < -m_maxExtension )
2001-04-24 16:00:16 +02:00
{
m_extendDir = EXTEND_LEFT;
}
else
{
m_extension -= _frames << 3;
}
}
2001-04-24 21:14:52 +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-06-06 17:04:20 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcPendulumHazard::render()
{
int x1,y1,x2,y2;
int minX, maxX, minY, maxY;
DVECTOR offset = CLevel::getCameraPos();
CHazardThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
}
x1 = Pos.vx - offset.vx;
x2 = m_base.vx - offset.vx;
y1 = Pos.vy - offset.vy;
y2 = m_base.vy - offset.vy;
minX = x1;
maxX = x2;
if ( minX > maxX )
{
minX = x2;
maxX = x1;
}
minY = y1;
maxY = y2;
if ( minY > maxY )
{
minY = y2;
maxY = y1;
}
if ( maxX >= 0 && minX <= VidGetScrW() )
{
if ( maxY >= 0 && minY <= VidGetScrH() )
{
DrawLine( x1, y1, x2, y2, 0, 0, 0, 0 );
}
}
}