SBSPSS/source/enemy/nsjfish.cpp

400 lines
8.5 KiB
C++
Raw Normal View History

2001-01-18 20:54:06 +01:00
/*=========================================================================
nsjfish.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
2001-04-20 00:09:59 +02:00
#ifndef __ENEMY_NSJFISH_H__
#include "enemy\nsjfish.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-01-18 20:54:06 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-04-20 18:25:35 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-05 00:34:23 +02:00
#ifndef __PROJECTL_PRNPCSPR_H__
#include "projectl\prnpcspr.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 00:09:59 +02:00
void CNpcSmallJellyfishEnemy::render()
2001-01-18 20:54:06 +01:00
{
2001-04-20 18:25:35 +02:00
SprFrame = NULL;
2001-01-18 20:54:06 +01:00
2001-04-20 18:25:35 +02:00
if ( m_isActive )
2001-01-18 20:54:06 +01:00
{
2001-04-20 18:25:35 +02:00
CEnemyThing::render();
// Render
DVECTOR renderPos;
2001-04-27 20:30:19 +02:00
DVECTOR origRenderPos;
2001-04-20 18:25:35 +02:00
DVECTOR offset = CLevel::getCameraPos();
2001-04-21 19:29:15 +02:00
int spriteWidth = m_spriteBank->getFrameWidth( m_frame >> 8 );
int spriteHeight = m_spriteBank->getFrameHeight( m_frame >> 8 );
2001-04-20 18:25:35 +02:00
2001-04-27 20:30:19 +02:00
renderPos.vx = Pos.vx - offset.vx;
origRenderPos.vx = renderPos.vx;
renderPos.vx += m_drawOffset.vx;
2001-04-21 19:29:15 +02:00
2001-04-27 20:30:19 +02:00
renderPos.vy = Pos.vy - offset.vy;
origRenderPos.vy = renderPos.vy;
renderPos.vy += m_drawOffset.vy - ( spriteHeight >> 1 );
2001-04-20 18:25:35 +02:00
2001-05-05 16:58:49 +02:00
CRECT collisionRect = getCollisionArea();
collisionRect.x1 -= Pos.vx;
collisionRect.x2 -= Pos.vx;
collisionRect.y1 -= Pos.vy;
collisionRect.y2 -= Pos.vy;
if ( renderPos.vx + collisionRect.x2 >= 0 && renderPos.vx + collisionRect.x1 <= VidGetScrW() )
2001-04-20 18:25:35 +02:00
{
2001-05-05 16:58:49 +02:00
if ( renderPos.vy + collisionRect.y2 >= 0 && renderPos.vy + collisionRect.y1 <= VidGetScrH() )
2001-04-20 18:25:35 +02:00
{
2001-05-03 15:11:45 +02:00
SprFrame = m_spriteBank->printRotatedScaledSprite( FRM_JELLYFISH1_SWIM1 + ( m_frame >> 8 ),renderPos.vx,renderPos.vy,4096,4096,m_drawRotation,10);
2001-05-03 21:39:35 +02:00
setRGB0( SprFrame, 255, 128, 255 ); // Let me know if these change! ALso ket me know when the different coloured ones go in pls! (pkg)
2001-04-27 20:30:19 +02:00
// get xmax, xmin, ymax, ymin
s32 XMax;
s32 XMin;
s32 YMax;
s32 YMin;
XMin=SprFrame->x0;
if (XMin>SprFrame->x1) XMin=SprFrame->x1;
if (XMin>SprFrame->x2) XMin=SprFrame->x2;
if (XMin>SprFrame->x3) XMin=SprFrame->x3;
XMax=SprFrame->x0;
if (XMax<SprFrame->x1) XMax=SprFrame->x1;
if (XMax<SprFrame->x2) XMax=SprFrame->x2;
if (XMax<SprFrame->x3) XMax=SprFrame->x3;
YMin=SprFrame->y0;
if (YMin>SprFrame->y1) YMin=SprFrame->y1;
if (YMin>SprFrame->y2) YMin=SprFrame->y2;
if (YMin>SprFrame->y3) YMin=SprFrame->y3;
YMax=SprFrame->y0;
if (YMax<SprFrame->y1) YMax=SprFrame->y1;
if (YMax<SprFrame->y2) YMax=SprFrame->y2;
if (YMax<SprFrame->y3) YMax=SprFrame->y3;
XMax -= origRenderPos.vx;
XMin -= origRenderPos.vx;
YMax -= origRenderPos.vy;
YMin -= origRenderPos.vy;
setCollisionSize( ( XMax - XMin ), ( YMax - YMin ) );
setCollisionCentreOffset( ( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 );
2001-04-20 18:25:35 +02:00
}
}
2001-01-18 20:54:06 +01:00
}
}
2001-05-05 00:34:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 00:09:59 +02:00
void CNpcSmallJellyfishEnemy::processClose( int _frames )
2001-01-18 20:54:06 +01:00
{
s32 moveX = 0, moveY = 0;
s16 moveDist = 0;
s32 moveVel = 0;
2001-02-22 22:00:56 +01:00
if ( playerXDistSqr + playerYDistSqr > 10000 )
2001-01-18 20:54:06 +01:00
{
this->m_controlFunc = NPC_CONTROL_MOVEMENT;
}
else
{
bool pathComplete;
2001-01-23 18:03:27 +01:00
bool waypointChange;
2001-04-28 19:39:24 +02:00
s32 xDist, yDist;
2001-01-18 20:54:06 +01:00
2001-04-28 19:39:24 +02:00
s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange, &xDist, &yDist );
2001-01-18 20:54:06 +01:00
if ( pathComplete )
{
this->m_controlFunc = NPC_CONTROL_MOVEMENT;
}
else
{
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
}
2001-02-07 17:42:13 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-01-18 20:54:06 +01:00
if ( m_evadeClockwise )
{
headingToPlayer += 1024;
}
else
{
headingToPlayer -= 1024;
}
2001-04-05 16:17:24 +02:00
headingToPlayer &= 4095;
2001-01-18 20:54:06 +01:00
s16 decDir, incDir;
decDir = headingToPlayer - headingToTarget;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToTarget - headingToPlayer;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist < 128 )
{
// evasion angle is close to angle required to go to waypoint, hence resume waypoint movement
this->m_controlFunc = NPC_CONTROL_MOVEMENT;
this->m_timerFunc = NPC_TIMER_EVADE_DONE;
this->m_timerTimer = GameState::getOneSecondInFrames();
this->m_sensorFunc = NPC_SENSOR_NONE;
}
else
{
decDir = m_heading - headingToPlayer;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToPlayer - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = -decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist < -128 )
{
moveDist = -128;
}
else if ( moveDist > 128 )
{
moveDist = 128;
}
m_heading += moveDist;
2001-04-18 18:34:17 +02:00
m_heading &= 4095;
2001-01-18 20:54:06 +01:00
moveX = ( _frames * 3 * rcos( m_heading ) ) >> 12;
moveY = ( _frames * 3 * rsin( m_heading ) ) >> 12;
moveVel = ( _frames * 3 ) << 8;
2001-02-22 22:00:56 +01:00
if ( processGroundCollisionReverse( &moveX, &moveY ) )
2001-02-16 18:15:56 +01:00
{
2001-02-22 22:00:56 +01:00
m_evadeClockwise = !m_evadeClockwise;
2001-02-16 18:15:56 +01:00
}
2001-01-18 20:54:06 +01:00
processMovementModifier(_frames, moveX, moveY, moveVel, moveDist);
}
}
}
}
2001-04-20 00:09:59 +02:00
2001-05-05 00:34:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 00:09:59 +02:00
bool CNpcSmallJellyfishEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr + playerYDistSqr < 5625 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_evadeClockwise = getRnd() % 2;
return( true );
}
else
{
return( false );
}
}
}
}
2001-05-05 00:34:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 00:09:59 +02:00
void CNpcSmallJellyfishEnemy::processMovementModifier( int _frames, s32 distX, s32 distY, s32 dist, s16 headingChange )
{
s32 newX, newY;
s32 preShiftX, preShiftY;
s16 headingVal;
//u16 jellyfishData[5] = { 96, 192, 256, 192, 128, };
2001-04-23 15:07:58 +02:00
u16 jellyfishData[6] = { 256, 256, 96, 48, 96, 256, };
2001-04-20 00:09:59 +02:00
u32 dataPoint;
m_movementTimer += _frames;
2001-04-23 15:07:58 +02:00
if ( m_movementTimer > ( GameState::getOneSecondInFrames() >> 1 ) )
2001-04-20 00:09:59 +02:00
{
m_movementTimer = 0;
}
dataPoint = 5 * m_movementTimer;
if ( dataPoint != 0 )
{
2001-04-23 15:07:58 +02:00
dataPoint /= ( GameState::getOneSecondInFrames() >> 1 );
2001-04-20 00:09:59 +02:00
}
2001-04-20 18:13:23 +02:00
m_frame = ( ( m_movementTimer * ( getFrameCount() - 1 ) << 8 ) ) / GameState::getOneSecondInFrames();
2001-04-20 00:09:59 +02:00
s32 resistance;
s32 absVelocity = abs( m_velocity );
s32 reqVelocity = dist;
resistance = _frames * NPC_JELLYFISH_RESISTANCE;
if ( absVelocity < resistance )
{
resistance = absVelocity;
}
if ( absVelocity != 0 )
{
resistance = -( resistance * m_velocity ) / absVelocity;
}
else
{
resistance = 0;
}
m_velocity += resistance;
headingVal = abs( headingChange );
if ( headingVal > 128 )
{
headingVal = 128;
}
reqVelocity = dist * jellyfishData[dataPoint];
reqVelocity >>= 8;
reqVelocity *= 128 + ( 128 - headingVal );
reqVelocity >>= 8;
s32 absReqVelocity = abs( reqVelocity );
if ( absReqVelocity > absVelocity )
{
m_velocity += reqVelocity >> 1;
}
preShiftX = ( m_velocity >> 8 ) * rcos( m_heading );
preShiftY = ( m_velocity >> 8 ) * rsin( m_heading );
newX = preShiftX >> 12;
if ( !newX && preShiftX )
{
newX = preShiftX / abs( preShiftX );
}
newY = preShiftY >> 12;
if ( !newY && preShiftY )
{
newY = preShiftY / abs( preShiftY );
}
Pos.vx += newX;
Pos.vy += newY;
2001-04-26 17:39:18 +02:00
m_drawRotation = m_heading;
2001-04-20 00:09:59 +02:00
}
2001-05-05 00:34:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSmallJellyfishEnemy::fireAsProjectile( s16 heading )
{
m_isActive = false;
if ( m_data[m_type].respawning )
{
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 4 * GameState::getOneSecondInFrames();
}
else
{
setToShutdown();
}
DVECTOR newPos = Pos;
newPos.vy -= 10;
CEnemyAsSpriteProjectile *projectile;
projectile = new( "blower projectile" ) CEnemyAsSpriteProjectile;
projectile->init( newPos,
heading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
projectile->setLayerCollision( m_layerCollision );
projectile->setGraphic( FRM_JELLYFISH1_SWIM1 );
projectile->setHasRGB( true );
projectile->setRGB( 255, 128, 255 );
}