diff --git a/source/player/player.cpp b/source/player/player.cpp index 4195c7228..3fe7c45e5 100644 --- a/source/player/player.cpp +++ b/source/player/player.cpp @@ -37,6 +37,10 @@ #include "player\pmodes.h" #endif +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + // to be removed #include "gfx\tpage.h" @@ -219,9 +223,6 @@ m_animFrame=0; m_lives=CGameSlotManager::getSlotData().m_lives; - xHighRes = 0; - yHighRes = 0; - m_cameraOffset.vx=0; m_cameraOffset.vy=0; m_cameraScrollDir=0; @@ -1464,15 +1465,6 @@ void CPlayer::shove( DVECTOR move ) { 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.vy = Pos.vy + move.vy; diff --git a/source/player/player.h b/source/player/player.h index 248c128c5..461579466 100644 --- a/source/player/player.h +++ b/source/player/player.h @@ -326,8 +326,6 @@ private: public: void setPlatform( CThing *newPlatform ); void clearPlatform(); - int xHighRes; - int yHighRes; private: CThing *m_platform; bool m_onPlatform; diff --git a/source/thing/thing.cpp b/source/thing/thing.cpp index 8e4b99fba..9e7a471fd 100644 --- a/source/thing/thing.cpp +++ b/source/thing/thing.cpp @@ -130,13 +130,26 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - thing1->removeAllChild(); - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2)) + //if ( !thing1->hasChild( thing2 ) ) { - thing1->addChild( thing2 ); - thing1->collidedWith(thing2); + thing1->removeAllChild(); + if(thing1->canCollide()&& + thing1->checkCollisionAgainst(thing2)) + { + thing1->addChild( thing2 ); + + thing1->collidedWith(thing2); + } } + /*else + { + DVECTOR thatPos = thing2->getPos(); + + thatPos.vy = thing1->getNewYPos( thing2 ); + thing2->setNewCollidedPos( thatPos ); + thing1->collidedWith(thing2); + }*/ + thing1=thing1->m_nextThing; } @@ -297,7 +310,6 @@ void CThing::init() setCollisionSize(20,20); // Some temporary defaults.. (pkg) setCollisionCentreOffset(0,0); m_collisionAngle = 0; - m_collisionStickyBoundary = 0; m_centreCollision = false; } @@ -510,6 +522,29 @@ CThing *List=Next; 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: Purpose: @@ -546,6 +581,119 @@ void CThing::updateCollisionArea() m_collisionArea.y2=m_collisionArea.y1+m_collisionSize.vy; } +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ + +s32 CThing::getNewYPos(CThing *_thisThing) +{ + CRECT thisRect; + DVECTOR thatPos = _thisThing->getPos(); + + thisRect = getCollisionArea(); + + // 'render' collision box at correct angle + + SVECTOR testPointsNonRel[4]; + VECTOR testPoints[4]; + + testPointsNonRel[0].vx = thisRect.x1 - Pos.vx; + testPointsNonRel[0].vy = thisRect.y1 - Pos.vy; + + testPointsNonRel[1].vx = thisRect.x2 - Pos.vx; + testPointsNonRel[1].vy = thisRect.y1 - Pos.vy; + + 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( m_collisionAngle, &mtx ); + + int i; + + for ( i = 0 ; i < 4 ; i++ ) + { + ApplyMatrix( &mtx, &testPointsNonRel[i], &testPoints[i] ); + + testPoints[i].vx += Pos.vx; + testPoints[i].vy += Pos.vy; + } + + // 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 ); +} + /*---------------------------------------------------------------------- Function: Purpose: @@ -574,11 +722,6 @@ int CThing::checkCollisionAgainst(CThing *_thisThing) // 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 @@ -633,105 +776,9 @@ int CThing::checkCollisionAgainst(CThing *_thisThing) 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 - - SVECTOR testPointsNonRel[4]; - VECTOR testPoints[4]; - - testPointsNonRel[0].vx = thisRect.x1 - Pos.vx; - testPointsNonRel[0].vy = thisRect.y1 - Pos.vy; - - testPointsNonRel[1].vx = thisRect.x2 - Pos.vx; - testPointsNonRel[1].vy = thisRect.y1 - Pos.vy; - - 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; - - SetIdentNoTrans(&mtx ); - RotMatrixZ( m_collisionAngle, &mtx ); - - int i; - - for ( i = 0 ; i < 4 ; i++ ) - { - ApplyMatrix( &mtx, &testPointsNonRel[i], &testPoints[i] ); - - testPoints[i].vx += Pos.vx; - testPoints[i].vy += Pos.vy; - } - - // 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; - } - } - } - } - - thatPos.vy = highestY; + thatPos.vy = getNewYPos( _thisThing ); _thisThing->setNewCollidedPos( thatPos ); } diff --git a/source/thing/thing.h b/source/thing/thing.h index d6f590fa8..093d5bb5f 100644 --- a/source/thing/thing.h +++ b/source/thing/thing.h @@ -95,6 +95,7 @@ public: void addChild(CThing *Child); void removeChild(CThing *Child); void removeAllChild(); + bool hasChild(CThing *Child); DVECTOR getPos() {return Pos;} @@ -127,6 +128,8 @@ public: virtual int checkCollisionAgainst(CThing *_thisThing); void updateCollisionArea(); virtual void collidedWith(CThing *_thisThing) {;} + s32 getNewYPos( CThing *_thisThing ); + void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;} protected: typedef struct { @@ -138,8 +141,6 @@ protected: void setCollisionCentreOffset(int _x,int _y) {m_collisionCentreOffset.vx=_x;m_collisionCentreOffset.vy=_y;} void setCollisionCentreOffset(DVECTOR xy) {m_collisionCentreOffset=xy;} 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;} int getCollisionRadius() {return m_collisionRadius;} CRECT getCollisionArea() {return m_collisionArea;} @@ -151,7 +152,6 @@ private: DVECTOR m_collisionSize; DVECTOR m_collisionCentreOffset; int m_collisionRadius; - int m_collisionStickyBoundary; // for platforms CRECT m_collisionArea; DVECTOR m_collisionCentre; s16 m_collisionAngle;