Bloc de changement de polarité utilisable une fois
This commit is contained in:
parent
c8d7e49e91
commit
774b60464c
|
@ -19,7 +19,9 @@ protected:
|
||||||
static void init(std::ifstream& file, Object::Ptr object);
|
static void init(std::ifstream& file, Object::Ptr object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
sf::Time last_activation;
|
sf::Sprite icon_sprite;
|
||||||
|
float opacity;
|
||||||
|
bool used;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +40,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Prépare les textures avant le dessin du bloc
|
* 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
|
* Appelé lorsque le bloc changeur est activé par un objet
|
||||||
|
|
Binary file not shown.
|
@ -41,7 +41,7 @@ void GravityBlock::draw(Level& level) {
|
||||||
Block::draw(level);
|
Block::draw(level);
|
||||||
|
|
||||||
// on anime l'opacité de l'icône
|
// 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));
|
icon_sprite.setColor(sf::Color(255, 255, 255, opacity));
|
||||||
|
|
||||||
// on dessine l'icône
|
// on dessine l'icône
|
||||||
|
|
|
@ -1,34 +1,48 @@
|
||||||
#include "manager.hpp"
|
#include "manager.hpp"
|
||||||
|
#include "utility.hpp"
|
||||||
#include "switch_block.hpp"
|
#include "switch_block.hpp"
|
||||||
#include "game.hpp"
|
#include "game.hpp"
|
||||||
|
|
||||||
const unsigned int SwitchBlock::TYPE_ID = 6;
|
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() {}
|
SwitchBlock::~SwitchBlock() {}
|
||||||
|
|
||||||
Object::Ptr SwitchBlock::clone() const {
|
Object::Ptr SwitchBlock::clone() const {
|
||||||
return Object::Ptr(new SwitchBlock(*this));
|
return Object::Ptr(new SwitchBlock(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchBlock::prepareDraw(ResourceManager& resources) {
|
void SwitchBlock::draw(Level& level) {
|
||||||
Block::prepareDraw(resources);
|
// on dessine le bloc normal
|
||||||
sprite.setTexture(resources.getTexture("switch_block.tga"));
|
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) {
|
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);
|
Block::activate(game, object);
|
||||||
|
|
||||||
// on échange la polarité de l'objet en contact, si le dernier
|
// on échange la polarité de l'objet en contact
|
||||||
// objet touché par la balle n'est pas ce bloc et si un temps
|
object->setCharge(-object->getCharge());
|
||||||
// d'une seconde est passé
|
used = true;
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SwitchBlock::getTypeId() const {
|
unsigned int SwitchBlock::getTypeId() const {
|
||||||
|
|
Loading…
Reference in New Issue