SBSPSS/source/hazard/hbbarrel.cpp

247 lines
4.6 KiB
C++
Raw Normal View History

2001-05-05 23:02:59 +02:00
/*=========================================================================
hbbarrel.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HBBARREL_H__
#include "hazard\hbbarrel.h"
#endif
2001-05-25 23:16:13 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-05-05 23:02:59 +02:00
#ifndef __LAYER_COLLISION_H__
#include "level\layercollision.h"
#endif
2001-05-05 23:47:56 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __LEVEL_LEVEL_H__
#include "level\level.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-05 23:02:59 +02:00
void CNpcBouncingBarrelHazard::init()
{
CNpcHazard::init();
m_lastWaypoint = Pos;
2001-05-05 23:47:56 +02:00
m_rotation = 0;
m_rockRotation = 0;
m_rockDir = true;
2001-05-25 23:16:13 +02:00
m_hitPlayer = false;
2001-05-05 23:02:59 +02:00
}
2001-05-05 23:47:56 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-05 23:02:59 +02:00
void CNpcBouncingBarrelHazard::processMovement( int _frames )
{
s32 moveX = 0, moveY = 0;
s32 moveVel = 0;
s32 moveDist = 0;
s32 waypointXDist;
s32 waypointYDist;
s32 waypointHeading;
s32 groundHeight;
// deal with horizontal
2001-05-25 23:16:13 +02:00
if ( m_hitPlayer )
2001-05-05 23:02:59 +02:00
{
2001-05-25 23:16:13 +02:00
Pos.vy += m_speed * _frames;
if ( m_speed < 3 )
2001-05-05 23:02:59 +02:00
{
2001-05-25 23:16:13 +02:00
m_speed++;
2001-05-05 23:02:59 +02:00
}
2001-05-25 23:16:13 +02:00
m_rotation += 64 * _frames;
m_rotation &= 4095;
2001-05-05 23:02:59 +02:00
2001-07-23 21:26:37 +02:00
DVECTOR const &offset = CLevel::getCameraPos();
2001-05-14 17:08:47 +02:00
2001-05-25 23:16:13 +02:00
s32 yPos = Pos.vy - offset.vy;
2001-05-05 23:47:56 +02:00
2001-05-25 23:16:13 +02:00
if ( yPos > VidGetScrH() )
{
Pos = m_base;
m_hitPlayer = false;
m_npcPath.resetPath();
}
2001-05-05 23:47:56 +02:00
}
else
{
2001-05-25 23:16:13 +02:00
bool pathComplete;
if ( m_npcPath.thinkFlat( Pos, &pathComplete, &waypointXDist, &waypointYDist, &waypointHeading, 1 ) )
{
if ( pathComplete )
{
Pos = m_base;
m_hitPlayer = false;
m_npcPath.resetPath();
}
m_lastWaypoint = Pos;
}
2001-05-05 23:47:56 +02:00
2001-05-25 23:16:13 +02:00
moveX = 3 * _frames;
2001-05-05 23:47:56 +02:00
2001-05-25 23:16:13 +02:00
if ( moveX > abs( waypointXDist ) )
2001-05-05 23:47:56 +02:00
{
2001-05-25 23:16:13 +02:00
moveX = abs( waypointXDist );
2001-05-05 23:47:56 +02:00
}
2001-05-25 23:16:13 +02:00
if ( waypointHeading == 2048 )
2001-05-05 23:47:56 +02:00
{
2001-05-25 23:16:13 +02:00
moveX = -moveX;
m_rotation -= 256 * _frames;
m_rotation &= 4095;
}
else
{
m_rotation += 256 * _frames;
m_rotation &= 4095;
2001-05-05 23:47:56 +02:00
}
2001-05-05 23:02:59 +02:00
2001-05-25 23:16:13 +02:00
if ( m_rockDir )
{
m_rockRotation += 30 * _frames;
2001-05-05 23:02:59 +02:00
2001-05-25 23:16:13 +02:00
if ( m_rockRotation > 256 )
{
m_rockDir = false;
}
}
else
{
m_rockRotation -= 30 * _frames;
2001-05-05 23:02:59 +02:00
2001-05-25 23:16:13 +02:00
if ( m_rockRotation < -256 )
{
m_rockDir = true;
}
}
2001-05-05 23:02:59 +02:00
2001-05-25 23:16:13 +02:00
Pos.vx += moveX;
2001-05-14 17:08:47 +02:00
2001-05-25 23:16:13 +02:00
// deal with vertical
2001-05-14 17:08:47 +02:00
2001-05-25 23:16:13 +02:00
DVECTOR nextWaypoint;
nextWaypoint.vx = waypointXDist + Pos.vx;
nextWaypoint.vy = waypointYDist + Pos.vy;
2001-05-05 23:02:59 +02:00
2001-05-25 23:16:13 +02:00
s32 waypointDist = abs( nextWaypoint.vx - m_lastWaypoint.vx );
if ( waypointDist < 1 )
{
waypointDist = 1;
}
if ( waypointYDist > 0 )
{
s32 sineVal = ( abs( Pos.vx - nextWaypoint.vx ) * 1024 ) / waypointDist;
2001-05-05 23:02:59 +02:00
2001-05-25 23:16:13 +02:00
Pos.vy = nextWaypoint.vy - ( ( abs( nextWaypoint.vy - m_lastWaypoint.vy ) * rsin( sineVal ) ) >> 12 );
}
else if ( waypointYDist < 0 )
{
s32 sineVal = ( abs( Pos.vx - m_lastWaypoint.vx ) * 1024 ) / waypointDist;
Pos.vy = m_lastWaypoint.vy - ( ( abs( nextWaypoint.vy - m_lastWaypoint.vy ) * rsin( sineVal ) ) >> 12 );
}
2001-07-12 22:15:10 +02:00
int groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, 16 );
if ( groundHeight < 8 )
{
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__ACORN_LAND, true );
}
}
2001-05-05 23:02:59 +02:00
}
}
2001-05-05 23:47:56 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcBouncingBarrelHazard::render()
{
CHazardThing::render();
2001-05-14 23:08:03 +02:00
if (canRender())
2001-05-05 23:47:56 +02:00
{
2001-05-14 23:08:03 +02:00
DVECTOR &renderPos=getRenderPos();
2001-05-05 23:47:56 +02:00
2001-05-14 23:08:03 +02:00
SVECTOR rotation;
rotation.vx = m_rockRotation;
rotation.vy = 0;
rotation.vz = m_rotation;
2001-05-05 23:47:56 +02:00
2001-05-14 23:08:03 +02:00
VECTOR scale;
scale.vx = ONE;
scale.vy = ONE;
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
2001-05-05 23:47:56 +02:00
}
}
2001-05-17 21:28:08 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-25 23:16:13 +02:00
void CNpcBouncingBarrelHazard::collidedWith( CThing *_thisThing )
{
if ( m_isActive )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
if ( !m_hitPlayer )
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
2001-07-12 22:15:10 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__ACORN_LAND, true );
2001-05-25 23:16:13 +02:00
m_hitPlayer = true;
m_speed = -5;
}
break;
}
default:
break;
}
}
}