2001-04-24 23:03:46 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
pbranch.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PBRANCH_H__
|
|
|
|
#include "platform\pbranch.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-02 01:41:00 +02:00
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-01 20:39:41 +02:00
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PLAYER_PLAYER_H__
|
|
|
|
#include "player\player.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-04-24 23:03:46 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcBranchPlatform::postInit()
|
|
|
|
{
|
2001-05-10 01:14:35 +02:00
|
|
|
sBBox boundingBox = m_modelGfx->GetBBox();
|
2001-05-10 21:22:34 +02:00
|
|
|
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ) << 1, PLATFORMCOLLISIONHEIGHT );
|
2001-05-10 01:14:35 +02:00
|
|
|
|
|
|
|
if ( m_reversed )
|
|
|
|
{
|
|
|
|
setCollisionCentreOffset( boundingBox.XMax, 18 + ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setCollisionCentreOffset( boundingBox.XMin, 18 + ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) );
|
|
|
|
}
|
2001-05-05 15:54:34 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
m_angularVelocity = 0;
|
2001-04-24 23:03:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
void CNpcBranchPlatform::setWaypoints( sThingPlatform *ThisPlatform )
|
2001-04-24 23:03:46 +02:00
|
|
|
{
|
2001-04-25 21:22:15 +02:00
|
|
|
int pointNum;
|
|
|
|
|
|
|
|
u16 *PntList=(u16*)MakePtr(ThisPlatform,sizeof(sThingPlatform));
|
|
|
|
|
|
|
|
u16 initXPos, newXPos, newYPos;
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
initXPos = newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
|
|
|
DVECTOR startPos;
|
|
|
|
startPos.vx = newXPos << 4;
|
|
|
|
startPos.vy = newYPos << 4;
|
|
|
|
|
|
|
|
init( startPos );
|
|
|
|
|
|
|
|
if ( ThisPlatform->PointCount > 1 )
|
2001-04-24 23:03:46 +02:00
|
|
|
{
|
2001-04-25 21:22:15 +02:00
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
|
|
|
|
if ( newXPos < initXPos )
|
2001-04-24 23:03:46 +02:00
|
|
|
{
|
2001-04-25 21:22:15 +02:00
|
|
|
m_reversed = true;
|
2001-04-24 23:03:46 +02:00
|
|
|
}
|
2001-04-25 21:22:15 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_reversed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_reversed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-05-02 17:32:47 +02:00
|
|
|
void CNpcBranchPlatform::collidedWith( CThing *_thisThing )
|
|
|
|
{
|
|
|
|
switch(_thisThing->getThingType())
|
|
|
|
{
|
|
|
|
case TYPE_PLAYER:
|
|
|
|
{
|
|
|
|
if ( m_detectCollision && m_isActive )
|
|
|
|
{
|
|
|
|
CPlayer *player;
|
|
|
|
DVECTOR playerPos;
|
|
|
|
CRECT collisionArea;
|
|
|
|
|
|
|
|
// Only interested in SBs feet colliding with the box (pkg)
|
|
|
|
player=(CPlayer*)_thisThing;
|
|
|
|
playerPos=player->getPos();
|
|
|
|
collisionArea=getCollisionArea();
|
|
|
|
if(playerPos.vx>=collisionArea.x1&&playerPos.vx<=collisionArea.x2&&
|
|
|
|
playerPos.vy>=collisionArea.y1&&playerPos.vy<=collisionArea.y2)
|
|
|
|
{
|
|
|
|
if ( ( m_reversed && playerPos.vx <= Pos.vx ) || ( !m_reversed && playerPos.vx >= Pos.vx ) )
|
|
|
|
{
|
|
|
|
player->setPlatform( this );
|
|
|
|
|
|
|
|
if(getHeightFromPlatformAtPosition(playerPos.vx,playerPos.vy)==0)
|
|
|
|
{
|
|
|
|
m_contact = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-05-09 22:29:21 +02:00
|
|
|
case TYPE_HAZARD:
|
|
|
|
break;
|
|
|
|
|
2001-05-02 17:32:47 +02:00
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
void CNpcBranchPlatform::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
s16 newAngle = getCollisionAngle();
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
if ( m_contact )
|
|
|
|
{
|
2001-05-01 21:36:24 +02:00
|
|
|
//if ( ( m_reversed && newAngle < -256 ) || newAngle > 256 )
|
|
|
|
//{
|
2001-04-25 21:22:15 +02:00
|
|
|
// flick player upwards
|
2001-05-01 21:36:24 +02:00
|
|
|
//GameScene.getPlayer()->springPlayerUp();
|
|
|
|
//}
|
|
|
|
|
|
|
|
CPlayer *player = GameScene.getPlayer();
|
|
|
|
|
|
|
|
if ( m_reversed )
|
|
|
|
{
|
2001-05-15 00:29:01 +02:00
|
|
|
if ( m_angularVelocity > 8 && newAngle < -20 )
|
2001-05-01 21:36:24 +02:00
|
|
|
{
|
|
|
|
player->springPlayerUp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-15 00:29:01 +02:00
|
|
|
if ( m_angularVelocity < -8 && newAngle > 20 )
|
2001-05-01 21:36:24 +02:00
|
|
|
{
|
|
|
|
player->springPlayerUp();
|
|
|
|
}
|
2001-04-25 21:22:15 +02:00
|
|
|
}
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
s16 angularForce = 3 * _frames;
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
if ( m_reversed )
|
|
|
|
{
|
|
|
|
angularForce = -angularForce;
|
|
|
|
}
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
m_angularVelocity += angularForce;
|
|
|
|
}
|
2001-05-14 23:57:11 +02:00
|
|
|
else if ( ( getRnd() % 50 ) == 0 )
|
|
|
|
{
|
|
|
|
s16 angularForce = 6 * _frames;
|
|
|
|
|
|
|
|
if ( m_reversed )
|
|
|
|
{
|
|
|
|
angularForce = -angularForce;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_angularVelocity += angularForce;
|
|
|
|
}
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-05-15 00:29:01 +02:00
|
|
|
s32 resistance = -( 10 * _frames * newAngle ) >> 8;
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
if ( newAngle > 0 && resistance > -2 )
|
|
|
|
{
|
|
|
|
resistance = -2;
|
|
|
|
}
|
|
|
|
else if ( newAngle < 0 && resistance < 2 )
|
|
|
|
{
|
|
|
|
resistance = 2;
|
|
|
|
}
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
// get direction of resistance
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
m_angularVelocity += resistance;
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
newAngle += m_angularVelocity;
|
2001-04-24 23:03:46 +02:00
|
|
|
|
2001-04-25 21:22:15 +02:00
|
|
|
if ( m_angularVelocity )
|
|
|
|
{
|
|
|
|
m_angularVelocity += -m_angularVelocity / abs( m_angularVelocity );
|
2001-05-01 21:36:24 +02:00
|
|
|
|
|
|
|
if ( m_angularVelocity > 40 )
|
|
|
|
{
|
|
|
|
m_angularVelocity = 40;
|
|
|
|
}
|
|
|
|
else if ( m_angularVelocity < -40 )
|
|
|
|
{
|
|
|
|
m_angularVelocity = -40;
|
|
|
|
}
|
2001-04-24 23:03:46 +02:00
|
|
|
}
|
2001-04-25 21:22:15 +02:00
|
|
|
|
|
|
|
/*if ( newAngle > 320 )
|
|
|
|
{
|
|
|
|
newAngle = 320;
|
|
|
|
}
|
|
|
|
else if ( newAngle < -320 )
|
|
|
|
{
|
|
|
|
newAngle = -320;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
setCollisionAngle( newAngle );
|
2001-04-24 23:03:46 +02:00
|
|
|
}
|
2001-05-02 01:41:00 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-05-03 17:34:02 +02:00
|
|
|
int BX=-16;
|
2001-05-05 22:00:27 +02:00
|
|
|
int BY=+18;
|
2001-05-02 01:41:00 +02:00
|
|
|
void CNpcBranchPlatform::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;
|
|
|
|
if ( m_reversed )
|
2001-05-02 01:41:00 +02:00
|
|
|
{
|
2001-05-10 18:16:57 +02:00
|
|
|
rotation.vy = 0;
|
|
|
|
rotation.vz = getCollisionAngle();
|
|
|
|
renderPos.vx-= BX;
|
|
|
|
renderPos.vy+= BY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rotation.vy = 0;
|
|
|
|
rotation.vz = getCollisionAngle();
|
|
|
|
renderPos.vx+= BX;
|
|
|
|
renderPos.vy+= BY;
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
x1=0;
|
|
|
|
x2=0;
|
|
|
|
y1=0;
|
|
|
|
y2=0;
|
2001-05-02 01:41:00 +02:00
|
|
|
|
2001-05-02 17:32:47 +02:00
|
|
|
if ( m_reversed )
|
|
|
|
{
|
|
|
|
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
|
|
|
|
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
|
|
|
|
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
|
|
|
|
}
|
2001-05-02 01:41:00 +02:00
|
|
|
|
|
|
|
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
|
2001-05-10 18:16:57 +02:00
|
|
|
|
2001-05-02 01:41:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-10 01:14:35 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcBranchPlatform::calculateBoundingBoxSize()
|
|
|
|
{
|
|
|
|
int angle;
|
|
|
|
DVECTOR centre;
|
|
|
|
int length;
|
|
|
|
int x1,y1,x2,y2;
|
|
|
|
|
|
|
|
angle=getCollisionAngle();
|
|
|
|
centre=getCollisionCentre();
|
|
|
|
|
|
|
|
//halfLength=m_platformWidth/2;
|
|
|
|
sBBox boundingBox = m_modelGfx->GetBBox();
|
|
|
|
length = ( boundingBox.XMax - boundingBox.XMin );
|
|
|
|
|
|
|
|
x1=-length*mcos(angle&4095)>>12;
|
|
|
|
y1=-length*msin(angle&4095)>>12;
|
|
|
|
x2=+length*mcos(angle&4095)>>12;
|
|
|
|
y2=+length*msin(angle&4095)>>12;
|
|
|
|
|
2001-05-10 21:22:34 +02:00
|
|
|
setCollisionSize(abs(x2-x1),abs(y2-y1)+PLATFORMCOLLISIONHEIGHT);
|
2001-05-10 01:14:35 +02:00
|
|
|
}
|