Ajout du bloc inverseur

This commit is contained in:
Mattéo Delabre 2016-04-11 13:35:29 +02:00
parent 42413aee72
commit 6661472d1a
7 changed files with 119 additions and 1 deletions

60
include/switch_block.hpp Normal file
View File

@ -0,0 +1,60 @@
#ifndef __PTF_SWITCH_BLOCK_HPP__
#define __PTF_SWITCH_BLOCK_HPP__
#include <SFML/Graphics.hpp>
#include <memory>
#include "block.hpp"
#include "level.hpp"
class SwitchBlock : public Block {
public:
typedef std::shared_ptr<SwitchBlock> Ptr;
protected:
/**
* Initialisation des propriétés du bloc changeur donné
* depuis le fichier donné
*/
static void init(std::ifstream& file, Object::Ptr object);
public:
/**
* Identifiant unique du type "bloc changeur"
*/
static const unsigned int TYPE_ID;
SwitchBlock();
virtual ~SwitchBlock();
/**
* Clone ce bloc changeur en un bloc changeur 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 changeur est activé par un objet
*/
virtual void activate(Level& level, Object* object);
/**
* Récupère l'identifiant de type des blocs changeurs
*/
virtual unsigned int getTypeId() const;
/**
* Chargement d'un bloc changeur depuis le fichier donné
*/
static Object::Ptr load(std::ifstream& file);
/**
* Sauvegarde le bloc changeur dans le fichier donné
*/
virtual void save(std::ofstream& file) const;
};
#endif

View File

@ -67,6 +67,11 @@ private:
*/
Object::Ptr createPlayer();
/**
* Crée un objet de type SwitchBlock
*/
Object::Ptr createSwitchBlock();
/**
* Crée un objet de type FinishBlock
*/

Binary file not shown.

View File

@ -3,6 +3,7 @@
#include "player.hpp"
#include "block.hpp"
#include "gravity_block.hpp"
#include "switch_block.hpp"
#include "finish_block.hpp"
#include "kill_block.hpp"
#include <boost/filesystem.hpp>
@ -37,7 +38,8 @@ std::map<unsigned int, std::function<Object::Ptr(std::ifstream&)>> object_type_m
{Block::TYPE_ID, Block::load},
{GravityBlock::TYPE_ID, GravityBlock::load},
{FinishBlock::TYPE_ID, FinishBlock::load},
{KillBlock::TYPE_ID, KillBlock::load}
{KillBlock::TYPE_ID, KillBlock::load},
{SwitchBlock::TYPE_ID, SwitchBlock::load}
};
/**

41
src/switch_block.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "switch_block.hpp"
#include "level.hpp"
const unsigned int SwitchBlock::TYPE_ID = 6;
SwitchBlock::SwitchBlock() : Block() {}
SwitchBlock::~SwitchBlock() {}
Object::Ptr SwitchBlock::clone() const {
return Object::Ptr(new SwitchBlock(*this));
}
void SwitchBlock::prepareDraw(ResourceManager& resources) {
Block::prepareDraw(resources);
sprite.setTexture(resources.getTexture("switch_block.tga"));
}
void SwitchBlock::activate(Level& level, Object* object) {
Block::activate(level, object);
// TODO: implémenter le comportmeent des blocs changeurs
}
unsigned int SwitchBlock::getTypeId() const {
return TYPE_ID;
}
void SwitchBlock::init(std::ifstream& file, Object::Ptr object) {
// lecture des propriétés d'un bloc
Block::init(file, object);
}
Object::Ptr SwitchBlock::load(std::ifstream& file) {
Object::Ptr object = Object::Ptr(new SwitchBlock);
SwitchBlock::init(file, object);
return object;
}
void SwitchBlock::save(std::ofstream& file) const {
// écriture des propriétés d'un bloc
Block::save(file);
}

View File

@ -2,6 +2,7 @@
#include "block.hpp"
#include "player.hpp"
#include "gravity_block.hpp"
#include "switch_block.hpp"
#include "finish_block.hpp"
#include "kill_block.hpp"
#include <utility>
@ -44,6 +45,10 @@ Object::Ptr WidgetToolbar::createPlayer() {
return player;
}
Object::Ptr WidgetToolbar::createSwitchBlock() {
return Object::Ptr(new SwitchBlock);
}
Object::Ptr WidgetToolbar::createFinishBlock() {
return Object::Ptr(new FinishBlock);
}
@ -89,6 +94,11 @@ WidgetToolbar::WidgetToolbar(Manager& manager) : manager(manager), selected(null
std::bind(&WidgetToolbar::createPlayer, this)
);
player_cat->addObject(
resources.getTexture("toolbar_switch_block.tga"),
std::bind(&WidgetToolbar::createSwitchBlock, this)
);
player_cat->addObject(
resources.getTexture("toolbar_kill_block.tga"),
std::bind(&WidgetToolbar::createKillBlock, this)