From 774b60464cad34220bdfe99bbd6a1a9d81792c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Sun, 17 Apr 2016 23:30:21 +0200 Subject: [PATCH] =?UTF-8?q?Bloc=20de=20changement=20de=20polarit=C3=A9=20u?= =?UTF-8?q?tilisable=20une=20fois?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/switch_block.hpp | 6 +++-- res/textures/switch_block.tga | Bin 2571 -> 1292 bytes src/gravity_block.cpp | 2 +- src/switch_block.cpp | 42 ++++++++++++++++++++++------------ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/include/switch_block.hpp b/include/switch_block.hpp index bacaa71..1e7d26c 100644 --- a/include/switch_block.hpp +++ b/include/switch_block.hpp @@ -19,7 +19,9 @@ protected: static void init(std::ifstream& file, Object::Ptr object); public: - sf::Time last_activation; + sf::Sprite icon_sprite; + float opacity; + bool used; public: /** @@ -38,7 +40,7 @@ public: /** * Prépare les textures avant le dessin du bloc */ - virtual void prepareDraw(ResourceManager& resources); + virtual void draw(Level& level); /** * Appelé lorsque le bloc changeur est activé par un objet diff --git a/res/textures/switch_block.tga b/res/textures/switch_block.tga index 4515a59b73c2f68ba83d15a44f2f35b2e2a36f0e..e94b436329cc889d5d0bda14784527afa413f4ac 100644 GIT binary patch literal 1292 zcmb`HPiPZC6vn5CiM47#4TvJC7g5kg5j^+@^%5baW|Qnj#MpQ!l$wa*Q4utnu8Q?f zwOT>&AgIM6#Uee3Xw+5&s|XcDL=PU7Y!;#C_EVHYn?xVq1NAexwQfd>%QHitZ34s8} zfB_Hz>hK7b`>yQ?7 z!K(NLYZ;>j%;(iwSMxnw?YdA=Sf4>qvS^V3*Fz~ACMxC~dN%89Pn-2=!*nYb=x0fp zsYi}OM08DnlVx-w_=K@l5(f;^=|qA?+H~)q=Q@w74@`kzGs%3Ii@;lO53B-wpb5|# zE#+js76}-+nkDHh_mOy1Z*LV!G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zMn)kkx3k{fUKKEPMFd|^UllYOO%}`UvyP4q6*P5YLQ@|{^ewCf?5avfsQYsab3wBN zUlUR6&R!agMin$oAVj~Vd4}jvmRkQ*S69DNYSR?t1VQ+Z<}9KE82Wj6dHJOhP1Bjs zH2V?l$2|FyrR`fKnqCZuzN8liqCJ`Rae8{X3Yy+29MAKY^rpcx|B#{gQ&LjSXJ==j z2QNq~zaSa~JpYbfOo;!0o#94&eEe$(uaV;!0_gRHSVx9kjEIOh#m-FHLThU)mh1)M l=mp2KUv_L|b^w>ymp-4Qrp2Zw+)hZj_0gws2}!Yf?tg=D7$5)u diff --git a/src/gravity_block.cpp b/src/gravity_block.cpp index 65acda7..e792413 100644 --- a/src/gravity_block.cpp +++ b/src/gravity_block.cpp @@ -41,7 +41,7 @@ void GravityBlock::draw(Level& level) { Block::draw(level); // on anime l'opacité de l'icône - opacity = Utility::animateValue(opacity, 2, used ? 0 : 255); + opacity = Utility::animateValue(opacity, 5, used ? 0 : 255); icon_sprite.setColor(sf::Color(255, 255, 255, opacity)); // on dessine l'icône diff --git a/src/switch_block.cpp b/src/switch_block.cpp index bd671be..43f2465 100644 --- a/src/switch_block.cpp +++ b/src/switch_block.cpp @@ -1,34 +1,48 @@ #include "manager.hpp" +#include "utility.hpp" #include "switch_block.hpp" #include "game.hpp" const unsigned int SwitchBlock::TYPE_ID = 6; -SwitchBlock::SwitchBlock() : Block() {} +SwitchBlock::SwitchBlock() : Block(), opacity(255), used(false) { + icon_sprite.setOrigin(sf::Vector2f(23, 23)); +} + SwitchBlock::~SwitchBlock() {} Object::Ptr SwitchBlock::clone() const { return Object::Ptr(new SwitchBlock(*this)); } -void SwitchBlock::prepareDraw(ResourceManager& resources) { - Block::prepareDraw(resources); - sprite.setTexture(resources.getTexture("switch_block.tga")); +void SwitchBlock::draw(Level& level) { + // on dessine le bloc normal + Block::draw(level); + + // on anime l'opacité de l'icône + opacity = Utility::animateValue(opacity, 5, used ? 0 : 255); + icon_sprite.setColor(sf::Color(255, 255, 255, opacity)); + + // on dessine l'icône + icon_sprite.setTexture(level.getResourceManager().getTexture( + "switch_block.tga" + )); + + icon_sprite.setPosition(getPosition()); + level.getWindow().draw(icon_sprite); } void SwitchBlock::activate(Game& game, Object::Ptr object) { + // on ne peut utiliser le bloc qu'une seule fois + if (used) { + return; + } + Block::activate(game, object); - // on échange la polarité de l'objet en contact, si le dernier - // objet touché par la balle n'est pas ce bloc et si un temps - // d'une seconde est passé - sf::Time current_time = game.getManager().getCurrentTime(); - - if (current_time - last_activation >= sf::seconds(1) && - object->getLastActivator().lock() != shared_from_this()) { - last_activation = current_time; - object->setCharge(-object->getCharge()); - } + // on échange la polarité de l'objet en contact + object->setCharge(-object->getCharge()); + used = true; } unsigned int SwitchBlock::getTypeId() const {