2016-04-12 16:11:36 +00:00
|
|
|
#include "manager.hpp"
|
2016-04-17 21:30:21 +00:00
|
|
|
#include "utility.hpp"
|
2016-04-11 11:35:29 +00:00
|
|
|
#include "switch_block.hpp"
|
2016-04-11 12:16:20 +00:00
|
|
|
#include "game.hpp"
|
2016-04-11 11:35:29 +00:00
|
|
|
|
|
|
|
const unsigned int SwitchBlock::TYPE_ID = 6;
|
|
|
|
|
2016-04-17 21:30:21 +00:00
|
|
|
SwitchBlock::SwitchBlock() : Block(), opacity(255), used(false) {
|
|
|
|
icon_sprite.setOrigin(sf::Vector2f(23, 23));
|
|
|
|
}
|
|
|
|
|
2016-04-11 11:35:29 +00:00
|
|
|
SwitchBlock::~SwitchBlock() {}
|
|
|
|
|
|
|
|
Object::Ptr SwitchBlock::clone() const {
|
|
|
|
return Object::Ptr(new SwitchBlock(*this));
|
|
|
|
}
|
|
|
|
|
2016-04-17 21:30:21 +00:00
|
|
|
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);
|
2016-04-11 11:35:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 14:32:19 +00:00
|
|
|
void SwitchBlock::activate(Game& game, Object::Ptr object) {
|
2016-04-17 21:30:21 +00:00
|
|
|
// on ne peut utiliser le bloc qu'une seule fois
|
|
|
|
if (used) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-11 14:32:19 +00:00
|
|
|
|
2016-04-17 21:30:21 +00:00
|
|
|
Block::activate(game, object);
|
2016-04-11 17:35:58 +00:00
|
|
|
|
2016-04-17 21:30:21 +00:00
|
|
|
// on échange la polarité de l'objet en contact
|
|
|
|
object->setCharge(-object->getCharge());
|
|
|
|
used = true;
|
2016-04-11 11:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SwitchBlock::getTypeId() const {
|
|
|
|
return TYPE_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchBlock::init(std::ifstream& file, Object::Ptr object) {
|
|
|
|
// lecture des propriétés d'un bloc
|
|
|
|
Block::init(file, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::Ptr SwitchBlock::load(std::ifstream& file) {
|
|
|
|
Object::Ptr object = Object::Ptr(new SwitchBlock);
|
|
|
|
SwitchBlock::init(file, object);
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchBlock::save(std::ofstream& file) const {
|
|
|
|
// écriture des propriétés d'un bloc
|
|
|
|
Block::save(file);
|
|
|
|
}
|