2001-05-05 18:46:08 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
psbarrel.h
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_PSBARREL_H__
|
|
|
|
#include "platform\psbarrel.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
|
|
|
|
|
|
|
|
|
2001-05-31 22:54:55 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcSteerableBarrelPlatform::postInit()
|
|
|
|
{
|
|
|
|
CNpcPlatform::postInit();
|
|
|
|
|
|
|
|
m_currentSpeed = 0;
|
|
|
|
m_moveXHighRes = 0;
|
|
|
|
}
|
|
|
|
|
2001-05-05 18:46:08 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcSteerableBarrelPlatform::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
s32 maxHeight = 20;
|
|
|
|
s32 fallSpeed = 3;
|
|
|
|
s8 yMovement = fallSpeed * _frames;
|
|
|
|
s32 groundHeight;
|
|
|
|
|
|
|
|
s32 moveX = 0;
|
|
|
|
s32 moveY = 0;
|
|
|
|
|
2001-05-31 22:54:55 +02:00
|
|
|
CPlayer *player = GameScene.getPlayer();
|
|
|
|
|
2001-05-05 18:46:08 +02:00
|
|
|
if ( m_contact )
|
|
|
|
{
|
2001-07-21 21:14:40 +02:00
|
|
|
player->setReverseCameraMovement(true);
|
|
|
|
|
2001-07-23 21:26:37 +02:00
|
|
|
DVECTOR const &playerPos = player->getPos();
|
2001-05-05 18:46:08 +02:00
|
|
|
|
2001-06-08 17:02:29 +02:00
|
|
|
s32 playerMovement = player->getMovement();
|
2001-06-05 16:05:10 +02:00
|
|
|
|
2001-06-05 21:18:55 +02:00
|
|
|
/*s32 speedChange = -playerVel->vx << 8;
|
2001-06-05 16:05:10 +02:00
|
|
|
|
|
|
|
if ( speedChange > ( _frames << 5 ) )
|
|
|
|
{
|
|
|
|
speedChange = _frames << 5;
|
|
|
|
}
|
|
|
|
else if ( speedChange < -( _frames << 5 ) )
|
|
|
|
{
|
|
|
|
speedChange = -_frames << 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentSpeed += speedChange;
|
|
|
|
|
|
|
|
if ( m_currentSpeed > ( m_speed << 8 ) )
|
|
|
|
{
|
|
|
|
m_currentSpeed = ( m_speed << 8 );
|
|
|
|
}
|
|
|
|
else if ( m_currentSpeed < -( m_speed << 8 ) )
|
|
|
|
{
|
|
|
|
m_currentSpeed = -( m_speed << 8 );
|
2001-06-05 21:18:55 +02:00
|
|
|
}*/
|
|
|
|
|
2001-06-08 17:02:29 +02:00
|
|
|
m_currentSpeed = -playerMovement;
|
2001-06-05 16:05:10 +02:00
|
|
|
|
|
|
|
/*s32 playerX = playerPos.vx - this->Pos.vx;
|
2001-05-05 18:46:08 +02:00
|
|
|
|
|
|
|
if ( playerX > 5 )
|
|
|
|
{
|
2001-05-31 22:54:55 +02:00
|
|
|
// increase barrel speed to right
|
|
|
|
|
2001-06-05 16:05:10 +02:00
|
|
|
m_currentSpeed += _frames << 2;
|
2001-05-05 18:46:08 +02:00
|
|
|
|
2001-05-31 22:54:55 +02:00
|
|
|
if ( m_currentSpeed > ( m_speed << 8 ) )
|
|
|
|
{
|
|
|
|
m_currentSpeed = ( m_speed << 8 );
|
|
|
|
}
|
2001-05-05 18:46:08 +02:00
|
|
|
}
|
|
|
|
else if ( playerX < -5 )
|
|
|
|
{
|
2001-06-05 16:05:10 +02:00
|
|
|
m_currentSpeed -= _frames << 2;
|
2001-05-05 18:46:08 +02:00
|
|
|
|
2001-05-31 22:54:55 +02:00
|
|
|
if ( m_currentSpeed < -( m_speed << 8 ) )
|
|
|
|
{
|
|
|
|
m_currentSpeed = -( m_speed << 8 );
|
|
|
|
}
|
2001-06-05 16:05:10 +02:00
|
|
|
}*/
|
2001-05-31 22:54:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// reduce speed
|
|
|
|
|
2001-06-05 21:18:55 +02:00
|
|
|
/*s32 speedReduce = -m_currentSpeed;
|
2001-05-05 18:46:08 +02:00
|
|
|
|
2001-05-31 22:54:55 +02:00
|
|
|
if ( speedReduce > _frames )
|
2001-05-05 18:46:08 +02:00
|
|
|
{
|
2001-05-31 22:54:55 +02:00
|
|
|
speedReduce = _frames;
|
2001-05-05 18:46:08 +02:00
|
|
|
}
|
2001-05-31 22:54:55 +02:00
|
|
|
else if ( speedReduce < -_frames )
|
2001-05-05 18:46:08 +02:00
|
|
|
{
|
2001-05-31 22:54:55 +02:00
|
|
|
speedReduce = -_frames;
|
2001-05-05 18:46:08 +02:00
|
|
|
}
|
2001-05-31 22:54:55 +02:00
|
|
|
|
2001-06-05 21:18:55 +02:00
|
|
|
m_currentSpeed += speedReduce;*/
|
|
|
|
|
|
|
|
m_currentSpeed = 0;
|
2001-05-31 22:54:55 +02:00
|
|
|
}
|
|
|
|
|
2001-06-05 21:18:55 +02:00
|
|
|
/*m_moveXHighRes += m_currentSpeed * _frames;
|
2001-05-31 22:54:55 +02:00
|
|
|
|
|
|
|
moveX = m_moveXHighRes >> 8;
|
2001-06-05 21:18:55 +02:00
|
|
|
m_moveXHighRes -= moveX << 8;*/
|
|
|
|
|
2001-06-08 17:02:29 +02:00
|
|
|
moveX = m_currentSpeed;
|
2001-05-31 22:54:55 +02:00
|
|
|
|
|
|
|
// check for collision
|
|
|
|
|
2001-06-08 17:02:29 +02:00
|
|
|
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + moveX, Pos.vy ) < -maxHeight )
|
2001-05-31 22:54:55 +02:00
|
|
|
{
|
|
|
|
moveX = 0;
|
|
|
|
m_currentSpeed = 0;
|
|
|
|
}
|
|
|
|
|
2001-06-08 17:02:29 +02:00
|
|
|
m_rotation += ( m_currentSpeed * 30 * _frames ) >> 2;
|
2001-06-05 22:21:11 +02:00
|
|
|
m_rotation &= 4095;
|
2001-05-31 22:54:55 +02:00
|
|
|
|
|
|
|
if ( m_contact )
|
|
|
|
{
|
|
|
|
DVECTOR shove;
|
2001-06-05 21:18:55 +02:00
|
|
|
shove.vx = moveX;
|
2001-05-31 22:54:55 +02:00
|
|
|
shove.vy = 0;
|
|
|
|
player->shove(shove);
|
2001-05-05 18:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for vertical movement
|
|
|
|
|
2001-06-08 17:02:29 +02:00
|
|
|
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx + moveX, Pos.vy, yMovement + 16 );
|
2001-05-05 18:46:08 +02:00
|
|
|
|
|
|
|
if ( groundHeight <= yMovement )
|
|
|
|
{
|
|
|
|
// groundHeight <= yMovement indicates either just above ground or on or below ground
|
|
|
|
|
|
|
|
moveY = groundHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// fall
|
|
|
|
|
|
|
|
moveY = yMovement;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
2001-05-25 22:51:17 +02:00
|
|
|
|
|
|
|
s32 minX, maxX;
|
|
|
|
|
|
|
|
m_npcPath.getPathXExtents( &minX, &maxX );
|
|
|
|
|
|
|
|
if ( minX != maxX )
|
|
|
|
{
|
|
|
|
if ( Pos.vx < minX )
|
|
|
|
{
|
|
|
|
Pos.vx = minX;
|
2001-05-31 22:54:55 +02:00
|
|
|
m_currentSpeed = 0;
|
2001-05-25 22:51:17 +02:00
|
|
|
}
|
|
|
|
else if ( Pos.vx > maxX )
|
|
|
|
{
|
|
|
|
Pos.vx = maxX;
|
2001-05-31 22:54:55 +02:00
|
|
|
m_currentSpeed = 0;
|
2001-05-25 22:51:17 +02:00
|
|
|
}
|
|
|
|
}
|
2001-05-05 18:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcSteerableBarrelPlatform::render()
|
|
|
|
{
|
|
|
|
if ( m_isActive )
|
|
|
|
{
|
|
|
|
CPlatformThing::render();
|
|
|
|
|
2001-05-14 23:08:03 +02:00
|
|
|
if (canRender())
|
2001-05-05 18:46:08 +02:00
|
|
|
{
|
2001-05-14 23:08:03 +02:00
|
|
|
DVECTOR &renderPos=getRenderPos();
|
2001-07-23 21:26:37 +02:00
|
|
|
DVECTOR const &offset = CLevel::getCameraPos();
|
2001-05-14 23:08:03 +02:00
|
|
|
|
|
|
|
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);
|
2001-05-05 18:46:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-31 22:54:55 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcSteerableBarrelPlatform::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-05-31 22:54:55 +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-05-31 22:54:55 +02:00
|
|
|
|
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-05-31 22:54:55 +02:00
|
|
|
{
|
|
|
|
if ( checkCollisionDelta( _thisThing, 0, 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 >= 0 && height < 1 )
|
|
|
|
{
|
|
|
|
player->setPlatform( this );
|
|
|
|
|
|
|
|
m_contact = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_NPC:
|
|
|
|
case TYPE_HAZARD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|