SBSPSS/source/enemy/ngary.cpp

82 lines
1.5 KiB
C++
Raw Normal View History

2001-02-12 18:46:49 +01:00
/*=========================================================================
ngary.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
2001-02-12 21:03:44 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-02-12 18:46:49 +01:00
2001-02-27 22:25:22 +01:00
void CNpcFriend::processGaryMovement( int _frames )
2001-02-12 18:46:49 +01:00
{
2001-02-12 21:03:44 +01:00
s8 multiplier = -1 + ( 2 * m_extension );
2001-04-04 21:55:49 +02:00
s32 maxHeight = 20;
2001-02-27 22:25:22 +01:00
s32 fallSpeed = 3;
2001-02-15 21:50:52 +01:00
s8 yMovement = fallSpeed * _frames;
s8 groundHeight;
2001-02-12 21:03:44 +01:00
// check vertical collision
2001-05-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-02-15 21:50:52 +01:00
if ( groundHeight <= 0 )
2001-02-12 18:52:04 +01:00
{
2001-02-15 21:50:52 +01:00
// groundHeight <= 0 indicates either on ground or below ground
2001-02-12 21:03:44 +01:00
// check horizontal collision
2001-05-25 20:43:47 +02:00
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
2001-02-12 21:03:44 +01:00
{
// reverse direction
m_extension = !m_extension;
}
else
{
2001-02-15 21:50:52 +01:00
// make sure we are on the ground, not below it
2001-02-12 21:03:44 +01:00
2001-02-15 21:50:52 +01:00
Pos.vy += groundHeight;
2001-02-12 21:03:44 +01:00
Pos.vx += multiplier * _frames;
}
2001-02-12 18:52:04 +01:00
}
else
{
2001-02-15 21:50:52 +01:00
// above ground
if ( groundHeight < yMovement )
2001-02-12 21:03:44 +01:00
{
2001-02-15 21:50:52 +01:00
// colliding with ground
2001-02-12 21:03:44 +01:00
2001-02-15 21:50:52 +01:00
Pos.vy += groundHeight;
2001-05-25 20:43:47 +02:00
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
2001-02-12 21:03:44 +01:00
{
2001-02-15 21:50:52 +01:00
// reverse direction
2001-02-12 21:03:44 +01:00
2001-02-15 21:50:52 +01:00
m_extension = !m_extension;
}
else
{
Pos.vx += multiplier * _frames;
}
2001-02-12 21:03:44 +01:00
}
else
{
2001-02-15 21:50:52 +01:00
Pos.vy += yMovement;
2001-02-12 21:03:44 +01:00
}
2001-02-12 18:52:04 +01:00
}
2001-02-12 18:46:49 +01:00
}