SBSPSS/source/hazard/hfalling.cpp

294 lines
5.6 KiB
C++
Raw Normal View History

2001-04-24 15:46:16 +02:00
/*=========================================================================
hfalling.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HFALLING_H__
#include "hazard\hfalling.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-10 23:30:17 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-25 21:30:37 +02:00
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-05-10 23:30:17 +02:00
2001-04-24 15:46:16 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::init()
{
CNpcHazard::init();
2001-05-10 21:27:57 +02:00
m_movementTimer = 2 * GameState::getOneSecondInFrames();
m_respawnRate = 4;
2001-05-10 23:30:17 +02:00
m_bounceFinish = false;
2001-05-25 21:30:37 +02:00
m_spinFinish = false;
m_rotation = 0;
2001-05-30 16:49:38 +02:00
m_growing = true;
m_scale = 0;
2001-04-24 15:46:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::processMovement( int _frames )
{
2001-05-30 16:49:38 +02:00
if ( m_growing )
2001-04-24 15:46:16 +02:00
{
2001-05-30 16:49:38 +02:00
m_scale = ( ( ( 2 * GameState::getOneSecondInFrames() ) - m_movementTimer ) << 12 ) / ( 2 * GameState::getOneSecondInFrames() );
2001-04-24 15:46:16 +02:00
2001-05-30 16:49:38 +02:00
if ( m_movementTimer > 0 )
2001-05-10 23:30:17 +02:00
{
2001-05-30 16:49:38 +02:00
m_movementTimer -= _frames;
if ( m_movementTimer < 0 )
2001-05-14 22:07:52 +02:00
{
2001-05-30 16:49:38 +02:00
m_movementTimer = 0;
2001-05-14 22:07:52 +02:00
}
2001-04-24 15:46:16 +02:00
}
2001-05-30 16:49:38 +02:00
else
2001-05-25 21:30:37 +02:00
{
2001-05-30 16:49:38 +02:00
m_growing = false;
m_movementTimer = 2 * GameState::getOneSecondInFrames();
2001-05-25 21:30:37 +02:00
}
2001-05-10 23:30:17 +02:00
}
else
{
2001-05-30 16:49:38 +02:00
s8 groundHeight;
s8 yMovement;
2001-05-10 23:30:17 +02:00
2001-05-30 16:49:38 +02:00
if ( m_bounceFinish )
{
if ( m_bounceDir )
2001-05-10 23:30:17 +02:00
{
2001-05-30 16:49:38 +02:00
Pos.vx += 2 * _frames;
2001-05-10 23:30:17 +02:00
}
else
{
2001-05-30 16:49:38 +02:00
Pos.vx -= 2 * _frames;
2001-05-10 23:30:17 +02:00
}
2001-05-30 16:49:38 +02:00
Pos.vy += m_speed * _frames;
2001-05-10 23:30:17 +02:00
2001-05-30 16:49:38 +02:00
/*if ( Pos.vy > ( m_bouncePos.vy + 32 ) )
2001-05-10 23:30:17 +02:00
{
2001-05-30 16:49:38 +02:00
m_bounceFinish = false;
}
else*/
{
if ( m_speed < 3 )
{
m_speed++;
}
}
2001-05-10 23:30:17 +02:00
2001-05-30 16:49:38 +02:00
if ( m_spinFinish )
{
m_rotation += 64 * _frames;
m_rotation &= 4095;
}
}
else
{
if ( m_movementTimer > 0 )
{
m_movementTimer -= _frames;
2001-05-14 22:07:52 +02:00
2001-05-30 16:49:38 +02:00
if ( m_movementTimer <= 0 )
{
Pos = m_base;
}
else
{
Pos.vx = m_base.vx + ( -3 + ( getRnd() % 7 ) );
Pos.vy = m_base.vy + ( -3 + ( getRnd() % 7 ) );
}
2001-05-10 23:30:17 +02:00
}
else
{
2001-05-30 16:49:38 +02:00
yMovement = 3 * _frames;
2001-04-24 15:46:16 +02:00
2001-05-30 16:49:38 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight < yMovement )
{
2001-08-07 16:10:12 +02:00
if ( m_soundId == NOT_PLAYING )
2001-06-18 21:06:43 +02:00
{
2001-08-07 16:10:12 +02:00
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__ACORN_LAND, true );
}
2001-05-30 16:49:38 +02:00
2001-08-07 16:10:12 +02:00
// colliding with ground
2001-05-30 16:49:38 +02:00
2001-08-07 16:10:12 +02:00
Pos.vy += groundHeight;
2001-07-31 20:52:10 +02:00
2001-08-07 16:10:12 +02:00
m_bounceFinish = true;
m_speed = -5;
m_bounceDir = getRnd() % 2;
2001-07-31 20:52:10 +02:00
2001-08-07 16:10:12 +02:00
m_bouncePos = Pos;
2001-05-30 16:49:38 +02:00
}
else
{
// drop down
Pos.vy += yMovement;
}
2001-05-10 23:30:17 +02:00
}
2001-04-24 15:46:16 +02:00
}
2001-05-14 22:07:52 +02:00
2001-07-23 21:26:37 +02:00
DVECTOR const &offset = CLevel::getCameraPos();
2001-05-14 22:07:52 +02:00
2001-05-30 16:49:38 +02:00
s32 yPos = Pos.vy - offset.vy;
2001-05-14 22:07:52 +02:00
2001-05-30 16:49:38 +02:00
if ( yPos > VidGetScrH() )
{
m_isActive = false;
m_timerActive = true;
m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames();
m_growing = true;
m_scale = 0;
}
2001-05-14 22:07:52 +02:00
}
2001-04-24 15:46:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::processTimer( int _frames )
{
m_timer -= _frames;
if ( m_timer < 0 )
{
m_timerActive = false;
m_isActive = true;
Pos = m_base;
2001-05-10 21:27:57 +02:00
m_movementTimer = 2 * GameState::getOneSecondInFrames();
2001-05-10 23:30:17 +02:00
m_bounceFinish = false;
2001-05-25 21:30:37 +02:00
m_spinFinish = false;
m_rotation = 0;
2001-04-24 15:46:16 +02:00
}
}
2001-05-12 19:24:44 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-14 22:07:52 +02:00
2001-05-12 19:24:44 +02:00
void CNpcFallingHazard::collidedWith( CThing *_thisThing )
{
2001-05-25 21:30:37 +02:00
if ( m_movementTimer <= 0 && m_isActive )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
m_bounceFinish = true;
m_spinFinish = true;
m_speed = -5;
m_bounceDir = getRnd() % 2;
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 21:30:37 +02:00
m_bouncePos = Pos;
break;
}
default:
break;
}
}
2001-05-12 19:24:44 +02:00
}
2001-05-14 22:07:52 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-14 23:08:03 +02:00
void CNpcFallingHazard::setWaypoints( sThingHazard *ThisHazard )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
u16 newXPos, newYPos;
2001-05-30 00:07:28 +02:00
m_npcPath.setWaypointCount( ThisHazard->PointCount - 1 );
2001-05-14 23:08:03 +02:00
newXPos = (u16) *PntList;
2001-05-30 00:07:28 +02:00
setWaypointPtr( PntList );
2001-05-14 23:08:03 +02:00
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
2001-05-31 18:24:48 +02:00
startPos.vx = ( newXPos << 4 ) + 8;
startPos.vy = ( newYPos << 4 ) + 16;
2001-05-14 23:08:03 +02:00
Pos = startPos;
m_base = Pos;
2001-06-19 22:07:57 +02:00
s32 minX, maxX, minY, maxY;
m_npcPath.getPathXExtents( &minX, &maxX );
m_npcPath.getPathYExtents( &minY, &maxY );
m_thinkArea.x1 = minX;
m_thinkArea.x2 = maxX;
m_thinkArea.y1 = minY;
m_thinkArea.y2 = maxY;
2001-05-14 23:08:03 +02:00
}
2001-05-25 21:30:37 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFallingHazard::render()
{
CHazardThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
2001-07-10 22:05:37 +02:00
sBBox boundingBox = m_modelGfx->GetBBox();
renderPos.vy -= boundingBox.YMax - boundingBox.YMin;
2001-05-25 21:30:37 +02:00
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = m_rotation;
VECTOR scale;
2001-05-30 16:49:38 +02:00
scale.vx = m_scale;
2001-07-10 21:39:19 +02:00
scale.vy = -m_scale;
2001-05-30 16:49:38 +02:00
scale.vz = m_scale;
2001-05-25 21:30:37 +02:00
2001-07-31 22:29:25 +02:00
m_modelGfx->RenderNoClip(renderPos,&rotation,&scale);
2001-05-25 21:30:37 +02:00
}
}