This commit is contained in:
parent
a2e03eae31
commit
d04702d6a5
295
source/platform/pbaloon.cpp
Normal file
295
source/platform/pbaloon.cpp
Normal file
@ -0,0 +1,295 @@
|
||||
/*=========================================================================
|
||||
|
||||
pbaloon.h
|
||||
|
||||
Author: CRB
|
||||
Created:
|
||||
Project: Spongebob
|
||||
Purpose:
|
||||
|
||||
Copyright (c) 2001 Climax Development Ltd
|
||||
|
||||
===========================================================================*/
|
||||
|
||||
#ifndef __PLATFORM_PBALOON_H__
|
||||
#include "platform\pbaloon.h"
|
||||
#endif
|
||||
|
||||
#ifndef __PLATFORM_PLATFORM_H__
|
||||
#include "platform\platform.h"
|
||||
#endif
|
||||
|
||||
#ifndef __GAME_GAME_H__
|
||||
#include "game\game.h"
|
||||
#endif
|
||||
|
||||
#ifndef __SPR_SPRITES_H__
|
||||
#include <sprites.h>
|
||||
#endif
|
||||
|
||||
#ifndef __UTILS_HEADER__
|
||||
#include "utils\utils.h"
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CBridgeBalloon::render()
|
||||
{
|
||||
sBBox &ScrBBox=CThingManager::getRenderBBox();
|
||||
DVECTOR const &CamPos=CLevel::getCameraPos();
|
||||
|
||||
u8 renderFlag = true;
|
||||
if ( Pos.vx < ScrBBox.XMin || Pos.vx > ScrBBox.XMax ) renderFlag=false;
|
||||
if ( Pos.vy < ScrBBox.YMin || Pos.vy > ScrBBox.YMax ) renderFlag=false;
|
||||
|
||||
if ( renderFlag )
|
||||
{
|
||||
DVECTOR renderPos;
|
||||
renderPos.vx = Pos.vx - CamPos.vx;
|
||||
renderPos.vy = Pos.vy - CamPos.vy;
|
||||
|
||||
m_spriteBank->printFT4(FRM__BALLOON,renderPos.vx,renderPos.vy,0,0,10);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CBridgeBalloon::init()
|
||||
{
|
||||
m_spriteBank=new ("enemy sprites") SpriteBank();
|
||||
m_spriteBank->load(SPRITES_SPRITES_SPR);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CBridgeBalloon::shutdown()
|
||||
{
|
||||
if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CBridgeBalloon::checkCollisionAgainst(CThing *_thisThing, int _frames)
|
||||
{
|
||||
DVECTOR projectilePos = _thisThing->getPos();
|
||||
|
||||
s32 xDist = projectilePos.vx - Pos.vx;
|
||||
s32 yDist = projectilePos.vy - Pos.vy;
|
||||
|
||||
s32 dist = ( xDist * xDist ) + ( yDist * yDist );
|
||||
|
||||
if ( dist < 5000 )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CNpcBalloonBridgePlatform::postInit()
|
||||
{
|
||||
CNpcPlatform::postInit();
|
||||
|
||||
m_balloonCount = BRIDGE_NUM_BALLOONS;
|
||||
|
||||
for ( int i = 0 ; i < BRIDGE_NUM_BALLOONS ; i++ )
|
||||
{
|
||||
m_balloon[i] = new ("bridge balloon") CBridgeBalloon;
|
||||
m_balloon[i]->init();
|
||||
}
|
||||
|
||||
m_targetHeight = m_base.vy + ( ( ( BRIDGE_NUM_BALLOONS - m_balloonCount ) * m_maxExtension ) / BRIDGE_NUM_BALLOONS );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CNpcBalloonBridgePlatform::shutdown()
|
||||
{
|
||||
for ( int i = 0 ; i < BRIDGE_NUM_BALLOONS ; i++ )
|
||||
{
|
||||
if ( m_balloon[i] )
|
||||
{
|
||||
m_balloon[i]->shutdown();
|
||||
|
||||
delete( m_balloon[i] );
|
||||
|
||||
m_balloon[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CNpcPlatform::shutdown();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CNpcBalloonBridgePlatform::setWaypoints( sThingPlatform *ThisPlatform )
|
||||
{
|
||||
u16 *PntList=(u16*)MakePtr(ThisPlatform,sizeof(sThingPlatform));
|
||||
|
||||
u16 newXPos, newYPos;
|
||||
|
||||
// get master platform init pos
|
||||
|
||||
newXPos = (u16) *PntList;
|
||||
PntList++;
|
||||
newYPos = (u16) *PntList;
|
||||
PntList++;
|
||||
|
||||
DVECTOR startPos;
|
||||
startPos.vx = newXPos << 4;
|
||||
startPos.vy = newYPos << 4;
|
||||
|
||||
init( startPos );
|
||||
|
||||
m_extension = 0;
|
||||
|
||||
// get master platform max vertical extension
|
||||
|
||||
newXPos = (u16) *PntList;
|
||||
PntList++;
|
||||
newYPos = (u16) *PntList;
|
||||
PntList++;
|
||||
|
||||
m_maxExtension = abs( ( newYPos << 4 ) - startPos.vy );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CNpcBalloonBridgePlatform::processMovement( int _frames )
|
||||
{
|
||||
if ( m_balloonCount )
|
||||
{
|
||||
m_velocity = m_targetHeight - Pos.vy;
|
||||
|
||||
if ( m_velocity > 3 * _frames )
|
||||
{
|
||||
m_velocity = 3 * _frames;
|
||||
}
|
||||
else if ( m_velocity < -3 * _frames )
|
||||
{
|
||||
m_velocity = -3 * _frames;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_velocity = 3 * _frames;
|
||||
}
|
||||
|
||||
Pos.vy += m_velocity;
|
||||
|
||||
DVECTOR balloonPos;
|
||||
|
||||
for ( int i = 0 ; i < BRIDGE_NUM_BALLOONS ; i++ )
|
||||
{
|
||||
balloonPos = Pos;
|
||||
balloonPos.vx += -20 + ( 40 * ( i > 1 ) );
|
||||
balloonPos.vy -= 30 + ( 20 * ( i % 2 ) );
|
||||
|
||||
if ( m_balloon[i] )
|
||||
{
|
||||
m_balloon[i]->setPos( balloonPos );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CNpcBalloonBridgePlatform::render()
|
||||
{
|
||||
if ( m_isActive )
|
||||
{
|
||||
CPlatformThing::render();
|
||||
|
||||
for ( int i = 0 ; i < BRIDGE_NUM_BALLOONS ; i++ )
|
||||
{
|
||||
if ( m_balloon[i] )
|
||||
{
|
||||
m_balloon[i]->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Render
|
||||
if (canRender())
|
||||
{
|
||||
DVECTOR &renderPos=getRenderPos();
|
||||
|
||||
m_modelGfx->Render(renderPos);
|
||||
}
|
||||
else if ( !m_balloonCount )
|
||||
{
|
||||
setToShutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CNpcBalloonBridgePlatform::checkCollisionAgainst(CThing *_thisThing, int _frames)
|
||||
{
|
||||
switch(_thisThing->getThingType())
|
||||
{
|
||||
case TYPE_PLAYERPROJECTILE:
|
||||
{
|
||||
for ( int i = 0 ; i < BRIDGE_NUM_BALLOONS ; i++ )
|
||||
{
|
||||
if ( m_balloon[i] )
|
||||
{
|
||||
if ( m_balloon[i]->checkCollisionAgainst( _thisThing, _frames ) )
|
||||
{
|
||||
m_balloon[i]->shutdown();
|
||||
|
||||
delete( m_balloon[i] );
|
||||
|
||||
m_balloon[i] = NULL;
|
||||
|
||||
_thisThing->setToShutdown();
|
||||
|
||||
m_balloonCount--;
|
||||
|
||||
m_targetHeight = m_base.vy + ( ( ( BRIDGE_NUM_BALLOONS - m_balloonCount ) * m_maxExtension ) / BRIDGE_NUM_BALLOONS );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
int collided = false;
|
||||
|
||||
if ( m_detectCollision && m_isActive && !isSetToShutdown() )
|
||||
{
|
||||
CRECT thisRect, thatRect;
|
||||
|
||||
thisRect = getCollisionArea();
|
||||
thatRect = _thisThing->getCollisionArea();
|
||||
|
||||
DVECTOR posDelta = getPosDelta();
|
||||
|
||||
thisRect.y1 -= abs( posDelta.vy ) >> 1;
|
||||
thisRect.y2 += abs( posDelta.vy ) >> 1;
|
||||
|
||||
posDelta = _thisThing->getPosDelta();
|
||||
|
||||
thatRect.y1 -= abs( posDelta.vy ) >> 1;
|
||||
thatRect.y2 += abs( posDelta.vy ) >> 1;
|
||||
|
||||
if(((thisRect.x1>=thatRect.x1&&thisRect.x1<=thatRect.x2)||(thisRect.x2>=thatRect.x1&&thisRect.x2<=thatRect.x2)||(thisRect.x1<=thatRect.x1&&thisRect.x2>=thatRect.x2))&&
|
||||
((thisRect.y1>=thatRect.y1&&thisRect.y1<=thatRect.y2)||(thisRect.y2>=thatRect.y1&&thisRect.y2<=thatRect.y2)||(thisRect.y1<=thatRect.y1&&thisRect.y2>=thatRect.y2)))
|
||||
{
|
||||
collided = true;
|
||||
}
|
||||
}
|
||||
|
||||
return( collided );
|
||||
}
|
||||
}
|
||||
}
|
57
source/platform/pbaloon.h
Normal file
57
source/platform/pbaloon.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*=========================================================================
|
||||
|
||||
pbaloon.h
|
||||
|
||||
Author: CRB
|
||||
Created:
|
||||
Project: Spongebob
|
||||
Purpose:
|
||||
|
||||
Copyright (c) 2001 Climax Development Ltd
|
||||
|
||||
===========================================================================*/
|
||||
|
||||
#ifndef __PLATFORM_PBALOON_H__
|
||||
#define __PLATFORM_PBALOON_H__
|
||||
|
||||
#ifndef __PLATFORM_PLATFORM_H__
|
||||
#include "platform\platform.h"
|
||||
#endif
|
||||
|
||||
class CBridgeBalloon
|
||||
{
|
||||
public:
|
||||
virtual void setPos( DVECTOR newPos ) {Pos = newPos;}
|
||||
void render();
|
||||
void init();
|
||||
void shutdown();
|
||||
virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
|
||||
protected:
|
||||
DVECTOR Pos;
|
||||
SpriteBank *m_spriteBank;
|
||||
};
|
||||
|
||||
class CNpcBalloonBridgePlatform : public CNpcPlatform
|
||||
{
|
||||
public:
|
||||
virtual void postInit();
|
||||
virtual void render();
|
||||
virtual void shutdown();
|
||||
protected:
|
||||
virtual void setWaypoints( sThingPlatform *ThisPlatform );
|
||||
virtual void processMovement( int _frames );
|
||||
virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
|
||||
|
||||
s32 m_maxExtension;
|
||||
s8 m_balloonCount;
|
||||
s32 m_targetHeight;
|
||||
|
||||
enum
|
||||
{
|
||||
BRIDGE_NUM_BALLOONS = 4,
|
||||
};
|
||||
|
||||
CBridgeBalloon *m_balloon[BRIDGE_NUM_BALLOONS];
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user