From 4353b056c1b4c768d8c12aa0793ef133b470a9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Sat, 9 Apr 2016 04:58:46 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20commit=20pr=C3=A9c=C3=A9dent=20(de?= =?UTF-8?q?ux=20fichiers=20manquants)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/level.hpp | 14 ++++++++++++++ src/level.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/level.hpp b/include/level.hpp index 214273b..3bdb22d 100644 --- a/include/level.hpp +++ b/include/level.hpp @@ -8,6 +8,9 @@ #include "manager.hpp" #include "resource_manager.hpp" +// liste des directions de la gravité +enum class GravityDirection {NORTH, EAST, SOUTH, WEST}; + /** * La classe Level est une abstraction des * classes affichant une collection d'objets, comme @@ -21,6 +24,7 @@ private: sf::Sprite background; std::string music_name; + sf::Vector2f gravity; std::vector objects; std::vector> zone; @@ -103,6 +107,16 @@ public: */ void setBackground(sf::Sprite set_background); + /** + * Récupère le vecteur gravité + */ + sf::Vector2f getGravity() const; + + /** + * Modifie la direction de la gravité + */ + void setGravity(GravityDirection direction); + /** * Récupère la liste des objets */ diff --git a/src/level.cpp b/src/level.cpp index fcc0769..fe6ea32 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -7,6 +7,8 @@ #include #include "level.hpp" +const float GRAVITY = 235; + /** * Dictionnaire associant les types d'objets * à des instances qui seront utilisées pour la @@ -17,7 +19,7 @@ std::map> object_type_map {Block::TYPE_ID, Block::load} }; -Level::Level(Manager& manager) : View(manager) {} +Level::Level(Manager& manager) : View(manager), gravity(0, GRAVITY) {} Level::~Level() {} void Level::load(std::ifstream& file) { @@ -190,6 +192,30 @@ void Level::setBackground(sf::Sprite set_background) { background = set_background; } +sf::Vector2f Level::getGravity() const { + return gravity; +} + +void Level::setGravity(GravityDirection direction) { + switch (direction) { + case GravityDirection::NORTH: + gravity = sf::Vector2f(0, -GRAVITY); + break; + + case GravityDirection::WEST: + gravity = sf::Vector2f(GRAVITY, 0); + break; + + case GravityDirection::SOUTH: + gravity = sf::Vector2f(0, GRAVITY); + break; + + case GravityDirection::EAST: + gravity = sf::Vector2f(-GRAVITY, 0); + break; + } +} + std::vector& Level::getObjects() { return objects; }