SBSPSS/source/enemy/nsdart.cpp

237 lines
4.6 KiB
C++
Raw Normal View History

2001-04-21 18:38:15 +02:00
/*=========================================================================
nsdart.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __ENEMY_NSDART_H__
#include "enemy\nsdart.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#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-05-15 22:21:05 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-05 00:34:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-21 18:38:15 +02:00
void CNpcSquidDartEnemy::render()
{
SprFrame = NULL;
if ( m_isActive )
{
CEnemyThing::render();
2001-05-14 23:08:03 +02:00
if (canRender())
2001-04-21 19:29:15 +02:00
{
2001-05-14 23:08:03 +02:00
DVECTOR &renderPos=getRenderPos();
2001-05-15 22:21:05 +02:00
// bodge
if ( m_reversed )
{
renderPos.vx += 32;
}
else
{
renderPos.vx -= 32;
}
2001-07-16 18:27:32 +02:00
//renderPos.vy -= 6;
2001-05-15 22:21:05 +02:00
// bodge
2001-04-21 19:29:15 +02:00
2001-05-14 23:08:03 +02:00
int frame = FRM_SQUIDDART_SWIM0001 + ( m_frame >> 8 );
2001-04-21 18:38:15 +02:00
2001-05-25 21:08:35 +02:00
SprFrame = CGameScene::getSpriteBank()->printFT4(frame,renderPos.vx,renderPos.vy,m_reversed,0,0);
2001-05-15 22:21:05 +02:00
2001-05-14 23:21:18 +02:00
//setRGB0( SprFrame, 255, 128, 255 );
2001-05-05 16:58:49 +02:00
2001-05-14 23:08:03 +02:00
/*s32 XMax = SprFrame->x1 - origRenderPos.vx;
s32 XMin = SprFrame->x0 - origRenderPos.vx;
s32 YMax = SprFrame->y2 - origRenderPos.vy;
s32 YMin = SprFrame->y0 - origRenderPos.vy;*/
2001-04-27 20:30:19 +02:00
2001-05-14 23:08:03 +02:00
s32 XMax = SprFrame->x1 - renderPos.vx;
s32 XMin = SprFrame->x0 - renderPos.vx;
2001-04-27 20:30:19 +02:00
2001-05-14 23:08:03 +02:00
s32 YMax = SprFrame->y2 - renderPos.vy;
s32 YMin = SprFrame->y0 - renderPos.vy;
2001-04-27 20:30:19 +02:00
2001-05-14 23:08:03 +02:00
setCollisionSize( ( XMax - XMin ), ( YMax - YMin ) );
2001-05-15 22:21:05 +02:00
// bodge
2001-07-16 18:27:32 +02:00
//setCollisionCentreOffset( 0, 0 ); //( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 );
setCollisionCentreOffset( 0, ( YMax + YMin ) >> 1 ); //( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 );
2001-04-21 18:38:15 +02:00
}
}
}
2001-05-05 00:34:23 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSquidDartEnemy::fireAsProjectile( s16 heading )
{
m_isActive = false;
setToShutdown();
DVECTOR newPos = Pos;
newPos.vy -= 10;
CEnemyAsSpriteProjectile *projectile;
2001-06-14 18:07:48 +02:00
projectile = CEnemyAsSpriteProjectile::Create();
2001-05-05 00:34:23 +02:00
projectile->init( newPos,
heading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-05-25 20:43:47 +02:00
2001-05-05 00:34:23 +02:00
projectile->setGraphic( FRM_SQUIDDART_SWIM0001 );
projectile->setHasRGB( true );
projectile->setRGB( 255, 128, 255 );
2001-05-15 00:59:31 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
s32 CNpcSquidDartEnemy::getFrameShift( int _frames )
{
return( ( _frames << 8 ) >> 2 );
}
2001-05-15 22:21:05 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CNpcSquidDartEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr + playerYDistSqr < 20000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
2001-05-25 19:09:51 +02:00
m_attack = false;
2001-05-15 22:21:05 +02:00
2001-05-21 23:16:42 +02:00
// sound
2001-06-18 21:06:43 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
2001-07-12 22:15:10 +02:00
m_soundId = NOT_PLAYING;
2001-06-18 21:06:43 +02:00
}
2001-05-15 22:21:05 +02:00
return( true );
}
else
{
return( false );
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSquidDartEnemy::processClose( int _frames )
{
2001-05-25 19:09:51 +02:00
s32 movement;
2001-07-17 18:38:59 +02:00
s32 yAim = playerYDist - 20;
2001-07-16 18:35:15 +02:00
//s32 maxSpeed = m_data[m_type].speed * _frames;
s32 maxSpeed = m_speed * _frames;
2001-05-15 22:21:05 +02:00
2001-05-25 19:09:51 +02:00
if ( m_attack )
{
movement = m_xPos - Pos.vx;
2001-05-15 22:21:05 +02:00
2001-05-25 19:09:51 +02:00
if ( movement )
{
if ( movement > maxSpeed )
{
movement = maxSpeed;
}
else if ( movement < -maxSpeed )
{
movement = -maxSpeed;
}
2001-05-15 22:21:05 +02:00
2001-05-25 19:09:51 +02:00
Pos.vx += movement;
2001-07-12 22:15:10 +02:00
if( m_soundId != NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SQUIDDART_ATTACK, true );
}
2001-05-25 19:09:51 +02:00
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}
}
else
{
2001-07-17 18:38:59 +02:00
if ( abs( yAim ) > 5 )
2001-05-25 19:09:51 +02:00
{
movement = yAim;
if ( movement > maxSpeed )
{
movement = maxSpeed;
}
else if ( movement < -maxSpeed )
{
movement = -maxSpeed;
}
2001-05-15 22:21:05 +02:00
2001-05-25 19:09:51 +02:00
Pos.vy += movement;
}
else
{
m_attack = true;
m_xPos = Pos.vx + playerXDist;
}
2001-05-15 22:21:05 +02:00
2001-05-25 19:09:51 +02:00
if ( playerXDist > 0 )
{
m_heading = 0;
}
else
{
m_heading = 2048;
}
2001-05-15 22:21:05 +02:00
}
2001-05-21 18:51:45 +02:00
if ( !m_animPlaying )
{
m_frame = 0;
m_animNo = m_data[m_type].moveAnim;
m_animPlaying = true;
2001-05-25 19:09:51 +02:00
2001-05-21 18:51:45 +02:00
}
2001-05-15 22:21:05 +02:00
}