SBSPSS/source/enemy/nsstomp.cpp

205 lines
4.1 KiB
C++
Raw Normal View History

2001-01-23 18:02:45 +01:00
/*=========================================================================
nsstomp.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 22:22:16 +02:00
#ifndef __ENEMY_NSSTOMP_H__
#include "enemy\nsstomp.h"
#endif
2001-01-23 18:02:45 +01:00
#ifndef __GAME_GAME_H__
2001-02-14 17:04:41 +01:00
#include "game\game.h"
2001-01-23 18:02:45 +01:00
#endif
#ifndef __PLAYER_PLAYER_H__
2001-02-14 17:04:41 +01:00
#include "player\player.h"
2001-01-23 18:02:45 +01:00
#endif
2001-04-02 17:52:09 +02:00
#ifndef __ANIM_STOMPER_HEADER__
#include <ACTOR_STOMPER_ANIM.h>
#endif
2001-06-07 16:56:35 +02:00
#include "fx\fx.h"
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-01-23 18:02:45 +01:00
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 21:03:06 +02:00
void CNpcSkullStomperEnemy::processEnemyCollision( CThing *thisThing )
{
// do nothing
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcSkullStomperEnemy::postInit()
{
m_extendDir = EXTEND_DOWN;
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
bool CNpcSkullStomperEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
if ( playerXDistSqr < 10000 && playerYDist >= 0 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_DOWN;
2001-06-18 21:06:43 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SKULL_ATTACK, true );
2001-04-20 22:22:16 +02:00
return( true );
}
else
{
return( false );
}
}
}
}
2001-06-06 15:27:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 22:22:16 +02:00
void CNpcSkullStomperEnemy::processClose( int _frames )
2001-01-23 18:02:45 +01:00
{
2001-02-15 21:50:52 +01:00
s8 groundHeight;
s8 yMovement;
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_STOMPER_CRUSH;
m_frame = 0;
}
2001-01-23 18:02:45 +01:00
if ( m_timerTimer > 0 )
{
// wait
}
else
{
2001-02-14 17:04:41 +01:00
if ( m_extendDir == EXTEND_DOWN )
2001-01-23 18:02:45 +01:00
{
2001-02-15 21:50:52 +01:00
yMovement = m_data[m_type].speed * _frames;
2001-02-14 17:04:41 +01:00
2001-05-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-02-14 17:04:41 +01:00
2001-02-15 21:50:52 +01:00
if ( groundHeight < yMovement )
{
// colliding with ground
2001-02-14 17:04:41 +01:00
2001-07-12 20:53:06 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FALLING_ROCK_LAND, true );
2001-02-15 21:50:52 +01:00
Pos.vy += groundHeight;
2001-02-14 17:04:41 +01:00
2001-01-26 16:16:07 +01:00
// pause and change direction
2001-07-03 00:23:03 +02:00
m_timerTimer = GameState::getOneSecondInFrames();
2001-01-26 16:16:07 +01:00
m_extendDir = EXTEND_UP;
2001-06-07 16:56:35 +02:00
for ( int i = 0 ; i < 20 ; i++ )
{
DVECTOR bubblePos = Pos;
bubblePos.vx += 20 - ( getRnd() % 41 );
CFX::Create( CFX::FX_TYPE_BUBBLE_WATER, bubblePos );
}
2001-01-26 16:16:07 +01:00
}
2001-02-14 17:04:41 +01:00
else
{
// drop down
2001-01-26 16:16:07 +01:00
2001-02-15 21:50:52 +01:00
Pos.vy += yMovement;
2001-02-14 17:04:41 +01:00
}
2001-01-23 18:02:45 +01:00
}
else
{
2001-02-14 17:04:41 +01:00
if ( m_base.vx - Pos.vx == 0 && m_base.vy - Pos.vy == 0 )
2001-01-23 18:02:45 +01:00
{
2001-02-14 17:04:41 +01:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
m_npcPath.resetPath();
2001-01-23 18:02:45 +01:00
}
else
{
2001-02-14 17:04:41 +01:00
// return to original position
2001-01-26 16:16:07 +01:00
2001-02-14 17:04:41 +01:00
processGenericGotoTarget( _frames, m_base.vx - Pos.vx, m_base.vy - Pos.vy, 1 );
2001-01-23 18:02:45 +01:00
}
}
}
2001-06-06 15:27:46 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-12 23:47:22 +02:00
void CNpcSkullStomperEnemy::collidedWith( CThing *_thisThing )
{
if ( m_isActive && !m_isCaught && !m_isDying )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
ATTACK_STATE playerState = player->getAttackState();
if(playerState==ATTACK_STATE__NONE)
{
if ( !player->isRecoveringFromHit() )
{
CPlayer *player = GameScene.getPlayer();
player->takeDamage( m_data[m_type].damageToUserType,REACT__GET_DIRECTION_FROM_THING,(CThing*)this );
}
}
else
{
drawAttackEffect();
}
break;
}
case TYPE_ENEMY:
break;
default:
ASSERT(0);
break;
}
}
}