SBSPSS/source/platform/pseesaw.cpp

164 lines
3.1 KiB
C++
Raw Normal View History

2001-04-30 18:04:15 +02:00
/*=========================================================================
pseesaw.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PSEESAW_H__
#include "platform\pseesaw.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-02 01:41:00 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-04-30 18:04:15 +02:00
void CNpcSeesawPlatform::postInit()
{
CNpcPlatform::postInit();
m_angularVelocity = 0;
m_currentAngle = 0;
}
void CNpcSeesawPlatform::processMovement( int _frames )
{
s32 forceActing = 0;
if ( m_contact )
{
// find if user is to left or right of platform centre
CPlayer *player = GameScene.getPlayer();
DVECTOR playerPos = player->getPos();
s32 distX = playerPos.vx - this->Pos.vx;
if ( distX > 0 )
{
forceActing = 64 * _frames;
m_angularVelocity += forceActing;
}
else if ( distX < 0 )
{
forceActing = -64 * _frames;
m_angularVelocity += forceActing;
}
}
if ( !forceActing && m_angularVelocity )
{
// reduce velocity until 0
s32 m_angularResistance = -( 64 * _frames * m_angularVelocity ) / abs( m_angularVelocity );
if ( m_angularResistance < -m_angularVelocity )
{
m_angularResistance = -m_angularVelocity;
}
else if ( m_angularResistance > m_angularVelocity )
{
m_angularResistance = m_angularVelocity;
}
m_angularVelocity += m_angularResistance;
}
if ( m_angularVelocity > ( 20 << 8 ) )
{
m_angularVelocity = 20 << 8;
}
else if ( m_angularVelocity < -( 20 << 8 ) )
{
m_angularVelocity = -( 20 << 8 );
}
s32 newAngle = m_currentAngle + m_angularVelocity;
2001-05-02 18:46:38 +02:00
if ( newAngle > ( 340 << 8 ) )
2001-04-30 18:04:15 +02:00
{
2001-05-02 18:46:38 +02:00
newAngle = 340 << 8;
2001-04-30 18:04:15 +02:00
m_angularVelocity = 0;
}
2001-05-02 18:46:38 +02:00
else if ( newAngle < -( 340 << 8 ) )
2001-04-30 18:04:15 +02:00
{
2001-05-02 18:46:38 +02:00
newAngle = -( 340 << 8 );
2001-04-30 18:04:15 +02:00
m_angularVelocity = 0;
}
m_currentAngle = newAngle;
setCollisionAngle( newAngle >> 8 );
2001-05-02 01:41:00 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSeesawPlatform::render()
{
if ( m_isActive )
{
CPlatformThing::render();
2001-05-10 18:16:57 +02:00
if (canRender())
2001-05-02 01:41:00 +02:00
{
2001-05-10 18:16:57 +02:00
DVECTOR &renderPos=getRenderPos();
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = getCollisionAngle();
2001-05-02 01:41:00 +02:00
2001-05-10 18:16:57 +02:00
VECTOR scale;
scale.vx = ONE;
scale.vy = ONE;
scale.vz = ONE;
2001-05-02 01:41:00 +02:00
2001-05-10 18:16:57 +02:00
m_modelGfx->Render(renderPos,&rotation,&scale);
2001-05-02 01:41:00 +02:00
#if defined (__USER_paul__) || defined (__USER_charles__)
2001-05-10 18:47:35 +02:00
DVECTOR offset = CLevel::getCameraPos();
2001-05-02 17:32:47 +02:00
DVECTOR size;
2001-05-02 01:41:00 +02:00
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
2001-05-02 17:32:47 +02:00
size=getCollisionSize();
halfLength=size.vx>>1;
2001-05-02 01:41:00 +02:00
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}