Implémentation initiale des blocs d'arrivée / tueurs
This commit is contained in:
parent
7cf8d24f91
commit
b36f072009
|
@ -46,9 +46,9 @@ public:
|
||||||
virtual float getRadius() const;
|
virtual float getRadius() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calcule la texture à afficher pour ce bloc
|
* Prépare les textures avant le dessin du bloc
|
||||||
*/
|
*/
|
||||||
virtual std::string getTexture();
|
virtual void prepareDraw(ResourceManager& resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dessin du bloc dans la fenêtre donnée
|
* Dessin du bloc dans la fenêtre donnée
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#ifndef __PTF_FINISH_BLOCK_HPP__
|
||||||
|
#define __PTF_FINISH_BLOCK_HPP__
|
||||||
|
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include "block.hpp"
|
||||||
|
#include "level.hpp"
|
||||||
|
|
||||||
|
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"
|
||||||
|
*/
|
||||||
|
static const unsigned int TYPE_ID;
|
||||||
|
|
||||||
|
FinishBlock();
|
||||||
|
virtual ~FinishBlock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone ce bloc d'arrivée en un bloc d'arrivée avec les mêmes propriétés
|
||||||
|
*/
|
||||||
|
virtual Object::Ptr clone() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prépare les textures avant le dessin du bloc
|
||||||
|
*/
|
||||||
|
virtual void prepareDraw(ResourceManager& resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appelé lorsque le bloc d'arrivée est activé par un objet
|
||||||
|
*/
|
||||||
|
virtual void activate(Level& level, Object* object);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère l'identifiant de type des blocs d'arrivée
|
||||||
|
*/
|
||||||
|
virtual unsigned int getTypeId() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chargement d'un bloc d'arrivée depuis le fichier donné
|
||||||
|
*/
|
||||||
|
static Object::Ptr load(std::ifstream& file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauvegarde le bloc d'arrivée dans le fichier donné
|
||||||
|
*/
|
||||||
|
virtual void save(std::ofstream& file) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -35,9 +35,9 @@ public:
|
||||||
virtual Object::Ptr clone() const;
|
virtual Object::Ptr clone() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calcule la texture à afficher pour ce bloc
|
* Prépare les textures avant le dessin du bloc
|
||||||
*/
|
*/
|
||||||
virtual std::string getTexture();
|
virtual void prepareDraw(ResourceManager& resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appelé lorsque le bloc de gravité est activé par un objet
|
* Appelé lorsque le bloc de gravité est activé par un objet
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#ifndef __PTF_KILL_BLOCK_HPP__
|
||||||
|
#define __PTF_KILL_BLOCK_HPP__
|
||||||
|
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include "block.hpp"
|
||||||
|
#include "level.hpp"
|
||||||
|
|
||||||
|
class KillBlock : public Block {
|
||||||
|
public:
|
||||||
|
typedef std::shared_ptr<KillBlock> Ptr;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* Initialisation des propriétés du bloc tueur donné
|
||||||
|
* depuis le fichier donné
|
||||||
|
*/
|
||||||
|
static void init(std::ifstream& file, Object::Ptr object);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Identifiant unique du type "bloc tueur"
|
||||||
|
*/
|
||||||
|
static const unsigned int TYPE_ID;
|
||||||
|
|
||||||
|
KillBlock();
|
||||||
|
virtual ~KillBlock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone ce bloc tueur en un bloc tueur avec les mêmes propriétés
|
||||||
|
*/
|
||||||
|
virtual Object::Ptr clone() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prépare les textures avant le dessin du bloc
|
||||||
|
*/
|
||||||
|
virtual void prepareDraw(ResourceManager& resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appelé lorsque le bloc tueur est activé par un objet
|
||||||
|
*/
|
||||||
|
virtual void activate(Level& level, Object* object);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère l'identifiant de type des blocs tueurs
|
||||||
|
*/
|
||||||
|
virtual unsigned int getTypeId() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chargement d'un bloc tueur depuis le fichier donné
|
||||||
|
*/
|
||||||
|
static Object::Ptr load(std::ifstream& file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauvegarde le bloc tueur dans le fichier donné
|
||||||
|
*/
|
||||||
|
virtual void save(std::ofstream& file) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -67,6 +67,16 @@ private:
|
||||||
*/
|
*/
|
||||||
Object::Ptr createPlayer();
|
Object::Ptr createPlayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée un objet de type FinishBlock
|
||||||
|
*/
|
||||||
|
Object::Ptr createFinishBlock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée un objet de type KillBlock
|
||||||
|
*/
|
||||||
|
Object::Ptr createKillBlock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée un objet de type GravityBlock
|
* Crée un objet de type GravityBlock
|
||||||
*/
|
*/
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -6,12 +6,7 @@
|
||||||
|
|
||||||
const unsigned int Block::TYPE_ID = 2;
|
const unsigned int Block::TYPE_ID = 2;
|
||||||
|
|
||||||
Block::Block() : Object() {
|
Block::Block() : Object() {}
|
||||||
// déplacement de l'origine au centre du bloc
|
|
||||||
sprite.setOrigin(sf::Vector2f(23, 23));
|
|
||||||
select_sprite.setOrigin(sf::Vector2f(23, 23));
|
|
||||||
}
|
|
||||||
|
|
||||||
Block::~Block() {}
|
Block::~Block() {}
|
||||||
|
|
||||||
Object::Ptr Block::clone() const {
|
Object::Ptr Block::clone() const {
|
||||||
|
@ -34,18 +29,24 @@ void Block::save(std::ofstream& file) const {
|
||||||
Object::save(file);
|
Object::save(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Block::getTexture() {
|
void Block::prepareDraw(ResourceManager& resources) {
|
||||||
|
std::string texture_name = "movable_block.tga";
|
||||||
|
|
||||||
if (getMass() == 0) {
|
if (getMass() == 0) {
|
||||||
return "block.tga";
|
texture_name = "block.tga";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "movable_block.tga";
|
sprite.setTexture(resources.getTexture(texture_name));
|
||||||
|
sprite.setOrigin(sf::Vector2f(23, 23));
|
||||||
|
|
||||||
|
select_sprite.setTexture(resources.getTexture("block_select.tga"));
|
||||||
|
select_sprite.setOrigin(sf::Vector2f(23, 23));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Block::draw(Level& level) {
|
void Block::draw(Level& level) {
|
||||||
// utilisation de la texture
|
// utilisation de la texture
|
||||||
sf::RenderWindow& window = level.getWindow();
|
sf::RenderWindow& window = level.getWindow();
|
||||||
sprite.setTexture(level.getResourceManager().getTexture(getTexture()));
|
prepareDraw(level.getResourceManager());
|
||||||
|
|
||||||
// coloration du bloc selon sa charge
|
// coloration du bloc selon sa charge
|
||||||
if (getCharge() > 0) {
|
if (getCharge() > 0) {
|
||||||
|
@ -61,10 +62,6 @@ void Block::draw(Level& level) {
|
||||||
|
|
||||||
if (isSelected()) {
|
if (isSelected()) {
|
||||||
select_sprite.setPosition(getPosition());
|
select_sprite.setPosition(getPosition());
|
||||||
select_sprite.setTexture(
|
|
||||||
level.getResourceManager().getTexture("block_select.tga")
|
|
||||||
);
|
|
||||||
|
|
||||||
window.draw(select_sprite);
|
window.draw(select_sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "finish_block.hpp"
|
||||||
|
#include "level.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(Level& level, Object* object) {
|
||||||
|
Block::activate(level, object);
|
||||||
|
// TODO: implémenter le comportmeent des blocs d'arrivée
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -10,8 +10,7 @@ Object::Ptr GravityBlock::clone() const {
|
||||||
return Object::Ptr(new GravityBlock(*this));
|
return Object::Ptr(new GravityBlock(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GravityBlock::getTexture() {
|
void GravityBlock::prepareDraw(ResourceManager& resources) {
|
||||||
// texturage et coloration du bloc selon ses propriétés
|
|
||||||
std::string texture_name = "gravity_block_";
|
std::string texture_name = "gravity_block_";
|
||||||
|
|
||||||
switch (gravity_direction) {
|
switch (gravity_direction) {
|
||||||
|
@ -32,7 +31,7 @@ std::string GravityBlock::getTexture() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return texture_name + ".tga";
|
sprite.setTexture(resources.getTexture(texture_name + ".tga"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GravityBlock::activate(Level& level, Object* object) {
|
void GravityBlock::activate(Level& level, Object* object) {
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "kill_block.hpp"
|
||||||
|
#include "level.hpp"
|
||||||
|
|
||||||
|
const unsigned int KillBlock::TYPE_ID = 5;
|
||||||
|
|
||||||
|
KillBlock::KillBlock() : Block() {}
|
||||||
|
KillBlock::~KillBlock() {}
|
||||||
|
|
||||||
|
Object::Ptr KillBlock::clone() const {
|
||||||
|
return Object::Ptr(new KillBlock(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KillBlock::prepareDraw(ResourceManager& resources) {
|
||||||
|
Block::prepareDraw(resources);
|
||||||
|
sprite.setTexture(resources.getTexture("kill_block.tga"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KillBlock::activate(Level& level, Object* object) {
|
||||||
|
Block::activate(level, object);
|
||||||
|
// TODO: implémenter le comportmeent des blocs tueurs
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int KillBlock::getTypeId() const {
|
||||||
|
return TYPE_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KillBlock::init(std::ifstream& file, Object::Ptr object) {
|
||||||
|
// lecture des propriétés d'un bloc
|
||||||
|
Block::init(file, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr KillBlock::load(std::ifstream& file) {
|
||||||
|
Object::Ptr object = Object::Ptr(new KillBlock);
|
||||||
|
KillBlock::init(file, object);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KillBlock::save(std::ofstream& file) const {
|
||||||
|
// écriture des propriétés d'un bloc
|
||||||
|
Block::save(file);
|
||||||
|
}
|
|
@ -2,6 +2,8 @@
|
||||||
#include "block.hpp"
|
#include "block.hpp"
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "gravity_block.hpp"
|
#include "gravity_block.hpp"
|
||||||
|
#include "finish_block.hpp"
|
||||||
|
#include "kill_block.hpp"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
const int PADDING = 8;
|
const int PADDING = 8;
|
||||||
|
@ -42,6 +44,14 @@ Object::Ptr WidgetToolbar::createPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object::Ptr WidgetToolbar::createFinishBlock() {
|
||||||
|
return Object::Ptr(new FinishBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr WidgetToolbar::createKillBlock() {
|
||||||
|
return Object::Ptr(new KillBlock);
|
||||||
|
}
|
||||||
|
|
||||||
Object::Ptr WidgetToolbar::createGravityBlock(GravityDirection direction) {
|
Object::Ptr WidgetToolbar::createGravityBlock(GravityDirection direction) {
|
||||||
GravityBlock::Ptr gravity_block = GravityBlock::Ptr(new GravityBlock);
|
GravityBlock::Ptr gravity_block = GravityBlock::Ptr(new GravityBlock);
|
||||||
gravity_block->setGravityDirection(direction);
|
gravity_block->setGravityDirection(direction);
|
||||||
|
@ -59,23 +69,36 @@ Object::Ptr WidgetToolbar::createObject() {
|
||||||
WidgetToolbar::WidgetToolbar(Manager& manager) : manager(manager), selected(nullptr) {
|
WidgetToolbar::WidgetToolbar(Manager& manager) : manager(manager), selected(nullptr) {
|
||||||
// catégorie des objets plaçables de base
|
// catégorie des objets plaçables de base
|
||||||
ResourceManager& resources = manager.getResourceManager();
|
ResourceManager& resources = manager.getResourceManager();
|
||||||
ToolbarCategory::Ptr basic_cat = addCategory("BASE");
|
ToolbarCategory::Ptr block_cat = addCategory("BLOCS");
|
||||||
|
|
||||||
selected = basic_cat->addObject(
|
selected = block_cat->addObject(
|
||||||
resources.getTexture("toolbar_block.tga"),
|
resources.getTexture("toolbar_block.tga"),
|
||||||
std::bind(&WidgetToolbar::createBlock, this)
|
std::bind(&WidgetToolbar::createBlock, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
basic_cat->addObject(
|
block_cat->addObject(
|
||||||
resources.getTexture("toolbar_movable_block.tga"),
|
resources.getTexture("toolbar_movable_block.tga"),
|
||||||
std::bind(&WidgetToolbar::createMovableBlock, this)
|
std::bind(&WidgetToolbar::createMovableBlock, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
basic_cat->addObject(
|
// catégorie des blocs contrôlant les joueurs
|
||||||
|
ToolbarCategory::Ptr player_cat = addCategory("JOUEURS");
|
||||||
|
|
||||||
|
player_cat->addObject(
|
||||||
resources.getTexture("toolbar_player.tga"),
|
resources.getTexture("toolbar_player.tga"),
|
||||||
std::bind(&WidgetToolbar::createPlayer, this)
|
std::bind(&WidgetToolbar::createPlayer, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
player_cat->addObject(
|
||||||
|
resources.getTexture("toolbar_kill_block.tga"),
|
||||||
|
std::bind(&WidgetToolbar::createKillBlock, this)
|
||||||
|
);
|
||||||
|
|
||||||
|
player_cat->addObject(
|
||||||
|
resources.getTexture("toolbar_finish_block.tga"),
|
||||||
|
std::bind(&WidgetToolbar::createFinishBlock, this)
|
||||||
|
);
|
||||||
|
|
||||||
// catégorie des blocs changeant la gravité
|
// catégorie des blocs changeant la gravité
|
||||||
ToolbarCategory::Ptr gravity_cat = addCategory(L"GRAVITÉ");
|
ToolbarCategory::Ptr gravity_cat = addCategory(L"GRAVITÉ");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue