This commit is contained in:
parent
86e2243ddb
commit
4dbd7f53b8
@ -76,32 +76,33 @@ void CLayerCollision::shutdown()
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight)
|
int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight)
|
||||||
{
|
{
|
||||||
int mapX,mapY,xFraction,yFraction;
|
int xFraction,yFraction;
|
||||||
int distanceFromGround;
|
int distanceFromGround;
|
||||||
int colHeight;
|
int colHeight;
|
||||||
int maxHeightToCheck;
|
int maxHeightToCheck;
|
||||||
|
u8 *MapPtr,T;
|
||||||
|
|
||||||
mapX=_x>>4;
|
|
||||||
// mapY=(_y>>4)*MapWidth;
|
|
||||||
mapY=GetYPos(_y>>4);
|
|
||||||
xFraction=_x&0x0f;
|
xFraction=_x&0x0f;
|
||||||
yFraction=16-(_y&0x0f);
|
yFraction=16-(_y&0x0f);
|
||||||
|
MapPtr=getMapPtr(_x,_y);
|
||||||
distanceFromGround=0;
|
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)
|
if(colHeight)
|
||||||
{
|
{
|
||||||
// Inside a collision block.. find the nearest ground above this point
|
// 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
|
maxHeightToCheck=-_maxHeight-16; // Need to check one block more incase we cross onto a new block
|
||||||
while(colHeight==16)
|
while(colHeight==16)
|
||||||
{
|
{
|
||||||
mapY-=MapWidth;
|
MapPtr-=MapWidth;
|
||||||
distanceFromGround-=16;
|
distanceFromGround-=16;
|
||||||
if(distanceFromGround<=maxHeightToCheck)
|
if(distanceFromGround<=maxHeightToCheck)
|
||||||
{
|
{
|
||||||
return -_maxHeight;
|
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;
|
distanceFromGround+=yFraction-colHeight;
|
||||||
if(distanceFromGround<-_maxHeight)distanceFromGround=-_maxHeight;
|
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
|
maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block
|
||||||
while(colHeight==0)
|
while(colHeight==0)
|
||||||
{
|
{
|
||||||
mapY+=MapWidth;
|
MapPtr+=MapWidth;
|
||||||
distanceFromGround+=16;
|
distanceFromGround+=16;
|
||||||
if(distanceFromGround>=maxHeightToCheck)
|
if(distanceFromGround>=maxHeightToCheck)
|
||||||
{
|
{
|
||||||
return _maxHeight;
|
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;
|
distanceFromGround+=yFraction-colHeight;
|
||||||
if(distanceFromGround>_maxHeight)distanceFromGround=_maxHeight;
|
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 CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion,int _maxHeight=32)
|
||||||
{
|
{
|
||||||
int mapX,mapY,xFraction,yFraction;
|
int xFraction,yFraction;
|
||||||
int distanceFromGround;
|
int distanceFromGround;
|
||||||
int colHeight;
|
int colHeight;
|
||||||
int maxHeightToCheck;
|
int maxHeightToCheck;
|
||||||
|
u8 *MapPtr,T;
|
||||||
|
|
||||||
mapX=_x>>4;
|
|
||||||
// mapY=(_y>>4)*MapWidth;
|
|
||||||
mapY=GetYPos(_y>>4);
|
|
||||||
xFraction=_x&0x0f;
|
xFraction=_x&0x0f;
|
||||||
yFraction=16-(_y&0x0f);
|
yFraction=16-(_y&0x0f);
|
||||||
|
MapPtr=getMapPtr(_x,_y);
|
||||||
distanceFromGround=0;
|
distanceFromGround=0;
|
||||||
|
|
||||||
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
|
T=*MapPtr;
|
||||||
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion )
|
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
|
||||||
|
if ( (T & COLLISION_TYPE_MASK) == _exclusion )
|
||||||
{
|
{
|
||||||
colHeight = 0;
|
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
|
maxHeightToCheck=-_maxHeight-16; // Need to check one block more incase we cross onto a new block
|
||||||
while(colHeight==16)
|
while(colHeight==16)
|
||||||
{
|
{
|
||||||
mapY-=MapWidth;
|
MapPtr-=MapWidth;
|
||||||
distanceFromGround-=16;
|
distanceFromGround-=16;
|
||||||
if(distanceFromGround<=maxHeightToCheck)
|
if(distanceFromGround<=maxHeightToCheck)
|
||||||
{
|
{
|
||||||
return -_maxHeight;
|
return -_maxHeight;
|
||||||
}
|
}
|
||||||
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
|
T=*MapPtr;
|
||||||
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion )
|
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
|
||||||
|
if ( (T & COLLISION_TYPE_MASK) == _exclusion )
|
||||||
{
|
{
|
||||||
colHeight = 0;
|
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
|
maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block
|
||||||
while(colHeight==0)
|
while(colHeight==0)
|
||||||
{
|
{
|
||||||
mapY+=MapWidth;
|
MapPtr+=MapWidth;
|
||||||
distanceFromGround+=16;
|
distanceFromGround+=16;
|
||||||
if(distanceFromGround>=maxHeightToCheck)
|
if(distanceFromGround>=maxHeightToCheck)
|
||||||
{
|
{
|
||||||
return _maxHeight;
|
return _maxHeight;
|
||||||
}
|
}
|
||||||
colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction];
|
T=*MapPtr;
|
||||||
if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion )
|
colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction];
|
||||||
|
if ( (T & COLLISION_TYPE_MASK) == _exclusion )
|
||||||
{
|
{
|
||||||
colHeight = 0;
|
colHeight = 0;
|
||||||
}
|
}
|
||||||
@ -265,12 +269,6 @@ int CLayerCollision::getHeightFromGroundCart(int _x,int _y,int _maxHeight)
|
|||||||
return distanceFromGround;
|
return distanceFromGround;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int CLayerCollision::getHeightFromGroundAmmo(int _x,int _y,int _maxHeight)
|
|
||||||
{
|
|
||||||
return( CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_NORMAL, _maxHeight ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
#ifdef __SHOW_COLLISION__
|
#ifdef __SHOW_COLLISION__
|
||||||
#include "gfx\prim.h"
|
#include "gfx\prim.h"
|
||||||
|
@ -33,24 +33,28 @@ virtual void shutdown();
|
|||||||
int getHeightFromGroundExcluding(int _x,int _y,int _exclusion,int _maxHeight=32);
|
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 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 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[Ofs]);
|
||||||
// return(&Map[(_x>>4)+((_y>>4)*MapWidth)]);
|
// 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 (Col);
|
||||||
// return Map[(_x>>4)+((_y>>4)*MapWidth)];
|
// return Map[(_x>>4)+((_y>>4)*MapWidth)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline u8 Get(int X,int Y)
|
inline u8 Get(int X,int Y)
|
||||||
{
|
{
|
||||||
|
ASSERT((Y>=0-COL_Y_OFS) && (Y<MapHeight+COL_Y_OFS));
|
||||||
int Ofs=(X)+GetYPos(Y);
|
int Ofs=(X)+GetYPos(Y);
|
||||||
return(Map[Ofs] & COLLISION_TILE_MASK);
|
return(Map[Ofs] & COLLISION_TILE_MASK);
|
||||||
// return(Map[X+(Y*MapWidth)]&COLLISION_TILE_MASK);
|
// return(Map[X+(Y*MapWidth)]&COLLISION_TILE_MASK);
|
||||||
|
Loading…
Reference in New Issue
Block a user