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"

View file

@ -25,6 +25,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 getHeightFromGroundCart(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)]);}

View file

@ -45,6 +45,8 @@ void CNpcCartPlatform::postInit()
calculateNonRotatedCollisionData();
m_playerAttached = false;
m_rebound = false;
m_reboundTimer = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -60,6 +62,11 @@ void CNpcCartPlatform::processMovement( int _frames )
bool pathComplete;
if ( m_reboundTimer > 0 )
{
m_reboundTimer -= _frames;
}
if ( !m_playerAttached )
{
m_playerAttached = true;
@ -75,6 +82,38 @@ void CNpcCartPlatform::processMovement( int _frames )
}
if ( m_isActivated )
{
if ( m_rebound )
{
moveX = -4 * _frames;
m_vertSpeed += 192;
if ( m_vertSpeed > ( 5 << 8 ) )
{
m_vertSpeed = 5 << 8;
}
else if ( m_vertSpeed < -( 6 << 8 ) )
{
m_vertSpeed = -( 6 << 8 );
}
moveY = ( m_vertSpeed >> 8 ) * _frames;
groundHeight = CGameScene::getCollision()->getHeightFromGroundCart( Pos.vx + moveX, Pos.vy + moveY, 16 );
if ( groundHeight < 0 )
{
// have touched down
m_rebound = false;
moveY += groundHeight;
}
Pos.vx += moveX;
Pos.vy += moveY;
}
else
{
m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &heading );
@ -103,7 +142,7 @@ void CNpcCartPlatform::processMovement( int _frames )
moveY = ( m_vertSpeed >> 8 ) * _frames;
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx + moveX, Pos.vy + moveY, 16 );
groundHeight = CGameScene::getCollision()->getHeightFromGroundCart( Pos.vx + moveX, Pos.vy + moveY, 16 );
if ( groundHeight < 0 )
{
@ -119,7 +158,7 @@ void CNpcCartPlatform::processMovement( int _frames )
s32 checkDist = yMovement + 50;
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx + moveX, Pos.vy, checkDist );
groundHeight = CGameScene::getCollision()->getHeightFromGroundCart( Pos.vx + moveX, Pos.vy, checkDist );
if ( groundHeight < checkDist )
{
@ -156,6 +195,7 @@ void CNpcCartPlatform::processMovement( int _frames )
Pos.vx += moveX;
Pos.vy += moveY;
}
// sort out draw rotation
@ -169,7 +209,7 @@ void CNpcCartPlatform::processMovement( int _frames )
s32 yDiff;
yDiff = CGameScene::getCollision()->getHeightFromGround( testPos1.vx, testPos1.vy, sensorDist + 1 );
yDiff = CGameScene::getCollision()->getHeightFromGroundCart( testPos1.vx, testPos1.vy, sensorDist + 1 );
if ( yDiff <= sensorDist )
{
@ -178,7 +218,7 @@ void CNpcCartPlatform::processMovement( int _frames )
testPos1.vy += yDiff;
}
yDiff = CGameScene::getCollision()->getHeightFromGround( testPos2.vx, testPos2.vy, sensorDist + 1 );
yDiff = CGameScene::getCollision()->getHeightFromGroundCart( testPos2.vx, testPos2.vy, sensorDist + 1 );
if ( yDiff <= sensorDist )
{
@ -193,10 +233,29 @@ void CNpcCartPlatform::processMovement( int _frames )
heading = ratan2( yDist, xDist );
setCollisionAngle( heading );
if ( m_reboundTimer <= 0 )
{
switch ( CGameScene::getCollision()->getCollisionBlock( testPos2.vx, testPos2.vy - 8 ) & COLLISION_TYPE_MASK )
{
case COLLISION_TYPE_FLAG_DAMAGE:
{
m_vertSpeed = -8 << 8;
m_reboundTimer = 2 * GameState::getOneSecondInFrames();
m_rebound = true;
Pos.vy -= 8;
break;
}
default:
break;
}
}
}
else
{
groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 );
groundHeight = CGameScene::getCollision()->getHeightFromGroundCart( Pos.vx, Pos.vy, yMovement + 16 );
if ( groundHeight <= yMovement )
{

View file

@ -34,6 +34,9 @@ protected:
u8 m_inJump;
s32 m_vertSpeed;
u8 m_playerAttached;
u8 m_rebound;
s32 m_reboundTimer;
};
#endif