This commit is contained in:
Charles 2001-05-21 14:22:26 +00:00
parent 7c42177848
commit c2d7d07d8b
20 changed files with 261 additions and 844 deletions

View File

@ -189,31 +189,6 @@ void CNpcStaticClamEnemy::processClose( int _frames )
m_isStunned = false;
}
/*void CNpcStaticClamEnemy::processShot( int _frames )
{
if ( !m_isStunned )
{
switch( m_data[m_type].shotFunc )
{
case NPC_SHOT_NONE:
{
// do nothing
break;
}
case NPC_SHOT_GENERIC:
{
m_isStunned = true;
break;
}
}
}
m_controlFunc = NPC_CONTROL_MOVEMENT;
}*/
void CNpcStaticClamEnemy::collidedWith( CThing *_thisThing )
{
if ( m_isActive && !m_isCaught && !m_isDying )
@ -232,56 +207,3 @@ void CNpcStaticClamEnemy::collidedWith( CThing *_thisThing )
}
}
}
/*int CNpcStaticClamEnemy::checkCollisionAgainst( CThing *_thisThing, int _frames )
{
DVECTOR pos,thisThingPos;
int radius;
int collided;
pos = getCollisionCentre();
thisThingPos=_thisThing->getCollisionCentre();
radius=getCollisionRadius()+_thisThing->getCollisionRadius();
collided=false;
if(abs(pos.vx-thisThingPos.vx)<radius&&
abs(pos.vy-thisThingPos.vy)<radius)
{
CRECT thisRect,thatRect;
thisRect=getCollisionArea();
thatRect=_thisThing->getCollisionArea();
if(((thisRect.x1>=thatRect.x1&&thisRect.x1<=thatRect.x2)||(thisRect.x2>=thatRect.x1&&thisRect.x2<=thatRect.x2)||(thisRect.x1<=thatRect.x1&&thisRect.x2>=thatRect.x2))&&
((thisRect.y1>=thatRect.y1&&thisRect.y1<=thatRect.y2)||(thisRect.y2>=thatRect.y1&&thisRect.y2<=thatRect.y2)||(thisRect.y1<=thatRect.y1&&thisRect.y2>=thatRect.y2)))
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
if ( m_isStunned && m_isActive )
{
CPlayer *player = (CPlayer *) _thisThing;
s32 playerDeltaY = player->getPosDelta().vy;
if ( thisThingPos.vy - playerDeltaY <= getNewYPos( _thisThing ) )
{
player->setPlatform( this );
}
}
break;
}
default:
break;
}
collided=true;
}
}
return collided;
}*/

View File

@ -36,11 +36,9 @@ class CNpcStaticClamEnemy : public CNpcClamEnemy
{
public:
virtual void postInit();
//virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
virtual u8 hasBeenAttacked() {return( false );}
protected:
virtual void collidedWith(CThing *_thisThing);
//virtual void processShot( int _frames );
virtual void processClose( int _frames );
u8 m_isStunned;

View File

@ -119,32 +119,6 @@ void CNpcBouncePlatform::render()
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR centre;
DVECTOR size;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}

View File

