2001-07-05 22:07:49 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
pfblock.h
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PFBLOCK_H__
|
|
|
|
#include "platform\pfblock.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcFallingBlockPlatform::postInit()
|
|
|
|
{
|
|
|
|
CNpcPlatform::postInit();
|
|
|
|
|
|
|
|
m_isTriggered = false;
|
|
|
|
m_isFalling = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-07-05 23:50:02 +02:00
|
|
|
void CNpcFallingBlockPlatform::trigger()
|
|
|
|
{
|
|
|
|
m_isTriggered = true;
|
|
|
|
m_timer = GameState::getOneSecondInFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-07-05 22:07:49 +02:00
|
|
|
void CNpcFallingBlockPlatform::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
if ( m_isTriggered )
|
|
|
|
{
|
|
|
|
if ( m_timer > 0 )
|
|
|
|
{
|
|
|
|
m_timer -= _frames;
|
|
|
|
|
|
|
|
if ( m_timer <= 0 )
|
|
|
|
{
|
|
|
|
Pos = m_base;
|
|
|
|
m_isFalling = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pos.vx = m_base.vx + ( -3 + ( getRnd() % 7 ) );
|
|
|
|
Pos.vy = m_base.vy + ( -3 + ( getRnd() % 7 ) );
|
|
|
|
|
|
|
|
if ( m_soundId == NOT_PLAYING )
|
|
|
|
{
|
|
|
|
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_RATTLE, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DVECTOR offset = CLevel::getCameraPos();
|
|
|
|
|
|
|
|
s32 yPos = Pos.vy - offset.vy;
|
|
|
|
|
|
|
|
if ( yPos > VidGetScrH() )
|
|
|
|
{
|
|
|
|
setToShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 moveY = m_speed * _frames;
|
|
|
|
|
|
|
|
Pos.vy += moveY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-07-06 17:54:47 +02:00
|
|
|
void CNpcFallingBlockPlatform::collidedWith( CThing *_thisThing )
|
2001-07-05 22:07:49 +02:00
|
|
|
{
|
2001-07-06 17:54:47 +02:00
|
|
|
switch(_thisThing->getThingType())
|
2001-07-05 22:07:49 +02:00
|
|
|
{
|
2001-07-06 17:54:47 +02:00
|
|
|
case TYPE_PLAYER:
|
|
|
|
{
|
|
|
|
CPlayer *player;
|
|
|
|
DVECTOR playerPos;
|
|
|
|
CRECT collisionArea;
|
2001-07-12 16:10:26 +02:00
|
|
|
CRECT playerCollisionArea;
|
2001-07-06 17:54:47 +02:00
|
|
|
|
|
|
|
// Only interested in SBs feet colliding with the box (pkg)
|
|
|
|
player=(CPlayer*)_thisThing;
|
|
|
|
playerPos=player->getPos();
|
2001-07-12 16:10:26 +02:00
|
|
|
playerCollisionArea = player->getCollisionArea();
|
2001-07-06 17:54:47 +02:00
|
|
|
collisionArea=getCollisionArea();
|
|
|
|
|
|
|
|
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-07-06 17:54:47 +02:00
|
|
|
{
|
|
|
|
if ( m_isFalling )
|
|
|
|
{
|
|
|
|
int height = getHeightFromPlatformAtPosition( playerPos.vx, playerPos.vy );
|
|
|
|
|
|
|
|
if ( height < -threshold )
|
|
|
|
{
|
|
|
|
player->takeDamage( DAMAGE__HIT_ENEMY, REACT__GET_DIRECTION_FROM_THING, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2001-07-05 22:07:49 +02:00
|
|
|
}
|
|
|
|
}
|