This commit is contained in:
Charles 2001-01-19 21:46:30 +00:00
parent 7d427ff926
commit b2d3ef1445
9 changed files with 474 additions and 24 deletions

View File

@ -56,6 +56,10 @@ enemy_src := 2denemy \
npcpath \
nsjfish \
nclam \
nscrab \
nnsfish \
ngpirate \
nshrkman \
enemy
fileio_src := fileio \

View File

@ -28,7 +28,7 @@ void CNpc::processCloseClamAttack( int _frames )
{
s32 velocity;
if ( m_extendOut )
if ( m_extendDir == EXTEND_UP )
{
m_movementTimer -= _frames;
@ -45,10 +45,10 @@ void CNpc::processCloseClamAttack( int _frames )
}
else
{
m_extendOut = false;
m_extendDir = EXTEND_DOWN;
}
}
else
else if ( m_extendDir == EXTEND_DOWN )
{
// retract

View File

@ -112,7 +112,7 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] =
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
0,
128,
},
@ -123,7 +123,7 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] =
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_CLAM_ATTACK,
NPC_TIMER_NONE,
3,
0,
128,
},
@ -163,12 +163,203 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] =
128,
},
{ // NPC_SEA_SNAKE_1
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
256,
},
{ // NPC_SEA_SNAKE_2
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
256,
},
{ // NPC_PUFFA_FISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_ANGLER_FISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
1,
128,
},
{ // NPC_HERMIT_CRAB
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_MINE
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_BOOGER_MONSTER
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_SPIDER_CRAB
NPC_INIT_DEFAULT,
NPC_SENSOR_SPIDER_CRAB_USER_CLOSE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_SPIDER_CRAB_ATTACK,
NPC_TIMER_NONE,
false,
3,
2048,
},
{ // NPC_EYEBALL
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_BABY_OCTOPUS
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_ZOMBIE_FISH_FOLK
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_NINJA_STARFISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NINJA_STARFISH_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NINJA_STARFISH_ATTACK,
NPC_TIMER_NONE,
false,
3,
64,
},
{ // NPC_GHOST
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_GHOST_PIRATE
NPC_INIT_DEFAULT,
NPC_SENSOR_GHOST_PIRATE_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_GHOST_PIRATE_ATTACK,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_FLAMING_SKULL
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_SHARK_MAN
NPC_INIT_DEFAULT,
NPC_SENSOR_SHARK_MAN_USER_VISIBLE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_SHARK_MAN_ATTACK,
NPC_TIMER_NONE,
false,
3,
2048,
},
};
void CNpc::init()
{
m_type = NPC_FISH_FOLK;
m_type = NPC_SHARK_MAN;
m_heading = 3072;
m_movementTimer = 0;
@ -201,7 +392,7 @@ void CNpc::init()
m_npcPath.addWaypoint( newPos );
newPos.vx = 500;
/*newPos.vx = 500;
newPos.vy = 100;
m_npcPath.addWaypoint( newPos );
@ -209,7 +400,7 @@ void CNpc::init()
newPos.vx = 100;
newPos.vy = 100;
m_npcPath.addWaypoint( newPos );
m_npcPath.addWaypoint( newPos );*/
m_npcPath.setPathType( REPEATING_PATH );
@ -277,13 +468,14 @@ bool CNpc::processSensor()
DVECTOR playerPos = player->getPos();
s32 xDist, yDist;
s32 xDistSqr, yDistSqr;
xDistSqr = playerPos.vx - this->Pos.vx;
xDistSqr *= xDistSqr;
xDist = playerPos.vx - this->Pos.vx;
xDistSqr = xDist * xDist;
yDistSqr = playerPos.vy - this->Pos.vy;
yDistSqr *= yDistSqr;
yDist = playerPos.vy - this->Pos.vy;
yDistSqr = yDist * yDist;
switch( m_sensorFunc )
{
@ -291,8 +483,8 @@ bool CNpc::processSensor()
{
if ( xDistSqr + yDistSqr < 10000 )
{
this->m_controlFunc = NPC_CONTROL_CLOSE;
this->m_evadeClockwise = ( getRnd() % 2 ) - 1;
m_controlFunc = NPC_CONTROL_CLOSE;
m_evadeClockwise = ( getRnd() % 2 ) - 1;
return( true );
}
@ -306,11 +498,11 @@ bool CNpc::processSensor()
{
if ( xDistSqr + yDistSqr < 10000 )
{
this->m_controlFunc = NPC_CONTROL_CLOSE;
this->m_extendOut = true;
this->m_extension = 0;
this->m_movementTimer = GameState::getOneSecondInFrames() >> 3;
this->m_velocity = ( getRnd() % 6 ) + 1;
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
m_movementTimer = GameState::getOneSecondInFrames() >> 3;
m_velocity = ( getRnd() % 6 ) + 1;
return( true );
}
@ -320,6 +512,167 @@ bool CNpc::processSensor()
}
}
case NPC_SENSOR_SPIDER_CRAB_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extension = 0;
m_velocity = 5;
m_extensionBase = Pos;
if ( playerPos.vx < Pos.vx )
{
m_extendDir = EXTEND_LEFT;
}
else
{
m_extendDir = EXTEND_RIGHT;
}
return( true );
}
else
{
return( false );
}
}
case NPC_SENSOR_NINJA_STARFISH_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_velocity = m_data[m_type].speed;
return( true );
}
else
{
return( false );
}
}
case NPC_SENSOR_GHOST_PIRATE_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
m_movementTimer = GameState::getOneSecondInFrames() >> 1;
m_velocity = 4;
return( true );
}
else
{
return( false );
}
}
case NPC_SENSOR_SHARK_MAN_USER_VISIBLE:
{
s32 xDistWaypoint, yDistWaypoint;
if ( abs( xDist ) < 500 )
{
// within range
// make sure user is closer to shark man than next waypoint
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
if ( abs( xDist ) < abs( xDistWaypoint ) )
{
s16 headingToPlayer = ratan2( yDist, xDist );
s16 decDir, incDir, moveDist;
s32 headingToWaypoint = ratan2( yDistWaypoint, xDistWaypoint );
// check waypoint is in the same direction as the user
decDir = headingToPlayer - headingToWaypoint;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToWaypoint - headingToPlayer;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist > 512 )
{
return( false );
}
else
{
// check if shark man is facing user
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;
}
if ( moveDist < 1024 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_velocity = 8;
return( true );
}
else
{
return( false );
}
}
}
else
{
return( false );
}
}
else
{
return( false );
}
}
default:
return( false );
}
@ -485,6 +838,26 @@ void CNpc::processClose(int _frames)
break;
case NPC_CLOSE_SPIDER_CRAB_ATTACK:
processCloseSpiderCrabAttack( _frames );
break;
case NPC_CLOSE_NINJA_STARFISH_ATTACK:
processCloseNinjaStarfishAttack( _frames );
break;
case NPC_CLOSE_GHOST_PIRATE_ATTACK:
processCloseGhostPirateAttack( _frames );
break;
case NPC_CLOSE_SHARK_MAN_ATTACK:
processCloseSharkManAttack( _frames );
break;
default:
break;
}

