SBSPSS/source/enemy/nscrab.cpp

346 lines
7.0 KiB
C++
Raw Normal View History

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
2001-04-20 00:09:59 +02:00
#ifndef __ENEMY_NSCRAB_H__
#include "enemy\nscrab.h"
#endif
2001-01-19 20:11:00 +01:00
#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-04-20 22:22:16 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::postInit()
{
m_npcPath.setPathType( CNpcPath::PONG_PATH );
2001-04-26 23:29:44 +02:00
if ( m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy - 8, 16 ) <= 0 )
2001-04-20 22:22:16 +02:00
{
// starting off below ground, jump initially
m_velocity = 5;
m_state = SPIDER_CRAB_INIT_JUMP;
}
}
2001-04-20 00:09:59 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CNpcSpiderCrabEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
2001-05-10 01:14:35 +02:00
if ( abs( playerXDist ) < 64 )
2001-04-20 00:09:59 +02:00
{
// only attack if within path extents
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( playerXDist < 0 )
{
m_extendDir = EXTEND_LEFT;
2001-05-10 01:14:35 +02:00
if ( ( Pos.vx + playerXDist ) < minX )
2001-04-20 00:09:59 +02:00
{
return( false );
}
}
else
{
m_extendDir = EXTEND_RIGHT;
2001-05-10 01:14:35 +02:00
if ( ( Pos.vx + playerXDist ) > maxX )
2001-04-20 00:09:59 +02:00
{
return( false );
}
}
2001-05-10 01:14:35 +02:00
m_attackDist = abs( playerXDist );
2001-04-20 00:09:59 +02:00
m_controlFunc = NPC_CONTROL_CLOSE;
m_extension = 0;
m_velocity = 5;
m_base = Pos;
return( true );
}
else
{
return( false );
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::processClose( 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-05-10 01:14:35 +02:00
if ( m_extension > m_attackDist )
2001-01-19 20:11:00 +01:00
{
2001-05-10 01:14:35 +02:00
m_extension = m_attackDist;
2001-04-04 21:55:49 +02:00
completed = true;
}
2001-05-10 01:14:35 +02:00
else if ( m_extension < -m_attackDist )
2001-04-04 21:55:49 +02:00
{
2001-05-10 01:14:35 +02:00
m_extension = -m_attackDist;
2001-04-04 21:55:49 +02:00
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;
2001-05-10 01:14:35 +02:00
newPos.vy = m_base.vy - ( ( SPIDER_CRAB_HEIGHT * rsin( abs( ( m_extension << 11 ) / m_attackDist ) ) ) >> 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
2001-04-20 00:09:59 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::processCollision()
2001-04-05 22:44:30 +02:00
{
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
}
2001-04-20 00:09:59 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::processSpiderCrabInitJumpMovement( int _frames )
2001-04-19 01:12:24 +02:00
{
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 );
2001-04-26 23:29:44 +02:00
/*if ( m_extension > 64 )
2001-04-19 01:12:24 +02:00
{
// check for collision on the way back down
if ( m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy ) < 0 )
{
collision = true;
}
}
if ( completed || collision )
2001-04-26 23:29:44 +02:00
{
m_state = SPIDER_CRAB_DEFAULT;
}*/
if ( m_extension > 64 )
2001-04-19 01:12:24 +02:00
{
2001-04-20 22:22:16 +02:00
m_state = SPIDER_CRAB_DEFAULT;
2001-04-19 01:12:24 +02:00
}
}
2001-04-20 00:09:59 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::processMovement(int _frames)
2001-04-19 01:12:24 +02:00
{
2001-04-20 00:09:59 +02:00
s32 moveX = 0, moveY = 0;
s32 moveVel = 0;
s32 moveDist = 0;
2001-04-19 01:12:24 +02:00
2001-04-20 22:22:16 +02:00
if ( m_state == SPIDER_CRAB_INIT_JUMP )
2001-04-20 00:09:59 +02:00
{
processSpiderCrabInitJumpMovement( _frames );
}
else
{
processGenericFixedPathWalk( _frames, &moveX, &moveY );
2001-04-19 01:12:24 +02:00
2001-04-20 00:09:59 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
2001-04-19 01:12:24 +02:00
}
}
2001-04-20 00:09:59 +02:00
processMovementModifier( _frames, moveX, moveY, moveVel, moveDist );
}
2001-04-26 17:20:21 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 distY, s32 dist, s16 headingChange )
{
Pos.vx += distX;
Pos.vy += distY;
// sort out draw rotation
DVECTOR testPos1, testPos2;
testPos1 = testPos2 = Pos;
testPos1.vx -= 10;
testPos2.vx += 10;
testPos1.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 );
2001-05-08 20:57:00 +02:00
testPos2.vy += m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, 16 );
2001-04-26 17:20:21 +02:00
s32 xDist = testPos2.vx - testPos1.vx;
s32 yDist = testPos2.vy - testPos1.vy;
s16 heading = ratan2( yDist, xDist );
m_drawRotation = heading;
}
2001-04-26 23:29:44 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSpiderCrabEnemy::processEnemyCollision( CThing *thisThing )
{
if ( m_state != SPIDER_CRAB_INIT_JUMP )
{
CNpcEnemy::processEnemyCollision( thisThing );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
u8 CNpcSpiderCrabEnemy::canCollideWithEnemy()
{
return( m_state != SPIDER_CRAB_INIT_JUMP );
}