This commit is contained in:
Charles 2001-04-27 14:39:10 +00:00
parent c3df1a873c
commit 10541233ce
4 changed files with 499 additions and 0 deletions

101
source/friend/fdata.cpp Normal file
View File

@ -0,0 +1,101 @@
/*=========================================================================
fdata.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
CNpcFriend::NPC_FRIEND_DATA CNpcFriend::m_data[NPC_FRIEND_UNIT_TYPE_MAX] =
{
{ // NPC_FRIEND_BARNACLE_BOY
ACTORS_CLAM_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
{ // NPC_FRIEND_GARY
ACTORS_CLAM_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
{ // NPC_FRIEND_KRUSTY
ACTORS_CLAM_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
{ // NPC_FRIEND_MERMAID_MAN
ACTORS_CLAM_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
{ // NPC_FRIEND_PATRICK
ACTORS_CLAM_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
{ // NPC_FRIEND_SANDY_CHEEKS
ACTORS_CLAM_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
{ // NPC_FRIEND_SQUIDWARD
ACTORS_SQUIDWARD_SBK,
NPC_FRIEND_MOVEMENT_STATIC,
true,
3,
128,
false,
DAMAGE__HIT_ENEMY,
},
};
CNpcFriend::NPC_FRIEND_UNIT_TYPE CNpcFriend::mapEditConvertTable[NPC_FRIEND_UNIT_TYPE_MAX] =
{
NPC_FRIEND_BARNACLE_BOY,
NPC_FRIEND_GARY,
NPC_FRIEND_KRUSTY,
NPC_FRIEND_MERMAID_MAN,
NPC_FRIEND_PATRICK,
NPC_FRIEND_SANDY_CHEEKS,
NPC_FRIEND_SQUIDWARD,
};

82
source/friend/fgary.cpp Normal file
View File

@ -0,0 +1,82 @@
/*=========================================================================
fgary.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
void CNpcFriend::processGaryMovement( int _frames )
{
s8 multiplier = -1 + ( 2 * m_extension );
s32 maxHeight = 20;
s32 fallSpeed = 3;
s8 yMovement = fallSpeed * _frames;
s8 groundHeight;
// check vertical collision
groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= 0 )
{
// groundHeight <= 0 indicates either on ground or below ground
// check horizontal collision
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
{
// reverse direction
m_extension = !m_extension;
}
else
{
// make sure we are on the ground, not below it
Pos.vy += groundHeight;
Pos.vx += multiplier * _frames;
}
}
else
{
// above ground
if ( groundHeight < yMovement )
{
// colliding with ground
Pos.vy += groundHeight;
if ( m_layerCollision->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
{
// reverse direction
m_extension = !m_extension;
}
else
{
Pos.vx += multiplier * _frames;
}
}
else
{
Pos.vy += yMovement;
}
}
}

212
source/friend/friend.cpp Normal file
View File

@ -0,0 +1,212 @@
/*=========================================================================
friend.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __GAME_CONVO_H__
#include "game\convo.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Friend NPCs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcFriend *CNpcFriend::Create(sThingActor *ThisActor)
{
CNpcFriend *friendNpc;
NPC_FRIEND_UNIT_TYPE friendType = CNpcFriend::getTypeFromMapEdit( ThisActor->Type );
switch( friendType )
{
case CNpcFriend::NPC_FRIEND_SQUIDWARD:
{
friendNpc = new ("squidward") CNpcFriend;
break;
}
default:
{
printf("UNKNOWN %i\n",friendType);
friendNpc = NULL;
ASSERT(0);
break;
}
}
ASSERT( friendNpc );
friendNpc->setType( friendType );
u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor));
u16 newXPos, newYPos;
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
startPos.vx = newXPos << 4;
startPos.vy = newYPos << 4;
friendNpc->init( startPos );
return( friendNpc );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcFriend::NPC_FRIEND_UNIT_TYPE CNpcFriend::getTypeFromMapEdit( u16 newType )
{
return( mapEditConvertTable[newType - NPC_FRIEND_MAPEDIT_OFFSET] );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::init()
{
CNpcThing::init();
m_extension = EXTEND_RIGHT;
m_actorGfx = CActorPool::GetActor( (FileEquate) m_data[m_type].skelType );
//m_animPlaying = true;
m_animNo = 0;
m_frame = 0;
m_reversed = false;
DVECTOR ofs = getCollisionSize();
m_drawOffset.vx = 0;
m_drawOffset.vy = -( ofs.vy >> 1 );
setCollisionCentreOffset( 0, -( ofs.vy >> 1 ) );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::init( DVECTOR initPos )
{
init();
Pos = initPos;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::shutdown()
{
//m_spriteBank->dump(); delete m_spriteBank;
delete m_actorGfx;
CNpcThing::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::think(int _frames)
{
CNpcThing::think(_frames);
switch( m_data[m_type].movementFunc )
{
case NPC_FRIEND_MOVEMENT_GARY:
processGaryMovement( _frames );
break;
case NPC_FRIEND_MOVEMENT_STATIC:
default:
break;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::render()
{
CNpcThing::render();
// Render
DVECTOR renderPos;
DVECTOR offset = CLevel::getCameraPos();
renderPos.vx = Pos.vx - offset.vx;
renderPos.vy = Pos.vy - offset.vy;
if ( renderPos.vx >= 0 && renderPos.vx <= VidGetScrW() )
{
if ( renderPos.vy >= 0 && renderPos.vy <= VidGetScrH() )
{
m_actorGfx->Render(renderPos,m_animNo,m_frame,m_reversed);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::processEvent( GAME_EVENT evt, CThing *sourceThing )
{
switch( evt )
{
case USER_REQUEST_TALK_EVENT:
{
if ( m_data[this->m_type].canTalk )
{
DVECTOR sourcePos;
s32 xDiffSqr, yDiffSqr;
// check talk distance
sourcePos = sourceThing->getPos();
xDiffSqr = this->Pos.vx - sourcePos.vx;
xDiffSqr *= xDiffSqr;
yDiffSqr = this->Pos.vy - sourcePos.vy;
yDiffSqr *= yDiffSqr;
if ( xDiffSqr + yDiffSqr < 10000 )
{
if( !CConversation::isActive() )
{
CConversation::trigger( SCRIPTS_SPEECHTEST_DAT );
}
}
}
break;
}
default:
// ignore
break;
}
}

104
source/friend/friend.h Normal file
View File

@ -0,0 +1,104 @@
/*=========================================================================
friend.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __FRIEND_FRIEND_H__
#define __FRIEND_FRIEND_H__
#ifndef __THING_THING_H__
#include "thing/thing.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
class CNpcFriend : public CNpcThing
{
public:
enum NPC_FRIEND_UNIT_TYPE
{
NPC_FRIEND_BARNACLE_BOY = 0,
NPC_FRIEND_GARY = 1,
NPC_FRIEND_KRUSTY,
NPC_FRIEND_MERMAID_MAN,
NPC_FRIEND_PATRICK,
NPC_FRIEND_SANDY_CHEEKS,
NPC_FRIEND_SQUIDWARD,
NPC_FRIEND_UNIT_TYPE_MAX,
};
void init();
void init( DVECTOR initPos );
void shutdown();
void think(int _frames);
void render();
void processEvent( GAME_EVENT evt, CThing *sourceThing );
void setLayerCollision( class CLayerCollision *_layer ) {m_layerCollision=_layer;}
void setType( NPC_FRIEND_UNIT_TYPE newType ) {m_type = newType;}
static CNpcFriend *Create(sThingActor *ThisActor);
static NPC_FRIEND_UNIT_TYPE getTypeFromMapEdit( u16 newType );
private:
class CLayerCollision *m_layerCollision;
protected:
enum NPC_FRIEND_MOVEMENT_FUNC
{
NPC_FRIEND_MOVEMENT_STATIC = 0,
NPC_FRIEND_MOVEMENT_GARY = 1,
};
typedef struct NPC_FRIEND_DATA_TYPE
{
int skelType;
NPC_FRIEND_MOVEMENT_FUNC movementFunc;
bool canTalk;
u8 speed;
u16 turnSpeed;
bool detectCollision;
DAMAGE_TYPE damageToUserType;
}
NPC_FRIEND_DATA;
// gary functions
void processGaryMovement( int _frames );
// data
static NPC_FRIEND_DATA m_data[NPC_FRIEND_UNIT_TYPE_MAX];
static NPC_FRIEND_UNIT_TYPE mapEditConvertTable[NPC_FRIEND_UNIT_TYPE_MAX];
enum
{
EXTEND_RIGHT = true,
EXTEND_LEFT = false,
NPC_FRIEND_MAPEDIT_OFFSET = 1,
};
// internal variables
NPC_FRIEND_UNIT_TYPE m_type;
s32 m_extension;
int m_frame;
int m_animNo;
CActorGfx *m_actorGfx;
DVECTOR m_drawOffset;
bool m_reversed;
};
#endif