View File

@ -49,6 +49,22 @@ protected:
NPC_SQUID_DART,
NPC_FISH_FOLK,
NPC_PRICKLY_BUG,
NPC_SEA_SNAKE_1,
NPC_SEA_SNAKE_2,
NPC_PUFFA_FISH,
NPC_ANGLER_FISH,
NPC_HERMIT_CRAB,
NPC_MINE,
NPC_BOOGER_MONSTER,
NPC_SPIDER_CRAB,
NPC_EYEBALL,
NPC_BABY_OCTOPUS,
NPC_ZOMBIE_FISH_FOLK,
NPC_NINJA_STARFISH,
NPC_GHOST,
NPC_GHOST_PIRATE,
NPC_FLAMING_SKULL,
NPC_SHARK_MAN,
NPC_UNIT_TYPE_MAX,
};
@ -72,6 +88,10 @@ protected:
NPC_SENSOR_NONE = 0,
NPC_SENSOR_JELLYFISH_USER_CLOSE = 1,
NPC_SENSOR_CLAM_USER_CLOSE,
NPC_SENSOR_SPIDER_CRAB_USER_CLOSE,
NPC_SENSOR_NINJA_STARFISH_USER_CLOSE,
NPC_SENSOR_GHOST_PIRATE_USER_CLOSE,
NPC_SENSOR_SHARK_MAN_USER_VISIBLE,
};
enum NPC_CLOSE_FUNC
@ -79,6 +99,10 @@ protected:
NPC_CLOSE_NONE = 0,
NPC_CLOSE_JELLYFISH_EVADE = 1,
NPC_CLOSE_CLAM_ATTACK,
NPC_CLOSE_SPIDER_CRAB_ATTACK,
NPC_CLOSE_NINJA_STARFISH_ATTACK,
NPC_CLOSE_GHOST_PIRATE_ATTACK,
NPC_CLOSE_SHARK_MAN_ATTACK,
};
enum NPC_MOVEMENT_FUNC
@ -106,6 +130,10 @@ protected:
enum
{
NPC_JELLYFISH_RESISTANCE = 64,
EXTEND_UP = true,
EXTEND_DOWN = false,
EXTEND_RIGHT = true,
EXTEND_LEFT = false,
};
@ -143,6 +171,22 @@ protected:
void processCloseClamAttack( int _frames );
// spider crab functions
void processCloseSpiderCrabAttack( int _frames );
// ninja starfish functions
void processCloseNinjaStarfishAttack( int _frames );
// ghost pirate functions
void processCloseGhostPirateAttack( int _frames );
// shark man functions
void processCloseSharkManAttack( int _frames );
// data
static NPC_DATA m_data[NPC_UNIT_TYPE_MAX];
@ -160,7 +204,8 @@ protected:
bool m_evadeClockwise;
s32 m_timerTimer;
s32 m_extension;
bool m_extendOut;
bool m_extendDir;
DVECTOR m_extensionBase;
};

View File

@ -19,10 +19,10 @@ bool CNpcWaypoint::isPointNear( DVECTOR testPos, s32 *xDist, s32 *yDist )
{
s32 xDistSqr, yDistSqr;
*xDist = testPos.vx - this->pos.vx;
*xDist = this->pos.vx - testPos.vx;
xDistSqr = (*xDist) * (*xDist);
*yDist = testPos.vy - this->pos.vy;
*yDist = this->pos.vy - testPos.vy;
yDistSqr = (*yDist) * (*yDist);
if ( xDistSqr + yDistSqr < 100 )
@ -117,6 +117,11 @@ bool CNpcPath::incPath()
return( false );
}
bool CNpcPath::getDistToNextWaypoint( DVECTOR currentPos, s32 *distX, s32 *distY )
{
return( waypoint[currentWaypoint].isPointNear( currentPos, distX, distY ) );
}
s32 CNpcPath::think( DVECTOR currentPos, bool *pathComplete )
{
s32 xDist, yDist;
@ -128,7 +133,7 @@ s32 CNpcPath::think( DVECTOR currentPos, bool *pathComplete )
*pathComplete = incPath();
}
s32 headingToTarget = ratan2( -yDist, -xDist );
s32 headingToTarget = ratan2( yDist, xDist );
return( headingToTarget );
}

View File

@ -51,6 +51,7 @@ public:
void setPathType( NPC_PATH_TYPE newPathType );
bool incPath();
s32 think( DVECTOR currentPos, bool *pathComplete );
bool getDistToNextWaypoint( DVECTOR currentPos, s32 *distX, s32 *distY );
};
#endif

View File

@ -33,10 +33,12 @@ void CNpc::processCloseSpiderCrabAttack( int _frames )
if ( m_extendDir == EXTEND_RIGHT )
{
Pos.vx += velocity;
m_heading = 0;
}
else
{
Pos.vx -= velocity;
m_heading = 2048;
}
s32 horizontalExtension = abs( Pos.vx - m_extensionBase.vx );

View File

@ -61,7 +61,11 @@ void CNpc::processCloseSharkManAttack( int _frames )
moveDist = incDir;
}
if ( abs( moveDist ) < 1024 )
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
if ( abs( moveDist ) < 1024 && abs( xDistWaypoint ) >= abs( xDist ) )
{
// continue charge

View File

@ -129,6 +129,14 @@ SOURCE=..\..\..\source\enemy\nclam.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\source\enemy\ngpirate.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\source\enemy\nnsfish.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\source\enemy\npc.cpp
# End Source File
# Begin Source File
@ -145,6 +153,14 @@ SOURCE=..\..\..\source\enemy\npcpath.h
# End Source File
# Begin Source File
SOURCE=..\..\..\source\enemy\nscrab.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\source\enemy\nshrkman.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\source\enemy\nsjfish.cpp
# End Source File
# End Group