@ -37,7 +37,14 @@
void CNpcBranchPlatform::postInit()
{
sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ) << 1, PLATFORMCOLLISIONHEIGHT );
boundingBox.YMin = ( ( boundingBox.YMin - boundingBox.YMax ) >> 1 ) + boundingBox.YMax;
m_boundingBox = boundingBox;
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
//CNpcPlatform::postInit();
/*sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ) << 1, ( boundingBox.YMax - boundingBox.YMin ) );
if ( m_reversed )
{
@ -46,7 +53,7 @@ void CNpcBranchPlatform::postInit()
else
{
setCollisionCentreOffset( boundingBox.XMin, 18 + ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) );
}
}*/
m_angularVelocity = 0;
}
@ -93,7 +100,7 @@ void CNpcBranchPlatform::setWaypoints( sThingPlatform *ThisPlatform )
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcBranchPlatform::collidedWith( CThing *_thisThing )
/*void CNpcBranchPlatform::collidedWith( CThing *_thisThing )
{
switch(_thisThing->getThingType())
{
@ -134,7 +141,7 @@ void CNpcBranchPlatform::collidedWith( CThing *_thisThing )
ASSERT(0);
break;
}
}
}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -267,68 +274,55 @@ void CNpcBranchPlatform::render()
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=0;
x2=0;
y1=0;
y2=0;
if ( m_reversed )
{
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
}
else
{
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
}
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcBranchPlatform::calculateBoundingBoxSize()
sBBox & CNpcBranchPlatform::getBBox()
{
return( m_boundingBox );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int CNpcBranchPlatform::getHeightFromPlatformAtPosition(int _x,int _y, int offsetX, int offsetY)
{
DVECTOR top;
int angle;
DVECTOR centre;
int length;
int x1,y1,x2,y2;
CRECT collisionArea = getCollisionArea();
if ( m_reversed )
{
top.vx = offsetX + collisionArea.x2;
}
else
{
top.vx = offsetX + collisionArea.x1;
}
//sBBox boundingBox = m_modelGfx->GetBBox();
sBBox boundingBox = getBBox();
//top.vy = collisionArea.y1;
top.vy = boundingBox.YMin + Pos.vy + offsetY;
angle=getCollisionAngle();
centre=getCollisionCentre();
if(angle==0)
{
// Non-rotated platform
return( top.vy - _y );
}
else
{
// Rotate backwards to find height at current position
//return( ( top.vy - _y ) + ( ( top.vx - _x ) * msin( -angle & 4095 ) >> 12 ) );
//halfLength=m_platformWidth/2;
sBBox boundingBox = m_modelGfx->GetBBox();
length = ( boundingBox.XMax - boundingBox.XMin );
int hypotenuse = ( ( top.vx - _x ) << 12 ) / rcos( angle );
x1=-length*mcos(angle&4095)>>12;
y1=-length*msin(angle&4095)>>12;
x2=+length*mcos(angle&4095)>>12;
y2=+length*msin(angle&4095)>>12;
int angleHeight = -( hypotenuse * rsin( angle ) ) >> 12;
setCollisionSize(abs(x2-x1),abs(y2-y1)+PLATFORMCOLLISIONHEIGHT);
return( ( top.vy - _y ) + angleHeight );
}
}

View File

@ -23,15 +23,19 @@ class CNpcBranchPlatform : public CNpcPlatform
public:
virtual void postInit();
virtual void render();
virtual int getHeightFromPlatformAtPosition(int _x,int _y, int offsetX = 0, int offsetY = 0);
protected:
virtual void setWaypoints( sThingPlatform *ThisPlatform );
virtual void processMovement( int _frames );
virtual sBBox &getBBox();
virtual void collidedWith(CThing *_thisThing);
virtual void calculateBoundingBoxSize();
//virtual void collidedWith(CThing *_thisThing);
//virtual void calculateBoundingBoxSize();
//virtual int getHeightFromPlatformAtPosition(int _x,int _y, int offsetX = 0, int offsetY = 0);
s32 m_angularVelocity;
u8 m_reversed;
sBBox m_boundingBox;
};
#endif

View File

@ -165,33 +165,6 @@ void CNpcCartPlatform::render()
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}

View File

@ -29,37 +29,6 @@
void CNpcClamPlatform::render()
{
CPlatformThing::render();
if (canRender())
{
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR &renderPos=getRenderPos();
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -214,112 +214,6 @@ void CNpcDualPlatform::render()
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
/*
x1 = Pos.vx - offset.vx;
x2 = m_lineBase.vx - offset.vx;
if ( x1 > x2 )
{
int tempX = x1;
x1 = x2;
x2 = tempX;
}
y1 = Pos.vy - offset.vy;
y2 = m_lineBase.vy - offset.vy;
if ( y1 > y2 )
{
int tempY = y1;
y1 = y2;
y2 = tempY;
}
if ( y1 < 0 )
{
y1 = 0;
}
if ( y2 > VidGetScrH() )
{
y2 = VidGetScrH();
}
if ( x2 >= 0 && x1 <= VidGetScrW() )
{
if ( y2 >= 0 && y1 <= VidGetScrH() )
{
DrawLine( x1, y1, x2, y2, 0, 0, 0, 0 );
}
}
if ( m_isMaster )
{
DVECTOR otherLineBase = m_otherPlatform->getLineBase();
x1 = otherLineBase.vx - offset.vx;
x2 = m_lineBase.vx - offset.vx;
if ( x1 > x2 )
{
int tempX = x1;
x1 = x2;
x2 = tempX;
}
y1 = otherLineBase.vy - offset.vy;
y2 = m_lineBase.vy - offset.vy;
if ( y1 > y2 )
{
int tempY = y1;
y1 = y2;
y2 = tempY;
}
if ( x1 < 0 )
{
x1 = 0;
}
if ( x2 > VidGetScrW() )
{
x2 = VidGetScrW();
}
if ( x2 >= 0 && x1 <= VidGetScrW() )
{
if ( y2 >= 0 && y1 <= VidGetScrH() )
{
DrawLine( x1, y1, x2, y2, 0, 0, 0, 0 );
}
}
*/
}
}
}

