This commit is contained in:
Daveo 2001-08-14 19:19:13 +00:00
parent 86e2243ddb
commit 4dbd7f53b8
2 changed files with 40 additions and 38 deletions

View File

@ -76,32 +76,33 @@ void CLayerCollision::shutdown()
/*****************************************************************************/
int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight)
{
int mapX,mapY,xFraction,yFraction;
int distanceFromGround;
int colHeight;
int maxHeightToCheck;
int xFraction,yFraction;
int distanceFromGround;
int colHeight;
int maxHeightToCheck;
u8 *MapPtr,T;
mapX=_x>>4;
// mapY=(_y>>4)*MapWidth;
mapY=GetYPos(_y>>4);
xFraction=_x&0x0f;
yFraction=16-(_y&0x0f);
MapPtr=getMapPtr(_x,_y);
distanceFromGround=0;
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
T=*MapPtr;
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
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;
MapPtr-=MapWidth;
distanceFromGround-=16;
if(distanceFromGround<=maxHeightToCheck)
{
return -_maxHeight;
}
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
T=*MapPtr;
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
}
distanceFromGround+=yFraction-colHeight;
if(distanceFromGround<-_maxHeight)distanceFromGround=-_maxHeight;
@ -113,13 +114,14 @@ int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight)
maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block
while(colHeight==0)
{
mapY+=MapWidth;
MapPtr+=MapWidth;
distanceFromGround+=16;
if(distanceFromGround>=maxHeightToCheck)
{
return _maxHeight;
}
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
T=*MapPtr;
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
}
distanceFromGround+=yFraction-colHeight;
if(distanceFromGround>_maxHeight)distanceFromGround=_maxHeight;
@ -131,20 +133,20 @@ int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight)
/*****************************************************************************/
int CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion,int _maxHeight=32)
{
int mapX,mapY,xFraction,yFraction;
int distanceFromGround;
int colHeight;
int maxHeightToCheck;
int xFraction,yFraction;
int distanceFromGround;
int colHeight;
int maxHeightToCheck;
u8 *MapPtr,T;
mapX=_x>>4;
// mapY=(_y>>4)*MapWidth;
mapY=GetYPos(_y>>4);
xFraction=_x&0x0f;
yFraction=16-(_y&0x0f);
MapPtr=getMapPtr(_x,_y);
distanceFromGround=0;
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion )
T=*MapPtr;
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
if ( (T & COLLISION_TYPE_MASK) == _exclusion )
{
colHeight = 0;
}
@ -154,14 +156,15 @@ int CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion
maxHeightToCheck=-_maxHeight-16; // Need to check one block more incase we cross onto a new block
while(colHeight==16)
{
mapY-=MapWidth;
MapPtr-=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) == _exclusion )
T=*MapPtr;
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
if ( (T & COLLISION_TYPE_MASK) == _exclusion )
{
colHeight = 0;
}
@ -176,14 +179,15 @@ int CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion
maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block
while(colHeight==0)
{
mapY+=MapWidth;
MapPtr+=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) == _exclusion )
T=*MapPtr;
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
if ( (T & COLLISION_TYPE_MASK) == _exclusion )
{
colHeight = 0;
}
@ -265,12 +269,6 @@ int CLayerCollision::getHeightFromGroundCart(int _x,int _y,int _maxHeight)
return distanceFromGround;
}
/*****************************************************************************/
int CLayerCollision::getHeightFromGroundAmmo(int _x,int _y,int _maxHeight)
{
return( CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_NORMAL, _maxHeight ) );
}
/*****************************************************************************/
#ifdef __SHOW_COLLISION__
#include "gfx\prim.h"

View File

@ -33,24 +33,28 @@ virtual void shutdown();
int getHeightFromGroundExcluding(int _x,int _y,int _exclusion,int _maxHeight=32);
int getHeightFromGroundNonSB(int _x,int _y,int _maxHeight=32) {return( CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_SB_NOMOVE, _maxHeight ) );}
int getHeightFromGroundCart(int _x,int _y,int _maxHeight=32);
int getHeightFromGroundAmmo(int _x,int _y,int _maxHeight=32);
int getHeightFromGroundAmmo(int _x,int _y,int _maxHeight=32) {return(CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_NORMAL, _maxHeight ));}
inline u8 *getMapPtr(int _x,int _y)
inline u8 *getMapPtr(int X,int Y)
{
int Ofs=(_x>>4)+GetYPos(_y>>4);
X>>=4;
Y>>=4;
ASSERT((Y>=0-COL_Y_OFS) && (Y<MapHeight+COL_Y_OFS));
int Ofs=(X)+GetYPos(Y);
return(&Map[Ofs]);
// return(&Map[(_x>>4)+((_y>>4)*MapWidth)]);
}
inline int getCollisionBlock(int _x,int _y)
inline int getCollisionBlock(int X,int Y)
{
u8 Col=*getMapPtr(_x,_y);
u8 Col=*getMapPtr(X,Y);
return (Col);
// return Map[(_x>>4)+((_y>>4)*MapWidth)];
}
inline u8 Get(int X,int Y)
{
ASSERT((Y>=0-COL_Y_OFS) && (Y<MapHeight+COL_Y_OFS));
int Ofs=(X)+GetYPos(Y);
return(Map[Ofs] & COLLISION_TILE_MASK);
// return(Map[X+(Y*MapWidth)]&COLLISION_TILE_MASK);