SBSPSS/source/platform/pjellfsh.cpp

180 lines
4.0 KiB
C++
Raw Normal View History

2001-05-05 19:51:08 +02:00
/*=========================================================================
pjellfsh.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PJELLFSH_H__
#include "platform\pjellfsh.h"
#endif
2001-05-05 21:08:02 +02:00
#ifndef __LEVEL_LEVEL_H__
#include "level\level.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-14 16:21:04 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcJellyfishPlatform::postInit()
{
2001-05-25 20:41:35 +02:00
sBBox boundingBox = m_modelGfx->GetBBox();
boundingBox.YMin += 8;
2001-08-14 00:09:17 +02:00
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ) - 16, ( boundingBox.YMax - boundingBox.YMin ) );
2001-05-25 20:41:35 +02:00
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
calculateNonRotatedCollisionData();
setCollisionAngle( m_tiltAngle >> 8 );
m_npcPath.setPathType( CNpcPath::PONG_PATH );
2001-05-14 16:21:04 +02:00
m_vertScale = 0;
m_dipCount = 0;
2001-05-14 20:48:54 +02:00
m_dipOffset = 0;
2001-07-12 22:15:10 +02:00
m_contactTimeout = 0;
2001-07-24 22:11:23 +02:00
m_silent = true;
2001-05-14 16:21:04 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcJellyfishPlatform::collidedWith( CThing *_thisThing )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
if ( m_detectCollision && m_isActive )
{
CPlayer *player;
2001-07-23 21:26:37 +02:00
// DVECTOR playerPos;
// CRECT collisionArea;
// CRECT playerArea;
2001-05-14 16:21:04 +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 &playerArea=player->getCollisionArea();
CRECT const &collisionArea=getCollisionArea();
2001-05-14 16:21:04 +02:00
s32 height = getHeightFromPlatformAtPosition(playerPos.vx,playerPos.vy);
2001-07-12 16:10:26 +02:00
if(playerArea.x2>=collisionArea.x1&&playerArea.x1<=collisionArea.x2&&
2001-05-14 16:21:04 +02:00
playerPos.vy>=collisionArea.y1&&playerPos.vy<=collisionArea.y2)
//if(((playerArea.x1>=collisionArea.x1&&playerArea.x1<=collisionArea.x2)||(playerArea.x2>=collisionArea.x1&&playerArea.x2<=collisionArea.x2)||(playerArea.x1<=collisionArea.x1&&playerArea.x2>=collisionArea.x2))&&
//((playerArea.y1>=thatRect.y1&&playerArea.y1<=thatRect.y2)||(playerArea.y2>=thatRect.y1&&playerArea.y2<=thatRect.y2)||(playerArea.y1<=thatRect.y1&&playerArea.y2>=thatRect.y2)))
{
player->setPlatform( this );
if( height == 0 )
{
m_contact = true;
2001-07-12 22:15:10 +02:00
2001-08-14 00:09:17 +02:00
DVECTOR playerDelta;
playerDelta = player->getPosDelta();
if ( playerDelta.vy == 0 )
{
// force dip to complete since player is not dropping onto jellyfish
m_dipCount = GameState::getOneSecondInFrames();
}
2001-07-12 22:15:10 +02:00
if ( m_contactTimeout <= 0 )
{
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_LAND_ON_JELLYFISH, true );
}
}
m_contactTimeout = 2;
2001-05-14 16:21:04 +02:00
}
}
}
break;
}
default:
break;
}
}
2001-05-05 19:51:08 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-14 16:21:04 +02:00
void CNpcJellyfishPlatform::think( int _frames )
{
/*if ( m_contact )
{
if ( m_vertScale > -2048 )
{
m_vertScale -= 10;
}
Pos.vy += 3;
}
else if ( m_vertScale < 0 )
{
m_vertScale += 10;
}*/
2001-07-12 22:15:10 +02:00
if ( m_contactTimeout > 0 )
{
m_contactTimeout--;
}
2001-05-14 16:21:04 +02:00
if ( m_contact )
{
if ( m_dipCount < GameState::getOneSecondInFrames() )
{
s16 sineVal = ( m_dipCount << 10 ) / GameState::getOneSecondInFrames();
2001-05-14 20:48:54 +02:00
m_dipOffset = ( 4 * rcos( sineVal ) ) >> 12;
2001-05-14 16:21:04 +02:00
m_dipCount += _frames;
}
2001-05-14 20:48:54 +02:00
else
{
m_dipOffset = 0;
}
2001-05-14 16:21:04 +02:00
}
else
{
m_dipCount = 0;
2001-05-14 20:48:54 +02:00
m_dipOffset = 0;
2001-05-14 16:21:04 +02:00
}
2001-05-14 20:48:54 +02:00
Pos.vy += m_dipOffset;
2001-07-31 21:09:30 +02:00
s32 minY, maxY;
m_npcPath.getPathYExtents( &minY, &maxY );
if ( Pos.vy > ( maxY + 16 ) )
{
Pos.vy = maxY + 16;
}
2001-05-14 16:21:04 +02:00
CNpcLinearPlatform::think( _frames );
}