Modification de la polarité : Ctrl + Scroll
This commit is contained in:
parent
578d950ec7
commit
a5146dfc3d
|
@ -9,7 +9,7 @@ namespace Constants {
|
|||
* pour le calcul de l'attraction coulombienne entre
|
||||
* deux objets
|
||||
*/
|
||||
static const float ATTRACTION = 2000000;
|
||||
static const float ATTRACTION = 500000;
|
||||
|
||||
/**
|
||||
* Correction positionnelle : pourcentage de correction
|
||||
|
|
|
@ -159,8 +159,28 @@ void Editor::processEvent(const sf::Event& event) {
|
|||
drag_mode = Editor::DragMode::NONE;
|
||||
}
|
||||
|
||||
// lorsqu'on scrolle on déplace la vue
|
||||
// lorsqu'on scrolle on déplace la vue ou change la polarité
|
||||
if (event.type == sf::Event::MouseWheelScrolled) {
|
||||
// si on a Ctrl appuyé, on change la polarité
|
||||
if (getManager().isKeyPressed(Manager::Modifier::CONTROL)) {
|
||||
sf::Vector2i mouse_position(event.mouseWheelScroll.x, event.mouseWheelScroll.y);
|
||||
sf::Vector2f position = pixelToCoords(mouse_position);
|
||||
Object::Ptr pointed_object = getObject(position);
|
||||
|
||||
if (pointed_object != nullptr) {
|
||||
float new_charge = pointed_object->getCharge() +
|
||||
event.mouseWheelScroll.delta;
|
||||
|
||||
if (new_charge != 0) {
|
||||
new_charge /= std::abs(new_charge);
|
||||
}
|
||||
|
||||
pointed_object->setCharge(new_charge);
|
||||
}
|
||||
}
|
||||
|
||||
// sinon, on déplace la vue
|
||||
else {
|
||||
sf::View camera = getCamera();
|
||||
|
||||
// la molette est horizontale ssi. elle l'est vraiment ou
|
||||
|
@ -171,14 +191,20 @@ void Editor::processEvent(const sf::Event& event) {
|
|||
getManager().isKeyPressed(Manager::Modifier::SHIFT))
|
||||
);
|
||||
|
||||
if (horizontal) {
|
||||
camera.move(sf::Vector2f(event.mouseWheelScroll.delta, 0) * WHEEL_SCROLL_SPEED);
|
||||
if (!horizontal) {
|
||||
camera.move(
|
||||
sf::Vector2f(0, event.mouseWheelScroll.delta) *
|
||||
WHEEL_SCROLL_SPEED
|
||||
);
|
||||
} else {
|
||||
camera.move(sf::Vector2f(0, event.mouseWheelScroll.delta) * WHEEL_SCROLL_SPEED);
|
||||
camera.move(
|
||||
sf::Vector2f(event.mouseWheelScroll.delta, 0) *
|
||||
WHEEL_SCROLL_SPEED
|
||||
);
|
||||
}
|
||||
|
||||
setCamera(camera);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// gestion des touches
|
||||
|
|
|
@ -76,6 +76,7 @@ void Player::draw(Level& level) {
|
|||
sprite.setOutlineColor(sf::Color(255, 0, 0));
|
||||
} else {
|
||||
sprite.setOutlineColor(sf::Color::Black);
|
||||
}
|
||||
|
||||
// coloration du joueur en fonction de son numéro
|
||||
if (getPlayerNumber() == 0) {
|
||||
|
@ -83,7 +84,6 @@ void Player::draw(Level& level) {
|
|||
} else if (getPlayerNumber() == 1) {
|
||||
sprite.setFillColor(sf::Color(92, 107, 192));
|
||||
}
|
||||
}
|
||||
|
||||
// déplacement du sprite à la position de la balle
|
||||
sprite.setPosition(getPosition());
|
||||
|
|
Loading…
Reference in New Issue