2016-04-12 16:11:36 +00:00
|
|
|
#include "resource_manager.hpp"
|
2016-04-09 03:43:40 +00:00
|
|
|
#include "gravity_block.hpp"
|
2016-04-11 12:16:20 +00:00
|
|
|
#include "game.hpp"
|
2016-04-09 03:43:40 +00:00
|
|
|
|
|
|
|
const unsigned int GravityBlock::TYPE_ID = 3;
|
|
|
|
|
|
|
|
GravityBlock::GravityBlock() : Block() {}
|
|
|
|
GravityBlock::~GravityBlock() {}
|
|
|
|
|
2016-04-10 05:37:09 +00:00
|
|
|
Object::Ptr GravityBlock::clone() const {
|
|
|
|
return Object::Ptr(new GravityBlock(*this));
|
2016-04-09 03:43:40 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 00:49:40 +00:00
|
|
|
void GravityBlock::prepareDraw(ResourceManager& resources) {
|
2016-04-11 01:24:51 +00:00
|
|
|
Block::prepareDraw(resources);
|
2016-04-09 03:51:55 +00:00
|
|
|
std::string texture_name = "gravity_block_";
|
|
|
|
|
|
|
|
switch (gravity_direction) {
|
|
|
|
case GravityDirection::NORTH:
|
|
|
|
texture_name += "north";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GravityDirection::EAST:
|
|
|
|
texture_name += "east";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GravityDirection::SOUTH:
|
|
|
|
texture_name += "south";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GravityDirection::WEST:
|
|
|
|
texture_name += "west";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-11 00:49:40 +00:00
|
|
|
sprite.setTexture(resources.getTexture(texture_name + ".tga"));
|
2016-04-09 03:51:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 14:32:19 +00:00
|
|
|
void GravityBlock::activate(Game& game, Object::Ptr object) {
|
2016-04-11 12:16:20 +00:00
|
|
|
Block::activate(game, object);
|
2016-04-09 03:43:40 +00:00
|
|
|
|
|
|
|
// lorsque le bloc est activé, il transmet son
|
|
|
|
// sens de gravité au niveau
|
2016-04-11 12:16:20 +00:00
|
|
|
game.setGravityDirection(gravity_direction);
|
2016-04-09 03:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GravityBlock::getTypeId() const {
|
|
|
|
return TYPE_ID;
|
|
|
|
}
|
|
|
|
|
2016-04-10 05:37:09 +00:00
|
|
|
void GravityBlock::init(std::ifstream& file, Object::Ptr object) {
|
|
|
|
GravityBlock::Ptr gravity_block = std::dynamic_pointer_cast<GravityBlock>(object);
|
|
|
|
|
2016-04-09 03:43:40 +00:00
|
|
|
// lecture de la direction de la gravité
|
|
|
|
char gravity_direction;
|
|
|
|
file.read(&gravity_direction, 1);
|
2016-04-10 05:37:09 +00:00
|
|
|
gravity_block->setGravityDirection((GravityDirection) gravity_direction);
|
2016-04-09 03:43:40 +00:00
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
// lecture des propriétés d'un bloc
|
2016-04-10 05:37:09 +00:00
|
|
|
Block::init(file, object);
|
|
|
|
}
|
2016-04-09 03:43:40 +00:00
|
|
|
|
2016-04-10 05:37:09 +00:00
|
|
|
Object::Ptr GravityBlock::load(std::ifstream& file) {
|
|
|
|
Object::Ptr object = Object::Ptr(new GravityBlock);
|
|
|
|
GravityBlock::init(file, object);
|
2016-04-09 03:43:40 +00:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2016-04-10 04:53:45 +00:00
|
|
|
void GravityBlock::save(std::ofstream& file) const {
|
|
|
|
// écriture de la direction de la gravité
|
|
|
|
char write_gravity_direction = (char) gravity_direction;
|
|
|
|
file.write(&write_gravity_direction, 1);
|
|
|
|
|
|
|
|
// écriture des propriétés d'un bloc
|
|
|
|
Block::save(file);
|
|
|
|
}
|
|
|
|
|
2016-04-09 03:43:40 +00:00
|
|
|
GravityDirection GravityBlock::getGravityDirection() const {
|
|
|
|
return gravity_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GravityBlock::setGravityDirection(GravityDirection set_gravity_direction) {
|
|
|
|
gravity_direction = set_gravity_direction;
|
|
|
|
}
|