diff --git a/source/enemy/nsdart.cpp b/source/enemy/nsdart.cpp index 1ce75edcd..1cb376fe4 100644 --- a/source/enemy/nsdart.cpp +++ b/source/enemy/nsdart.cpp @@ -65,7 +65,7 @@ void CNpcSquidDartEnemy::render() int frame = FRM_SQUIDDART_SWIM0001 + ( m_frame >> 8 ); - SprFrame = CGameScene::getSpriteBank()->printFT4(frame,renderPos.vx,renderPos.vy,m_reversed,0,10); + SprFrame = CGameScene::getSpriteBank()->printFT4(frame,renderPos.vx,renderPos.vy,m_reversed,0,0); //setRGB0( SprFrame, 255, 128, 255 ); diff --git a/source/friend/fgary.cpp b/source/friend/fgary.cpp index 5e268bbdd..e8bfc0555 100644 --- a/source/friend/fgary.cpp +++ b/source/friend/fgary.cpp @@ -3,9 +3,9 @@ fgary.cpp Author: CRB - Created: + Created: Project: Spongebob - Purpose: + Purpose: Copyright (c) 2000 Climax Development Ltd @@ -34,6 +34,19 @@ void CNpcGaryFriend::think( int _frames ) groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 ); + if ( m_platform ) + { + s32 platformHeight = m_platform->getHeightFromPlatformAtPosition( Pos.vx, Pos.vy ); + + if ( platformHeight < groundHeight ) + { + groundHeight = platformHeight; + } + + //Pos.vy += platformHeight; + //return; + } + if ( groundHeight <= 0 ) { // groundHeight <= 0 indicates either on ground or below ground diff --git a/source/friend/friend.cpp b/source/friend/friend.cpp index 32401c92a..78094ddf8 100644 --- a/source/friend/friend.cpp +++ b/source/friend/friend.cpp @@ -3,9 +3,9 @@ friend.cpp Author: CRB - Created: + Created: Project: Spongebob - Purpose: + Purpose: Copyright (c) 2000 Climax Development Ltd @@ -174,6 +174,7 @@ void CNpcFriend::init() m_animNo = m_data[m_type].idleAnim; m_frame = 0; m_reversed = false; + m_platform = NULL; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -245,6 +246,7 @@ void CNpcFriend::render() m_actorGfx->Render(renderPos,m_animNo,(m_frame>>8),m_reversed); sBBox boundingBox = m_actorGfx->GetBBox(); + boundingBox.YMax = 0; setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) ); setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 ); } diff --git a/source/friend/friend.h b/source/friend/friend.h index b3a098540..f564fcfb7 100644 --- a/source/friend/friend.h +++ b/source/friend/friend.h @@ -3,9 +3,9 @@ friend.h Author: CRB - Created: + Created: Project: Spongebob - Purpose: + Purpose: Copyright (c) 2000 Climax Development Ltd @@ -22,6 +22,10 @@ #include "player\player.h" #endif +#ifndef __PLATFORM_PLATFORM_H__ +#include "platform\platform.h" +#endif + class CNpcFriend : public CNpcThing { public: @@ -51,6 +55,8 @@ public: void setType( NPC_FRIEND_UNIT_TYPE newType ) {m_type = newType;} + void setPlatform( CNpcPlatform *platform ) {m_platform = platform;} + void clearPlatform() {m_platform = NULL;} static CNpcFriend *Create(sThingActor *ThisActor); static NPC_FRIEND_UNIT_TYPE getTypeFromMapEdit( u16 newType ); @@ -90,9 +96,10 @@ protected: }; // internal variables - + NPC_FRIEND_UNIT_TYPE m_type; s32 m_extension; + CNpcPlatform *m_platform; int m_frame; int m_animNo; diff --git a/source/platform/pdual.cpp b/source/platform/pdual.cpp index 51b3a3791..649f4c449 100644 --- a/source/platform/pdual.cpp +++ b/source/platform/pdual.cpp @@ -15,6 +15,10 @@ #include "platform\pdual.h" #endif +#ifndef __HAZARD_HAZARD_H__ +#include "hazard\hazard.h" +#endif + #ifndef __UTILS_HEADER__ #include "utils\utils.h" #endif @@ -231,4 +235,77 @@ const CRECT *CNpcDualPlatform::getThinkBBox() objThinkBox.y2 = thinkBBox.YMax; return &objThinkBox; -} \ No newline at end of file +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcDualPlatform::collidedWith( CThing *_thisThing ) +{ + switch(_thisThing->getThingType()) + { + case TYPE_PLAYER: + { + CPlayer *player; + DVECTOR playerPos; + CRECT collisionArea; + + // Only interested in SBs feet colliding with the box (pkg) + player=(CPlayer*)_thisThing; + playerPos=player->getPos(); + collisionArea=getCollisionArea(); + + 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; + } + } + } + } + + break; + } + + case TYPE_NPC: + break; + + case TYPE_HAZARD: + { + m_contact = true; + + CNpcHazard *hazard; + + hazard = (CNpcHazard *)_thisThing; + + hazard->setPlatform( this ); + + break; + } + + default: + ASSERT(0); + break; + } +} diff --git a/source/platform/pdual.h b/source/platform/pdual.h index fe3002061..850aa13c9 100644 --- a/source/platform/pdual.h +++ b/source/platform/pdual.h @@ -32,6 +32,7 @@ public: protected: virtual void setWaypoints( sThingPlatform *ThisPlatform ); virtual void processMovement( int _frames ); + virtual void collidedWith(CThing *_thisThing); u8 m_isMaster; CNpcDualPlatform *m_otherPlatform; diff --git a/source/platform/platform.cpp b/source/platform/platform.cpp index ea7f4e82e..fd7bb3a84 100644 --- a/source/platform/platform.cpp +++ b/source/platform/platform.cpp @@ -29,6 +29,10 @@ #include "player\player.h" #endif +#ifndef __FRIEND_FRIEND_H__ +#include "friend\friend.h" +#endif + #ifndef __HAZARD_HAZARD_H__ #include "hazard\hazard.h" #endif @@ -249,7 +253,7 @@ CNpcPlatform *CNpcPlatform::Create(sThingPlatform *ThisPlatform) platform = new ("cart platform") CNpcCartPlatform; break; } - + case NPC_SEESAW_PLATFORM: { platform = new ("seesaw platform") CNpcSeesawPlatform; @@ -668,7 +672,7 @@ void CNpcPlatform::setCollisionAngle(int newAngle) m_collisionAngle=newAngle; // CPlatformThing::setCollisionAngle(newAngle); calculateBoundingBoxSize(); - + CPlayer *player; // Is the player stood on this platform as it rotates? @@ -966,19 +970,55 @@ void CNpcPlatform::collidedWith( CThing *_thisThing ) break; } - case TYPE_HAZARD: + case TYPE_NPC: { - m_contact = true; + CNpcFriend *friendNpc; + DVECTOR friendPos; + CRECT collisionArea; - CNpcHazard *hazard; + friendNpc = (CNpcFriend*) _thisThing; + friendPos = friendNpc->getPos(); + collisionArea=getCollisionArea(); - hazard = (CNpcHazard *)_thisThing; + s32 threshold = abs( collisionArea.y2 - collisionArea.y1 ); - hazard->setPlatform( this ); + if ( threshold > 16 ) + { + threshold = 16; + } + + if( friendPos.vx >= collisionArea.x1 && friendPos.vx <= collisionArea.x2 ) + { + if ( checkCollisionDelta( _thisThing, threshold, collisionArea ) ) + { + int height = getHeightFromPlatformAtPosition( friendPos.vx, friendPos.vy ); + + friendNpc->setPlatform( this ); + + m_contact = true; + } + else + { + if( friendPos.vy >= collisionArea.y1 && friendPos.vy <= collisionArea.y2 ) + { + int height = getHeightFromPlatformAtPosition( friendPos.vx, friendPos.vy ); + + if ( height >= -threshold && height < 1 ) + { + friendNpc->setPlatform( this ); + + m_contact = true; + } + } + } + } break; } + case TYPE_HAZARD: + break; + default: ASSERT(0); break; diff --git a/source/thing/thing.cpp b/source/thing/thing.cpp index d3c40d4f7..120ae7c70 100644 --- a/source/thing/thing.cpp +++ b/source/thing/thing.cpp @@ -3,9 +3,9 @@ thing.cpp Author: PKG - Created: + Created: Project: Spongebob - Purpose: + Purpose: Copyright (c) 2001 Climax Development Ltd @@ -40,6 +40,10 @@ #include "friend\friend.h" #include "fx\fx.h" +#ifndef __FRIEND_FRIEND_H__ +#include "friend\friend.h" +#endif + #ifndef __HAZARD_HRWEIGHT_H__ #include "hazard\hrweight.h" #endif @@ -172,7 +176,7 @@ int i; /*---------------------------------------------------------------------- Function: - Purpose: + Purpose: Params: Returns: ---------------------------------------------------------------------- */ @@ -346,7 +350,7 @@ DVECTOR const &CamPos=CLevel::getCameraPos(); CRECT const *ThingRect= thing->getThinkBBox(); bool Flag=true; // Will speed this up - + if (!thing->alwaysThink()) { if (ThingRect->x2x1>m_ThinkBBox.XMax) Flag=false; @@ -537,6 +541,32 @@ DVECTOR const &CamPos=CLevel::getCameraPos(); } thing1=thing1->m_nextCollisionThing; } + + // Friendly npc -> Platform projectile collision - first clear platforms + + CNpcFriend *friendNpc = (CNpcFriend *) s_CollisionLists[CThing::TYPE_NPC]; + while( friendNpc ) + { + friendNpc->clearPlatform(); + friendNpc = (CNpcFriend *) friendNpc->m_nextCollisionThing; + } + + // now detect new platform + + thing1=s_CollisionLists[CThing::TYPE_PLATFORM]; + while(thing1) + { + thing2=s_CollisionLists[CThing::TYPE_NPC]; + while(thing2) + { + if(thing1->checkCollisionAgainst(thing2, _frames)) + { + thing1->collidedWith(thing2); + } + thing2=thing2->m_nextCollisionThing; + } + thing1=thing1->m_nextCollisionThing; + } } // Shut emm down, sh sh shut em down, we shutem down for(i=0;igetThingType(); int SubType=Thing->getThingSubType(); CThing **List=s_FreeList[Type]; - + // Check its been aquired/set correctly ASSERT(SubType!=1234); @@ -851,7 +881,7 @@ void CThing::init() ---------------------------------------------------------------------- */ void CThing::shutdown() { - if (ParentThing) + if (ParentThing) { // Is child ParentThing->removeChild(this); } @@ -872,7 +902,7 @@ void CThing::shutdown() ---------------------------------------------------------------------- */ void CThing::think(int _frames) { - PosDelta.vx=Pos.vx-PosLast.vx; + PosDelta.vx=Pos.vx-PosLast.vx; PosDelta.vy=Pos.vy-PosLast.vy; PosLast=Pos; @@ -1036,7 +1066,7 @@ CThing *List=NextThing; if ( List ) { // Find end of list - while (List->NextThing) + while (List->NextThing) { List=List->NextThing; } @@ -1327,4 +1357,3 @@ void CTriggerThing::setTargetBox(int _x,int _y,int _w,int _h) } -