SBSPSS/source/friend/fgary.cpp

261 lines
5.4 KiB
C++
Raw Normal View History

2001-04-27 16:39:10 +02:00
/*=========================================================================
fgary.cpp
Author: CRB
2001-05-25 21:08:35 +02:00
Created:
2001-04-27 16:39:10 +02:00
Project: Spongebob
2001-05-25 21:08:35 +02:00
Purpose:
2001-04-27 16:39:10 +02:00
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
2001-04-27 17:09:10 +02:00
#ifndef __FRIEND_FGARY_H__
#include "friend\fgary.h"
2001-04-27 16:39:10 +02:00
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-30 22:24:02 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-06-06 18:19:00 +02:00
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-30 22:24:02 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcGaryFriend::postInit()
{
CNpcFriend::postInit();
m_started = false;
2001-06-06 18:19:00 +02:00
m_fallDeath = false;
m_drawRotation = 0;
2001-05-30 22:24:02 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-27 16:39:10 +02:00
2001-04-27 17:09:10 +02:00
void CNpcGaryFriend::think( int _frames )
2001-04-27 16:39:10 +02:00
{
2001-05-08 16:13:40 +02:00
CNpcFriend::think(_frames);
2001-04-27 17:09:10 +02:00
2001-06-06 18:19:00 +02:00
if ( m_fallDeath )
{
m_drawRotation += 64 * _frames;
m_drawRotation &= 4095;
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
Pos.vy += m_speed * _frames;
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
if ( m_speed < 5 )
{
m_speed++;
}
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
DVECTOR offset = CLevel::getCameraPos();
2001-05-25 21:08:35 +02:00
2001-06-06 18:19:00 +02:00
if ( Pos.vy - offset.vy > VidGetScrH() )
2001-05-25 21:08:35 +02:00
{
2001-06-06 18:19:00 +02:00
setToShutdown();
2001-05-25 21:08:35 +02:00
}
}
2001-06-06 18:19:00 +02:00
else
2001-04-27 16:39:10 +02:00
{
2001-06-06 18:19:00 +02:00
s8 multiplier = -1 + ( 2 * m_extension );
s32 maxHeight = 20;
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
s8 groundHeight;
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
// check vertical collision
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
switch ( CGameScene::getCollision()->getCollisionBlock( Pos.vx, Pos.vy ) & COLLISION_TYPE_MASK )
2001-04-27 16:39:10 +02:00
{
2001-06-06 18:19:00 +02:00
case COLLISION_TYPE_FLAG_DEATH_FALL:
case COLLISION_TYPE_FLAG_DEATH_INSTANT:
case COLLISION_TYPE_FLAG_DEATH_LIQUID:
{
CPlayer *player = GameScene.getPlayer();
player->takeDamage( DAMAGE__KILL_OUTRIGHT );
m_speed = -5;
m_fallDeath = true;
break;
}
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
default:
break;
2001-04-27 16:39:10 +02:00
}
2001-06-06 18:19:00 +02:00
if ( m_platform )
{
s32 platformHeight = m_platform->getHeightFromPlatformAtPosition( Pos.vx, Pos.vy );
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
if ( platformHeight < groundHeight )
2001-05-30 22:24:02 +02:00
{
2001-06-06 18:19:00 +02:00
groundHeight = platformHeight;
2001-05-30 22:24:02 +02:00
}
2001-06-06 18:19:00 +02:00
//Pos.vy += platformHeight;
//return;
2001-04-27 16:39:10 +02:00
}
2001-06-06 18:19:00 +02:00
if ( groundHeight <= 0 )
2001-04-27 16:39:10 +02:00
{
2001-06-06 18:19:00 +02:00
// groundHeight <= 0 indicates either on ground or below ground
2001-04-27 16:39:10 +02:00
2001-06-06 18:19:00 +02:00
// check horizontal collision
2001-04-27 16:39:10 +02:00
2001-05-25 20:43:47 +02:00
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
2001-04-27 16:39:10 +02:00
{
// reverse direction
m_extension = !m_extension;
2001-06-06 18:19:00 +02:00
m_reversed = !m_reversed;
2001-04-27 16:39:10 +02:00
}
else
{
2001-06-06 18:19:00 +02:00
// make sure we are on the ground, not below it
Pos.vy += groundHeight;
2001-05-30 22:24:02 +02:00
if ( m_started )
{
2001-06-01 18:30:37 +02:00
CSoundMediator::playSfx( CSoundMediator::SFX_GARY_DE_SNAIL );
2001-05-30 22:24:02 +02:00
Pos.vx += multiplier * _frames;
}
2001-04-27 16:39:10 +02:00
}
}
else
{
2001-06-06 18:19:00 +02:00
// above ground
if ( groundHeight < yMovement )
{
// colliding with ground
Pos.vy += groundHeight;
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
{
// reverse direction
m_extension = !m_extension;
}
else
{
if ( m_started )
{
CSoundMediator::playSfx( CSoundMediator::SFX_GARY_DE_SNAIL );
Pos.vx += multiplier * _frames;
}
}
}
else
{
Pos.vy += yMovement;
}
2001-04-27 16:39:10 +02:00
}
}
2001-05-30 22:24:02 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcGaryFriend::setupWaypoints( sThingActor *ThisActor )
{
if ( ThisActor->PointCount > 1 )
{
u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor));
u16 newXPos, newYPos;
// skip first waypoint
PntList++;
PntList++;
// get trigger position
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
m_triggerPos.vx = newXPos;
m_triggerPos.vy = newYPos;
}
}
2001-05-31 23:36:10 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcGaryFriend::render()
{
CNpcThing::render();
2001-06-06 18:19:00 +02:00
POLY_FT4 *frame;
2001-05-31 23:36:10 +02:00
// Render
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
2001-06-06 18:19:00 +02:00
frame = m_actorGfx->Render(renderPos,m_animNo,(m_frame>>8),m_reversed);
m_actorGfx->RotateScale( frame, renderPos, m_drawRotation, 4096, 4096 );
2001-05-31 23:36:10 +02:00
sBBox boundingBox = m_actorGfx->GetBBox();
boundingBox.YMax = 0;
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
}
}
2001-06-04 14:54:44 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcGaryFriend::startLeft()
{
start();
m_extension = EXTEND_LEFT;
m_reversed = true;
}
2001-06-04 15:20:30 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcGaryFriend::startRight()
{
start();
m_extension = EXTEND_RIGHT;
m_reversed = false;
}
2001-06-04 22:58:12 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CRECT *CNpcGaryFriend::getThinkBBox()
{
CRECT objThinkBox = getCollisionArea();
sBBox &thinkBBox = CThingManager::getThinkBBox();
objThinkBox.x1 = thinkBBox.XMin;
objThinkBox.x2 = thinkBBox.XMax;
objThinkBox.y1 = thinkBBox.YMin;
objThinkBox.y2 = thinkBBox.YMax;
return &objThinkBox;
}