예제 #1
0
CollisionDirection CollisionHandler::HandleCollisionWithRect(unsigned int _objId, sf::FloatRect _ref)
{
	DisplayableObject *obj = m_gameEngine->GetForegroundItem(_objId);
	CollisionDirection direction = DetectCollisionWithRect(obj->GetCoordinates(), _ref);
	ReactToCollision(*obj, _ref, direction);
	return direction;
}
예제 #2
0
CollisionDirection CollisionHandler::DetectCollisionWithObj(MovingObject& _obj, DisplayableObject& _ref)
{
	if (_obj.GetID() == _ref.GetID())
		return NO_COL;

	return DetectCollisionWithRect(_obj.GetCoordinates(), _ref.GetCoordinates());
}
예제 #3
0
void CollisionHandler::ReactToCollisionsWithObj(MovingObject& _obj, DisplayableObject& _ref, CollisionDirection _direction)
{
	ReactToCollision(_obj, _ref.GetCoordinates(), _direction);

	_obj.UpdateAfterCollision(Util::OppositeCollisionDirection(_direction), _ref.GetClass()); // Updates the state of the object, not its coordinates
	_obj.SetPosition(m_gameEngine->GetCoordinatesOfForegroundItem(_obj.GetID()));

	_ref.UpdateAfterCollision(_direction, _obj.GetClass());

	SendNewObjectPositionToGFX(_ref);
}
예제 #4
0
void CollisionHandler::ReactToCollision(DisplayableObject& _obj, sf::FloatRect _refRect, CollisionDirection _direction)
{
	sf::FloatRect objRect = _obj.GetCoordinates();
	switch (_direction)
	{
		case TOP:
			objRect.top -= (objRect.top + objRect.height - _refRect.top);
			break;
		case BOTTOM:
			objRect.top += (_refRect.top + _refRect.height - objRect.top);
			break;
		case LEFT:
			objRect.left -= (objRect.left + objRect.width - _refRect.left);
			break;
		case RIGHT:
			objRect.left += (_refRect.left + _refRect.width - objRect.left);
			break;
		case NO_COL:
		default:
			break;
	}
	m_gameEngine->UpdateForegroundItem(_obj.GetID(), objRect);
}