View File

@ -98,33 +98,6 @@ void CNpcFishHookPlatform::render()
if (canRender())
{
m_modelGfx->Render(renderPos);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
// draw Line (Literally!!)
if (renderPos.vx>0 && renderPos.vx<512)

View File

@ -142,61 +142,6 @@ void CNpcJellyfishPlatform::think( int _frames )
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcJellyfishPlatform::render()
{
if ( m_isActive )
{
CPlatformThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
//renderPos.vy += m_dipOffset;
SVECTOR rotation;
rotation.vx = 0;
rotation.vy = 0;
rotation.vz = 0;
VECTOR scale;
scale.vx = ONE;
//scale.vy = ONE + m_vertScale;
scale.vy = ONE;
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR centre;
DVECTOR size;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CRECT *CNpcJellyfishPlatform::getThinkBBox()
{
CRECT objThinkBox = getCollisionArea();

View File

@ -21,7 +21,6 @@
class CNpcJellyfishPlatform : public CNpcLinearPlatform
{
public:
virtual void render();
virtual void postInit();
virtual void think( int _frames );
virtual CRECT const *getThinkBBox();

View File

@ -489,8 +489,8 @@ void CNpcPlatform::reinit()
void CNpcPlatform::postInit()
{
sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), PLATFORMCOLLISIONHEIGHT);
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, boundingBox.YMin );
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
/*if ( m_type == NPC_LINEAR_PLATFORM )
{
@ -634,6 +634,9 @@ void CNpcPlatform::think(int _frames)
void CNpcPlatform::setCollisionAngle(int newAngle)
{
CPlatformThing::setCollisionAngle(newAngle);
calculateBoundingBoxSize();
CPlayer *player;
// Is the player stood on this platform as it rotates?
@ -643,7 +646,12 @@ void CNpcPlatform::setCollisionAngle(int newAngle)
DVECTOR playerPos;
playerPos=player->getPos();
if(getHeightFromPlatformAtPosition(playerPos.vx,playerPos.vy)==0)
DVECTOR shove;
shove.vx = 0;
shove.vy = getHeightFromPlatformAtPosition( playerPos.vx, playerPos.vy );
player->shove(shove);
/*if(getHeightFromPlatformAtPosition(playerPos.vx,playerPos.vy)==0)
{
// Ok.. currently stood on the platform - awkward bastard
DVECTOR centre;
@ -674,11 +682,8 @@ void CNpcPlatform::setCollisionAngle(int newAngle)
}
player->shove(shove);
}
}*/
}
CPlatformThing::setCollisionAngle(newAngle);
calculateBoundingBoxSize();
}
@ -686,7 +691,7 @@ void CNpcPlatform::setCollisionAngle(int newAngle)
void CNpcPlatform::calculateBoundingBoxSize()
{
int angle;
/*int angle;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
@ -703,11 +708,73 @@ void CNpcPlatform::calculateBoundingBoxSize()
x2=+halfLength*mcos(angle&4095)>>12;
y2=+halfLength*msin(angle&4095)>>12;
setCollisionSize(abs(x2-x1),abs(y2-y1)+PLATFORMCOLLISIONHEIGHT);
setCollisionSize( abs(x2-x1), abs(y2-y1) );
//sBBox boundingBox = m_modelGfx->GetBBox();
//setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
//setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
//setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );*/
//sBBox boundingBox = m_modelGfx->GetBBox();
sBBox boundingBox = getBBox();
// 'render' collision box at correct angle
SVECTOR testPointsNonRel[4];
VECTOR testPoints[4];
testPointsNonRel[0].vx = boundingBox.XMin;
testPointsNonRel[0].vy = boundingBox.YMin;
testPointsNonRel[1].vx = boundingBox.XMax;
testPointsNonRel[1].vy = boundingBox.YMin;
testPointsNonRel[2].vx = boundingBox.XMax;
testPointsNonRel[2].vy = boundingBox.YMax;
testPointsNonRel[3].vx = boundingBox.XMin;
testPointsNonRel[3].vy = boundingBox.YMax;
MATRIX mtx;
SetIdentNoTrans(&mtx );
RotMatrixZ( getCollisionAngle(), &mtx );
int i;
for ( i = 0 ; i < 4 ; i++ )
{
ApplyMatrix( &mtx, &testPointsNonRel[i], &testPoints[i] );
}
int x1, x2, y1, y2;
x1 = x2 = testPoints[0].vx;
y1 = y2 = testPoints[0].vy;
for ( i = 1 ; i < 4 ; i++ )
{
if ( testPoints[i].vy < y1 )
{
y1 = testPoints[i].vy;
}
else if ( testPoints[i].vy > y2 )
{
y2 = testPoints[i].vy;
}
if ( testPoints[i].vx < x1 )
{
x1 = testPoints[i].vx;
}
else if ( testPoints[i].vx > x2 )
{
x2 = testPoints[i].vx;
}
}
setCollisionSize( x2 - x1 + 1, y2 - y1 + 1 );
}
@ -819,6 +886,55 @@ void CNpcPlatform::processTimer( int _frames )
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
u8 CNpcPlatform::checkCollisionDelta( CThing *_thisThing, int threshold, CRECT collisionArea )
{
// check for case of "was not colliding previously because was above" +
// "is not colliding now because is below"
DVECTOR otherPos = _thisThing->getPos();
if ( getHeightFromPlatformAtPosition( otherPos.vx, otherPos.vy ) < 0 )
{
// is currently below platform landing point
DVECTOR otherPosDelta = _thisThing->getPosDelta();
DVECTOR posDelta = getPosDelta();
if ( otherPosDelta.vy > 0 || posDelta.vy < 0 )
{
// object is dropping vertically, or platform is rising vertically
// get both object's previous positions
s32 oldXPos = otherPos.vx - otherPosDelta.vx;
s32 oldYPos = otherPos.vy - otherPosDelta.vy;
collisionArea.x1 -= posDelta.vx;
collisionArea.x2 -= posDelta.vx;
collisionArea.y1 -= posDelta.vy;
s32 oldCollisionY = collisionArea.y2;
collisionArea.y2 -= posDelta.vy;
if ( oldXPos >= collisionArea.x1 && oldXPos <= collisionArea.x2 )
{
//if ( oldYPos < collisionArea.y1 + threshold ) //&& otherPos.vy > oldCollisionY )
if ( getHeightFromPlatformAtPosition( oldXPos, oldYPos, -posDelta.vx, -posDelta.vy ) > 0 )
{
// if object's old position was above old platform collision area,
// but is now below current platform collision area, we can assume
// the player has hit the platform in the intervening time
return( true );
}
}
}
}
return( false );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcPlatform::collidedWith( CThing *_thisThing )
{
switch(_thisThing->getThingType())
@ -835,15 +951,36 @@ void CNpcPlatform::collidedWith( CThing *_thisThing )
player=(CPlayer*)_thisThing;
playerPos=player->getPos();
collisionArea=getCollisionArea();
if(playerPos.vx>=collisionArea.x1&&playerPos.vx<=collisionArea.x2&&
playerPos.vy>=collisionArea.y1&&playerPos.vy<=collisionArea.y2)
{
player->setPlatform( this );
if(getHeightFromPlatformAtPosition(playerPos.vx,playerPos.vy)==0)
s32 threshold = abs( collisionArea.y2 - collisionArea.y1 );
if ( threshold > 16 )
{
threshold = 16;
}
if( playerPos.vx >= collisionArea.x1 && playerPos.vx <= collisionArea.x2 )
{
if ( checkCollisionDelta( _thisThing, threshold, collisionArea ) )
{
player->setPlatform( this );
m_contact = true;
}
else
{
if( playerPos.vy >= collisionArea.y1 && playerPos.vy <= collisionArea.y2 )
{
int height = getHeightFromPlatformAtPosition( playerPos.vx, playerPos.vy );
if ( height >= -threshold && height < 1 )
{
player->setPlatform( this );
m_contact = true;
}
}
}
}
}
@ -860,14 +997,6 @@ void CNpcPlatform::collidedWith( CThing *_thisThing )
hazard->setPlatform( this );
/*DVECTOR newPos = _thisThing->getPos();
s32 yDiff = getHeightFromPlatformAtPosition( newPos.vx, newPos.vy );
newPos.vy += yDiff;
_thisThing->setPos( newPos );*/
break;
}
@ -897,296 +1026,39 @@ void CNpcPlatform::render()
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef REMOVETHIS
s32 CNpcPlatform::getNewYPos(CThing *_thisThing)
int CNpcPlatform::checkCollisionAgainst(CThing *_thisThing, int _frames)
{
CRECT thisRect;
DVECTOR thatPos = _thisThing->getPos();
int collided = false;
CRECT thisRect, thatRect;
thisRect = getCollisionArea();
thatRect = _thisThing->getCollisionArea();
// 'render' collision box at correct angle
DVECTOR posDelta = getPosDelta();
SVECTOR testPointsNonRel[4];
VECTOR testPoints[4];
thisRect.y1 -= abs( posDelta.vy ) >> 1;
thisRect.y2 += abs( posDelta.vy ) >> 1;
testPointsNonRel[0].vx = thisRect.x1 - Pos.vx;
testPointsNonRel[0].vy = thisRect.y1 - Pos.vy;
posDelta = _thisThing->getPosDelta();
testPointsNonRel[1].vx = thisRect.x2 - Pos.vx;
testPointsNonRel[1].vy = thisRect.y1 - Pos.vy;
thatRect.y1 -= abs( posDelta.vy ) >> 1;
thatRect.y2 += abs( posDelta.vy ) >> 1;
testPointsNonRel[2].vx = thisRect.x2 - Pos.vx;
testPointsNonRel[2].vy = thisRect.y2 - Pos.vy;
testPointsNonRel[3].vx = thisRect.x1 - Pos.vx;
testPointsNonRel[3].vy = thisRect.y2 - Pos.vy;
MATRIX mtx;
SetIdentNoTrans(&mtx );
RotMatrixZ( getCollisionAngle(), &mtx );
int i;
for ( i = 0 ; i < 4 ; i++ )
if(((thisRect.x1>=thatRect.x1&&thisRect.x1<=thatRect.x2)||(thisRect.x2>=thatRect.x1&&thisRect.x2<=thatRect.x2)||(thisRect.x1<=thatRect.x1&&thisRect.x2>=thatRect.x2))&&
((thisRect.y1>=thatRect.y1&&thisRect.y1<=thatRect.y2)||(thisRect.y2>=thatRect.y1&&thisRect.y2<=thatRect.y2)||(thisRect.y1<=thatRect.y1&&thisRect.y2>=thatRect.y2)))
{
ApplyMatrix( &mtx, &testPointsNonRel[i], &testPoints[i] );
testPoints[i].vx += Pos.vx;
testPoints[i].vy += Pos.vy;
collided = true;
}
// now find the highest y pos
// first set highestY to lowest of the four points
s16 highestY = testPoints[0].vy;
for ( i = 1 ; i < 4 ; i++ )
{
if ( testPoints[i].vy > highestY ) // remember y is inverted
{
highestY = testPoints[i].vy;
}
}
for ( i = 0 ; i < 4 ; i++ )
{
int j = i + 1;
j %= 4;
VECTOR highestX, lowestX;
if ( testPoints[i].vx < testPoints[j].vx )
{
lowestX = testPoints[i];
highestX = testPoints[j];
}
else
{
lowestX = testPoints[j];
highestX = testPoints[i];
}
if ( highestX.vx == lowestX.vx )
{
// have to compare heights of both points to get highest
if ( lowestX.vy < highestY )
{
highestY = lowestX.vy;
}
if ( highestX.vy < highestY )
{
highestY = highestX.vy;
}
}
else
{
if ( thatPos.vx >= lowestX.vx && thatPos.vx <= highestX.vx )
{
// current position is above or below this line
s16 testY;
testY = lowestX.vy + ( ( thatPos.vx - lowestX.vx ) * ( highestX.vy - lowestX.vy ) ) /
( highestX.vx - lowestX.vx );
if ( testY < highestY )
{
highestY = testY;
}
}
}
}
return( highestY );
return( collided );
}
#endif // REMOVETHIS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef REMOVETHIS
int CNpcPlatform::checkCollisionAgainst(CThing *_thisThing, int _frames)
{
DVECTOR pos,thisThingPos;
int radius;
int collided;
MATRIX mtx;
pos=getCollisionCentre();
thisThingPos=_thisThing->getCollisionCentre();
radius=getCollisionRadius()+_thisThing->getCollisionRadius();
collided=false;
if(abs(pos.vx-thisThingPos.vx)<radius&&
abs(pos.vy-thisThingPos.vy)<radius)
{
CRECT thisRect,thatRect;
thisRect=getCollisionArea();
// ensure user 'sticks' to platform whilst it is moving along
thatRect=_thisThing->getCollisionArea();
// rotate thatPos opposite way to this CThing's collision angle, so that we can regard them both as being at 0 rotation
// get target thing's position
DVECTOR thatPos = _thisThing->getPos();
// get target thing's position relative to this thing's position
SVECTOR relativePos;
relativePos.vx = thatPos.vx - Pos.vx;
relativePos.vy = thatPos.vy - Pos.vy;
VECTOR newPos;
// get target thing's collision area relative to 0
thatRect.x1 -= thatPos.vx;
thatRect.y1 -= thatPos.vy;
thatRect.x2 -= thatPos.vx;
thatRect.y2 -= thatPos.vy;
SetIdentNoTrans(&mtx );
RotMatrixZ( -getCollisionAngle(), &mtx );
// rotation target relative position back to 0 by this thing's collision angle
ApplyMatrix( &mtx, &relativePos, &newPos );
// add on this thing's position to get new target thing's position after rotation around this thing
newPos.vx += Pos.vx;
newPos.vy += Pos.vy;
// reposition target thing's collision area
// horrible, horrible +2 shite is to deal with useless PSX innacurracies in calculations, which can cause it to
// believe that two collision areas are not *quite* colliding, even though they are
thatRect.x1 += newPos.vx - 2;
thatRect.y1 += newPos.vy - 2;
thatRect.x2 += newPos.vx + 2;
thatRect.y2 += newPos.vy + 2;
// check to see if bounding boxes collide
if(((thisRect.x1>=thatRect.x1&&thisRect.x1<=thatRect.x2)||(thisRect.x2>=thatRect.x1&&thisRect.x2<=thatRect.x2)||(thisRect.x1<=thatRect.x1&&thisRect.x2>=thatRect.x2))&&
((thisRect.y1>=thatRect.y1&&thisRect.y1<=thatRect.y2)||(thisRect.y2>=thatRect.y1&&thisRect.y2<=thatRect.y2)||(thisRect.y1<=thatRect.y1&&thisRect.y2>=thatRect.y2)))
{
collided=true;
// check to see if centre point (i.e. where the object is standing) collides too
if ( ( newPos.vx >= ( thisRect.x1 - 2 ) && newPos.vx <= ( thisRect.x2 + 2 ) ) &&
( newPos.vy >= ( thisRect.y1 - 2 ) && newPos.vy <= ( thisRect.y2 + 2 ) ) )
{
thatPos.vy = getNewYPos( _thisThing );
// vertical height change is the sum of the maximums of BOTH objects
// potentially, one object could be falling down through another object that is moving up
// hence we provide a certain leeway to compensate
s32 thisDeltaX = abs( getPosDelta().vx );
s32 thisDeltaY = abs( getPosDelta().vy );
s32 thisDelta;
if ( thisDeltaX > thisDeltaY )
{
thisDelta = thisDeltaX;
}
else
{
thisDelta = thisDeltaY;
}
s32 thatDeltaX = abs( _thisThing->getPosDelta().vx );
s32 thatDeltaY = abs( _thisThing->getPosDelta().vy );
s32 thatDelta;
if ( thatDeltaX > thatDeltaY )
{
thatDelta = thatDeltaX;
}
else
{
thatDelta = thatDeltaY;
}
s32 verticalDelta = thisDelta + thatDelta;
if ( thatPos.vy - _thisThing->getPos().vy >= -( verticalDelta ) )
{
if ( _thisThing->getHasPlatformCollided() )
{
// if this has already collided with a platform, check the current platform is
// (a) within 10 units,
// (b) higher
DVECTOR oldCollidedPos = _thisThing->getNewCollidedPos();
s32 oldY = abs( oldCollidedPos.vy - ( _thisThing->getPos().vy - verticalDelta ) );
s32 currentY = abs( thatPos.vy - ( _thisThing->getPos().vy - verticalDelta ) );
//if ( thatPos.vy < oldCollidedPos.vy )
if ( currentY < oldY )
{
_thisThing->setNewCollidedPos( thatPos );
}
}
else
{
_thisThing->setHasPlatformCollided( true );
_thisThing->setNewCollidedPos( thatPos );
}
}
}
}
}
return collided;
}
#endif // REMOVETHIS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -1197,22 +1069,35 @@ void CNpcPlatform::setTiltable( bool isTiltable )
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int CNpcPlatform::getHeightFromPlatformAtPosition(int _x,int _y)
int CNpcPlatform::getHeightFromPlatformAtPosition(int _x,int _y, int offsetX, int offsetY)
{
DVECTOR centre;
DVECTOR top;
int angle;
centre=getCollisionCentre();
CRECT collisionArea = getCollisionArea();
top.vx = offsetX + ( ( collisionArea.x1 + collisionArea.x2 ) >> 1 );
//sBBox boundingBox = m_modelGfx->GetBBox();
sBBox boundingBox = getBBox();
//top.vy = collisionArea.y1;
top.vy = boundingBox.YMin + Pos.vy + offsetY;
angle=getCollisionAngle();
if(angle==0)
{
// Non-rotated platform
return centre.vy-_y;
return( top.vy - _y );
}
else
{
// Rotate backwards to find height at current position
return (centre.vy-_y)+((centre.vx-_x)*msin(-angle&4095)>>12);
//return( ( top.vy - _y ) + ( ( top.vx - _x ) * msin( -angle & 4095 ) >> 12 ) );
int hypotenuse = ( ( top.vx - _x ) << 12 ) / rcos( angle );
int angleHeight = -( hypotenuse * rsin( angle ) ) >> 12;
return( ( top.vy - _y ) + angleHeight );
}
}

View File

@ -96,11 +96,9 @@ public:
void setType( NPC_PLATFORM_UNIT_TYPE newType ) {m_type = newType;}
void setTypeFromMapEdit( u16 newType );
void setLayerCollision( class CLayerCollision *_layer ) {m_layerCollision=_layer;}
#ifdef REMOVETHIS
// virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
virtual s32 getNewYPos( CThing *_thisThing );
#endif
int getHeightFromPlatformAtPosition(int _x,int _y);
virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
virtual u8 checkCollisionDelta( CThing *_thisThing, int threshold, CRECT collisionArea );
virtual int getHeightFromPlatformAtPosition(int _x,int _y, int offsetX = 0, int offsetY = 0);
void setTiltable( bool isTiltable );
void addWaypoint( s32 xPos, s32 yPos );
void setGraphic( sThingPlatform *ThisPlatform );
@ -164,6 +162,7 @@ protected:
virtual void processTimer( int _frames );
void processTilt( int _frames );
bool isCollisionWithGround();
virtual sBBox &getBBox() {return( m_modelGfx->GetBBox() );}
// data

View File

@ -137,30 +137,6 @@ void CNpcPendulumPlatform::render()
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR size;
DVECTOR centre;
int halfLength;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
x1 = x1Boundary = Pos.vx - offset.vx;

View File

@ -34,10 +34,6 @@ void CNpcRaftPlatform::postInit()
m_isActivated = false;
m_isSinking = false;
sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), PLATFORMCOLLISIONHEIGHT + ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) - 16 );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -124,32 +124,6 @@ void CNpcRetractingPlatform::render()
scale.vz = m_extension;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}

View File

@ -28,17 +28,6 @@
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSteerableBarrelPlatform::postInit()
{
CNpcPlatform::postInit();
sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), PLATFORMCOLLISIONHEIGHT + ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) - 32 );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcSteerableBarrelPlatform::processMovement( int _frames )
@ -134,31 +123,6 @@ void CNpcSteerableBarrelPlatform::render()
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}

View File

@ -21,7 +21,6 @@
class CNpcSteerableBarrelPlatform : public CNpcPlatform
{
public:
virtual void postInit();
virtual void render();
protected:
virtual void processMovement( int _frames );

View File

@ -132,32 +132,6 @@ void CNpcSeesawPlatform::render()
scale.vz = ONE;
m_modelGfx->Render(renderPos,&rotation,&scale);
#if defined (__USER_paul__) || defined (__USER_charles__)
DVECTOR offset = CLevel::getCameraPos();
DVECTOR size;
DVECTOR centre;
int halfLength;
int x1,y1,x2,y2;
centre=getCollisionCentre();
size=getCollisionSize();
halfLength=size.vx>>1;
x1=-halfLength*mcos(getCollisionAngle()&4095)>>12;
y1=-halfLength*msin(getCollisionAngle()&4095)>>12;
x2=+halfLength*mcos(getCollisionAngle()&4095)>>12;
y2=+halfLength*msin(getCollisionAngle()&4095)>>12;
centre.vx-=offset.vx;
centre.vy-=offset.vy;
x1+=centre.vx;
y1+=centre.vy;
x2+=centre.vx;
y2+=centre.vy;
DrawLine(x1,y1,x2,y2,0,255,0,0);
#endif
}
}
}

