SBSPSS/source/platform/psbarrel.cpp

129 lines
2.3 KiB
C++
Raw Normal View History

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
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSteerableBarrelPlatform::processMovement( int _frames )
{
s32 maxHeight = 20;
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
s32 groundHeight;
s32 moveX = 0;
s32 moveY = 0;
if ( m_contact )
{
CPlayer *player = GameScene.getPlayer();
DVECTOR playerPos = player->getPos();
s32 playerX = playerPos.vx - this->Pos.vx;
if ( playerX > 5 )
{
// roll barrel right
2001-05-09 23:27:23 +02:00
moveX = m_speed * _frames;
2001-05-05 18:46:08 +02:00
}
else if ( playerX < -5 )
{
2001-05-09 23:27:23 +02:00
moveX = -m_speed * _frames;
2001-05-05 18:46:08 +02:00
}
// check for collision
2001-05-25 20:43:47 +02:00
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + moveX, Pos.vy ) < -maxHeight )
2001-05-05 18:46:08 +02:00
{
moveX = 0;
}
if ( moveX > 0 )
{
m_rotation += 30 * _frames;
m_rotation &= 4095;
}
else if ( moveX < 0 )
{
m_rotation -= 30 * _frames;
m_rotation &= 4095;
}
}
// check for vertical movement
2001-05-25 20:43:47 +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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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();
DVECTOR offset = CLevel::getCameraPos();
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
}
}
}