This commit is contained in:
parent
dbf746a287
commit
dd6b6963e6
@ -139,7 +139,7 @@ void CNpcGaryFriend::think( int _frames )
|
||||
|
||||
// check vertical collision
|
||||
|
||||
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
|
||||
groundHeight = CGameScene::getCollision()->getHeightFromGroundNonSB( Pos.vx, Pos.vy, yMovement + 16 );
|
||||
|
||||
switch ( CGameScene::getCollision()->getCollisionBlock( Pos.vx, Pos.vy ) & COLLISION_TYPE_MASK )
|
||||
{
|
||||
@ -196,7 +196,7 @@ void CNpcGaryFriend::think( int _frames )
|
||||
|
||||
// check horizontal collision
|
||||
|
||||
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
|
||||
if ( CGameScene::getCollision()->getHeightFromGroundNonSB( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
|
||||
{
|
||||
// reverse direction
|
||||
|
||||
@ -233,7 +233,7 @@ void CNpcGaryFriend::think( int _frames )
|
||||
|
||||
Pos.vy += groundHeight;
|
||||
|
||||
if ( CGameScene::getCollision()->getHeightFromGround( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
|
||||
if ( CGameScene::getCollision()->getHeightFromGroundNonSB( Pos.vx + ( multiplier * _frames ), Pos.vy ) < -maxHeight )
|
||||
{
|
||||
// reverse direction
|
||||
|
||||
|
@ -207,6 +207,72 @@ int CLayerCollision::getHeightFromCeiling(int _x,int _y,int _maxHeight)
|
||||
}
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
int CLayerCollision::getHeightFromGroundNonSB(int _x,int _y,int _maxHeight)
|
||||
{
|
||||
int mapX,mapY,xFraction,yFraction;
|
||||
int distanceFromGround;
|
||||
int colHeight;
|
||||
int maxHeightToCheck;
|
||||
|
||||
mapX=_x>>4;
|
||||
mapY=(_y>>4)*MapWidth;
|
||||
xFraction=_x&0x0f;
|
||||
yFraction=16-(_y&0x0f);
|
||||
distanceFromGround=0;
|
||||
|
||||
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
|
||||
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == COLLISION_TYPE_FLAG_SB_NOMOVE )
|
||||
{
|
||||
colHeight = 0;
|
||||
}
|
||||
if(colHeight)
|
||||
{
|
||||
// Inside a collision block.. find the nearest ground above this point
|
||||
maxHeightToCheck=-_maxHeight-16; // Need to check one block more incase we cross onto a new block
|
||||
while(colHeight==16)
|
||||
{
|
||||
mapY-=MapWidth;
|
||||
distanceFromGround-=16;
|
||||
if(distanceFromGround<=maxHeightToCheck)
|
||||
{
|
||||
return -_maxHeight;
|
||||
}
|
||||
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
|
||||
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == COLLISION_TYPE_FLAG_SB_NOMOVE )
|
||||
{
|
||||
colHeight = 0;
|
||||
}
|
||||
}
|
||||
distanceFromGround+=yFraction-colHeight;
|
||||
if(distanceFromGround<-_maxHeight)distanceFromGround=-_maxHeight;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not inside a collision block.. find the nearest ground below this point
|
||||
maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block
|
||||
while(colHeight==0)
|
||||
{
|
||||
mapY+=MapWidth;
|
||||
distanceFromGround+=16;
|
||||
if(distanceFromGround>=maxHeightToCheck)
|
||||
{
|
||||
return _maxHeight;
|
||||
}
|
||||
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
|
||||
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == COLLISION_TYPE_FLAG_SB_NOMOVE )
|
||||
{
|
||||
colHeight = 0;
|
||||
}
|
||||
}
|
||||
distanceFromGround+=yFraction-colHeight;
|
||||
if(distanceFromGround>_maxHeight)distanceFromGround=_maxHeight;
|
||||
}
|
||||
|
||||
return distanceFromGround;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
#ifdef __SHOW_COLLISION__
|
||||
#include "gfx\prim.h"
|
||||
|
@ -24,6 +24,7 @@ virtual void shutdown();
|
||||
|
||||
u8 Get(int X,int Y) {return(Map[X+(Y*MapWidth)]&COLLISION_TILE_MASK);}
|
||||
int getHeightFromGround(int _x,int _y,int _maxHeight=32);
|
||||
int getHeightFromGroundNonSB(int _x,int _y,int _maxHeight=32);
|
||||
int getCollisionBlock(int _x,int _y) {return Map[(_x>>4)+((_y>>4)*MapWidth)];}
|
||||
|
||||
u8 *getMapPtr(int _x,int _y) {return(&Map[(_x>>4)+((_y>>4)*MapWidth)]);}
|
||||
|
Loading…
Reference in New Issue
Block a user