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-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-04-27 16:39:10 +02:00
|
|
|
s8 multiplier = -1 + ( 2 * m_extension );
|
|
|
|
s32 maxHeight = 20;
|
|
|
|
s32 fallSpeed = 3;
|
|
|
|
s8 yMovement = fallSpeed * _frames;
|
|
|
|
s8 groundHeight;
|
|
|
|
|
|
|
|
// check vertical collision
|
|
|
|
|
2001-05-25 20:43:47 +02:00
|
|
|
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
|
2001-04-27 16:39:10 +02:00
|
|
|
|
2001-05-25 21:08:35 +02:00
|
|
|
if ( m_platform )
|
|
|
|
{
|
|
|
|
s32 platformHeight = m_platform->getHeightFromPlatformAtPosition( Pos.vx, Pos.vy );
|
|
|
|
|
|
|
|
if ( platformHeight < groundHeight )
|
|
|
|
{
|
|
|
|
groundHeight = platformHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Pos.vy += platformHeight;
|
|
|
|
//return;
|
|
|
|
}
|
|
|
|
|
2001-04-27 16:39:10 +02:00
|
|
|
if ( groundHeight <= 0 )
|
|
|
|
{
|
|
|
|
// groundHeight <= 0 indicates either on ground or below ground
|
|
|
|
|
|
|
|
// check horizontal collision
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// make sure we are on the ground, not below it
|
|
|
|
|
|
|
|
Pos.vy += groundHeight;
|
|
|
|
|
|
|
|
Pos.vx += multiplier * _frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// above ground
|
|
|
|
|
|
|
|
if ( groundHeight < yMovement )
|
|
|
|
{
|
|
|
|
// colliding with ground
|
|
|
|
|
|
|
|
Pos.vy += groundHeight;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pos.vx += multiplier * _frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pos.vy += yMovement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|