2001-05-29 16:41:29 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
pconveyr.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PCONVEYR_H__
|
|
|
|
#include "platform\pconveyr.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PFALLNOR_H__
|
|
|
|
#include "platform\pfallnor.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-30 20:31:57 +02:00
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-05-29 16:41:29 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatformGenerator::collidedWith(CThing *_thisThing)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatformGenerator::render()
|
|
|
|
{
|
|
|
|
// no rendering
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatformGenerator::think( int _frames )
|
|
|
|
{
|
|
|
|
m_timer -= _frames;
|
|
|
|
|
|
|
|
if ( m_timer < 0 )
|
|
|
|
{
|
|
|
|
s32 second = GameState::getOneSecondInFrames();
|
|
|
|
|
|
|
|
m_timer = second;
|
|
|
|
|
2001-05-29 20:40:38 +02:00
|
|
|
m_timer += m_dataPtr->initTimer * second;
|
2001-05-29 16:41:29 +02:00
|
|
|
|
|
|
|
m_timer += second - ( getRnd() % ( 2 * second ) );
|
|
|
|
|
|
|
|
//m_timer = ( 3 * GameState::getOneSecondInFrames() ) + ( getRnd() % ( ( m_data[m_type].initTimer - 1 ) * GameState::getOneSecondInFrames() ) );
|
|
|
|
|
2001-05-30 00:07:28 +02:00
|
|
|
// generate new conveyor platform
|
2001-05-29 16:41:29 +02:00
|
|
|
|
|
|
|
CNpcPlatform *newPlatform = NULL;
|
|
|
|
newPlatform = CNpcPlatform::Create( NPC_CONVEYOR_PLATFORM );
|
|
|
|
|
|
|
|
ASSERT(newPlatform);
|
|
|
|
|
2001-05-29 20:40:38 +02:00
|
|
|
newPlatform->setThingSubType( NPC_CONVEYOR_PLATFORM );
|
2001-05-29 16:41:29 +02:00
|
|
|
newPlatform->setGraphic( m_graphicNum );
|
|
|
|
|
2001-05-30 00:07:28 +02:00
|
|
|
DVECTOR startPos = Pos;
|
|
|
|
newPlatform->init( startPos );
|
2001-05-29 16:41:29 +02:00
|
|
|
|
2001-05-30 00:07:28 +02:00
|
|
|
newPlatform->setWaypointCount( m_npcPath.getWaypointCount() );
|
|
|
|
newPlatform->setWaypointPtr( m_npcPath.getWaypointPtr() );
|
2001-05-29 16:41:29 +02:00
|
|
|
|
|
|
|
newPlatform->setTiltable( false );
|
|
|
|
newPlatform->postInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatform::postInit()
|
|
|
|
{
|
|
|
|
CNpcPlatform::postInit();
|
|
|
|
|
|
|
|
m_npcPath.setPathType( CNpcPath::SINGLE_USE_PATH );
|
2001-05-30 20:31:57 +02:00
|
|
|
|
|
|
|
m_spinFinish = false;
|
|
|
|
m_rotation = 0;
|
2001-07-10 18:20:32 +02:00
|
|
|
|
|
|
|
s32 minX, maxX, minY, maxY;
|
|
|
|
|
|
|
|
m_npcPath.getPathXExtents( &minX, &maxX );
|
|
|
|
m_npcPath.getPathYExtents( &minY, &maxY );
|
|
|
|
|
|
|
|
m_thinkArea.x1 = minX;
|
|
|
|
m_thinkArea.x2 = maxX;
|
|
|
|
m_thinkArea.y1 = minY;
|
|
|
|
m_thinkArea.y2 = maxY;
|
2001-05-29 16:41:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatform::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
s32 moveX = 0, moveY = 0;
|
|
|
|
s32 distX, distY;
|
|
|
|
bool pathComplete, waypointChange;
|
|
|
|
|
2001-05-30 20:31:57 +02:00
|
|
|
if ( m_spinFinish )
|
2001-05-29 16:41:29 +02:00
|
|
|
{
|
2001-05-30 20:31:57 +02:00
|
|
|
m_rotation += 64 * _frames;
|
|
|
|
m_rotation &= 4095;
|
|
|
|
|
2001-07-23 21:26:37 +02:00
|
|
|
DVECTOR const &offset = CLevel::getCameraPos();
|
2001-05-30 20:31:57 +02:00
|
|
|
|
|
|
|
Pos.vy += 3 * _frames;
|
|
|
|
|
|
|
|
s32 yPos = Pos.vy - offset.vy;
|
|
|
|
|
2001-05-30 21:20:38 +02:00
|
|
|
if ( yPos < 0 || yPos > VidGetScrH() )
|
2001-05-30 20:31:57 +02:00
|
|
|
{
|
|
|
|
setToShutdown();
|
|
|
|
}
|
2001-05-29 16:41:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-30 20:31:57 +02:00
|
|
|
m_npcPath.think( Pos, &pathComplete, &waypointChange, &distX, &distY );
|
2001-05-29 16:41:29 +02:00
|
|
|
|
2001-05-30 20:31:57 +02:00
|
|
|
if ( pathComplete )
|
|
|
|
{
|
|
|
|
m_spinFinish = true;
|
2001-05-29 16:41:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-30 20:31:57 +02:00
|
|
|
if ( distX )
|
2001-05-29 16:41:29 +02:00
|
|
|
{
|
2001-07-11 21:03:57 +02:00
|
|
|
int Time = GameState::getFramesSinceLast();
|
|
|
|
|
2001-05-30 20:31:57 +02:00
|
|
|
moveX = distX;
|
|
|
|
|
2001-07-11 21:03:57 +02:00
|
|
|
if ( moveX > Time )
|
2001-05-30 20:31:57 +02:00
|
|
|
{
|
2001-07-11 21:03:57 +02:00
|
|
|
moveX = Time;
|
2001-05-30 20:31:57 +02:00
|
|
|
}
|
2001-07-11 21:03:57 +02:00
|
|
|
else if ( moveX < -Time )
|
2001-05-30 20:31:57 +02:00
|
|
|
{
|
2001-07-11 21:03:57 +02:00
|
|
|
moveX = -Time;
|
2001-05-30 20:31:57 +02:00
|
|
|
}
|
2001-05-29 16:41:29 +02:00
|
|
|
}
|
2001-05-30 20:31:57 +02:00
|
|
|
else
|
2001-05-29 16:41:29 +02:00
|
|
|
{
|
2001-05-30 20:31:57 +02:00
|
|
|
moveY = distY;
|
|
|
|
|
|
|
|
s32 verticalMovement = 3 * _frames;
|
|
|
|
|
|
|
|
if ( moveY > verticalMovement )
|
|
|
|
{
|
|
|
|
moveY = verticalMovement;
|
|
|
|
}
|
|
|
|
else if ( moveY < -verticalMovement )
|
|
|
|
{
|
|
|
|
moveY = -verticalMovement;
|
|
|
|
}
|
2001-05-29 16:41:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatform::collidedWith( CThing *_thisThing )
|
|
|
|
{
|
|
|
|
switch(_thisThing->getThingType())
|
|
|
|
{
|
|
|
|
case TYPE_PLAYER:
|
|
|
|
{
|
|
|
|
CPlayer *player;
|
2001-07-23 21:26:37 +02:00
|
|
|
// DVECTOR playerPos;
|
|
|
|
// CRECT collisionArea;
|
2001-05-29 16:41:29 +02:00
|
|
|
|
|
|
|
// Only interested in SBs feet colliding with the box (pkg)
|
|
|
|
player=(CPlayer*)_thisThing;
|
2001-07-23 21:26:37 +02:00
|
|
|
DVECTOR const &playerPos=player->getPos();
|
|
|
|
CRECT const &collisionArea=getCollisionArea();
|
2001-05-29 16:41:29 +02:00
|
|
|
|
|
|
|
s32 threshold = abs( collisionArea.y2 - collisionArea.y1 );
|
|
|
|
|
|
|
|
if ( threshold > 16 )
|
|
|
|
{
|
|
|
|
threshold = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( playerPos.vx >= collisionArea.x1 && playerPos.vx <= collisionArea.x2 )
|
|
|
|
{
|
|
|
|
if ( checkCollisionDelta( _thisThing, threshold, collisionArea ) )
|
|
|
|
{
|
|
|
|
player->setPlatform( this );
|
|
|
|
|
|
|
|
m_contact = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( playerPos.vy >= collisionArea.y1 && playerPos.vy <= collisionArea.y2 )
|
|
|
|
{
|
|
|
|
int height = getHeightFromPlatformAtPosition( playerPos.vx, playerPos.vy );
|
|
|
|
|
|
|
|
if ( height >= -threshold && height < 1 )
|
|
|
|
{
|
|
|
|
player->setPlatform( this );
|
|
|
|
|
|
|
|
m_contact = true;
|
|
|
|
}
|
2001-07-11 21:42:11 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int distLeft, distRight;
|
|
|
|
|
2001-07-23 21:26:37 +02:00
|
|
|
DVECTOR const &playerCollisionSize = player->getCollisionSize();
|
2001-07-11 21:42:11 +02:00
|
|
|
|
|
|
|
distLeft = collisionArea.x1 - playerPos.vx - ( playerCollisionSize.vx >> 1 );
|
|
|
|
distRight = collisionArea.x2 - playerPos.vx + ( playerCollisionSize.vx >> 1 );
|
|
|
|
|
|
|
|
DVECTOR playerShove;
|
|
|
|
playerShove.vy = 0;
|
|
|
|
|
|
|
|
if ( abs( distLeft ) < abs( distRight ) )
|
|
|
|
{
|
|
|
|
playerShove.vx = distLeft;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerShove.vx = distRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
player->shove( playerShove );
|
|
|
|
}
|
2001-05-29 16:41:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_NPC:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_HAZARD:
|
|
|
|
{
|
2001-05-30 20:31:57 +02:00
|
|
|
if ( !m_spinFinish )
|
|
|
|
{
|
|
|
|
m_spinFinish = true;
|
|
|
|
}
|
2001-05-29 16:41:29 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-05-30 20:31:57 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcConveyorPlatform::render()
|
|
|
|
{
|
|
|
|
if ( m_isActive )
|
|
|
|
{
|
|
|
|
CPlatformThing::render();
|
|
|
|
|
|
|
|
// Render
|
|
|
|
if (canRender())
|
|
|
|
{
|
|
|
|
DVECTOR &renderPos=getRenderPos();
|
|
|
|
|
|
|
|
SVECTOR rotation;
|
|
|
|
rotation.vx = 0;
|
|
|
|
rotation.vy = 0;
|
|
|
|
rotation.vz = m_rotation;
|
|
|
|
|
|
|
|
VECTOR scale;
|
|
|
|
scale.vx = ONE;
|
|
|
|
scale.vy = ONE;
|
|
|
|
scale.vz = ONE;
|
|
|
|
|
|
|
|
m_modelGfx->Render(renderPos,&rotation,&scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int CNpcConveyorPlatform::checkCollisionAgainst(CThing *_thisThing, int _frames)
|
|
|
|
{
|
|
|
|
if ( m_spinFinish )
|
|
|
|
{
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return( CNpcPlatform::checkCollisionAgainst( _thisThing, _frames ) );
|
|
|
|
}
|
|
|
|
}
|