SBSPSS/source/platform/plift.cpp

276 lines
5.7 KiB
C++
Raw Normal View History

2001-06-06 16:13:58 +02:00
/*=========================================================================
plift.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PLIFT_H__
#include "platform\plift.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-06-06 20:40:34 +02:00
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
2001-06-06 16:13:58 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcLiftPlatform::postInit()
{
CNpcPlatform::postInit();
m_isActivated = false;
m_returning = false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcLiftPlatform::setWaypoints( sThingPlatform *ThisPlatform )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisPlatform,sizeof(sThingPlatform));
u16 newXPos, newYPos;
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
startPos.vx = ( newXPos << 4 ) + 8;
startPos.vy = ( newYPos << 4 ) + 16;
init( startPos );
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
m_maxExtension = ( ( newYPos << 4 ) + 16 ) - startPos.vy;
2001-06-19 22:07:57 +02:00
2001-06-25 23:04:43 +02:00
/*s32 minX, maxX, minY, maxY;
2001-06-19 22:07:57 +02:00
m_npcPath.getPathXExtents( &minX, &maxX );
2001-06-25 23:04:43 +02:00
m_npcPath.getPathYExtents( &minY, &maxY );*/
2001-06-19 22:07:57 +02:00
2001-06-25 23:04:43 +02:00
m_thinkArea.x1 = startPos.vx;
m_thinkArea.x2 = startPos.vx + 1;
m_thinkArea.y1 = startPos.vy;
m_thinkArea.y2 = startPos.vy + m_maxExtension;
if ( m_thinkArea.y1 > m_thinkArea.y2 )
{
s32 temp = m_thinkArea.y2;
m_thinkArea.y2 = m_thinkArea.y1;
m_thinkArea.y1 = temp;
}
2001-06-06 16:13:58 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcLiftPlatform::processMovement( int _frames )
{
if ( m_contact )
{
if ( !m_isActivated )
{
m_isActivated = true;
m_timer = GameState::getOneSecondInFrames();
}
}
if ( m_isActivated )
{
if ( m_timer <= 0 )
{
s32 extension;
if ( m_returning )
{
extension = -m_extension;
}
else
{
extension = m_maxExtension - m_extension;
}
s32 maxMove = m_speed * _frames;
if ( extension > maxMove )
{
extension = maxMove;
}
else if ( extension < -maxMove )
{
extension = -maxMove;
}
if ( extension )
{
m_extension += extension;
2001-07-24 22:11:23 +02:00
if(m_soundId==NOT_PLAYING)
{
m_soundId=CSoundMediator::playSfx(CSoundMediator::SFX_ELEVATOR_LOOP,true,true);
}
2001-06-06 16:13:58 +02:00
}
else
{
2001-07-24 22:11:23 +02:00
if ( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId=CSoundMediator::playSfx(CSoundMediator::SFX_ELEVATOR_STOP,true,true);
2001-06-06 16:13:58 +02:00
if ( m_returning )
{
m_isActivated = false;
m_returning = false;
}
else
{
m_timer = GameState::getOneSecondInFrames();
m_returning = true;
}
}
}
Pos.vy = m_base.vy + m_extension;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcLiftPlatform::processTimer( int _frames )
{
if ( m_timer > 0 )
{
m_timer -= _frames;
}
}
2001-06-06 20:40:34 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcLiftPlatform::collidedWith( CThing *_thisThing )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player;
2001-07-23 21:26:37 +02:00
// DVECTOR playerPos;
// CRECT collisionArea;
// CRECT playerCollisionArea;
2001-06-06 20:40:34 +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 &playerCollisionArea = player->getCollisionArea();
CRECT const &collisionArea=getCollisionArea();
2001-06-06 20:40:34 +02:00
s32 threshold = abs( collisionArea.y2 - collisionArea.y1 );
if ( threshold > 16 )
{
threshold = 16;
}
2001-07-12 16:10:26 +02:00
//if( playerPos.vx >= collisionArea.x1 && playerPos.vx <= collisionArea.x2 )
if( playerCollisionArea.x2 >= collisionArea.x1 && playerCollisionArea.x1 <= collisionArea.x2 )
2001-06-06 20:40:34 +02:00
{
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;
}
}
}
}
break;
}
case TYPE_NPC:
{
CNpcFriend *friendNpc;
2001-07-23 21:26:37 +02:00
// DVECTOR friendPos;
// CRECT collisionArea;
2001-06-06 20:40:34 +02:00
friendNpc = (CNpcFriend*) _thisThing;
2001-07-23 21:26:37 +02:00
DVECTOR const &friendPos = friendNpc->getPos();
2001-07-26 16:56:43 +02:00
CRECT const &friendCollisionArea = friendNpc->getCollisionArea();
2001-07-23 21:26:37 +02:00
CRECT const &collisionArea=getCollisionArea();
2001-06-06 20:40:34 +02:00
s32 threshold = abs( collisionArea.y2 - collisionArea.y1 );
if ( threshold > 16 )
{
threshold = 16;
}
2001-07-26 16:56:43 +02:00
if( friendCollisionArea.x2 >= collisionArea.x1 && friendCollisionArea.x1 <= collisionArea.x2 )
2001-06-06 20:40:34 +02:00
{
if ( checkCollisionDelta( _thisThing, threshold, collisionArea ) )
{
int height = getHeightFromPlatformAtPosition( friendPos.vx, friendPos.vy );
friendNpc->setPlatform( this );
}
else
{
if( friendPos.vy >= collisionArea.y1 && friendPos.vy <= collisionArea.y2 )
{
int height = getHeightFromPlatformAtPosition( friendPos.vx, friendPos.vy );
if ( height >= -threshold && height < 1 )
{
friendNpc->setPlatform( this );
}
}
}
}
break;
}
case TYPE_HAZARD:
break;
default:
ASSERT(0);
break;
}
}