diff --git a/source/enemy/ngary.cpp b/source/enemy/ngary.cpp index a84957740..f12866375 100644 --- a/source/enemy/ngary.cpp +++ b/source/enemy/ngary.cpp @@ -25,14 +25,20 @@ void CNpc::processGaryMovement( int _frames ) s8 multiplier = -1 + ( 2 * m_extension ); s32 maxHeight = 10; s32 fallSpeed = 5; + s8 yMovement = fallSpeed * _frames; + s8 groundHeight; // check vertical collision - if ( isCollisionWithGround() ) + 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->Get( ( Pos.vx + ( multiplier * _frames ) ) >> 4, ( Pos.vy - maxHeight ) >> 4 ) ) + if ( m_layerCollision->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight ) { // reverse direction @@ -40,50 +46,37 @@ void CNpc::processGaryMovement( int _frames ) } else { - s32 distY; - s32 lastPointY = 0; + // make sure we are on the ground, not below it - for ( distY = 0 ; distY <= maxHeight ; distY++ ) - { - if ( !m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy - distY ) >> 4 ) ) - { - break; - } - else - { - lastPointY--; - } - } - - Pos.vy += lastPointY; + Pos.vy += groundHeight; Pos.vx += multiplier * _frames; } } else { - if ( m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + ( fallSpeed * _frames ) ) >> 4 ) ) + // above ground + + if ( groundHeight < yMovement ) { - s32 distY; - s32 lastPointY = 0; + // colliding with ground - for ( distY = 1 ; distY <= _frames ; distY++ ) + Pos.vy += groundHeight; + + if ( m_layerCollision->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight ) { - if ( m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + distY ) >> 4 ) ) - { - break; - } - else - { - lastPointY++; - } - } + // reverse direction - Pos.vy += lastPointY; + m_extension = !m_extension; + } + else + { + Pos.vx += multiplier * _frames; + } } else { - Pos.vy += fallSpeed * _frames; + Pos.vy += yMovement; } } } \ No newline at end of file diff --git a/source/enemy/ngeneric.cpp b/source/enemy/ngeneric.cpp index 743dd9d47..be63a7c80 100644 --- a/source/enemy/ngeneric.cpp +++ b/source/enemy/ngeneric.cpp @@ -102,5 +102,5 @@ void CNpc::processGenericGetUserDist( int _frames, s32 *distX, s32 *distY ) bool CNpc::isCollisionWithGround() { ASSERT(m_layerCollision); - return m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + 1 ) >>4 ); + return m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + 1 ) >> 4 ) ? 16:0; } diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index 3e4991a5e..9966218d5 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -54,7 +54,7 @@ class CLayerCollision *CNpc::m_layerCollision; void CNpc::init() { - m_type = NPC_FALLING_ITEM; + m_type = NPC_GARY; m_heading = m_fireHeading = 0; m_movementTimer = 0; diff --git a/source/enemy/nsstomp.cpp b/source/enemy/nsstomp.cpp index 277abfc27..816157034 100644 --- a/source/enemy/nsstomp.cpp +++ b/source/enemy/nsstomp.cpp @@ -26,6 +26,9 @@ void CNpc::processCloseSkullStomperAttack( int _frames ) { + s8 groundHeight; + s8 yMovement; + if ( m_timerTimer > 0 ) { // wait @@ -34,26 +37,15 @@ void CNpc::processCloseSkullStomperAttack( int _frames ) { if ( m_extendDir == EXTEND_DOWN ) { - if ( m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + ( m_data[m_type].speed * _frames ) ) >> 4 ) ) + yMovement = m_data[m_type].speed * _frames; + + groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 ); + + if ( groundHeight < yMovement ) { // colliding with ground - s32 distY; - s32 lastPointY = 0; - - for ( distY = 1 ; distY <= ( m_data[m_type].speed * _frames ) ; distY++ ) - { - if ( m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + distY ) >> 4 ) ) - { - break; - } - else - { - lastPointY++; - } - } - - Pos.vy += lastPointY; + Pos.vy += groundHeight; // pause and change direction @@ -64,7 +56,7 @@ void CNpc::processCloseSkullStomperAttack( int _frames ) { // drop down - Pos.vy += m_data[m_type].speed * _frames; + Pos.vy += yMovement; } } else