This commit is contained in:
parent
3f2ebeb556
commit
af42f43345
7 changed files with 226 additions and 4 deletions
|
@ -166,6 +166,7 @@ void CNpcSeaSnakeEnemy::postInit()
|
|||
m_movementTimer = 2 * GameState::getOneSecondInFrames();
|
||||
m_collTimer = 0;
|
||||
m_meterOn=false;
|
||||
m_turnDir = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -249,7 +250,161 @@ void CNpcSeaSnakeEnemy::processMovement( int _frames )
|
|||
}
|
||||
}
|
||||
|
||||
processGenericFixedPathMove( _frames, &moveX, &moveY, &moveVel, &moveDist );
|
||||
switch( m_turnDir )
|
||||
{
|
||||
case NPC_SEA_SNAKE_CIRCLE_CLOCKWISE:
|
||||
{
|
||||
m_circleHeading += m_data[m_type].turnSpeed;
|
||||
|
||||
if ( m_circleHeading > 4096 )
|
||||
{
|
||||
m_circleHeading = 0;
|
||||
m_turnDir = 0;
|
||||
}
|
||||
|
||||
m_heading = ( m_origHeading + m_circleHeading ) & 4095;
|
||||
|
||||
s32 preShiftX = _frames * m_speed * rcos( m_heading );
|
||||
s32 preShiftY = _frames * m_speed * rsin( m_heading );
|
||||
|
||||
s32 moveX = preShiftX >> 12;
|
||||
if ( !moveX && preShiftX )
|
||||
{
|
||||
moveX = preShiftX / abs( preShiftX );
|
||||
}
|
||||
|
||||
s32 moveY = preShiftY >> 12;
|
||||
if ( !moveY && preShiftY )
|
||||
{
|
||||
moveY = preShiftY / abs( preShiftY );
|
||||
}
|
||||
|
||||
Pos.vx += moveX;
|
||||
Pos.vy += moveY;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NPC_SEA_SNAKE_CIRCLE_ANTICLOCKWISE:
|
||||
{
|
||||
m_circleHeading -= m_data[m_type].turnSpeed;
|
||||
|
||||
if ( m_circleHeading < -4096 )
|
||||
{
|
||||
m_circleHeading = 0;
|
||||
m_turnDir = 0;
|
||||
}
|
||||
|
||||
m_heading = ( m_origHeading + m_circleHeading ) & 4095;
|
||||
|
||||
s32 preShiftX = _frames * m_speed * rcos( m_heading );
|
||||
s32 preShiftY = _frames * m_speed * rsin( m_heading );
|
||||
|
||||
s32 moveX = preShiftX >> 12;
|
||||
if ( !moveX && preShiftX )
|
||||
{
|
||||
moveX = preShiftX / abs( preShiftX );
|
||||
}
|
||||
|
||||
s32 moveY = preShiftY >> 12;
|
||||
if ( !moveY && preShiftY )
|
||||
{
|
||||
moveY = preShiftY / abs( preShiftY );
|
||||
}
|
||||
|
||||
Pos.vx += moveX;
|
||||
Pos.vy += moveY;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
DVECTOR waypointPos;
|
||||
m_npcPath.getCurrentWaypointPos( &waypointPos );
|
||||
waypointPos.vy -= 8;
|
||||
|
||||
if ( CGameScene::getCollision()->getHeightFromGround( waypointPos.vx, waypointPos.vy ) < 0 )
|
||||
{
|
||||
// waypoint is either start or end waypoint
|
||||
|
||||
s32 distX, distY;
|
||||
|
||||
distX = waypointPos.vx - Pos.vx;
|
||||
distY = waypointPos.vy - Pos.vy;
|
||||
|
||||
if( !distX && !distY )
|
||||
{
|
||||
if ( isSnakeStopped() )
|
||||
{
|
||||
m_npcPath.incPath();
|
||||
|
||||
m_npcPath.getCurrentWaypointPos( &waypointPos );
|
||||
waypointPos.vy -= 8;
|
||||
|
||||
if ( CGameScene::getCollision()->getHeightFromGround( waypointPos.vx, waypointPos.vy ) < 0 )
|
||||
{
|
||||
// if next waypoint is ALSO a start/end waypoint, teleport directly to it
|
||||
|
||||
moveEntireSnake( waypointPos );
|
||||
oldPos.vx = waypointPos.vx;
|
||||
oldPos.vy = waypointPos.vy;
|
||||
|
||||
// increment path
|
||||
m_npcPath.incPath();
|
||||
|
||||
// point snake in correct direction
|
||||
m_npcPath.getCurrentWaypointPos( &waypointPos );
|
||||
|
||||
m_heading = ratan2( waypointPos.vy - Pos.vy, waypointPos.vx - Pos.vx ) & 4095;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
processGenericGotoTarget( _frames, distX, distY, m_speed );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( processGenericFixedPathMove( _frames, &moveX, &moveY, &moveVel, &moveDist ) )
|
||||
{
|
||||
// path has changed
|
||||
|
||||
DVECTOR newWaypointPos;
|
||||
|
||||
m_npcPath.getCurrentWaypointPos( &newWaypointPos );
|
||||
newWaypointPos.vy -= 8;
|
||||
|
||||
if ( newWaypointPos.vy == waypointPos.vy )
|
||||
{
|
||||
int testDir = newWaypointPos.vx - waypointPos.vx;
|
||||
|
||||
if ( testDir > 0 && testDir <= 16 )
|
||||
{
|
||||
// clockwise
|
||||
|
||||
m_turnDir = NPC_SEA_SNAKE_CIRCLE_CLOCKWISE;
|
||||
m_circleHeading = 0;
|
||||
m_origHeading = m_heading;
|
||||
m_npcPath.incPath();
|
||||
}
|
||||
else if ( testDir < 0 && testDir >= -16 )
|
||||
{
|
||||
// anticlockwise
|
||||
|
||||
m_turnDir = NPC_SEA_SNAKE_CIRCLE_ANTICLOCKWISE;
|
||||
m_circleHeading = 0;
|
||||
m_origHeading = m_heading;
|
||||
m_npcPath.incPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Pos.vx += moveX;
|
||||
Pos.vy += moveY;
|
||||
|
@ -751,3 +906,46 @@ s32 CNpcSeaSnakeEnemy::getFrameShift( int _frames )
|
|||
{
|
||||
return( ( _frames << 8 ) >> 3 );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
u8 CNpcSeaSnakeEnemy::isSnakeStopped()
|
||||
{
|
||||
if ( !m_segmentCount )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
|
||||
DVECTOR tailPos = m_segmentArray[m_segmentCount - 1].getPos();
|
||||
|
||||
if ( tailPos.vx == Pos.vx && tailPos.vy == Pos.vy )
|
||||
{
|
||||
return( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CNpcSeaSnakeEnemy::moveEntireSnake( DVECTOR newPos )
|
||||
{
|
||||
Pos.vx = newPos.vx;
|
||||
Pos.vy = newPos.vy;
|
||||
|
||||
int segmentCount;
|
||||
|
||||
for ( segmentCount = 0 ; segmentCount < m_segmentCount ; segmentCount++ )
|
||||
{
|
||||
m_segmentArray[segmentCount].setPos( Pos );
|
||||
}
|
||||
|
||||
s16 maxArraySize = NPC_SEA_SNAKE_LENGTH * NPC_SEA_SNAKE_SPACING;
|
||||
|
||||
for ( int histLength = 0 ; histLength < maxArraySize ; histLength++ )
|
||||
{
|
||||
m_positionHistoryArray[histLength].pos = Pos;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue