This commit is contained in:
parent
dc9561dc93
commit
c33e2a4acd
5 changed files with 131 additions and 5 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
/*=========================================================================
|
||||||
|
|
||||||
|
npc.cpp
|
||||||
|
|
||||||
|
Author: CRB
|
||||||
|
Created:
|
||||||
|
Project: Spongebob
|
||||||
|
Purpose:
|
||||||
|
|
||||||
|
Copyright (c) 2000 Climax Development Ltd
|
||||||
|
|
||||||
|
===========================================================================*/
|
||||||
|
|
||||||
#include "enemy\npc.h"
|
#include "enemy\npc.h"
|
||||||
|
|
||||||
#ifndef __LEVEL_LEVEL_H__
|
#ifndef __LEVEL_LEVEL_H__
|
||||||
|
@ -190,7 +203,7 @@ void CNpc::processEvent( GAME_EVENT evt, CThing *sourceThing )
|
||||||
if ( m_data[this->m_type].canTalk )
|
if ( m_data[this->m_type].canTalk )
|
||||||
{
|
{
|
||||||
DVECTOR sourcePos;
|
DVECTOR sourcePos;
|
||||||
int xDiffSqr, yDiffSqr;
|
s32 xDiffSqr, yDiffSqr;
|
||||||
|
|
||||||
// check talk distance
|
// check talk distance
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*=========================================================================
|
||||||
|
|
||||||
|
npc.h
|
||||||
|
|
||||||
|
Author: CRB
|
||||||
|
Created:
|
||||||
|
Project: Spongebob
|
||||||
|
Purpose:
|
||||||
|
|
||||||
|
Copyright (c) 2000 Climax Development Ltd
|
||||||
|
|
||||||
|
===========================================================================*/
|
||||||
|
|
||||||
#ifndef __NPC_H__
|
#ifndef __NPC_H__
|
||||||
#define __NPC_H__
|
#define __NPC_H__
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
|
|
||||||
===========================================================================*/
|
===========================================================================*/
|
||||||
|
|
||||||
|
#ifndef __ENEMY_NCPPATH_H__
|
||||||
|
#include "enemy\ncppath.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
bool CNpcWaypoint::isPointNear( DVECTOR testPos )
|
bool CNpcWaypoint::isPointNear( DVECTOR testPos )
|
||||||
{
|
{
|
||||||
s32 xDistSqr, yDistSqr;
|
s32 xDistSqr, yDistSqr;
|
||||||
|
@ -31,6 +35,22 @@ bool CNpcWaypoint::isPointNear( DVECTOR testPos )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CNpcPath::initPath()
|
||||||
|
{
|
||||||
|
int loop;
|
||||||
|
|
||||||
|
for ( loop = 0 ; loop < NPC_MAX_WAYPOINTS ; loop++ )
|
||||||
|
{
|
||||||
|
waypoint[loop].pos.vx = 0;
|
||||||
|
waypoint[loop].pox.vy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathType = SINGLE_USE_PATH;
|
||||||
|
currentWaypoint = 0;
|
||||||
|
waypointCount = 0;
|
||||||
|
reversePath = false;
|
||||||
|
}
|
||||||
|
|
||||||
void CNpcPath::addWaypoint( DVECTOR newPos )
|
void CNpcPath::addWaypoint( DVECTOR newPos )
|
||||||
{
|
{
|
||||||
if ( waypointCount < NPC_MAX_WAYPOINTS )
|
if ( waypointCount < NPC_MAX_WAYPOINTS )
|
||||||
|
@ -40,6 +60,71 @@ void CNpcPath::addWaypoint( DVECTOR newPos )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPathType( NPC_PATH_TYPE newPathType );
|
void CNpcPath::setPathType( NPC_PATH_TYPE newPathType )
|
||||||
bool incPath();
|
{
|
||||||
bool CNpcPath::incPath
|
pathType = newPathType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CNpcPath::incPath()
|
||||||
|
{
|
||||||
|
if ( !reversePath )
|
||||||
|
{
|
||||||
|
if ( currentWaypoint < waypointCount )
|
||||||
|
{
|
||||||
|
currentWaypoint++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch( pathType )
|
||||||
|
{
|
||||||
|
case SINGLE_USE_PATH:
|
||||||
|
// path is completed
|
||||||
|
|
||||||
|
return( true );
|
||||||
|
|
||||||
|
case REPEATING_PATH:
|
||||||
|
// go back to start
|
||||||
|
|
||||||
|
currentWaypoint = 0;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PONG_PATH:
|
||||||
|
// reverse path
|
||||||
|
|
||||||
|
reversePath = !reversePath;
|
||||||
|
currentWaypoint--;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// must be pong path if reversed
|
||||||
|
|
||||||
|
if ( currentWaypoint > 0 )
|
||||||
|
{
|
||||||
|
currentWaypoint--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reversePath = !reversePath;
|
||||||
|
currentWaypoint++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNpcPath::think( DVECTOR currentPos )
|
||||||
|
{
|
||||||
|
CNpcWaypoint *currentWaypoint;
|
||||||
|
|
||||||
|
currentWaypoint = &waypoint[currentWaypoint]
|
||||||
|
|
||||||
|
if ( currentWaypoint->isPointNear( currentPos ) )
|
||||||
|
{
|
||||||
|
incPath();
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
===========================================================================*/
|
===========================================================================*/
|
||||||
|
|
||||||
|
#ifndef __ENEMY_NCPPATH_H__
|
||||||
|
#define __ENEMY_NCPPATH_H__
|
||||||
|
|
||||||
class CNpcWaypoint
|
class CNpcWaypoint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -38,9 +41,14 @@ private:
|
||||||
NPC_PATH_TYPE pathType;
|
NPC_PATH_TYPE pathType;
|
||||||
u8 currentWaypoint;
|
u8 currentWaypoint;
|
||||||
u8 waypointCount;
|
u8 waypointCount;
|
||||||
|
bool reversePath;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void initPath();
|
||||||
void addWaypoint( DVECTOR newPos );
|
void addWaypoint( DVECTOR newPos );
|
||||||
void setPathType( NPC_PATH_TYPE newPathType );
|
void setPathType( NPC_PATH_TYPE newPathType );
|
||||||
bool incPath();
|
bool incPath();
|
||||||
|
void think( DVECTOR currentPos );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -131,6 +131,14 @@ SOURCE=..\..\..\source\enemy\npc.cpp
|
||||||
|
|
||||||
SOURCE=..\..\..\source\enemy\npc.h
|
SOURCE=..\..\..\source\enemy\npc.h
|
||||||
# End Source File
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\source\enemy\npcpath.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\source\enemy\npcpath.h
|
||||||
|
# End Source File
|
||||||
# End Group
|
# End Group
|
||||||
# Begin Group "fileio"
|
# Begin Group "fileio"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue