SBSPSS/source/platform/pbounce.cpp

151 lines
2.8 KiB
C++
Raw Normal View History

2001-05-01 22:29:42 +02:00
/*=========================================================================
pbounce.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLATFORM_PBOUNCE_H__
#include "platform\pbounce.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-02 16:29:10 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
void CNpcBouncePlatform::postInit()
{
2001-05-05 15:54:34 +02:00
CNpcPlatform::postInit();
2001-05-02 16:29:10 +02:00
m_vertScale = 0;
m_vertVelocity = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-01 22:29:42 +02:00
void CNpcBouncePlatform::think( int _frames )
{
if ( m_contact )
{
CPlayer *player = GameScene.getPlayer();
2001-05-02 16:29:10 +02:00
if ( m_vertVelocity > 20 && m_vertScale < -100 )
{
player->springPlayerUp();
}
s16 vertForce = -30 * _frames;
m_vertVelocity += vertForce;
2001-05-01 22:29:42 +02:00
m_contact = false;
}
2001-05-02 16:29:10 +02:00
s32 resistance = -( 10 * _frames * m_vertScale ) >> 8;
if ( m_vertScale > 0 && resistance > -1 )
{
resistance = -1;
}
else if ( m_vertScale < 0 && resistance < 1 )
{
resistance = 1;
}
// get direction of resistance
m_vertVelocity += resistance;
m_vertScale += m_vertVelocity;
if ( m_vertVelocity )
{
s32 absVertVelocity = abs( m_vertVelocity );
m_vertVelocity += -m_vertVelocity / abs( m_vertVelocity );
if ( abs( m_vertVelocity ) < 10 )
{
m_vertVelocity = 0;
}
if ( m_vertVelocity > 60 )
{
m_vertVelocity = 60;
}
else if ( m_vertVelocity < -60 )
{
m_vertVelocity = -60;
}
}
2001-05-01 22:29:42 +02:00
CPlatformThing::think(_frames);
2001-05-02 16:29:10 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcBouncePlatform::render()
{
if ( m_isActive )
{
CPlatformThing::render();
2001-05-10 18:22:45 +02:00
if (canRender())
2001-05-02 16:29:10 +02:00
{
2001-05-10 18:22:45 +02:00
DVECTOR &renderPos=getRenderPos();
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = 0;
2001-05-02 16:29:10 +02:00
2001-05-10 18:22:45 +02:00
VECTOR scale;
scale.vx = ONE;
scale.vy = ONE + m_vertScale;
scale.vz = ONE;
2001-05-02 16:29:10 +02:00
2001-05-10 18:22:45 +02:00
m_modelGfx->Render(renderPos,&rotation,&scale);
2001-05-02 16:29:10 +02:00
#if defined (__USER_paul__) || defined (__USER_charles__)
2001-05-10 21:01:02 +02:00
DVECTOR offset = CLevel::getCameraPos();
2001-05-02 16:29:10 +02:00
DVECTOR centre;
2001-05-02 17:32:47 +02:00
DVECTOR size;
2001-05-02 16:29:10 +02:00
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
2001-05-02 17:32:47 +02:00
size=getCollisionSize();
halfLength=size.vx>>1;
2001-05-02 16:29:10 +02:00
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
2001-05-10 18:22:45 +02:00
2001-05-02 16:29:10 +02:00
}
2001-05-01 22:29:42 +02:00
}