This commit is contained in:
Charles 2001-07-06 19:42:07 +00:00
parent b033c27b2b
commit c685da55e0
4 changed files with 173 additions and 44 deletions

View file

@ -273,6 +273,72 @@ int CLayerCollision::getHeightFromGroundNonSB(int _x,int _y,int _maxHeight)
return distanceFromGround;
}
/*****************************************************************************/
int CLayerCollision::getHeightFromGroundCart(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_DAMAGE )
{
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_DAMAGE )
{
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_DAMAGE )
{
colHeight = 0;
}
}
distanceFromGround+=yFraction-colHeight;
if(distanceFromGround>_maxHeight)distanceFromGround=_maxHeight;
}
return distanceFromGround;
}
/*****************************************************************************/
#ifdef __SHOW_COLLISION__
#include "gfx\prim.h"