diff --git a/include/ball.hpp b/include/ball.hpp index 8a5d746..7d73e60 100644 --- a/include/ball.hpp +++ b/include/ball.hpp @@ -20,9 +20,7 @@ protected: static constexpr float MOVE = 100; public: - Ball(float x, float y) : PhysicsObject(x, y), shape(10 * mass) { - shape.setOrigin(sf::Vector2f(10 * mass, 10 * mass)); - } + Ball(float x, float y); /** * Dessine la balle dans la fenêtre donnée @@ -37,9 +35,7 @@ public: /** * Détermine la couche d'affichage de l'objet */ - unsigned int getLayer() { - return 1; - } + unsigned int getLayer(); }; #endif diff --git a/include/block.hpp b/include/block.hpp index 717c70b..35d417e 100644 --- a/include/block.hpp +++ b/include/block.hpp @@ -14,9 +14,7 @@ protected: public: static constexpr float GRID = 32; - Block(float x, float y) : Object(x, y), shape(sf::Vector2f(Block::GRID, Block::GRID)) { - shape.setOrigin(sf::Vector2f(Block::GRID / 2, Block::GRID / 2)); - } + Block(float x, float y); /** * Dessin du bloc dans la fenêtre donnée @@ -37,9 +35,7 @@ public: /** * Détermine la couche d'affichage de l'objet */ - unsigned int getLayer() { - return 0; - } + unsigned int getLayer(); }; #endif diff --git a/include/engine_state.hpp b/include/engine_state.hpp index 2b96563..06b0e1d 100644 --- a/include/engine_state.hpp +++ b/include/engine_state.hpp @@ -18,7 +18,7 @@ struct EngineState { std::array keys; float delta; - EngineState() { + EngineState() : delta(0.f) { // aucune touche n'est enfoncée au démarrage keys.fill(false); } diff --git a/include/object.hpp b/include/object.hpp index edd395b..30d0869 100644 --- a/include/object.hpp +++ b/include/object.hpp @@ -11,8 +11,7 @@ protected: int charge; public: - Object(float x, float y) : - position(x, y), charge(0) {} + Object(float x, float y); /** * Dessine l'objet dans la fenêtre donnée @@ -57,9 +56,7 @@ public: * qui doit être dessinée avant celle du second */ struct ObjectCompare { - bool operator()(Object* const &t1, Object* const &t2) { - return t1->getLayer() > t2->getLayer(); - } + bool operator()(Object* const &t1, Object* const &t2); }; #endif diff --git a/include/physics_object.hpp b/include/physics_object.hpp index fa4951d..34e778a 100644 --- a/include/physics_object.hpp +++ b/include/physics_object.hpp @@ -22,9 +22,7 @@ protected: static constexpr float GRAVITY = 20; public: - PhysicsObject(float x, float y) : - Object(x, y), mass(1), accelLine(sf::LinesStrip, 2), - velLine(sf::LinesStrip, 2) {} + PhysicsObject(float x, float y); /** * Dessine l'objet dans la fenêtre donnée diff --git a/src/ball.cpp b/src/ball.cpp index 61db850..5217195 100644 --- a/src/ball.cpp +++ b/src/ball.cpp @@ -1,5 +1,9 @@ #include "ball.hpp" +Ball::Ball(float x, float y) : PhysicsObject(x, y), shape(10 * mass) { + shape.setOrigin(sf::Vector2f(10 * mass, 10 * mass)); +} + void Ball::draw(sf::RenderWindow& window) { PhysicsObject::draw(window); @@ -22,6 +26,10 @@ std::unique_ptr Ball::getAABB() { )); } +unsigned int Ball::getLayer() { + return 1; +} + sf::Vector2f Ball::getForces(EngineState& state) { sf::Vector2f forces = PhysicsObject::getForces(state); diff --git a/src/block.cpp b/src/block.cpp index 24c147e..2fbc918 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -1,5 +1,9 @@ #include "block.hpp" +Block::Block(float x, float y) : Object(x, y), shape(sf::Vector2f(Block::GRID, Block::GRID)) { + shape.setOrigin(sf::Vector2f(Block::GRID / 2, Block::GRID / 2)); +} + void Block::draw(sf::RenderWindow& window) { // chargement de la texture de test if (!texture.loadFromFile("./res/block.png")) { @@ -31,3 +35,7 @@ std::unique_ptr Block::getAABB() { Block::GRID, Block::GRID )); } + +unsigned int Block::getLayer() { + return 0; +} diff --git a/src/object.cpp b/src/object.cpp index 6bf913a..aa01179 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -1,5 +1,7 @@ #include "object.hpp" +Object::Object(float x, float y) : position(x, y), charge(0) {} + sf::Vector2f Object::getPosition() { return position; } @@ -11,3 +13,7 @@ int Object::getCharge() { void Object::setCharge(int set_charge) { charge = set_charge; } + +bool ObjectCompare::operator()(Object* const &t1, Object* const &t2) { + return t1->getLayer() > t2->getLayer(); +} diff --git a/src/physics_object.cpp b/src/physics_object.cpp index 76f148b..7a43c0c 100644 --- a/src/physics_object.cpp +++ b/src/physics_object.cpp @@ -1,5 +1,9 @@ #include "physics_object.hpp" +PhysicsObject::PhysicsObject(float x, float y) : + Object(x, y), mass(1), accelLine(sf::LinesStrip, 2), + velLine(sf::LinesStrip, 2) {} + void PhysicsObject::draw(sf::RenderWindow& window) { velLine[0].position = position; velLine[0].color = sf::Color::Green;