This commit is contained in:
parent
6b8d4291c2
commit
979a8ca669
4 changed files with 162 additions and 125 deletions
|
@ -37,6 +37,10 @@
|
||||||
#include "player\pmodes.h"
|
#include "player\pmodes.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __UTILS_HEADER__
|
||||||
|
#include "utils\utils.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// to be removed
|
// to be removed
|
||||||
#include "gfx\tpage.h"
|
#include "gfx\tpage.h"
|
||||||
|
|
||||||
|
@ -219,9 +223,6 @@ m_animFrame=0;
|
||||||
|
|
||||||
m_lives=CGameSlotManager::getSlotData().m_lives;
|
m_lives=CGameSlotManager::getSlotData().m_lives;
|
||||||
|
|
||||||
xHighRes = 0;
|
|
||||||
yHighRes = 0;
|
|
||||||
|
|
||||||
m_cameraOffset.vx=0;
|
m_cameraOffset.vx=0;
|
||||||
m_cameraOffset.vy=0;
|
m_cameraOffset.vy=0;
|
||||||
m_cameraScrollDir=0;
|
m_cameraScrollDir=0;
|
||||||
|
@ -1464,15 +1465,6 @@ void CPlayer::shove( DVECTOR move )
|
||||||
{
|
{
|
||||||
DVECTOR newPos;
|
DVECTOR newPos;
|
||||||
|
|
||||||
/*xHighRes += move.vx % 4096;
|
|
||||||
yHighRes += move.vy % 4096;
|
|
||||||
|
|
||||||
newPos.vx = Pos.vx + ( move.vx >> 12 ) + ( xHighRes >> 12 );
|
|
||||||
newPos.vy = Pos.vy + ( move.vy >> 12 ) + ( yHighRes >> 12 );
|
|
||||||
|
|
||||||
xHighRes %= 4096;
|
|
||||||
yHighRes %= 4096;*/
|
|
||||||
|
|
||||||
newPos.vx = Pos.vx + move.vx;
|
newPos.vx = Pos.vx + move.vx;
|
||||||
newPos.vy = Pos.vy + move.vy;
|
newPos.vy = Pos.vy + move.vy;
|
||||||
|
|
||||||
|
|
|
@ -326,8 +326,6 @@ private:
|
||||||
public:
|
public:
|
||||||
void setPlatform( CThing *newPlatform );
|
void setPlatform( CThing *newPlatform );
|
||||||
void clearPlatform();
|
void clearPlatform();
|
||||||
int xHighRes;
|
|
||||||
int yHighRes;
|
|
||||||
private:
|
private:
|
||||||
CThing *m_platform;
|
CThing *m_platform;
|
||||||
bool m_onPlatform;
|
bool m_onPlatform;
|
||||||
|
|
|
@ -129,14 +129,27 @@ void CThingManager::thinkAllThings(int _frames)
|
||||||
thing1=s_thingLists[CThing::TYPE_PLATFORM];
|
thing1=s_thingLists[CThing::TYPE_PLATFORM];
|
||||||
thing2=s_thingLists[CThing::TYPE_PLAYER];
|
thing2=s_thingLists[CThing::TYPE_PLAYER];
|
||||||
while(thing1&&thing2)
|
while(thing1&&thing2)
|
||||||
|
{
|
||||||
|
//if ( !thing1->hasChild( thing2 ) )
|
||||||
{
|
{
|
||||||
thing1->removeAllChild();
|
thing1->removeAllChild();
|
||||||
if(thing1->canCollide()&&
|
if(thing1->canCollide()&&
|
||||||
thing1->checkCollisionAgainst(thing2))
|
thing1->checkCollisionAgainst(thing2))
|
||||||
{
|
{
|
||||||
thing1->addChild( thing2 );
|
thing1->addChild( thing2 );
|
||||||
|
|
||||||
thing1->collidedWith(thing2);
|
thing1->collidedWith(thing2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/*else
|
||||||
|
{
|
||||||
|
DVECTOR thatPos = thing2->getPos();
|
||||||
|
|
||||||
|
thatPos.vy = thing1->getNewYPos( thing2 );
|
||||||
|
thing2->setNewCollidedPos( thatPos );
|
||||||
|
thing1->collidedWith(thing2);
|
||||||
|
}*/
|
||||||
|
|
||||||
thing1=thing1->m_nextThing;
|
thing1=thing1->m_nextThing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +310,6 @@ void CThing::init()
|
||||||
setCollisionSize(20,20); // Some temporary defaults.. (pkg)
|
setCollisionSize(20,20); // Some temporary defaults.. (pkg)
|
||||||
setCollisionCentreOffset(0,0);
|
setCollisionCentreOffset(0,0);
|
||||||
m_collisionAngle = 0;
|
m_collisionAngle = 0;
|
||||||
m_collisionStickyBoundary = 0;
|
|
||||||
m_centreCollision = false;
|
m_centreCollision = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,6 +522,29 @@ CThing *List=Next;
|
||||||
Next=NULL;
|
Next=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------
|
||||||
|
Function:
|
||||||
|
Purpose:
|
||||||
|
Params:
|
||||||
|
Returns:
|
||||||
|
---------------------------------------------------------------------- */
|
||||||
|
bool CThing::hasChild(CThing *Child)
|
||||||
|
{
|
||||||
|
CThing *nextChild = Next;
|
||||||
|
|
||||||
|
while( nextChild )
|
||||||
|
{
|
||||||
|
if ( nextChild == Child )
|
||||||
|
{
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
nextChild = nextChild->Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return( false );
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------
|
/*----------------------------------------------------------------------
|
||||||
Function:
|
Function:
|
||||||
Purpose:
|
Purpose:
|
||||||
|
@ -552,89 +587,13 @@ void CThing::updateCollisionArea()
|
||||||
Params:
|
Params:
|
||||||
Returns:
|
Returns:
|
||||||
---------------------------------------------------------------------- */
|
---------------------------------------------------------------------- */
|
||||||
int CThing::checkCollisionAgainst(CThing *_thisThing)
|
|
||||||
|
s32 CThing::getNewYPos(CThing *_thisThing)
|
||||||
{
|
{
|
||||||
DVECTOR pos,thisThingPos;
|
CRECT thisRect;
|
||||||
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
|
|
||||||
|
|
||||||
thisRect.x1 -= m_collisionStickyBoundary;
|
|
||||||
thisRect.y1 -= m_collisionStickyBoundary;
|
|
||||||
thisRect.x2 += m_collisionStickyBoundary;
|
|
||||||
thisRect.y2 += m_collisionStickyBoundary;
|
|
||||||
|
|
||||||
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();
|
DVECTOR thatPos = _thisThing->getPos();
|
||||||
|
|
||||||
// get target thing's position relative to this thing's position
|
thisRect = getCollisionArea();
|
||||||
|
|
||||||
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( -m_collisionAngle, &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
|
|
||||||
|
|
||||||
thatRect.x1 += newPos.vx;
|
|
||||||
thatRect.y1 += newPos.vy;
|
|
||||||
thatRect.x2 += newPos.vx;
|
|
||||||
thatRect.y2 += newPos.vy;
|
|
||||||
|
|
||||||
// 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 && newPos.vx <= thisRect.x2 ) &&
|
|
||||||
( newPos.vy >= thisRect.y1 && newPos.vy <= thisRect.y2 ) )
|
|
||||||
{
|
|
||||||
thisRect=getCollisionArea();
|
|
||||||
_thisThing->setCentreCollision( true );
|
|
||||||
|
|
||||||
// 'render' collision box at correct angle
|
// 'render' collision box at correct angle
|
||||||
|
|
||||||
|
@ -653,6 +612,7 @@ int CThing::checkCollisionAgainst(CThing *_thisThing)
|
||||||
testPointsNonRel[3].vx = thisRect.x1 - Pos.vx;
|
testPointsNonRel[3].vx = thisRect.x1 - Pos.vx;
|
||||||
testPointsNonRel[3].vy = thisRect.y2 - Pos.vy;
|
testPointsNonRel[3].vy = thisRect.y2 - Pos.vy;
|
||||||
|
|
||||||
|
MATRIX mtx;
|
||||||
SetIdentNoTrans(&mtx );
|
SetIdentNoTrans(&mtx );
|
||||||
RotMatrixZ( m_collisionAngle, &mtx );
|
RotMatrixZ( m_collisionAngle, &mtx );
|
||||||
|
|
||||||
|
@ -731,7 +691,94 @@ int CThing::checkCollisionAgainst(CThing *_thisThing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thatPos.vy = highestY;
|
return( highestY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------
|
||||||
|
Function:
|
||||||
|
Purpose:
|
||||||
|
Params:
|
||||||
|
Returns:
|
||||||
|
---------------------------------------------------------------------- */
|
||||||
|
int CThing::checkCollisionAgainst(CThing *_thisThing)
|
||||||
|
{
|
||||||
|
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( -m_collisionAngle, &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
|
||||||
|
|
||||||
|
thatRect.x1 += newPos.vx;
|
||||||
|
thatRect.y1 += newPos.vy;
|
||||||
|
thatRect.x2 += newPos.vx;
|
||||||
|
thatRect.y2 += newPos.vy;
|
||||||
|
|
||||||
|
// 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 && newPos.vx <= thisRect.x2 ) &&
|
||||||
|
( newPos.vy >= thisRect.y1 && newPos.vy <= thisRect.y2 ) )
|
||||||
|
{
|
||||||
|
_thisThing->setCentreCollision( true );
|
||||||
|
|
||||||
|
thatPos.vy = getNewYPos( _thisThing );
|
||||||
|
|
||||||
_thisThing->setNewCollidedPos( thatPos );
|
_thisThing->setNewCollidedPos( thatPos );
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ public:
|
||||||
void addChild(CThing *Child);
|
void addChild(CThing *Child);
|
||||||
void removeChild(CThing *Child);
|
void removeChild(CThing *Child);
|
||||||
void removeAllChild();
|
void removeAllChild();
|
||||||
|
bool hasChild(CThing *Child);
|
||||||
|
|
||||||
|
|
||||||
DVECTOR getPos() {return Pos;}
|
DVECTOR getPos() {return Pos;}
|
||||||
|
@ -127,6 +128,8 @@ public:
|
||||||
virtual int checkCollisionAgainst(CThing *_thisThing);
|
virtual int checkCollisionAgainst(CThing *_thisThing);
|
||||||
void updateCollisionArea();
|
void updateCollisionArea();
|
||||||
virtual void collidedWith(CThing *_thisThing) {;}
|
virtual void collidedWith(CThing *_thisThing) {;}
|
||||||
|
s32 getNewYPos( CThing *_thisThing );
|
||||||
|
void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;}
|
||||||
protected:
|
protected:
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -138,8 +141,6 @@ protected:
|
||||||
void setCollisionCentreOffset(int _x,int _y) {m_collisionCentreOffset.vx=_x;m_collisionCentreOffset.vy=_y;}
|
void setCollisionCentreOffset(int _x,int _y) {m_collisionCentreOffset.vx=_x;m_collisionCentreOffset.vy=_y;}
|
||||||
void setCollisionCentreOffset(DVECTOR xy) {m_collisionCentreOffset=xy;}
|
void setCollisionCentreOffset(DVECTOR xy) {m_collisionCentreOffset=xy;}
|
||||||
void setCentreCollision(bool newCentreCollision) {m_centreCollision = newCentreCollision;}
|
void setCentreCollision(bool newCentreCollision) {m_centreCollision = newCentreCollision;}
|
||||||
void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;}
|
|
||||||
void setCollisionStickyBoundary(int boundary) {m_collisionStickyBoundary = boundary;}
|
|
||||||
void setCollisionAngle(int newAngle) {m_collisionAngle = newAngle;}
|
void setCollisionAngle(int newAngle) {m_collisionAngle = newAngle;}
|
||||||
int getCollisionRadius() {return m_collisionRadius;}
|
int getCollisionRadius() {return m_collisionRadius;}
|
||||||
CRECT getCollisionArea() {return m_collisionArea;}
|
CRECT getCollisionArea() {return m_collisionArea;}
|
||||||
|
@ -151,7 +152,6 @@ private:
|
||||||
DVECTOR m_collisionSize;
|
DVECTOR m_collisionSize;
|
||||||
DVECTOR m_collisionCentreOffset;
|
DVECTOR m_collisionCentreOffset;
|
||||||
int m_collisionRadius;
|
int m_collisionRadius;
|
||||||
int m_collisionStickyBoundary; // for platforms
|
|
||||||
CRECT m_collisionArea;
|
CRECT m_collisionArea;
|
||||||
DVECTOR m_collisionCentre;
|
DVECTOR m_collisionCentre;
|
||||||
s16 m_collisionAngle;
|
s16 m_collisionAngle;
|
||||||
|
|
Loading…
Add table
Reference in a new issue