Généralisation de la barre d'action au jeu
This commit is contained in:
parent
b7ebc8e91d
commit
656bd60643
|
@ -4,7 +4,6 @@
|
||||||
#include <SFGUI/Widgets.hpp>
|
#include <SFGUI/Widgets.hpp>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "../objects/object.hpp"
|
#include "../objects/object.hpp"
|
||||||
#include "../states/level.hpp"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Barre d'outils pour les actions en jeu
|
* Barre d'outils pour les actions en jeu
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "../states/level.hpp"
|
|
||||||
#include "../objects/object.hpp"
|
#include "../objects/object.hpp"
|
||||||
|
#include "../utility.hpp"
|
||||||
#include "object_button.hpp"
|
#include "object_button.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ private:
|
||||||
Object::Ptr createSwitchBlock();
|
Object::Ptr createSwitchBlock();
|
||||||
Object::Ptr createFinishBlock();
|
Object::Ptr createFinishBlock();
|
||||||
Object::Ptr createKillBlock();
|
Object::Ptr createKillBlock();
|
||||||
Object::Ptr createGravityBlock(GravityDirection direction);
|
Object::Ptr createGravityBlock(Utility::Direction direction);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectToolbar();
|
ObjectToolbar();
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "../utility.hpp"
|
||||||
#include "block.hpp"
|
#include "block.hpp"
|
||||||
|
|
||||||
class Game;
|
class Game;
|
||||||
enum class GravityDirection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Le bloc de gravité est un bloc spécial qui change l'orientation
|
* Le bloc de gravité est un bloc spécial qui change l'orientation
|
||||||
|
@ -19,7 +19,7 @@ public:
|
||||||
typedef std::shared_ptr<GravityBlock> Ptr;
|
typedef std::shared_ptr<GravityBlock> Ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GravityDirection gravity_direction;
|
Utility::Direction gravity_direction;
|
||||||
sf::Sprite icon_sprite;
|
sf::Sprite icon_sprite;
|
||||||
float opacity;
|
float opacity;
|
||||||
bool used;
|
bool used;
|
||||||
|
@ -73,12 +73,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* Récupère la direction de gravité du bloc changeur de gravité
|
* Récupère la direction de gravité du bloc changeur de gravité
|
||||||
*/
|
*/
|
||||||
GravityDirection getGravityDirection() const;
|
Utility::Direction getGravityDirection() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modifie la direction de gravité du bloc
|
* Modifie la direction de gravité du bloc
|
||||||
*/
|
*/
|
||||||
void setGravityDirection(GravityDirection set_gravity_direction);
|
void setGravityDirection(Utility::Direction set_gravity_direction);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef __SKIZZLE_EDITOR_HPP__
|
#ifndef __SKIZZLE_EDITOR_HPP__
|
||||||
#define __SKIZZLE_EDITOR_HPP__
|
#define __SKIZZLE_EDITOR_HPP__
|
||||||
|
|
||||||
#include "../gui/action_toolbar.hpp"
|
|
||||||
#include "../gui/object_toolbar.hpp"
|
#include "../gui/object_toolbar.hpp"
|
||||||
#include "level.hpp"
|
#include "level.hpp"
|
||||||
|
|
||||||
|
@ -22,10 +21,7 @@ private:
|
||||||
sf::Vector2f *drag_control_point;
|
sf::Vector2f *drag_control_point;
|
||||||
|
|
||||||
DragMode drag_mode;
|
DragMode drag_mode;
|
||||||
|
|
||||||
ActionToolbar action_toolbar;
|
|
||||||
ObjectToolbar object_toolbar;
|
ObjectToolbar object_toolbar;
|
||||||
sfg::Button::Ptr mute_button;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie l'objet pointé à la position donnée
|
* Renvoie l'objet pointé à la position donnée
|
||||||
|
@ -78,11 +74,16 @@ private:
|
||||||
void selectAll();
|
void selectAll();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Demande le dessin d'une frame
|
||||||
|
*/
|
||||||
|
void frame() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dessine tous les objets, le fond et
|
* Dessine tous les objets, le fond et
|
||||||
* l'interface de l'éditeur
|
* l'interface de l'éditeur
|
||||||
*/
|
*/
|
||||||
virtual void draw();
|
void draw() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Editor(Manager& manager);
|
Editor(Manager& manager);
|
||||||
|
@ -98,11 +99,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void processEvent(const sf::Event& event) override;
|
void processEvent(const sf::Event& event) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Demande le dessin d'une frame
|
|
||||||
*/
|
|
||||||
void frame() override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lance le test du niveau
|
* Lance le test du niveau
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -43,11 +43,16 @@ private:
|
||||||
bool isInZone(Object::Ptr object);
|
bool isInZone(Object::Ptr object);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Demande le dessin d'une frame
|
||||||
|
*/
|
||||||
|
void frame() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dessine tous les objets, le fond et
|
* Dessine tous les objets, le fond et
|
||||||
* l'interface de jeu
|
* l'interface de jeu
|
||||||
*/
|
*/
|
||||||
virtual void draw();
|
void draw() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* S'assure que la caméra est centrée sur les joueurs
|
* S'assure que la caméra est centrée sur les joueurs
|
||||||
|
@ -61,17 +66,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* Active l'état
|
* Active l'état
|
||||||
*/
|
*/
|
||||||
virtual void enable();
|
void enable() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Traite l'événement donné
|
* Traite l'événement donné
|
||||||
*/
|
*/
|
||||||
virtual void processEvent(const sf::Event& event);
|
void processEvent(const sf::Event& event) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Demande le dessin d'une frame
|
|
||||||
*/
|
|
||||||
virtual void frame();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tue l'objet donné
|
* Tue l'objet donné
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "../gui/action_toolbar.hpp"
|
||||||
|
#include "../utility.hpp"
|
||||||
#include "../objects/object.hpp"
|
#include "../objects/object.hpp"
|
||||||
#include "../objects/player.hpp"
|
#include "../objects/player.hpp"
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
// liste des directions de la gravité
|
|
||||||
enum class GravityDirection {NORTH, EAST, SOUTH, WEST};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* La classe Level est une abstraction des
|
* La classe Level est une abstraction des
|
||||||
* classes affichant une collection d'objets, comme
|
* classes affichant une collection d'objets, comme
|
||||||
|
@ -21,7 +20,7 @@ class Level : public State {
|
||||||
private:
|
private:
|
||||||
sf::View camera;
|
sf::View camera;
|
||||||
float camera_angle;
|
float camera_angle;
|
||||||
GravityDirection gravity_direction;
|
Utility::Direction gravity_direction;
|
||||||
|
|
||||||
sf::String name;
|
sf::String name;
|
||||||
std::string path;
|
std::string path;
|
||||||
|
@ -36,7 +35,16 @@ private:
|
||||||
std::vector<Player::Ptr> players;
|
std::vector<Player::Ptr> players;
|
||||||
std::vector<sf::Vector2f> zone;
|
std::vector<sf::Vector2f> zone;
|
||||||
|
|
||||||
|
sfg::Button::Ptr mute_button;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ActionToolbar action_toolbar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demande le dessin d'une frame
|
||||||
|
*/
|
||||||
|
virtual void frame();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dessine tous les objets et le fond à l'écran
|
* Dessine tous les objets et le fond à l'écran
|
||||||
*/
|
*/
|
||||||
|
@ -146,12 +154,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* Récupère la direction de la gravité
|
* Récupère la direction de la gravité
|
||||||
*/
|
*/
|
||||||
GravityDirection getGravityDirection();
|
Utility::Direction getGravityDirection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modifie la direction de la gravité
|
* Modifie la direction de la gravité
|
||||||
*/
|
*/
|
||||||
void setGravityDirection(GravityDirection set_gravity_direction);
|
void setGravityDirection(Utility::Direction set_gravity_direction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Récupère la liste des objets
|
* Récupère la liste des objets
|
||||||
|
|
|
@ -10,6 +10,11 @@ namespace Utility {
|
||||||
* avec la vitesse donnée
|
* avec la vitesse donnée
|
||||||
*/
|
*/
|
||||||
float animateValue(float current, float speed, float goal);
|
float animateValue(float current, float speed, float goal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste des directions
|
||||||
|
*/
|
||||||
|
enum class Direction {NORTH, EAST, SOUTH, WEST};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Binary file not shown.
|
@ -29,19 +29,19 @@ ObjectToolbar::ObjectToolbar() {
|
||||||
addCreator("kill_block", std::bind(&ObjectToolbar::createKillBlock, this));
|
addCreator("kill_block", std::bind(&ObjectToolbar::createKillBlock, this));
|
||||||
|
|
||||||
addCreator("gravity_block_north", std::bind(
|
addCreator("gravity_block_north", std::bind(
|
||||||
&ObjectToolbar::createGravityBlock, this, GravityDirection::NORTH
|
&ObjectToolbar::createGravityBlock, this, Utility::Direction::NORTH
|
||||||
));
|
));
|
||||||
|
|
||||||
addCreator("gravity_block_east", std::bind(
|
addCreator("gravity_block_east", std::bind(
|
||||||
&ObjectToolbar::createGravityBlock, this, GravityDirection::EAST
|
&ObjectToolbar::createGravityBlock, this, Utility::Direction::EAST
|
||||||
));
|
));
|
||||||
|
|
||||||
addCreator("gravity_block_south", std::bind(
|
addCreator("gravity_block_south", std::bind(
|
||||||
&ObjectToolbar::createGravityBlock, this, GravityDirection::SOUTH
|
&ObjectToolbar::createGravityBlock, this, Utility::Direction::SOUTH
|
||||||
));
|
));
|
||||||
|
|
||||||
addCreator("gravity_block_west", std::bind(
|
addCreator("gravity_block_west", std::bind(
|
||||||
&ObjectToolbar::createGravityBlock, this, GravityDirection::WEST
|
&ObjectToolbar::createGravityBlock, this, Utility::Direction::WEST
|
||||||
));
|
));
|
||||||
|
|
||||||
// attachement de la liste des créateurs à l'interface
|
// attachement de la liste des créateurs à l'interface
|
||||||
|
@ -117,7 +117,7 @@ Object::Ptr ObjectToolbar::createKillBlock() {
|
||||||
return Object::Ptr(new KillBlock);
|
return Object::Ptr(new KillBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr ObjectToolbar::createGravityBlock(GravityDirection direction) {
|
Object::Ptr ObjectToolbar::createGravityBlock(Utility::Direction 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);
|
||||||
return std::dynamic_pointer_cast<Object>(gravity_block);
|
return std::dynamic_pointer_cast<Object>(gravity_block);
|
||||||
|
|
|
@ -53,7 +53,7 @@ void GravityBlock::init(std::ifstream& file, Object::Ptr object) {
|
||||||
// lecture de la direction de la gravité
|
// lecture de la direction de la gravité
|
||||||
char gravity_direction;
|
char gravity_direction;
|
||||||
file.read(&gravity_direction, 1);
|
file.read(&gravity_direction, 1);
|
||||||
gravity_block->setGravityDirection((GravityDirection) gravity_direction);
|
gravity_block->setGravityDirection((Utility::Direction) gravity_direction);
|
||||||
|
|
||||||
// lecture des propriétés d'un bloc
|
// lecture des propriétés d'un bloc
|
||||||
Block::init(file, object);
|
Block::init(file, object);
|
||||||
|
@ -74,30 +74,30 @@ void GravityBlock::save(std::ofstream& file) const {
|
||||||
Block::save(file);
|
Block::save(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
GravityDirection GravityBlock::getGravityDirection() const {
|
Utility::Direction GravityBlock::getGravityDirection() const {
|
||||||
return gravity_direction;
|
return gravity_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GravityBlock::setGravityDirection(GravityDirection set_gravity_direction) {
|
void GravityBlock::setGravityDirection(Utility::Direction set_gravity_direction) {
|
||||||
gravity_direction = set_gravity_direction;
|
gravity_direction = set_gravity_direction;
|
||||||
|
|
||||||
// sélectionne le sprite d'icône selon la direction
|
// sélectionne le sprite d'icône selon la direction
|
||||||
std::string texture;
|
std::string texture;
|
||||||
|
|
||||||
switch (gravity_direction) {
|
switch (gravity_direction) {
|
||||||
case GravityDirection::NORTH:
|
case Utility::Direction::NORTH:
|
||||||
texture = "north";
|
texture = "north";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GravityDirection::EAST:
|
case Utility::Direction::EAST:
|
||||||
texture = "east";
|
texture = "east";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GravityDirection::SOUTH:
|
case Utility::Direction::SOUTH:
|
||||||
texture = "south";
|
texture = "south";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GravityDirection::WEST:
|
case Utility::Direction::WEST:
|
||||||
texture = "west";
|
texture = "west";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,30 +35,11 @@ inline sf::Vector2f roundVectorToGrid(sf::Vector2f input) {
|
||||||
Editor::Editor(Manager& manager) : Level(manager),
|
Editor::Editor(Manager& manager) : Level(manager),
|
||||||
drag_control_point(nullptr), drag_mode(Editor::DragMode::NONE) {
|
drag_control_point(nullptr), drag_mode(Editor::DragMode::NONE) {
|
||||||
|
|
||||||
// ajout des boutons dans la barre d'action
|
// ajout des boutons d'action de la barre d'action
|
||||||
action_toolbar.addButton(
|
action_toolbar.addButton(
|
||||||
*ResourceManager::get().getImage("toolbar/icon_back.tga"),
|
*ResourceManager::get().getImage("toolbar/icon_gear.tga")
|
||||||
std::bind(&Manager::popState, &getManager())
|
|
||||||
);
|
);
|
||||||
|
|
||||||
mute_button = action_toolbar.addButton(
|
|
||||||
*ResourceManager::get().getImage("toolbar/icon_music.tga"),
|
|
||||||
[]() {
|
|
||||||
// on inverse le drapeau de muet
|
|
||||||
ResourceManager::get().setMuted(
|
|
||||||
!ResourceManager::get().isMuted()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
action_toolbar.addSpacer(20, true, false);
|
|
||||||
|
|
||||||
action_toolbar.addButton(
|
|
||||||
*ResourceManager::get().getImage("toolbar/icon_no_music.tga")
|
|
||||||
);
|
|
||||||
|
|
||||||
action_toolbar.addSpacer(20, true, false);
|
|
||||||
|
|
||||||
action_toolbar.addButton(
|
action_toolbar.addButton(
|
||||||
*ResourceManager::get().getImage("toolbar/icon_save.tga"),
|
*ResourceManager::get().getImage("toolbar/icon_save.tga"),
|
||||||
std::bind(&Editor::save, this)
|
std::bind(&Editor::save, this)
|
||||||
|
@ -69,17 +50,11 @@ Editor::Editor(Manager& manager) : Level(manager),
|
||||||
std::bind(&Editor::test, this)
|
std::bind(&Editor::test, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
action_toolbar.addButton(
|
// ajout de la barre d'objets
|
||||||
*ResourceManager::get().getImage("toolbar/icon_gear.tga")
|
|
||||||
);
|
|
||||||
|
|
||||||
// signalement des sous-widgets
|
|
||||||
getManager().addWidget(action_toolbar.getWindow());
|
|
||||||
getManager().addWidget(object_toolbar.getWindow());
|
getManager().addWidget(object_toolbar.getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor::~Editor() {
|
Editor::~Editor() {
|
||||||
getManager().removeWidget(action_toolbar.getWindow());
|
|
||||||
getManager().removeWidget(object_toolbar.getWindow());
|
getManager().removeWidget(object_toolbar.getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +68,7 @@ void Editor::enable() {
|
||||||
// joue la musique de l'éditeur
|
// joue la musique de l'éditeur
|
||||||
ResourceManager::get().playMusic("editor.ogg");
|
ResourceManager::get().playMusic("editor.ogg");
|
||||||
|
|
||||||
// on affiche les barres d'outils
|
// on affiche la barre d'objets
|
||||||
action_toolbar.getWindow()->Show(true);
|
|
||||||
object_toolbar.getWindow()->Show(true);
|
object_toolbar.getWindow()->Show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,6 +267,8 @@ void Editor::frame() {
|
||||||
sf::RenderWindow& window = getManager().getWindow();
|
sf::RenderWindow& window = getManager().getWindow();
|
||||||
sf::Vector2i window_size = (sf::Vector2i) window.getSize();
|
sf::Vector2i window_size = (sf::Vector2i) window.getSize();
|
||||||
|
|
||||||
|
Level::frame();
|
||||||
|
|
||||||
// dessin de la frame
|
// dessin de la frame
|
||||||
draw();
|
draw();
|
||||||
|
|
||||||
|
@ -315,26 +291,10 @@ void Editor::frame() {
|
||||||
setCamera(camera);
|
setCamera(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mise à jour de l'icône du mute
|
|
||||||
sf::Image image;
|
|
||||||
|
|
||||||
if (ResourceManager::get().isMuted()) {
|
|
||||||
image = *ResourceManager::get().getImage("toolbar/icon_no_music.tga");
|
|
||||||
} else {
|
|
||||||
image = *ResourceManager::get().getImage("toolbar/icon_music.tga");
|
|
||||||
}
|
|
||||||
|
|
||||||
mute_button->SetImage(sfg::Image::Create(image));
|
|
||||||
|
|
||||||
// màj du titre de la fenêtre
|
// màj du titre de la fenêtre
|
||||||
getManager().setTitle(sf::String(L"Édition de ") + getName());
|
getManager().setTitle(sf::String(L"Édition de ") + getName());
|
||||||
|
|
||||||
// positionnement des barres d'outils au bon endroit
|
// positionnement de la barre d'objets
|
||||||
action_toolbar.getWindow()->SetAllocation(sf::FloatRect(
|
|
||||||
0, 0, window_size.x,
|
|
||||||
action_toolbar.getHeight()
|
|
||||||
));
|
|
||||||
|
|
||||||
object_toolbar.getWindow()->SetAllocation(sf::FloatRect(
|
object_toolbar.getWindow()->SetAllocation(sf::FloatRect(
|
||||||
window_size.x - object_toolbar.getWidth(),
|
window_size.x - object_toolbar.getWidth(),
|
||||||
action_toolbar.getHeight(),
|
action_toolbar.getHeight(),
|
||||||
|
|
|
@ -61,6 +61,7 @@ void Game::processEvent(const sf::Event& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::frame() {
|
void Game::frame() {
|
||||||
|
Level::frame();
|
||||||
sf::Time current_time = getManager().getCurrentTime();
|
sf::Time current_time = getManager().getCurrentTime();
|
||||||
|
|
||||||
if (current_time >= next_frame_time) {
|
if (current_time >= next_frame_time) {
|
||||||
|
|
|
@ -48,8 +48,8 @@ namespace {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::Level(Manager& manager) : State(manager) {
|
Level::Level(Manager& manager) : State(manager),
|
||||||
gravity_direction = GravityDirection::SOUTH;
|
gravity_direction(Utility::Direction::SOUTH) {
|
||||||
|
|
||||||
// métadonnées par défaut
|
// métadonnées par défaut
|
||||||
setName(sf::String("Nouveau niveau"));
|
setName(sf::String("Nouveau niveau"));
|
||||||
|
@ -67,9 +67,36 @@ Level::Level(Manager& manager) : State(manager) {
|
||||||
// ressources par défaut
|
// ressources par défaut
|
||||||
setMusic("");
|
setMusic("");
|
||||||
setBackground("");
|
setBackground("");
|
||||||
|
|
||||||
|
// ajout des boutons d'action de la barre d'action
|
||||||
|
action_toolbar.addButton(
|
||||||
|
*ResourceManager::get().getImage("toolbar/icon_back.tga"),
|
||||||
|
std::bind(&Manager::popState, &getManager())
|
||||||
|
);
|
||||||
|
|
||||||
|
mute_button = action_toolbar.addButton(
|
||||||
|
*ResourceManager::get().getImage("toolbar/icon_music.tga"),
|
||||||
|
[]() {
|
||||||
|
// on inverse le drapeau de muet
|
||||||
|
ResourceManager::get().setMuted(
|
||||||
|
!ResourceManager::get().isMuted()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
action_toolbar.addSpacer(5, true, false);
|
||||||
|
|
||||||
|
action_toolbar.addButton(
|
||||||
|
*ResourceManager::get().getImage("toolbar/icon_no_music.tga")
|
||||||
|
);
|
||||||
|
|
||||||
|
action_toolbar.addSpacer(5, true, false);
|
||||||
|
getManager().addWidget(action_toolbar.getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::~Level() {}
|
Level::~Level() {
|
||||||
|
getManager().removeWidget(action_toolbar.getWindow());
|
||||||
|
}
|
||||||
|
|
||||||
void Level::enable() {
|
void Level::enable() {
|
||||||
// positionnement par défaut de la caméra
|
// positionnement par défaut de la caméra
|
||||||
|
@ -78,6 +105,9 @@ void Level::enable() {
|
||||||
camera.setSize(window_size.x, window_size.y);
|
camera.setSize(window_size.x, window_size.y);
|
||||||
camera.setCenter(0, 0);
|
camera.setCenter(0, 0);
|
||||||
camera_angle = 180.f;
|
camera_angle = 180.f;
|
||||||
|
|
||||||
|
// on affiche la barre d'actions
|
||||||
|
action_toolbar.getWindow()->Show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::load() {
|
void Level::load() {
|
||||||
|
@ -251,6 +281,27 @@ void Level::processEvent(const sf::Event& event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Level::frame() {
|
||||||
|
sf::Vector2i window_size = (sf::Vector2i) getManager().getWindow().getSize();
|
||||||
|
|
||||||
|
// mise à jour de l'icône du mute en fonction de l'état
|
||||||
|
sf::Image image;
|
||||||
|
|
||||||
|
if (ResourceManager::get().isMuted()) {
|
||||||
|
image = *ResourceManager::get().getImage("toolbar/icon_no_music.tga");
|
||||||
|
} else {
|
||||||
|
image = *ResourceManager::get().getImage("toolbar/icon_music.tga");
|
||||||
|
}
|
||||||
|
|
||||||
|
mute_button->SetImage(sfg::Image::Create(image));
|
||||||
|
|
||||||
|
// positionnement de la barre d'actions
|
||||||
|
action_toolbar.getWindow()->SetAllocation(sf::FloatRect(
|
||||||
|
0, 0, window_size.x,
|
||||||
|
action_toolbar.getHeight()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
void Level::draw() {
|
void Level::draw() {
|
||||||
sf::RenderWindow& window = getManager().getWindow();
|
sf::RenderWindow& window = getManager().getWindow();
|
||||||
sf::Vector2u window_size = window.getSize();
|
sf::Vector2u window_size = window.getSize();
|
||||||
|
@ -375,16 +426,16 @@ void Level::setBackground(std::string set_background) {
|
||||||
|
|
||||||
sf::Vector2f Level::getGravity() const {
|
sf::Vector2f Level::getGravity() const {
|
||||||
switch (gravity_direction) {
|
switch (gravity_direction) {
|
||||||
case GravityDirection::NORTH:
|
case Utility::Direction::NORTH:
|
||||||
return sf::Vector2f(0, -GRAVITY);
|
return sf::Vector2f(0, -GRAVITY);
|
||||||
|
|
||||||
case GravityDirection::EAST:
|
case Utility::Direction::EAST:
|
||||||
return sf::Vector2f(GRAVITY, 0);
|
return sf::Vector2f(GRAVITY, 0);
|
||||||
|
|
||||||
case GravityDirection::SOUTH:
|
case Utility::Direction::SOUTH:
|
||||||
return sf::Vector2f(0, GRAVITY);
|
return sf::Vector2f(0, GRAVITY);
|
||||||
|
|
||||||
case GravityDirection::WEST:
|
case Utility::Direction::WEST:
|
||||||
return sf::Vector2f(-GRAVITY, 0);
|
return sf::Vector2f(-GRAVITY, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,16 +444,16 @@ sf::Vector2f Level::getGravity() const {
|
||||||
|
|
||||||
sf::Vector2f Level::getLeftDirection() const {
|
sf::Vector2f Level::getLeftDirection() const {
|
||||||
switch (gravity_direction) {
|
switch (gravity_direction) {
|
||||||
case GravityDirection::NORTH:
|
case Utility::Direction::NORTH:
|
||||||
return sf::Vector2f(MOVE, 0);
|
return sf::Vector2f(MOVE, 0);
|
||||||
|
|
||||||
case GravityDirection::EAST:
|
case Utility::Direction::EAST:
|
||||||
return sf::Vector2f(0, MOVE);
|
return sf::Vector2f(0, MOVE);
|
||||||
|
|
||||||
case GravityDirection::SOUTH:
|
case Utility::Direction::SOUTH:
|
||||||
return sf::Vector2f(-MOVE, 0);
|
return sf::Vector2f(-MOVE, 0);
|
||||||
|
|
||||||
case GravityDirection::WEST:
|
case Utility::Direction::WEST:
|
||||||
return sf::Vector2f(0, -MOVE);
|
return sf::Vector2f(0, -MOVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,11 +464,11 @@ sf::Vector2f Level::getRightDirection() const {
|
||||||
return -1.f * getLeftDirection();
|
return -1.f * getLeftDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
GravityDirection Level::getGravityDirection() {
|
Utility::Direction Level::getGravityDirection() {
|
||||||
return gravity_direction;
|
return gravity_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::setGravityDirection(GravityDirection set_gravity_direction) {
|
void Level::setGravityDirection(Utility::Direction set_gravity_direction) {
|
||||||
gravity_direction = set_gravity_direction;
|
gravity_direction = set_gravity_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue