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;
|
|
|
|
|
|
|
|
SwitchBlock::SwitchBlock() : Block() {}
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2016-04-11 14:32:19 +00:00
|
|
|
void SwitchBlock::activate(Game& game, Object::Ptr object) {
|
2016-04-11 12:16:20 +00:00
|
|
|
Block::activate(game, object);
|
2016-04-11 14:32:19 +00:00
|
|
|
|
2016-04-11 17:35:58 +00:00
|
|
|
// 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;
|
2016-04-11 14:32:19 +00:00
|
|
|
object->setCharge(-object->getCharge());
|
|
|
|
}
|
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);
|
|
|
|
}
|