Nettoyage de l'implémentation des blocs
This commit is contained in:
parent
fd56f8a377
commit
44fb241934
|
@ -18,20 +18,6 @@ class Block : public Object {
|
|||
public:
|
||||
typedef std::shared_ptr<Block> Ptr;
|
||||
|
||||
private:
|
||||
sf::Sprite select_sprite;
|
||||
|
||||
protected:
|
||||
mutable sf::Sprite sprite;
|
||||
sf::FloatRect aabb;
|
||||
|
||||
/**
|
||||
* Initialisation des propriétés du bloc donné
|
||||
* depuis le fichier donné
|
||||
*/
|
||||
static void init(std::ifstream& file, Object::Ptr object);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Identifiant unique du type "bloc"
|
||||
*/
|
||||
|
@ -55,11 +41,6 @@ public:
|
|||
*/
|
||||
virtual float getRadius() const;
|
||||
|
||||
/**
|
||||
* Prépare les textures avant le dessin du bloc
|
||||
*/
|
||||
virtual void prepareDraw();
|
||||
|
||||
/**
|
||||
* Dessin du bloc dans la fenêtre donnée
|
||||
*/
|
||||
|
@ -89,6 +70,17 @@ public:
|
|||
* Sauvegarde le bloc dans le fichier donné
|
||||
*/
|
||||
virtual void save(std::ofstream& file) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Initialisation des propriétés du bloc donné
|
||||
* depuis le fichier donné
|
||||
*/
|
||||
static void init(std::ifstream& file, Object::Ptr object);
|
||||
|
||||
private:
|
||||
sf::Sprite sprite;
|
||||
sf::FloatRect aabb;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,14 +16,6 @@ class FinishBlock : public Block {
|
|||
public:
|
||||
typedef std::shared_ptr<FinishBlock> Ptr;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Initialisation des propriétés du bloc d'arrivée donné
|
||||
* depuis le fichier donné
|
||||
*/
|
||||
static void init(std::ifstream& file, Object::Ptr object);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Identifiant unique du type "bloc d'arrivée"
|
||||
*/
|
||||
|
@ -38,9 +30,9 @@ public:
|
|||
virtual Object::Ptr clone() const;
|
||||
|
||||
/**
|
||||
* Prépare les textures avant le dessin du bloc
|
||||
* Dessine le bloc
|
||||
*/
|
||||
virtual void prepareDraw();
|
||||
virtual void draw(Level& level);
|
||||
|
||||
/**
|
||||
* Appelé lorsque le bloc d'arrivée est activé par un objet
|
||||
|
@ -61,6 +53,16 @@ public:
|
|||
* Sauvegarde le bloc d'arrivée dans le fichier donné
|
||||
*/
|
||||
virtual void save(std::ofstream& file) const;
|
||||
|
||||
private:
|
||||
sf::Sprite icon_sprite;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Initialisation des propriétés du bloc d'arrivée donné
|
||||
* depuis le fichier donné
|
||||
*/
|
||||
static void init(std::ifstream& file, Object::Ptr object);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -9,8 +9,6 @@ const unsigned int Block::TYPE_ID = 2;
|
|||
|
||||
Block::Block() : Object() {
|
||||
sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
select_sprite.setOrigin(sf::Vector2f(23, 23));
|
||||
|
||||
aabb = sf::FloatRect(
|
||||
-Manager::GRID / 2,
|
||||
-Manager::GRID / 2,
|
||||
|
@ -41,21 +39,21 @@ void Block::save(std::ofstream& file) const {
|
|||
Object::save(file);
|
||||
}
|
||||
|
||||
void Block::prepareDraw() {
|
||||
std::string texture_name = "movable_block.tga";
|
||||
|
||||
if (getMass() == 0) {
|
||||
texture_name = "block.tga";
|
||||
}
|
||||
|
||||
sprite.setTexture(*ResourceManager::get().getTexture("objects/" + texture_name));
|
||||
select_sprite.setTexture(*ResourceManager::get().getTexture("objects/block_select.tga"));
|
||||
}
|
||||
|
||||
void Block::draw(Level& level) {
|
||||
// utilisation de la texture
|
||||
sf::RenderWindow& window = level.getManager().getWindow();
|
||||
prepareDraw();
|
||||
// récupération de la texture correspondant au type de bloc
|
||||
std::string texture_name = "block.tga";
|
||||
|
||||
if (getMass() > 0) {
|
||||
texture_name = "movable_" + texture_name;
|
||||
}
|
||||
|
||||
if (isSelected()) {
|
||||
texture_name = "selected_" + texture_name;
|
||||
}
|
||||
|
||||
sprite.setTexture(*ResourceManager::get().getTexture(
|
||||
"objects/" + texture_name
|
||||
));
|
||||
|
||||
// coloration du bloc selon sa charge
|
||||
if (getCharge() > 0) {
|
||||
|
@ -67,12 +65,7 @@ void Block::draw(Level& level) {
|
|||
}
|
||||
|
||||
sprite.setPosition(getPosition());
|
||||
window.draw(sprite);
|
||||
|
||||
if (isSelected()) {
|
||||
select_sprite.setPosition(getPosition());
|
||||
window.draw(select_sprite);
|
||||
}
|
||||
level.getManager().getWindow().draw(sprite);
|
||||
}
|
||||
|
||||
void Block::activate(Game& game, Object::Ptr object) {
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
#include "manager.hpp"
|
||||
#include "resource_manager.hpp"
|
||||
#include "finish_block.hpp"
|
||||
#include "game.hpp"
|
||||
|
||||
const unsigned int FinishBlock::TYPE_ID = 4;
|
||||
|
||||
FinishBlock::FinishBlock() : Block() {}
|
||||
FinishBlock::FinishBlock() : Block() {
|
||||
icon_sprite.setOrigin(sf::Vector2f(23, 41));
|
||||
icon_sprite.setTexture(*ResourceManager::get().getTexture(
|
||||
"objects/finish_block.tga"
|
||||
));
|
||||
}
|
||||
|
||||
FinishBlock::~FinishBlock() {}
|
||||
|
||||
Object::Ptr FinishBlock::clone() const {
|
||||
return Object::Ptr(new FinishBlock(*this));
|
||||
}
|
||||
|
||||
void FinishBlock::prepareDraw() {
|
||||
Block::prepareDraw();
|
||||
sprite.setOrigin(sf::Vector2f(23, 41));
|
||||
sprite.setTexture(*ResourceManager::get().getTexture("objects/finish_block.tga"), true);
|
||||
void FinishBlock::draw(Level& level) {
|
||||
// on dessine le bloc normal
|
||||
Block::draw(level);
|
||||
|
||||
// on dessine l'icône
|
||||
icon_sprite.setPosition(getPosition());
|
||||
level.getManager().getWindow().draw(icon_sprite);
|
||||
}
|
||||
|
||||
void FinishBlock::activate(Game& game, Object::Ptr object) {
|
||||
|
|
Loading…
Reference in New Issue