2001-01-22 23:24:53 +01:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
neyeball.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 16:48:15 +02:00
|
|
|
#ifndef __ENEMY_NEYEBALL_H__
|
|
|
|
#include "enemy\neyeball.h"
|
|
|
|
#endif
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PLAYER_PLAYER_H__
|
|
|
|
#include "player\player.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PROJECTL_PROJECTL_H__
|
|
|
|
#include "projectl\projectl.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-17 17:27:03 +02:00
|
|
|
#ifndef __SPR_SPRITES_H__
|
|
|
|
#include <sprites.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2001-01-22 23:24:53 +01:00
|
|
|
|
2001-04-24 21:03:06 +02:00
|
|
|
void CNpcEyeballEnemy::processEnemyCollision( CThing *thisThing )
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2001-05-17 17:27:03 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
void CNpcEyeballEnemy::postInit()
|
|
|
|
{
|
2001-05-17 17:27:03 +02:00
|
|
|
DVECTOR eyeballPos = Pos;
|
|
|
|
|
2001-05-16 21:04:40 +02:00
|
|
|
m_fireHeading = m_heading;
|
2001-05-17 17:27:03 +02:00
|
|
|
m_drawRotation = ( m_heading + 1024 ) & 4095;
|
|
|
|
|
|
|
|
eyeballPos.vx += ( EYEBALL_DIST * rcos( m_heading ) ) >> 12;
|
|
|
|
eyeballPos.vy += ( EYEBALL_DIST * rsin( m_heading ) ) >> 12;
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
CProjectile *projectile;
|
2001-06-14 18:07:48 +02:00
|
|
|
projectile = CProjectile::Create();
|
2001-05-17 17:27:03 +02:00
|
|
|
projectile->init( eyeballPos, m_fireHeading, CProjectile::PROJECTILE_FIXED, CProjectile::PROJECTILE_INFINITE_LIFE );
|
|
|
|
projectile->setGraphic( FRM_EYEBALL_STATIC );
|
2001-04-20 16:48:15 +02:00
|
|
|
|
|
|
|
addChild( projectile );
|
|
|
|
}
|
|
|
|
|
2001-05-17 17:27:03 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcEyeballEnemy::shutdown()
|
|
|
|
{
|
|
|
|
deleteAllChild();
|
|
|
|
CNpcEnemy::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
bool CNpcEyeballEnemy::processSensor()
|
|
|
|
{
|
|
|
|
switch( m_sensorFunc )
|
|
|
|
{
|
|
|
|
case NPC_SENSOR_NONE:
|
|
|
|
return( false );
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if ( playerXDistSqr + playerYDistSqr < 40000 )
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_CLOSE;
|
|
|
|
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-17 17:27:03 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
void CNpcEyeballEnemy::processClose( int _frames )
|
2001-01-22 23:24:53 +01:00
|
|
|
{
|
2001-05-21 16:52:09 +02:00
|
|
|
CThing *Next=getNext();
|
|
|
|
|
2001-01-22 23:24:53 +01:00
|
|
|
if ( Next )
|
2001-04-04 00:01:52 +02:00
|
|
|
{
|
|
|
|
CProjectile *projectile;
|
|
|
|
|
|
|
|
projectile = (CProjectile *) Next;
|
|
|
|
|
|
|
|
if ( projectile->getMovementType() == CProjectile::PROJECTILE_FIXED )
|
|
|
|
{
|
|
|
|
projectile->setMovementType( CProjectile::PROJECTILE_USER_SEEK );
|
|
|
|
projectile->setState( CProjectile::PROJECTILE_ATTACK );
|
2001-05-21 23:16:42 +02:00
|
|
|
|
|
|
|
// sound
|
|
|
|
|
2001-06-18 21:06:43 +02:00
|
|
|
if ( m_soundId == NOT_PLAYING )
|
|
|
|
{
|
|
|
|
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_EYEBALL_SENTRY_ATTACK, true );
|
|
|
|
}
|
2001-04-04 00:01:52 +02:00
|
|
|
}
|
|
|
|
}
|
2001-04-20 16:48:15 +02:00
|
|
|
else
|
|
|
|
{
|
2001-05-17 17:27:03 +02:00
|
|
|
DVECTOR eyeballPos = Pos;
|
|
|
|
|
|
|
|
eyeballPos.vx += ( EYEBALL_DIST * rcos( m_heading ) ) >> 12;
|
|
|
|
eyeballPos.vy += ( EYEBALL_DIST * rsin( m_heading ) ) >> 12;
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
CProjectile *projectile;
|
2001-06-14 18:07:48 +02:00
|
|
|
projectile = CProjectile::Create();
|
2001-05-17 17:27:03 +02:00
|
|
|
projectile->init( eyeballPos, m_fireHeading, CProjectile::PROJECTILE_USER_SEEK, CProjectile::PROJECTILE_INFINITE_LIFE );
|
|
|
|
projectile->setGraphic( FRM_EYEBALL_STATIC );
|
2001-04-20 16:48:15 +02:00
|
|
|
projectile->setState( CProjectile::PROJECTILE_ATTACK );
|
|
|
|
|
|
|
|
addChild( projectile );
|
2001-05-21 23:16:42 +02:00
|
|
|
|
|
|
|
// sound
|
|
|
|
|
2001-06-18 21:06:43 +02:00
|
|
|
if ( m_soundId == NOT_PLAYING )
|
|
|
|
{
|
|
|
|
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_EYEBALL_SENTRY_ATTACK, true );
|
|
|
|
}
|
2001-04-20 16:48:15 +02:00
|
|
|
}
|
2001-05-17 17:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcEyeballEnemy::render()
|
|
|
|
{
|
|
|
|
SprFrame = NULL;
|
|
|
|
|
|
|
|
if ( m_isActive )
|
|
|
|
{
|
|
|
|
CEnemyThing::render();
|
|
|
|
|
|
|
|
if (canRender())
|
|
|
|
{
|
|
|
|
DVECTOR &renderPos=getRenderPos();
|
|
|
|
|
2001-05-25 20:43:47 +02:00
|
|
|
SprFrame = CGameScene::getSpriteBank()->printRotatedScaledSprite( FRM_EYEBALL_STALK, renderPos.vx, renderPos.vy, 4096, 4096, m_drawRotation, 10);
|
2001-05-17 17:27:03 +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 -= renderPos.vx;
|
|
|
|
XMin -= renderPos.vx;
|
|
|
|
YMax -= renderPos.vy;
|
|
|
|
YMin -= renderPos.vy;
|
|
|
|
|
|
|
|
setCollisionSize( ( XMax - XMin ), ( YMax - YMin ) );
|
|
|
|
setCollisionCentreOffset( ( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcEyeballEnemy::processEvent( GAME_EVENT evt, CThing *sourceThing )
|
|
|
|
{
|
|
|
|
switch( evt )
|
|
|
|
{
|
|
|
|
case PROJECTILE_RETURNED_TO_SOURCE_EVENT:
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
|
|
|
|
|
|
|
//removeChild( sourceThing );
|
|
|
|
//sourceThing->shutdown();
|
|
|
|
//delete sourceThing;
|
|
|
|
|
|
|
|
CProjectile *projectile;
|
|
|
|
projectile = (CProjectile *) sourceThing;
|
|
|
|
projectile->setMovementType( CProjectile::PROJECTILE_FIXED );
|
|
|
|
|
|
|
|
DVECTOR eyeballPos = Pos;
|
|
|
|
|
|
|
|
eyeballPos.vx += ( EYEBALL_DIST * rcos( m_heading ) ) >> 12;
|
|
|
|
eyeballPos.vy += ( EYEBALL_DIST * rsin( m_heading ) ) >> 12;
|
|
|
|
|
|
|
|
projectile->setPosition( eyeballPos );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2001-06-30 17:39:43 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2001-05-17 17:27:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
void CNpcEyeballEnemy::processShotDeathStart( int _frames )
|
2001-05-17 17:27:03 +02:00
|
|
|
{
|
2001-06-28 22:29:14 +02:00
|
|
|
CNpcEnemy::processShotDeathStart( _frames );
|
2001-05-30 00:07:28 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
CThing *Next=getNext();
|
|
|
|
if ( Next )
|
|
|
|
{
|
|
|
|
CProjectile *projectile;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
projectile = (CProjectile *) Next;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
if ( projectile->getMovementType() != CProjectile::PROJECTILE_FIXED )
|
2001-05-17 17:27:03 +02:00
|
|
|
{
|
2001-06-28 22:29:14 +02:00
|
|
|
projectile->setMovementType( CProjectile::PROJECTILE_DUMBFIRE );
|
|
|
|
projectile->setLifeTime( CProjectile::PROJECTILE_FINITE_LIFE );
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
removeChild( Next );
|
2001-05-17 17:27:03 +02:00
|
|
|
}
|
2001-06-28 22:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
void CNpcEyeballEnemy::processShotDeathEnd( int _frames )
|
|
|
|
{
|
|
|
|
CNpcEnemy::processShotDeathEnd( _frames );
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
m_heading = m_drawRotation - 1024;
|
|
|
|
m_heading &= 4095;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
CThing *Next=getNext();
|
|
|
|
if ( Next )
|
|
|
|
{
|
|
|
|
CProjectile *projectile;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
projectile = (CProjectile *) Next;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
DVECTOR eyeballPos = Pos;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
eyeballPos.vx += ( EYEBALL_DIST * rcos( m_heading ) ) >> 12;
|
|
|
|
eyeballPos.vy += ( EYEBALL_DIST * rsin( m_heading ) ) >> 12;
|
2001-05-17 17:27:03 +02:00
|
|
|
|
2001-06-28 22:29:14 +02:00
|
|
|
projectile->setPosition( eyeballPos );
|
|
|
|
projectile->setHeading( m_heading );
|
2001-05-17 17:27:03 +02:00
|
|
|
}
|
|
|
|
}
|