This commit is contained in:
Charles 2001-05-10 14:00:29 +00:00
parent 6fb47fb760
commit 429e2197f2
4 changed files with 436 additions and 0 deletions

255
source/enemy/nsjback.cpp Normal file
View File

@ -0,0 +1,255 @@
/*=========================================================================
nsjback.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NSJBACK_H__
#include "enemy\nsjback.h"
#endif
#ifndef __JELLFISH_JELLFISH_H__
#include "jellfish\jellfish.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSmallJellyfishBackgroundEnemy::postInit()
{
CNpcSmallJellyfishEnemy::postInit();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CNpcSmallJellyfishBackgroundEnemy::processSensor()
{
// no sensor
return( false );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSmallJellyfishBackgroundEnemy::processMovement( int _frames )
{
// change direction?
DVECTOR renderPos;
DVECTOR offset = CLevel::getCameraPos();
renderPos.vx = Pos.vx - offset.vx;
renderPos.vy = Pos.vy - offset.vy;
if ( renderPos.vx < -50 || renderPos.vx > VidGetScrW() + 50 ||
renderPos.vy < -50 || renderPos.vy > VidGetScrH() + 50 )
{
setToShutdown();
return;
}
if ( renderPos.vx >= 0 && renderPos.vx <= VidGetScrW() )
{
if ( renderPos.vy >= 0 && renderPos.vy <= VidGetScrH() )
{
u8 directionChange = getRnd() % 100;
if ( directionChange == 0 )
{
m_targetHeading += -1024 + ( getRnd() % 2049 );
}
}
}
s32 moveX, moveY, moveDist, moveVel;
s16 decDir, incDir;
s16 maxTurnRate = m_data[m_type].turnSpeed;
decDir = m_heading - m_targetHeading;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = m_targetHeading - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = -decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist < -maxTurnRate )
{
moveDist = -maxTurnRate;
}
else if ( moveDist > maxTurnRate )
{
moveDist = maxTurnRate;
}
m_heading += moveDist;
m_heading &= 4095;
s32 preShiftX = _frames * m_speed * rcos( m_heading );
s32 preShiftY = _frames * m_speed * rsin( m_heading );
moveX = preShiftX >> 12;
if ( !moveX && preShiftX )
{
moveX = preShiftX / abs( preShiftX );
}
moveY = preShiftY >> 12;
if ( !moveY && preShiftY )
{
moveY = preShiftY / abs( preShiftY );
}
moveVel = ( _frames * m_speed ) << 8;
if ( processGroundCollisionReverse( &moveX, &moveY ) )
{
m_targetHeading += 2048;
m_targetHeading &= 4095;
}
processMovementModifier( _frames, moveX, moveY, moveVel, moveDist );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSmallJellyfishBackgroundEnemy::shutdown()
{
CNpcSmallJellyfishEnemy::shutdown();
CJellyfishGenerator::decCounter();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSmallJellyfishBackgroundEnemy::processUserCollision( CThing *thisThing )
{
DVECTOR otherPos = thisThing->getPos();
DVECTOR otherDelta = thisThing->getPosDelta();
s32 xDist = Pos.vx - otherPos.vx;
s32 yDist = Pos.vy - otherPos.vy;
s16 headingFromTarget = ratan2( yDist, xDist );
if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) )
{
otherDelta.vx = -otherDelta.vx;
}
if ( ( yDist > 0 && otherDelta.vy < 0 ) || ( yDist < 0 && otherDelta.vy > 0 ) )
{
otherDelta.vy = -otherDelta.vy;
}
Pos.vx += otherDelta.vx;
Pos.vy += otherDelta.vy;
m_targetHeading = m_heading = headingFromTarget;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSmallJellyfishBackgroundEnemy::render()
{
SprFrame = NULL;
if ( m_isActive )
{
CEnemyThing::render();
// Render
DVECTOR renderPos;
DVECTOR origRenderPos;
DVECTOR offset = CLevel::getCameraPos();
int spriteWidth = m_spriteBank->getFrameWidth( m_frame >> 8 );
int spriteHeight = m_spriteBank->getFrameHeight( m_frame >> 8 );
renderPos.vx = Pos.vx - offset.vx;
origRenderPos.vx = renderPos.vx;
renderPos.vx += m_drawOffset.vx;
renderPos.vy = Pos.vy - offset.vy;
origRenderPos.vy = renderPos.vy;
renderPos.vy += m_drawOffset.vy - ( spriteHeight >> 1 );
CRECT collisionRect = getCollisionArea();
collisionRect.x1 -= Pos.vx;
collisionRect.x2 -= Pos.vx;
collisionRect.y1 -= Pos.vy;
collisionRect.y2 -= Pos.vy;
if ( renderPos.vx + collisionRect.x2 >= 0 && renderPos.vx + collisionRect.x1 <= VidGetScrW() )
{
if ( renderPos.vy + collisionRect.y2 >= 0 && renderPos.vy + collisionRect.y1 <= VidGetScrH() )
{
SprFrame = m_spriteBank->printRotatedScaledSprite( FRM_JELLYFISH1_SWIM1 + ( m_frame >> 8 ),renderPos.vx,renderPos.vy,4096,4096,m_drawRotation,15);
setRGB0( SprFrame, 255, 128, 255 ); // Let me know if these change! ALso ket me know when the different coloured ones go in pls! (pkg)
// get xmax, xmin, ymax, ymin
s32 XMax;
s32 XMin;
s32 YMax;
s32 YMin;
XMin=SprFrame->x0;
if (XMin>SprFrame->x1) XMin=SprFrame->x1;
if (XMin>SprFrame->x2) XMin=SprFrame->x2;
if (XMin>SprFrame->x3) XMin=SprFrame->x3;
XMax=SprFrame->x0;
if (XMax<SprFrame->x1) XMax=SprFrame->x1;
if (XMax<SprFrame->x2) XMax=SprFrame->x2;
if (XMax<SprFrame->x3) XMax=SprFrame->x3;
YMin=SprFrame->y0;
if (YMin>SprFrame->y1) YMin=SprFrame->y1;
if (YMin>SprFrame->y2) YMin=SprFrame->y2;
if (YMin>SprFrame->y3) YMin=SprFrame->y3;
YMax=SprFrame->y0;
if (YMax<SprFrame->y1) YMax=SprFrame->y1;
if (YMax<SprFrame->y2) YMax=SprFrame->y2;
if (YMax<SprFrame->y3) YMax=SprFrame->y3;
XMax -= origRenderPos.vx;
XMin -= origRenderPos.vx;
YMax -= origRenderPos.vy;
YMin -= origRenderPos.vy;
setCollisionSize( ( XMax - XMin ), ( YMax - YMin ) );
setCollisionCentreOffset( ( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 );
}
}
}
}

36
source/enemy/nsjback.h Normal file
View File

@ -0,0 +1,36 @@
/*=========================================================================
nsjback.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NSJBACK_H__
#define __ENEMY_NSJBACK_H__
#ifndef __ENEMY_NSJFISH_H__
#include "enemy\nsjfish.h"
#endif
class CNpcSmallJellyfishBackgroundEnemy : public CNpcSmallJellyfishEnemy
{
public:
virtual void render();
virtual void postInit();
virtual void setTargetHeading( s16 newTargetHeading ) {m_targetHeading = newTargetHeading;}
protected:
virtual bool processSensor();
virtual void processMovement( int _frames );
virtual void shutdown();
virtual void processUserCollision( CThing *thisThing );
s16 m_targetHeading;
};
#endif

View File

@ -0,0 +1,109 @@
/*=========================================================================
jellfish.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __JELLFISH_JELLFISH_H__
#include "jellfish\jellfish.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __ENEMY_NSJBACK_H__
#include "enemy\nsjback.h"
#endif
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
u8 CJellyfishGenerator::m_jellyfishCount;
s32 CJellyfishGenerator::m_timer;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CJellyfishGenerator::init()
{
m_timer = 1 * GameState::getOneSecondInFrames();
m_jellyfishCount = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CJellyfishGenerator::think( int _frames, CLevel *level )
{
if ( m_timer <= 0 )
{
if ( m_jellyfishCount < 10 )
{
// add jellyfish
m_timer = 1 * GameState::getOneSecondInFrames();
m_jellyfishCount++;
CNpcEnemy *enemy;
enemy = new( "jellyfish" ) CNpcSmallJellyfishBackgroundEnemy;
ASSERT(enemy);
enemy->setType( CNpcEnemy::NPC_SMALL_JELLYFISH_BACKGROUND );
enemy->init();
enemy->setLayerCollision( level->getCollisionLayer() );
DVECTOR offset = CLevel::getCameraPos();
DVECTOR startPos;
if ( ( getRnd() % 10 ) > 4 )
{
CNpcSmallJellyfishBackgroundEnemy *jfish = ( CNpcSmallJellyfishBackgroundEnemy * ) enemy;
jfish->setTargetHeading( 0 );
startPos.vx = offset.vx - 20;
}
else
{
CNpcSmallJellyfishBackgroundEnemy *jfish = ( CNpcSmallJellyfishBackgroundEnemy * ) enemy;
jfish->setTargetHeading( 2048 );
startPos.vx = offset.vx + VidGetScrW() + 20;
}
startPos.vy = offset.vy + ( getRnd() % VidGetScrH() );
enemy->setStartPos( startPos.vx >> 4, startPos.vy >> 4 );
enemy->postInit();
}
}
else
{
m_timer -= _frames;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CJellyfishGenerator::decCounter()
{
if ( m_jellyfishCount > 0 )
{
m_jellyfishCount--;
}
}

View File

@ -0,0 +1,36 @@
/*=========================================================================
jellfish.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __JELLFISH_JELLFISH_H__
#define __JELLFISH_JELLFISH_H__
#ifndef _GLOBAL_HEADER_
#include "system\global.h"
#endif
#ifndef __LEVEL_LEVEL_H__
#include "level\level.h"
#endif
class CJellyfishGenerator
{
public:
static void init();
static void think( int _frames, CLevel *level );
static void decCounter();
protected:
static u8 m_jellyfishCount;
static s32 m_timer;
};
#endif