View File

@ -3,9 +3,9 @@
player.cpp
Author: PKG
Created:
Created:
Project: Spongebob
Purpose:
Purpose:
Copyright (c) 2001 Climax Development Ltd
@ -694,17 +694,22 @@ if(newmode!=-1)
platform=isOnPlatform();
if(platform)
{
int platformOffset = ( ( CNpcPlatform* ) platform )->getHeightFromPlatformAtPosition( Pos.vx, Pos.vy );
Pos.vy += platformOffset;
DVECTOR posDelta;
posDelta=platform->getPosDelta();
if(((CNpcPlatform*)platform)->getHeightFromPlatformAtPosition(Pos.vx+posDelta.vx,Pos.vy+posDelta.vy)==0)
posDelta.vy = 0;
shove(posDelta);
/*if(((CNpcPlatform*)platform)->getHeightFromPlatformAtPosition(Pos.vx+posDelta.vx,Pos.vy+posDelta.vy)==0)
{
shove(posDelta);
}
}*/
}
m_allowConversation=false;
if(m_healthReactFrames)
{
m_healthReactFrames-=_frames;
@ -997,7 +1002,7 @@ if(getPadInputDown())
else if(m_cameraPos.vx>m_cameraPosLimitBox.x2) m_cameraPos.vx=m_cameraPosLimitBox.x2;
if(m_cameraPos.vy<m_cameraPosLimitBox.y1) m_cameraPos.vy=m_cameraPosLimitBox.y1;
else if(m_cameraPos.vy>m_cameraPosLimitBox.y2) m_cameraPos.vy=m_cameraPosLimitBox.y2;
CPlayerThing::think(_frames);
}
@ -1156,7 +1161,7 @@ for(int i=0;i<NUM_LASTPOS;i++)
POLY_FT4 *ft4;
sFrameHdr *fh;
int V,W,H,partH;
ft4=m_spriteBank->printFT4(FRM__WATERHILIGHT,HEALTH_ICONX,HEALTH_ICONY,0,0,0);
setSemiTrans(ft4,true);
@ -1583,7 +1588,7 @@ void CPlayer::respawn()
m_jellyfishAmmo=0;
m_moveVelocity.vx=m_moveVelocity.vy=0;
clearPlatform();
updateCollisionArea();
@ -1937,7 +1942,7 @@ PLAYERINPUT CPlayer::readPadInput()
input=PI_NONE;
pad=PadGetHeld(0);
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_UP))
{
input=(PLAYERINPUT)(input|PI_UP);
@ -2294,7 +2299,7 @@ int CPlayer::moveHorizontal(int _moveDistance)
hitWall=true;
_moveDistance=0;
// Get the height at this new position and then try the step-up code below.
// Without this, there are problems when you run up a slope and hit a wall at the same time
colHeight=getHeightFromGround(pos.vx,pos.vy);
@ -2340,7 +2345,7 @@ int CPlayer::moveHorizontal(int _moveDistance)
pos.vx+=_moveDistance;
setPlayerPos(&pos);
}
return hitWall;
}
@ -2380,4 +2385,4 @@ void CPlayer::getPlayerCollisionSize(int *_x,int *_y,int *_w,int *_h)
}
/*===========================================================================
end */
end */