Supporte aussi bien le Ctrl/Shift/Alt/System gauche que droit
This commit is contained in:
parent
1b14d4084d
commit
ef5ecc810d
|
@ -25,6 +25,11 @@ private:
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Énumération des modificateurs
|
||||||
|
*/
|
||||||
|
enum class Modifier {CONTROL, ALT, SHIFT, SYSTEM};
|
||||||
|
|
||||||
Manager();
|
Manager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,6 +87,12 @@ public:
|
||||||
* touche donnée ou non
|
* touche donnée ou non
|
||||||
*/
|
*/
|
||||||
bool isKeyPressed(sf::Keyboard::Key key) const;
|
bool isKeyPressed(sf::Keyboard::Key key) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie un booléen attestant de l'appui sur le
|
||||||
|
* modificateur
|
||||||
|
*/
|
||||||
|
bool isKeyPressed(Modifier modifier) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
class ResourceManager;
|
class ResourceManager;
|
||||||
class Manager;
|
|
||||||
class Object;
|
class Object;
|
||||||
|
class Manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe abstraite pour les états de jeu
|
* Classe abstraite pour les états de jeu
|
||||||
|
@ -38,20 +38,30 @@ public:
|
||||||
*/
|
*/
|
||||||
Manager& getManager();
|
Manager& getManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère le gestionnaire (version constante)
|
||||||
|
*/
|
||||||
|
const Manager& getManager() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Récupère le gestionnaire de ressources
|
* Récupère le gestionnaire de ressources
|
||||||
*/
|
*/
|
||||||
ResourceManager& getResourceManager();
|
ResourceManager& getResourceManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère le gestionnaire de ressources (version constante)
|
||||||
|
*/
|
||||||
|
const ResourceManager& getResourceManager() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Récupère la fenêtre
|
* Récupère la fenêtre
|
||||||
*/
|
*/
|
||||||
sf::RenderWindow& getWindow();
|
sf::RenderWindow& getWindow();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Récupère si une touche est pressée
|
* Récupère la fenêtre (version constante)
|
||||||
*/
|
*/
|
||||||
bool isKeyPressed(sf::Keyboard::Key key) const;
|
const sf::RenderWindow& getWindow() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -65,7 +65,7 @@ void Editor::processEvent(const sf::Event& event) {
|
||||||
|
|
||||||
if (event.mouseButton.button == sf::Mouse::Left) {
|
if (event.mouseButton.button == sf::Mouse::Left) {
|
||||||
// clic + shift : sélection par rectangle de sélection
|
// clic + shift : sélection par rectangle de sélection
|
||||||
if (isKeyPressed(sf::Keyboard::LShift)) {
|
if (getManager().isKeyPressed(Manager::Modifier::SHIFT)) {
|
||||||
drag_start = mouse_position;
|
drag_start = mouse_position;
|
||||||
drag_end = mouse_position;
|
drag_end = mouse_position;
|
||||||
drag_mode = DragMode::SELECT_RECT;
|
drag_mode = DragMode::SELECT_RECT;
|
||||||
|
@ -73,7 +73,7 @@ void Editor::processEvent(const sf::Event& event) {
|
||||||
|
|
||||||
// clic sur un objet : démarrage de la sélection libre
|
// clic sur un objet : démarrage de la sélection libre
|
||||||
else if (pointed_object != nullptr) {
|
else if (pointed_object != nullptr) {
|
||||||
if (isKeyPressed(sf::Keyboard::LControl)) {
|
if (getManager().isKeyPressed(Manager::Modifier::CONTROL)) {
|
||||||
drag_start = mouse_position;
|
drag_start = mouse_position;
|
||||||
drag_end = mouse_position;
|
drag_end = mouse_position;
|
||||||
drag_mode = DragMode::SELECT_BULK;
|
drag_mode = DragMode::SELECT_BULK;
|
||||||
|
|
|
@ -98,3 +98,21 @@ void Manager::setTitle(sf::String set_title) {
|
||||||
bool Manager::isKeyPressed(sf::Keyboard::Key key) const {
|
bool Manager::isKeyPressed(sf::Keyboard::Key key) const {
|
||||||
return sf::Keyboard::isKeyPressed(key) && window.hasFocus();
|
return sf::Keyboard::isKeyPressed(key) && window.hasFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Manager::isKeyPressed(Manager::Modifier modifier) const {
|
||||||
|
switch (modifier) {
|
||||||
|
case Manager::Modifier::CONTROL:
|
||||||
|
return isKeyPressed(sf::Keyboard::LControl) || isKeyPressed(sf::Keyboard::RControl);
|
||||||
|
|
||||||
|
case Manager::Modifier::ALT:
|
||||||
|
return isKeyPressed(sf::Keyboard::LAlt) || isKeyPressed(sf::Keyboard::RAlt);
|
||||||
|
|
||||||
|
case Manager::Modifier::SYSTEM:
|
||||||
|
return isKeyPressed(sf::Keyboard::LSystem) || isKeyPressed(sf::Keyboard::RSystem);
|
||||||
|
|
||||||
|
case Manager::Modifier::SHIFT:
|
||||||
|
return isKeyPressed(sf::Keyboard::LShift) || isKeyPressed(sf::Keyboard::RShift);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -41,21 +41,21 @@ sf::Vector2f Player::getForces(const Level& level) const {
|
||||||
|
|
||||||
// déplacement de la balle après appui sur les touches de direction
|
// déplacement de la balle après appui sur les touches de direction
|
||||||
if (getPlayerNumber() == 0) {
|
if (getPlayerNumber() == 0) {
|
||||||
if (level.isKeyPressed(sf::Keyboard::Left)) {
|
if (level.getManager().isKeyPressed(sf::Keyboard::Left)) {
|
||||||
forces += level.getLeftDirection();
|
forces += level.getLeftDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level.isKeyPressed(sf::Keyboard::Right)) {
|
if (level.getManager().isKeyPressed(sf::Keyboard::Right)) {
|
||||||
forces += level.getRightDirection();
|
forces += level.getRightDirection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPlayerNumber() == 1) {
|
if (getPlayerNumber() == 1) {
|
||||||
if (level.isKeyPressed(sf::Keyboard::Q)) {
|
if (level.getManager().isKeyPressed(sf::Keyboard::Q)) {
|
||||||
forces += level.getLeftDirection();
|
forces += level.getLeftDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level.isKeyPressed(sf::Keyboard::D)) {
|
if (level.getManager().isKeyPressed(sf::Keyboard::D)) {
|
||||||
forces += level.getRightDirection();
|
forces += level.getRightDirection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,22 @@ Manager& State::getManager() {
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Manager& State::getManager() const {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
ResourceManager& State::getResourceManager() {
|
ResourceManager& State::getResourceManager() {
|
||||||
return manager.getResourceManager();
|
return manager.getResourceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ResourceManager& State::getResourceManager() const {
|
||||||
|
return manager.getResourceManager();
|
||||||
|
}
|
||||||
|
|
||||||
sf::RenderWindow& State::getWindow() {
|
sf::RenderWindow& State::getWindow() {
|
||||||
return manager.getWindow();
|
return manager.getWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool State::isKeyPressed(sf::Keyboard::Key key) const {
|
const sf::RenderWindow& State::getWindow() const {
|
||||||
return manager.isKeyPressed(key);
|
return manager.getWindow();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue