2001-01-22 17:01:49 +01:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
projectl.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2000 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __PROJECTL_PROJECTL_H__
|
|
|
|
#include "projectl\projectl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GFX_SPRBANK_H__
|
|
|
|
#include "gfx\sprbank.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __LEVEL_LEVEL_H__
|
|
|
|
#include "level\level.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __FILE_EQUATES_H__
|
|
|
|
#include <biglump.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __SPR_UIGFX_H__
|
|
|
|
#include <uigfx.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
#ifndef __PLAYER_PLAYER_H__
|
|
|
|
#include "player\player.h"
|
|
|
|
#endif
|
|
|
|
|
2001-01-22 17:01:49 +01:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void CProjectile::init()
|
|
|
|
{
|
2001-02-28 23:03:18 +01:00
|
|
|
CEnemyProjectileThing::init();
|
|
|
|
|
2001-01-22 17:01:49 +01:00
|
|
|
m_spriteBank=new ("projectile sprites") SpriteBank();
|
|
|
|
m_spriteBank->load(UI_UIGFX_SPR);
|
|
|
|
|
|
|
|
m_heading = 0;
|
|
|
|
m_lifetime = GameState::getOneSecondInFrames() * 2;
|
2001-01-22 23:24:53 +01:00
|
|
|
m_movementType = PROJECTILE_DUMBFIRE;
|
|
|
|
m_lifetimeType = PROJECTILE_FINITE_LIFE;
|
|
|
|
m_state = PROJECTILE_ATTACK;
|
|
|
|
m_turnSpeed = 256;
|
2001-02-08 21:00:58 +01:00
|
|
|
m_extension = 0;
|
2001-01-22 17:01:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CProjectile::init( DVECTOR initPos, s16 initHeading )
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
|
|
|
m_heading = initHeading;
|
2001-02-08 21:00:58 +01:00
|
|
|
m_initPos = Pos = initPos;
|
2001-01-22 17:01:49 +01:00
|
|
|
}
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
void CProjectile::init( DVECTOR initPos, s16 initHeading, PROJECTILE_MOVEMENT_TYPE initMoveType, PROJECTILE_LIFETIME_TYPE initLifeType )
|
|
|
|
{
|
|
|
|
init( initPos, initHeading );
|
|
|
|
|
|
|
|
m_movementType = initMoveType;
|
|
|
|
m_lifetimeType = initLifeType;
|
|
|
|
}
|
|
|
|
|
2001-02-08 16:42:59 +01:00
|
|
|
void CProjectile::init( DVECTOR initPos, s16 initHeading, PROJECTILE_MOVEMENT_TYPE initMoveType, PROJECTILE_LIFETIME_TYPE initLifeType, s32 initLifetime )
|
|
|
|
{
|
|
|
|
init( initPos, initHeading, initMoveType, initLifeType );
|
|
|
|
|
|
|
|
m_lifetime = initLifetime;
|
|
|
|
}
|
|
|
|
|
2001-01-22 17:01:49 +01:00
|
|
|
void CProjectile::shutdown()
|
|
|
|
{
|
|
|
|
m_spriteBank->dump(); delete m_spriteBank;
|
2001-02-28 23:03:18 +01:00
|
|
|
|
|
|
|
CEnemyProjectileThing::shutdown();
|
2001-01-22 17:01:49 +01:00
|
|
|
}
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
bool CProjectile::processTargetSeek( int _frames, DVECTOR targetPos )
|
|
|
|
{
|
|
|
|
s32 moveX = 0, moveY = 0;
|
|
|
|
|
|
|
|
s16 moveDist = 0;
|
|
|
|
|
|
|
|
s32 moveVel = 0;
|
|
|
|
|
|
|
|
s32 xDist, yDist;
|
|
|
|
s32 xDistSqr, yDistSqr;
|
|
|
|
|
|
|
|
xDist = targetPos.vx - this->Pos.vx;
|
|
|
|
xDistSqr = xDist * xDist;
|
|
|
|
|
|
|
|
yDist = targetPos.vy - this->Pos.vy;
|
|
|
|
yDistSqr = yDist * yDist;
|
|
|
|
|
|
|
|
//if ( xDistSqr + yDistSqr > 22500 )
|
|
|
|
//{
|
|
|
|
//this->m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
{
|
|
|
|
s16 headingToTarget = ratan2( yDist, xDist );
|
|
|
|
s16 maxTurnRate = m_turnSpeed;
|
|
|
|
s16 decDir, incDir;
|
|
|
|
|
|
|
|
decDir = m_heading - headingToTarget;
|
|
|
|
|
|
|
|
if ( decDir < 0 )
|
|
|
|
{
|
|
|
|
decDir += ONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
incDir = headingToTarget - m_heading;
|
|
|
|
|
|
|
|
if ( incDir < 0 )
|
|
|
|
{
|
|
|
|
incDir += ONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( decDir < incDir )
|
|
|
|
{
|
|
|
|
moveDist = -decDir;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moveDist = incDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( moveDist < -maxTurnRate )
|
|
|
|
{
|
|
|
|
moveDist = -maxTurnRate;
|
|
|
|
}
|
|
|
|
else if ( moveDist > maxTurnRate )
|
|
|
|
{
|
|
|
|
moveDist = maxTurnRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_heading += moveDist;
|
|
|
|
|
|
|
|
m_heading = m_heading % ONE;
|
|
|
|
|
|
|
|
s32 preShiftX = _frames * 3 * rcos( m_heading );
|
|
|
|
s32 preShiftY = _frames * 3 * rsin( m_heading );
|
|
|
|
|
|
|
|
moveX = preShiftX >> 12;
|
|
|
|
if ( !moveX && preShiftX )
|
|
|
|
{
|
|
|
|
moveX = preShiftX / abs( preShiftX );
|
|
|
|
}
|
|
|
|
|
|
|
|
moveY = preShiftY >> 12;
|
|
|
|
if ( !moveY && preShiftY )
|
|
|
|
{
|
|
|
|
moveY = preShiftY / abs( preShiftY );
|
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vx += moveX;
|
|
|
|
Pos.vy += moveY;
|
|
|
|
}
|
|
|
|
|
|
|
|
xDist = targetPos.vx - this->Pos.vx;
|
|
|
|
xDistSqr = xDist * xDist;
|
|
|
|
|
|
|
|
yDist = targetPos.vy - this->Pos.vy;
|
|
|
|
yDistSqr = yDist * yDist;
|
|
|
|
|
|
|
|
if ( xDistSqr + yDistSqr < 100 )
|
|
|
|
{
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-04 00:01:52 +02:00
|
|
|
void CProjectile::setMovementType( PROJECTILE_MOVEMENT_TYPE moveType )
|
|
|
|
{
|
|
|
|
m_movementType = moveType;
|
|
|
|
}
|
|
|
|
|
|
|
|
CProjectile::PROJECTILE_MOVEMENT_TYPE CProjectile::getMovementType()
|
|
|
|
{
|
|
|
|
return( m_movementType );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProjectile::setState( PROJECTILE_STATE newState )
|
|
|
|
{
|
|
|
|
m_state = newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProjectile::setPosition( DVECTOR newPos )
|
|
|
|
{
|
|
|
|
Pos = newPos;
|
|
|
|
}
|
|
|
|
|
2001-01-22 17:01:49 +01:00
|
|
|
void CProjectile::think(int _frames)
|
|
|
|
{
|
2001-02-28 23:03:18 +01:00
|
|
|
CEnemyProjectileThing::think( _frames );
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
switch( m_movementType )
|
|
|
|
{
|
2001-04-04 00:01:52 +02:00
|
|
|
case PROJECTILE_FIXED:
|
|
|
|
{
|
|
|
|
// don't move at all
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
case PROJECTILE_USER_SEEK:
|
|
|
|
{
|
|
|
|
switch( m_state )
|
|
|
|
{
|
|
|
|
case PROJECTILE_RETURN:
|
|
|
|
{
|
|
|
|
if ( processTargetSeek( _frames, Parent->getPos() ) )
|
|
|
|
{
|
|
|
|
Parent->processEvent( PROJECTILE_RETURNED_TO_SOURCE_EVENT, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PROJECTILE_ATTACK:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
CPlayer *player = GameScene.getPlayer();
|
|
|
|
DVECTOR playerPos = player->getPos();
|
|
|
|
|
|
|
|
if ( processTargetSeek( _frames, playerPos ) )
|
|
|
|
{
|
|
|
|
m_state = PROJECTILE_RETURN;
|
|
|
|
}
|
2001-01-22 17:01:49 +01:00
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-01-22 17:01:49 +01:00
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-08 16:34:18 +01:00
|
|
|
case PROJECTILE_GAS_CLOUD:
|
|
|
|
{
|
2001-02-08 21:00:58 +01:00
|
|
|
u16 targetExtension = 100 << 8;
|
|
|
|
|
|
|
|
if ( m_extension < targetExtension )
|
|
|
|
{
|
|
|
|
m_extension += ( ( targetExtension - m_extension ) * _frames ) >> 8;
|
|
|
|
|
|
|
|
Pos = m_initPos;
|
|
|
|
Pos.vx += ( m_extension * rcos( m_heading ) ) >> 20;
|
|
|
|
Pos.vy += ( m_extension * rsin( m_heading ) ) >> 20;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// expand
|
|
|
|
}
|
2001-02-08 16:34:18 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
case PROJECTILE_DUMBFIRE:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Pos.vx += ( _frames * 3 * rcos( m_heading ) ) >> 12;
|
|
|
|
Pos.vy += ( _frames * 3 * rsin( m_heading ) ) >> 12;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_lifetimeType == PROJECTILE_FINITE_LIFE )
|
2001-01-22 17:01:49 +01:00
|
|
|
{
|
2001-01-22 23:24:53 +01:00
|
|
|
m_lifetime -= _frames;
|
|
|
|
|
|
|
|
if ( m_lifetime <= 0 )
|
|
|
|
{
|
|
|
|
shutdown();
|
|
|
|
delete this;
|
|
|
|
}
|
2001-01-22 17:01:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProjectile::render()
|
|
|
|
{
|
2001-02-28 23:03:18 +01:00
|
|
|
CEnemyProjectileThing::render();
|
|
|
|
|
2001-01-22 17:01:49 +01:00
|
|
|
DVECTOR offset;
|
|
|
|
int x,y;
|
|
|
|
int scrnWidth = VidGetScrW();
|
|
|
|
int scrnHeight = VidGetScrH();
|
|
|
|
int spriteWidth = m_spriteBank->getFrameWidth(FRM_BARNACLEBOY);
|
|
|
|
int spriteHeight = m_spriteBank->getFrameHeight(FRM_BARNACLEBOY);
|
|
|
|
|
|
|
|
offset = getScreenOffset();
|
|
|
|
|
2001-02-12 16:37:31 +01:00
|
|
|
x = Pos.vx - offset.vx /*+ ( scrnWidth >> 1 )*/ - ( spriteWidth >> 1 );
|
|
|
|
y = Pos.vy - offset.vy /*+ ( scrnHeight >> 1 )*/ - ( spriteHeight >> 1 );
|
2001-01-22 17:01:49 +01:00
|
|
|
|
2001-02-13 16:27:40 +01:00
|
|
|
if ( x < -spriteWidth || y < -spriteHeight || x > scrnWidth || y > scrnHeight )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-01-22 17:01:49 +01:00
|
|
|
m_spriteBank->printFT4(FRM_BARNACLEBOY,x,y,0,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
DVECTOR CProjectile::getScreenOffset()
|
|
|
|
{
|
|
|
|
return CLevel::getCameraPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProjectile::processEvent( GAME_EVENT evt, CThing *sourceThing )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|