skizzle/src/finish_block.cpp

53 lines
1.4 KiB
C++
Raw Normal View History

#include "resource_manager.hpp"
#include "finish_block.hpp"
2016-04-11 12:16:20 +00:00
#include "game.hpp"
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);
}
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);
}
}
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);
}