Вы можете выполнить простое наследование от класса Entity
. Я не знаю, почему ваша программа вылетает при возврате sf::FloatRect
объектов. Это также должно быть правильным решением этой проблемы.
#include <SFML/Graphics.hpp>
#include <iostream>
class Entity : public sf::RectangleShape {
public:
bool isColliding(Entity const& other) {
return this->getGlobalBounds().intersects(other.getGlobalBounds());
}
};
class Player : public Entity {};
class Zombie : public Entity {};
int main() {
Player player;
player.setPosition({ 200, 200 });
player.setSize({ 100, 100 });
Zombie enemy;
enemy.setPosition({ 151, 151 });
enemy.setSize({ 50, 50 });
std::cout << player.isColliding(enemy);
}