2016-04-12 16:11:36 +00:00
|
|
|
#include "resource_manager.hpp"
|
2016-04-11 00:49:40 +00:00
|
|
|
#include "finish_block.hpp"
|
2016-04-11 12:16:20 +00:00
|
|
|
#include "game.hpp"
|
2016-04-11 00:49:40 +00:00
|
|
|
|
|
|
|
const unsigned int FinishBlock::TYPE_ID = 4;
|
|
|
|
|
|
|
|
FinishBlock::FinishBlock() : Block() {}
|
|
|
|
FinishBlock::~FinishBlock() {}
|
|
|
|
|
|
|
|
Object::Ptr FinishBlock::clone() const {
|
|
|
|
return Object::Ptr(new FinishBlock(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishBlock::prepareDraw(ResourceManager& resources) {
|
|
|
|
Block::prepareDraw(resources);
|
|
|
|
sprite.setOrigin(sf::Vector2f(23, 41));
|
|
|
|
sprite.setTexture(resources.getTexture("finish_block.tga"), true);
|
|
|
|
}
|
|
|
|
|
2016-04-11 14:32:19 +00:00
|
|
|
void FinishBlock::activate(Game& game, Object::Ptr object) {
|
2016-04-11 12:16:20 +00:00
|
|
|
Block::activate(game, object);
|
2016-04-11 21:16:59 +00:00
|
|
|
|
|
|
|
// si un joueur touche le bloc d'arrivée,
|
|
|
|
// on le tue et s'il ne reste plus de joueur, on a gagné
|
|
|
|
if (object->getTypeId() == Player::TYPE_ID) {
|
|
|
|
if (game.getPlayers().size() == 1) {
|
|
|
|
game.setMode(Game::Mode::WON);
|
|
|
|
}
|
|
|
|
|
|
|
|
game.kill(object);
|
|
|
|
}
|
2016-04-11 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FinishBlock::getTypeId() const {
|
|
|
|
return TYPE_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishBlock::init(std::ifstream& file, Object::Ptr object) {
|
|
|
|
// lecture des propriétés d'un bloc
|
|
|
|
Block::init(file, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::Ptr FinishBlock::load(std::ifstream& file) {
|
|
|
|
Object::Ptr object = Object::Ptr(new FinishBlock);
|
|
|
|
FinishBlock::init(file, object);
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishBlock::save(std::ofstream& file) const {
|
|
|
|
// écriture des propriétés d'un bloc
|
|
|
|
Block::save(file);
|
|
|
|
}
|