Calcul dynamique des textures de blocs
This commit is contained in:
parent
dec8f56244
commit
fd6eb31847
|
@ -46,9 +46,9 @@ public:
|
|||
virtual float getRadius() const;
|
||||
|
||||
/**
|
||||
* Opérations de préparation de la texture du bloc
|
||||
* Calcule la texture à afficher pour ce bloc
|
||||
*/
|
||||
virtual void beforeDraw(Level& level);
|
||||
virtual std::string getTexture();
|
||||
|
||||
/**
|
||||
* Dessin du bloc dans la fenêtre donnée
|
||||
|
|
|
@ -35,9 +35,9 @@ public:
|
|||
virtual Object::Ptr clone() const;
|
||||
|
||||
/**
|
||||
* Opérations de préparation de la texture du bloc
|
||||
* Calcule la texture à afficher pour ce bloc
|
||||
*/
|
||||
virtual void beforeDraw(Level& level);
|
||||
virtual std::string getTexture();
|
||||
|
||||
/**
|
||||
* Appelé lorsque le bloc de gravité est activé par un objet
|
||||
|
|
|
@ -38,12 +38,20 @@ void Block::save(std::ofstream& file) const {
|
|||
Object::save(file);
|
||||
}
|
||||
|
||||
void Block::beforeDraw(Level& level) {
|
||||
// texturage et coloration du bloc selon ses propriétés
|
||||
sprite.setTexture(
|
||||
level.getResourceManager().getTexture("block.tga")
|
||||
);
|
||||
std::string Block::getTexture() {
|
||||
if (getMass() == 0) {
|
||||
return "block.tga";
|
||||
}
|
||||
|
||||
return "movable_block.tga";
|
||||
}
|
||||
|
||||
void Block::draw(Level& level) {
|
||||
// utilisation de la texture
|
||||
sf::RenderWindow& window = level.getWindow();
|
||||
sprite.setTexture(level.getResourceManager().getTexture(getTexture()));
|
||||
|
||||
// coloration du bloc selon sa charge
|
||||
if (getCharge() > 0) {
|
||||
sprite.setColor(sf::Color(180, 180, 255));
|
||||
} else if (getCharge() < 0) {
|
||||
|
@ -51,12 +59,6 @@ void Block::beforeDraw(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());
|
||||
window.draw(sprite);
|
||||
|
|
|
@ -10,9 +10,7 @@ Object::Ptr GravityBlock::clone() const {
|
|||
return Object::Ptr(new GravityBlock(*this));
|
||||
}
|
||||
|
||||
void GravityBlock::beforeDraw(Level& level) {
|
||||
Block::beforeDraw(level);
|
||||
|
||||
std::string GravityBlock::getTexture() {
|
||||
// texturage et coloration du bloc selon ses propriétés
|
||||
std::string texture_name = "gravity_block_";
|
||||
|
||||
|
@ -34,9 +32,7 @@ void GravityBlock::beforeDraw(Level& level) {
|
|||
break;
|
||||
}
|
||||
|
||||
sprite.setTexture(
|
||||
level.getResourceManager().getTexture(texture_name + ".tga")
|
||||
);
|
||||
return texture_name + ".tga";
|
||||
}
|
||||
|
||||
void GravityBlock::activated(Level& level, Object* object) {
|
||||
|
|
Loading…
Reference in New Issue