2001-01-19 20:11:00 +01:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
nscrab.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2000 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __ENEMY_NPC_H__
|
|
|
|
#include "enemy\npc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PLAYER_PLAYER_H__
|
|
|
|
#include "player\player.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-02 17:52:09 +02:00
|
|
|
#ifndef __ANIM_SPIDERCRAB_HEADER__
|
|
|
|
#include <ACTOR_SPIDERCRAB_ANIM.h>
|
|
|
|
#endif
|
|
|
|
|
2001-01-19 20:11:00 +01:00
|
|
|
|
2001-02-27 22:25:22 +01:00
|
|
|
void CNpcEnemy::processCloseSpiderCrabAttack( int _frames )
|
2001-01-19 20:11:00 +01:00
|
|
|
{
|
|
|
|
s32 velocity;
|
2001-02-22 17:56:27 +01:00
|
|
|
DVECTOR newPos = Pos;
|
2001-01-19 20:11:00 +01:00
|
|
|
|
2001-04-02 17:52:09 +02:00
|
|
|
if ( m_animNo != ANIM_SPIDERCRAB_JUMP )
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_SPIDERCRAB_JUMP;
|
|
|
|
m_frame = 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 20:11:00 +01:00
|
|
|
velocity = m_velocity * _frames;
|
|
|
|
|
|
|
|
if ( m_extendDir == EXTEND_RIGHT )
|
|
|
|
{
|
2001-04-04 21:55:49 +02:00
|
|
|
m_extension += velocity;
|
2001-01-19 22:46:30 +01:00
|
|
|
m_heading = 0;
|
2001-01-19 20:11:00 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-04 21:55:49 +02:00
|
|
|
m_extension -= velocity;
|
2001-01-19 22:46:30 +01:00
|
|
|
m_heading = 2048;
|
2001-01-19 20:11:00 +01:00
|
|
|
}
|
|
|
|
|
2001-04-04 21:55:49 +02:00
|
|
|
bool completed = false;
|
2001-01-19 20:11:00 +01:00
|
|
|
|
2001-04-04 21:55:49 +02:00
|
|
|
if ( m_extension > 128 )
|
2001-01-19 20:11:00 +01:00
|
|
|
{
|
2001-04-04 21:55:49 +02:00
|
|
|
m_extension = 128;
|
|
|
|
completed = true;
|
|
|
|
}
|
|
|
|
else if ( m_extension < -128 )
|
|
|
|
{
|
|
|
|
m_extension = -128;
|
|
|
|
completed = true;
|
|
|
|
}
|
2001-01-19 20:11:00 +01:00
|
|
|
|
2001-04-04 21:55:49 +02:00
|
|
|
newPos.vx = m_base.vx + m_extension;
|
|
|
|
newPos.vy = m_base.vy - ( ( 20 * rsin( abs( m_extension ) << 4 ) ) >> 12 );
|
2001-01-19 20:11:00 +01:00
|
|
|
|
2001-04-04 21:55:49 +02:00
|
|
|
s32 minX, maxX;
|
|
|
|
|
|
|
|
m_npcPath.getPathXExtents( &minX, &maxX );
|
|
|
|
|
|
|
|
if ( newPos.vx < minX )
|
|
|
|
{
|
|
|
|
newPos.vx = minX;
|
2001-01-19 20:11:00 +01:00
|
|
|
}
|
2001-04-04 21:55:49 +02:00
|
|
|
else if ( newPos.vx > maxX )
|
2001-01-19 20:11:00 +01:00
|
|
|
{
|
2001-04-04 21:55:49 +02:00
|
|
|
newPos.vx = maxX;
|
2001-02-22 17:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for collision with ground
|
|
|
|
|
|
|
|
if ( m_layerCollision->getHeightFromGround( newPos.vx, newPos.vy ) < 0 )
|
|
|
|
{
|
|
|
|
// abort jump
|
|
|
|
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
2001-04-04 21:55:49 +02:00
|
|
|
|
|
|
|
m_extension = 0;
|
|
|
|
completed = false;
|
2001-02-22 17:56:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pos = newPos;
|
2001-01-19 20:11:00 +01:00
|
|
|
}
|
2001-04-04 21:55:49 +02:00
|
|
|
|
|
|
|
if ( completed )
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
|
|
|
|
|
|
|
m_extension = 0;
|
|
|
|
}
|
2001-01-19 20:11:00 +01:00
|
|
|
}
|
2001-04-05 22:44:30 +02:00
|
|
|
|
|
|
|
void CNpcEnemy::processSpiderCrabCollision()
|
|
|
|
{
|
|
|
|
if ( m_oldControlFunc == NPC_CONTROL_CLOSE )
|
|
|
|
{
|
|
|
|
// bite player
|
|
|
|
|
|
|
|
if ( m_animNo != ANIM_SPIDERCRAB_BITE )
|
|
|
|
{
|
|
|
|
CPlayer *player = GameScene.getPlayer();
|
|
|
|
|
2001-04-18 18:34:17 +02:00
|
|
|
player->takeDamage( m_data[m_type].damageToUserType );
|
2001-04-05 22:44:30 +02:00
|
|
|
|
|
|
|
m_animNo = ANIM_SPIDERCRAB_BITE;
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_frame = 0;
|
|
|
|
}
|
|
|
|
else if ( !m_animPlaying )
|
|
|
|
{
|
|
|
|
m_controlFunc = NPC_CONTROL_MOVEMENT;
|
|
|
|
m_timerFunc = NPC_TIMER_ATTACK_DONE;
|
|
|
|
m_timerTimer = GameState::getOneSecondInFrames();
|
|
|
|
m_sensorFunc = NPC_SENSOR_NONE;
|
|
|
|
|
|
|
|
m_extension = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CPlayer *player = GameScene.getPlayer();
|
|
|
|
|
2001-04-18 18:34:17 +02:00
|
|
|
player->takeDamage( m_data[m_type].damageToUserType );
|
2001-04-05 22:44:30 +02:00
|
|
|
|
|
|
|
m_controlFunc = m_oldControlFunc;
|
|
|
|
}
|
2001-04-19 01:12:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNpcEnemy::processSpiderCrabInitJumpMovement( int _frames )
|
|
|
|
{
|
|
|
|
s32 velocity;
|
|
|
|
bool completed = false;
|
|
|
|
bool collision = false;
|
|
|
|
|
|
|
|
if ( m_animNo != ANIM_SPIDERCRAB_JUMP )
|
|
|
|
{
|
|
|
|
m_animPlaying = true;
|
|
|
|
m_animNo = ANIM_SPIDERCRAB_JUMP;
|
|
|
|
m_frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
velocity = m_velocity * _frames;
|
|
|
|
|
|
|
|
m_extension += velocity;
|
|
|
|
|
|
|
|
if ( m_extension > 128 )
|
|
|
|
{
|
|
|
|
m_extension = 128;
|
|
|
|
completed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vy = m_base.vy - ( ( 50 * rsin( abs( m_extension ) << 4 ) ) >> 12 );
|
|
|
|
|
|
|
|
if ( m_extension > 64 )
|
|
|
|
{
|
|
|
|
// check for collision on the way back down
|
|
|
|
|
|
|
|
if ( m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy ) < 0 )
|
|
|
|
{
|
|
|
|
collision = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( completed || collision )
|
|
|
|
{
|
|
|
|
m_movementFunc = m_data[m_type].movementFunc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNpcEnemy::processSpiderCrabSpawnerMovement( int _frames )
|
|
|
|
{
|
|
|
|
if ( getNumChildren() < 3 )
|
|
|
|
{
|
|
|
|
m_movementTimer -= _frames;
|
|
|
|
|
|
|
|
if ( m_movementTimer < 0 )
|
|
|
|
{
|
|
|
|
m_movementTimer = 3 * GameState::getOneSecondInFrames();
|
|
|
|
|
|
|
|
CNpcEnemy *enemy;
|
|
|
|
enemy = new( "spider crab" ) CNpcEnemy;
|
|
|
|
ASSERT(enemy);
|
|
|
|
enemy->setType( CNpcEnemy::NPC_SPIDER_CRAB );
|
|
|
|
enemy->init();
|
|
|
|
enemy->setLayerCollision( m_layerCollision );
|
|
|
|
enemy->setStartPos( Pos.vx >> 4, Pos.vy >> 4 );
|
|
|
|
|
|
|
|
CNpcWaypoint *sourceWaypoint = m_npcPath.getWaypointList();
|
|
|
|
|
|
|
|
if ( sourceWaypoint )
|
|
|
|
{
|
|
|
|
// skip first waypoint
|
|
|
|
|
|
|
|
sourceWaypoint = sourceWaypoint->nextWaypoint;
|
|
|
|
|
|
|
|
while( sourceWaypoint )
|
|
|
|
{
|
|
|
|
enemy->addWaypoint( sourceWaypoint->pos.vx >> 4, sourceWaypoint->pos.vy >> 4 );
|
|
|
|
sourceWaypoint = sourceWaypoint->nextWaypoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enemy->setPathType( m_npcPath.getPathType() );
|
|
|
|
|
|
|
|
enemy->postInit();
|
|
|
|
|
|
|
|
addChild( enemy );
|
|
|
|
}
|
|
|
|
}
|
2001-04-05 22:44:30 +02:00
|
|
|
}
|