From 28ed71d2542b4c684eac276de6f4fb44f480708c Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 17 Aug 2001 18:54:26 +0000 Subject: [PATCH] --- source/player/player.cpp | 11 ++++++++-- source/player/player.h | 1 + source/triggers/tsecret.cpp | 31 ++++++++++++++++++++++++--- source/triggers/tteleprt.cpp | 41 +++++++++++++++++++++++++++--------- 4 files changed, 69 insertions(+), 15 deletions(-) diff --git a/source/player/player.cpp b/source/player/player.cpp index 9342004da..aac9fbf41 100644 --- a/source/player/player.cpp +++ b/source/player/player.cpp @@ -3158,10 +3158,9 @@ void CPlayer::setPlayerCollisionSize(int _x,int _y,int _w,int _h) setCollisionSize(_w,_h); setCollisionCentreOffset(_x,_y); } + void CPlayer::getPlayerCollisionSize(int *_x,int *_y,int *_w,int *_h) { -// DVECTOR offset,size; - DVECTOR const &offset=getCollisionCentreOffset(); DVECTOR const &size=getCollisionSize(); @@ -3171,5 +3170,13 @@ DVECTOR const &size=getCollisionSize(); *_h=size.vy; } +void CPlayer::getPlayerNormalCollisionSize(int *_x,int *_y,int *_w,int *_h) +{ + *_x=0; + *_y=-COLSIZE_BASE_HEIGHT/2; + *_w=COLSIZE_BASE_WIDTH; + *_h=COLSIZE_BASE_HEIGHT; +} + /*=========================================================================== end */ \ No newline at end of file diff --git a/source/player/player.h b/source/player/player.h index 64c9d42cb..a83fed18c 100644 --- a/source/player/player.h +++ b/source/player/player.h @@ -491,6 +491,7 @@ public: void resetPlayerCollisionSizeToBase(); void setPlayerCollisionSize(int _x,int _y,int _w,int _h); void getPlayerCollisionSize(int *_x,int *_y,int *_w,int *_h); + void getPlayerNormalCollisionSize(int *_x,int *_y,int *_w,int *_h); diff --git a/source/triggers/tsecret.cpp b/source/triggers/tsecret.cpp index e29e88c55..f2cf653c6 100644 --- a/source/triggers/tsecret.cpp +++ b/source/triggers/tsecret.cpp @@ -22,6 +22,10 @@ #include "sound\sound.h" #endif +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + /* Std Lib ------- */ @@ -58,9 +62,30 @@ void CSecretAreaTrigger::collidedWith(CThing *_thisThing) { case TYPE_PLAYER: { - CSoundMediator::playSfx(CSoundMediator::SFX_SECRET_AREA); - shutdown(); - delete this; + // SB *might* be chopping to hit this trigger, so we only do the collision + // if he would normally hit it. + int x,y,w,h; + DVECTOR pos; + CRECT thisRect; + CRECT const &thatRect=getCollisionArea(); + int collided=true; + + ((CPlayer*)_thisThing)->getPlayerNormalCollisionSize(&x,&y,&w,&h); + pos=_thisThing->getPos(); + thisRect.x1=pos.vx+x-(w/2); + thisRect.y1=pos.vy+y-(h/2); + thisRect.x2=thisRect.x1+w; + thisRect.y2=thisRect.y1+h; + + if (thisRect.x2thatRect.x2) collided=false; + if (thisRect.y2thatRect.y2) collided=false; + if(collided) + { + // Ok.. so we've actually hit the thing properly :) + CSoundMediator::playSfx(CSoundMediator::SFX_SECRET_AREA); + shutdown(); + delete this; + } break; } diff --git a/source/triggers/tteleprt.cpp b/source/triggers/tteleprt.cpp index b3ca9e897..125048c98 100644 --- a/source/triggers/tteleprt.cpp +++ b/source/triggers/tteleprt.cpp @@ -73,21 +73,42 @@ void CTeleportTrigger::collidedWith(CThing *_thisThing) { case TYPE_PLAYER: { - if ( chapter == 5 && level == 5 ) + // SB *might* be chopping to hit this trigger, so we only do the collision + // if he would normally hit it. + int x,y,w,h; + DVECTOR pos; + CRECT thisRect; + CRECT const &thatRect=getCollisionArea(); + int collided=true; + + ((CPlayer*)_thisThing)->getPlayerNormalCollisionSize(&x,&y,&w,&h); + pos=_thisThing->getPos(); + thisRect.x1=pos.vx+x-(w/2); + thisRect.y1=pos.vy+y-(h/2); + thisRect.x2=thisRect.x1+w; + thisRect.y2=thisRect.y1+h; + + if (thisRect.x2thatRect.x2) collided=false; + if (thisRect.y2thatRect.y2) collided=false; + if(collided) { - if ( !CNpcGaryFriend::hasReachedDoor() ) + // Ok.. so we've actually hit the thing properly :) + if ( chapter == 5 && level == 5 ) { - // if we're on chapter 1, level 5, check Gary has reached the teleport point - // if he hasn't, don't let Spongey through + if ( !CNpcGaryFriend::hasReachedDoor() ) + { + // if we're on chapter 1, level 5, check Gary has reached the teleport point + // if he hasn't, don't let Spongey through - return; + return; + } } - } - if(GameScene.triggerTeleportEffect()) - { - ((CPlayer*)_thisThing)->clearPlatform(); - ((CPlayer*)_thisThing)->teleportTo(m_boxX1+8,m_boxY1+16); + if(GameScene.triggerTeleportEffect()) + { + ((CPlayer*)_thisThing)->clearPlatform(); + ((CPlayer*)_thisThing)->teleportTo(m_boxX1+8,m_boxY1+16); + } } break; }