SBSPSS/source/enemy/nshrkman.cpp

282 lines
5.3 KiB
C++
Raw Normal View History

2001-01-19 21:51:24 +01:00
/*=========================================================================
nshrkman.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_NSHRKMAN_H__
#include "enemy\nshrkman.h"
#endif
2001-01-19 21:51:24 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-06-13 15:52:26 +02:00
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-04-02 22:35:43 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-06-13 15:52:26 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
#endif
2001-06-21 00:02:19 +02:00
#ifndef __ANIM_MANRAY_HEADER__
#include <ACTOR_MANRAY_ANIM.h>
2001-04-02 17:52:09 +02:00
#endif
2001-06-13 15:52:26 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 16:48:15 +02:00
void CNpcSharkManEnemy::processMovement( int _frames )
2001-04-02 22:35:43 +02:00
{
2001-04-20 16:48:15 +02:00
s32 moveX = 0, moveY = 0;
2001-06-21 00:02:19 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_frame = 0;
m_animNo = m_data[m_type].moveAnim;
}
processGenericFixedPathWalk( _frames, &moveX, &moveY );
/*if ( m_movementTimer > 0 )
2001-04-02 22:35:43 +02:00
{
m_movementTimer -= _frames;
if ( m_animNo == m_data[m_type].moveAnim )
{
2001-04-20 16:48:15 +02:00
processGenericFixedPathWalk( _frames, &moveX, &moveY );
2001-04-02 22:35:43 +02:00
}
if ( !m_animPlaying )
{
m_animPlaying = true;
m_frame = 0;
}
}
else
{
// change anim
if ( m_animNo == m_data[m_type].moveAnim )
{
u8 newAction = getRnd() % 5;
switch( newAction )
{
case 0:
{
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_animNo = ANIM_SHARKMAN_IDLE1_;
break;
}
case 1:
{
m_movementTimer = GameState::getOneSecondInFrames() * 8;
m_animNo = m_data[m_type].moveAnim;
break;
}
case 2:
{
m_movementTimer = GameState::getOneSecondInFrames() * 1;
m_animNo = ANIM_SHARKMAN_IDLE2_;
break;
}
case 3:
{
m_movementTimer = GameState::getOneSecondInFrames() >> 1;
m_animNo = ANIM_SHARKMAN_KICK_SAND;
break;
}
case 4:
{
m_movementTimer = GameState::getOneSecondInFrames() * 3;
m_animNo = ANIM_SHARKMAN_PUSHUPS;
break;
}
}
}
else
{
// return to move anim
m_movementTimer = GameState::getOneSecondInFrames() * 8;
m_animNo = m_data[m_type].moveAnim;
}
m_animPlaying = true;
m_frame = 0;
2001-06-21 00:02:19 +02:00
}*/
2001-04-20 16:48:15 +02:00
processMovementModifier( _frames, moveX, moveY, 0, 0 );
2001-04-02 22:35:43 +02:00
}
2001-06-13 15:52:26 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 16:48:15 +02:00
void CNpcSharkManEnemy::processClose( int _frames )
2001-06-13 15:52:26 +02:00
{
2001-06-21 00:02:19 +02:00
if ( m_animNo != ANIM_MANRAY_ATTACK )
2001-06-13 15:52:26 +02:00
{
m_animPlaying = true;
2001-06-21 00:02:19 +02:00
m_animNo = ANIM_MANRAY_ATTACK;
2001-06-13 15:52:26 +02:00
m_frame = 0;
}
else if ( !m_animPlaying )
{
// anim finished, fire
DVECTOR newPos = Pos;
newPos.vy -= 50;
s32 xDist, yDist;
CPlayer *player = GameScene.getPlayer();
DVECTOR playerPos = player->getPos();
xDist = playerPos.vx - newPos.vx;
yDist = playerPos.vy - newPos.vy;
s16 heading = ratan2( yDist, xDist ) & 4095;
CProjectile *projectile;
2001-06-14 18:07:48 +02:00
projectile = CProjectile::Create();
2001-06-13 15:52:26 +02:00
projectile->init( newPos, heading );
projectile->setGraphic( FRM__LIGHTNING2 );
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
m_animNo = m_data[m_type].moveAnim;
m_animPlaying = true;
m_frame = 0;
}
}
/*void CNpcSharkManEnemy::processClose( int _frames )
2001-01-19 21:51:24 +01:00
{
2001-02-22 17:56:27 +01:00
s32 moveX = 0, moveY = 0;
s32 groundHeight;
2001-01-19 21:51:24 +01:00
s16 decDir, incDir, moveDist;
2001-02-22 17:56:27 +01:00
s32 direction;
2001-04-04 21:55:49 +02:00
s32 maxHeight = 20;
s32 fallSpeed = 3;
2001-02-22 17:56:27 +01:00
s8 yMovement = fallSpeed * _frames;
2001-01-19 21:51:24 +01:00
2001-02-07 17:42:13 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-01-19 21:51:24 +01:00
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = ANIM_SHARKMAN_RUN;
m_frame = 0;
}
2001-01-19 21:51:24 +01:00
decDir = m_heading - headingToPlayer;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToPlayer - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = -decDir;
}
else
{
moveDist = incDir;
}
2001-01-19 22:46:30 +01:00
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
2001-02-07 17:42:13 +01:00
if ( abs( moveDist ) < 1024 && abs( xDistWaypoint ) >= abs( playerXDist ) )
2001-01-19 21:51:24 +01:00
{
// continue charge
2001-02-22 17:56:27 +01:00
if ( playerXDist != 0 )
2001-01-19 21:51:24 +01:00
{
2001-02-22 17:56:27 +01:00
direction = playerXDist / abs( playerXDist );
2001-01-19 21:51:24 +01:00
}
else
{
2001-02-22 17:56:27 +01:00
direction = 1;
2001-01-19 21:51:24 +01:00
}
2001-05-25 20:43:47 +02:00
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( _frames * m_velocity * direction ), Pos.vy ) < -maxHeight )
2001-01-19 21:51:24 +01:00
{
2001-02-22 17:56:27 +01:00
// there is an obstacle in the way, abort
2001-01-19 21:51:24 +01:00
2001-02-22 17:56:27 +01:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
2001-04-02 22:35:43 +02:00
m_animNo = m_data[m_type].moveAnim;
2001-01-19 21:51:24 +01:00
}
2001-02-22 17:56:27 +01:00
else
{
// check for vertical movement
2001-01-19 21:51:24 +01:00
2001-05-25 20:43:47 +02:00
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
2001-02-22 17:56:27 +01:00
if ( groundHeight <= yMovement )
{
// groundHeight <= yMovement indicates either just above ground or on or below ground
moveX = _frames * m_velocity * direction;
moveY = groundHeight;
}
else
{
// fall
moveY = yMovement;
}
Pos.vx += moveX;
Pos.vy += moveY;
}
2001-01-19 21:51:24 +01:00
}
else
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
2001-04-02 22:35:43 +02:00
m_animNo = m_data[m_type].moveAnim;
2001-01-19 21:51:24 +01:00
}
2001-06-13 15:52:26 +02:00
}*/