diff --git a/include/block.hpp b/include/block.hpp index 92b70d9..f62a57c 100644 --- a/include/block.hpp +++ b/include/block.hpp @@ -46,9 +46,9 @@ public: virtual float getRadius() const; /** - * Opérations de préparation de la texture du bloc + * Calcule la texture à afficher pour ce bloc */ - virtual void beforeDraw(Level& level); + virtual std::string getTexture(); /** * Dessin du bloc dans la fenêtre donnée diff --git a/include/gravity_block.hpp b/include/gravity_block.hpp index 403b1b3..a65a73f 100644 --- a/include/gravity_block.hpp +++ b/include/gravity_block.hpp @@ -35,9 +35,9 @@ public: virtual Object::Ptr clone() const; /** - * Opérations de préparation de la texture du bloc + * Calcule la texture à afficher pour ce bloc */ - virtual void beforeDraw(Level& level); + virtual std::string getTexture(); /** * Appelé lorsque le bloc de gravité est activé par un objet diff --git a/src/block.cpp b/src/block.cpp index 777a26e..da8cb0e 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -38,12 +38,20 @@ void Block::save(std::ofstream& file) const { Object::save(file); } -void Block::beforeDraw(Level& level) { - // texturage et coloration du bloc selon ses propriétés - sprite.setTexture( - level.getResourceManager().getTexture("block.tga") - ); +std::string Block::getTexture() { + if (getMass() == 0) { + return "block.tga"; + } + return "movable_block.tga"; +} + +void Block::draw(Level& level) { + // utilisation de la texture + sf::RenderWindow& window = level.getWindow(); + sprite.setTexture(level.getResourceManager().getTexture(getTexture())); + + // coloration du bloc selon sa charge if (getCharge() > 0) { sprite.setColor(sf::Color(180, 180, 255)); } else if (getCharge() < 0) { @@ -51,12 +59,6 @@ void Block::beforeDraw(Level& level) { } else { sprite.setColor(sf::Color::White); } -} - -void Block::draw(Level& level) { - // utilisation de la texture - sf::RenderWindow& window = level.getWindow(); - beforeDraw(level); sprite.setPosition(getPosition()); window.draw(sprite); diff --git a/src/gravity_block.cpp b/src/gravity_block.cpp index 80fe85e..4ea8b2c 100644 --- a/src/gravity_block.cpp +++ b/src/gravity_block.cpp @@ -10,9 +10,7 @@ Object::Ptr GravityBlock::clone() const { return Object::Ptr(new GravityBlock(*this)); } -void GravityBlock::beforeDraw(Level& level) { - Block::beforeDraw(level); - +std::string GravityBlock::getTexture() { // texturage et coloration du bloc selon ses propriétés std::string texture_name = "gravity_block_"; @@ -34,9 +32,7 @@ void GravityBlock::beforeDraw(Level& level) { break; } - sprite.setTexture( - level.getResourceManager().getTexture(texture_name + ".tga") - ); + return texture_name + ".tga"; } void GravityBlock::activated(Level& level, Object* object) {