From 48896226dccc889e22858b9f94e17ce14bd2354d Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 12 Feb 2001 20:03:44 +0000 Subject: [PATCH] --- source/enemy/ngary.cpp | 64 +++++++++++++++++++++++++++++++++++++-- source/enemy/ngeneric.cpp | 2 +- source/enemy/npc.cpp | 2 ++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/source/enemy/ngary.cpp b/source/enemy/ngary.cpp index 5fa6fef55..a84957740 100644 --- a/source/enemy/ngary.cpp +++ b/source/enemy/ngary.cpp @@ -15,15 +15,75 @@ #include "enemy\npc.h" #endif +#ifndef __GAME_GAME_H__ +#include "game\game.h" +#endif + void CNpc::processGaryMovement( int _frames ) { + s8 multiplier = -1 + ( 2 * m_extension ); + s32 maxHeight = 10; + s32 fallSpeed = 5; + + // check vertical collision + if ( isCollisionWithGround() ) { - Pos.vx += _frames; + // check horizontal collision + + if ( m_layerCollision->Get( ( Pos.vx + ( multiplier * _frames ) ) >> 4, ( Pos.vy - maxHeight ) >> 4 ) ) + { + // reverse direction + + m_extension = !m_extension; + } + else + { + s32 distY; + s32 lastPointY = 0; + + for ( distY = 0 ; distY <= maxHeight ; distY++ ) + { + if ( !m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy - distY ) >> 4 ) ) + { + break; + } + else + { + lastPointY--; + } + } + + Pos.vy += lastPointY; + + Pos.vx += multiplier * _frames; + } } else { - Pos.vy += _frames; + if ( m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + ( fallSpeed * _frames ) ) >> 4 ) ) + { + s32 distY; + s32 lastPointY = 0; + + for ( distY = 1 ; distY <= _frames ; distY++ ) + { + if ( m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + distY ) >> 4 ) ) + { + break; + } + else + { + lastPointY++; + } + } + + Pos.vy += lastPointY; + } + else + { + Pos.vy += fallSpeed * _frames; + } } } \ No newline at end of file diff --git a/source/enemy/ngeneric.cpp b/source/enemy/ngeneric.cpp index a033a3411..743dd9d47 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>>4); + return m_layerCollision->Get( Pos.vx >> 4, ( Pos.vy + 1 ) >>4 ); } diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index f1dd7f99f..b718a6341 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -62,6 +62,8 @@ void CNpc::init() m_velocity = 0; m_extension = 0; + m_extension = EXTEND_RIGHT; + Pos.vx = 100; Pos.vy = 100;