CSC8503_Advanced_Game_Technologies / CSC8503 / CSC8503Common / BonusObject.cpp
BonusObject.cpp
Raw
#include "BonusObject.h"

void BonusObject::OnCollisionBegin(GameObject* otherObject) {
	//Only players can move and have Collect resolution
	if (owner == nullptr //Other players can't steal our bonus!
		&& otherObject->GetPhysicsObject()->IsAffectedByGravity() //Bonus objects cannot interact with other Bonus objects
		&& otherObject->GetPhysicsObject()->GetCollisionResolution() & CollisionResolution::Collect)
	{
		owner = otherObject;
		if (this->GetRenderObject()->GetColour() == Vector4(1.0f, 1.0f, 0.0f, 1.0f)) {
			bonusValue = 50;
		}

		if ((PlayerObject*)otherObject == otherObject){
			((PlayerObject*)otherObject)->PickUpItem((BonusObject*)this, bonusValue);
			((PlayerObject*)otherObject)->AddScore(((BonusObject*)this)->GetPointsValue());
			((BonusObject*)this)->MakeInactive();
		}
		if ((AIOpponentObject*)otherObject == otherObject) {
			((AIOpponentObject*)otherObject)->PickUpItem((BonusObject*)this, bonusValue);
			((AIOpponentObject*)otherObject)->AddScore(((BonusObject*)this)->GetPointsValue());
			((BonusObject*)this)->MakeInactive();
		}
	}
}