Chargement des textures du bloc de gravité

This commit is contained in:
Mattéo Delabre 2016-04-09 05:51:55 +02:00
parent 2515ed0d59
commit e9e924c719
4 changed files with 58 additions and 11 deletions

View File

@ -6,9 +6,11 @@
class Block : public Object {
private:
mutable sf::Sprite sprite;
mutable sf::Sprite select_sprite;
protected:
mutable sf::Sprite sprite;
public:
/**
* Identifiant unique du type "bloc"
@ -28,6 +30,11 @@ public:
*/
virtual std::unique_ptr<sf::FloatRect> getAABB() const;
/**
* Opérations de préparation de la texture du bloc
*/
virtual void beforeDraw(Level& level);
/**
* Dessin du bloc dans la fenêtre donnée
*/

View File

@ -22,6 +22,11 @@ public:
*/
virtual ObjectPtr clone() const;
/**
* Opérations de préparation de la texture du bloc
*/
virtual void beforeDraw(Level& level);
/**
* Appelé lorsque le bloc de gravité est activé par un objet
*/

View File

@ -32,15 +32,12 @@ ObjectPtr Block::load(std::ifstream& file) {
return object;
}
void Block::draw(Level& level) {
// utilisation de la texture
ResourceManager& resources = level.getResourceManager();
sf::RenderWindow& window = level.getWindow();
void Block::beforeDraw(Level& level) {
// texturage et coloration du bloc selon ses propriétés
sprite.setTexture(
level.getResourceManager().getTexture("block.tga")
);
sprite.setTexture(resources.getTexture("block.tga"));
select_sprite.setTexture(resources.getTexture("block_select.png"));
// coloration du bloc en fonction de sa charge
if (getCharge() > 0) {
sprite.setColor(sf::Color(180, 180, 255));
} else if (getCharge() < 0) {
@ -48,13 +45,22 @@ void Block::draw(Level& level) {
} else {
sprite.setColor(sf::Color::White);
}
}
void Block::draw(Level& level) {
// utilisation de la texture
sf::RenderWindow& window = level.getWindow();
beforeDraw(level);
sprite.setPosition(getPosition());
select_sprite.setPosition(getPosition());
window.draw(sprite);
if (isSelected()) {
select_sprite.setPosition(getPosition());
select_sprite.setTexture(
level.getResourceManager().getTexture("block_select.png")
);
window.draw(select_sprite);
}
}

View File

@ -10,6 +10,35 @@ ObjectPtr GravityBlock::clone() const {
return ObjectPtr(new GravityBlock(*this));
}
void GravityBlock::beforeDraw(Level& level) {
Block::beforeDraw(level);
// texturage et coloration du bloc selon ses propriétés
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;
}
sprite.setTexture(
level.getResourceManager().getTexture(texture_name + ".tga")
);
}
void GravityBlock::activated(Level& level, Object& object) {
Block::activated(level, object);