2001-01-18 22:18:53 +01:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
nclam.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_NCLAM_H__
|
|
|
|
#include "enemy\nclam.h"
|
|
|
|
#endif
|
|
|
|
|
2001-01-18 22:18:53 +01:00
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PLAYER_PLAYER_H__
|
|
|
|
#include "player\player.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
2001-02-28 22:05:39 +01:00
|
|
|
#ifndef __ANIM_CLAM_HEADER__
|
|
|
|
#include <ACTOR_CLAM_ANIM.h>
|
|
|
|
#endif
|
|
|
|
|
2001-01-18 22:18:53 +01:00
|
|
|
|
2001-04-24 21:03:06 +02:00
|
|
|
void CNpcClamEnemy::processEnemyCollision( CThing *thisThing )
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
bool CNpcClamEnemy::processSensor()
|
|
|
|
{
|
|
|
|
switch( m_sensorFunc )
|
|
|
|
{
|
|
|
|
case NPC_SENSOR_NONE:
|
|
|
|
return( false );
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if ( playerXDistSqr + playerYDistSqr < 10000 )
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_CLOSE;
|
|
|
|
m_extendDir = EXTEND_UP;
|
|
|
|
m_extension = 0;
|
|
|
|
m_movementTimer = GameState::getOneSecondInFrames() >> 3;
|
|
|
|
m_velocity = ( getRnd() % 6 ) + 1;
|
|
|
|
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-26 17:20:21 +02:00
|
|
|
void CNpcJumpingClamEnemy::postInit()
|
|
|
|
{
|
|
|
|
CNpcClamEnemy::postInit();
|
|
|
|
|
|
|
|
m_drawRotation = m_heading + 1024;
|
|
|
|
}
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
void CNpcJumpingClamEnemy::processClose( int _frames )
|
2001-01-18 22:18:53 +01:00
|
|
|
{
|
|
|
|
s32 velocity;
|
|
|
|
|
2001-01-19 22:46:30 +01:00
|
|
|
if ( m_extendDir == EXTEND_UP )
|
2001-01-18 22:18:53 +01:00
|
|
|
{
|
|
|
|
m_movementTimer -= _frames;
|
|
|
|
|
|
|
|
if ( m_movementTimer > 0 )
|
|
|
|
{
|
|
|
|
// extend
|
|
|
|
|
|
|
|
velocity = m_velocity * _frames;
|
|
|
|
|
|
|
|
m_extension += velocity;
|
|
|
|
|
|
|
|
Pos.vx += ( velocity * rcos( m_heading ) ) >> 12;
|
|
|
|
Pos.vy += ( velocity * rsin( m_heading ) ) >> 12;
|
2001-02-28 22:05:39 +01:00
|
|
|
|
|
|
|
if ( !m_animPlaying )
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
2001-04-26 17:20:21 +02:00
|
|
|
m_animNo = ANIM_CLAM_SNAPUP;
|
2001-02-28 22:05:39 +01:00
|
|
|
m_frame = 0;
|
|
|
|
}
|
2001-01-18 22:18:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-19 22:46:30 +01:00
|
|
|
m_extendDir = EXTEND_DOWN;
|
2001-01-18 22:18:53 +01:00
|
|
|
}
|
|
|
|
}
|
2001-01-19 22:46:30 +01:00
|
|
|
else if ( m_extendDir == EXTEND_DOWN )
|
2001-01-18 22:18:53 +01:00
|
|
|
{
|
|
|
|
// retract
|
|
|
|
|
|
|
|
if ( m_extension > 0 )
|
|
|
|
{
|
|
|
|
velocity = -_frames;
|
|
|
|
|
|
|
|
if ( m_extension < _frames )
|
|
|
|
{
|
|
|
|
velocity = m_extension - _frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_extension += velocity;
|
|
|
|
|
|
|
|
|
|
|
|
Pos.vx += ( velocity * rcos( m_heading ) ) >> 12;
|
|
|
|
Pos.vy += ( velocity * rsin( m_heading ) ) >> 12;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-28 22:05:39 +01:00
|
|
|
if ( !m_animPlaying )
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
|
|
|
}
|
2001-01-18 22:18:53 +01:00
|
|
|
}
|
|
|
|
}
|
2001-02-06 22:25:25 +01:00
|
|
|
}
|
2001-03-01 17:48:45 +01:00
|
|
|
|
2001-04-25 17:10:26 +02:00
|
|
|
void CNpcStaticClamEnemy::postInit()
|
|
|
|
{
|
|
|
|
CNpcClamEnemy::postInit();
|
|
|
|
|
|
|
|
m_isStunned = false;
|
|
|
|
m_isAnimating = false;
|
|
|
|
}
|
|
|
|
|
2001-04-20 16:48:15 +02:00
|
|
|
void CNpcStaticClamEnemy::processClose( int _frames )
|
2001-03-01 17:48:45 +01:00
|
|
|
{
|
2001-04-25 17:10:26 +02:00
|
|
|
if ( !m_isAnimating && !m_isStunned )
|
2001-03-01 17:48:45 +01:00
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
2001-04-01 22:22:49 +02:00
|
|
|
m_animNo = ANIM_CLAM_SIDESNAP;
|
2001-03-01 17:48:45 +01:00
|
|
|
m_frame = 0;
|
2001-04-25 17:10:26 +02:00
|
|
|
m_isAnimating = true;
|
|
|
|
}
|
|
|
|
else if ( !m_animPlaying )
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_animNo = m_data[m_type].initAnim;
|
|
|
|
m_frame = 0;
|
|
|
|
m_isAnimating = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNpcStaticClamEnemy::processShot()
|
|
|
|
{
|
|
|
|
if ( !m_isStunned )
|
|
|
|
{
|
|
|
|
switch( m_data[m_type].shotFunc )
|
|
|
|
{
|
|
|
|
case NPC_SHOT_NONE:
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NPC_SHOT_GENERIC:
|
|
|
|
{
|
|
|
|
m_isStunned = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-03-01 17:48:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
}
|
2001-04-25 17:10:26 +02:00
|
|
|
|
|
|
|
void CNpcStaticClamEnemy::collidedWith( CThing *_thisThing )
|
|
|
|
{
|
|
|
|
if ( !m_isStunned )
|
|
|
|
{
|
|
|
|
CNpcClamEnemy::collidedWith( _thisThing );
|
|
|
|
}
|
|
|
|
}
|
2001-04-25 18:18:52 +02:00
|
|
|
|
|
|
|
int CNpcStaticClamEnemy::checkCollisionAgainst( CThing *_thisThing, int _frames )
|
|
|
|
{
|
|
|
|
DVECTOR pos,thisThingPos;
|
|
|
|
int radius;
|
|
|
|
int collided;
|
|
|
|
|
|
|
|
pos = getCollisionCentre();
|
|
|
|
thisThingPos=_thisThing->getCollisionCentre();
|
|
|
|
|
|
|
|
radius=getCollisionRadius()+_thisThing->getCollisionRadius();
|
|
|
|
collided=false;
|
|
|
|
if(abs(pos.vx-thisThingPos.vx)<radius&&
|
|
|
|
abs(pos.vy-thisThingPos.vy)<radius)
|
|
|
|
{
|
|
|
|
CRECT thisRect,thatRect;
|
|
|
|
|
|
|
|
thisRect=getCollisionArea();
|
|
|
|
|
|
|
|
thatRect=_thisThing->getCollisionArea();
|
|
|
|
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
switch(_thisThing->getThingType())
|
|
|
|
{
|
|
|
|
case TYPE_PLAYER:
|
|
|
|
{
|
|
|
|
if ( m_isStunned && m_isActive )
|
|
|
|
{
|
|
|
|
CPlayer *player = (CPlayer *) _thisThing;
|
|
|
|
|
|
|
|
s32 playerDeltaY = player->getPosDelta().vy;
|
|
|
|
|
|
|
|
if ( thisThingPos.vy - playerDeltaY <= getNewYPos( _thisThing ) )
|
|
|
|
{
|
|
|
|
player->setPlatform( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
collided=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return collided;
|
|
|
|
}
|