From 313173de4689be427eaccac0db0e0ea536296b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Wed, 9 Mar 2016 19:42:09 +0100 Subject: [PATCH] Correction des erreurs de syntaxe --- ball.cpp | 13 +++++-------- ball.hpp | 2 +- engine.cpp | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ball.cpp b/ball.cpp index a7a97b0..544c1ad 100644 --- a/ball.cpp +++ b/ball.cpp @@ -22,18 +22,15 @@ sf::Vector2f Ball::getForces(State state) { // force d'attraction entre les balles et les blocs chargés if (getCharge() != 0) { - for (int j = 0; j < state.objects.size(); j++) { - Object attractiveObject = *objects[j]; + for (unsigned int j = 0; j < state.objects.size(); j++) { + Object *attractive = state.objects[j]; - if (i == j || attractiveObject.getCharge() == 0) { + if (attractive == this || attractive->getCharge() == 0) { continue; } // vecteur allant de l'objet attirant vers l'objet considéré - sf::Vector2f attraction( - attractiveObject.getPosition() - - object.getPosition() - ); + sf::Vector2f attraction(attractive->getPosition() - position); // la norme de ce vecteur est la distance entre les objets float distanceSquared = attraction.x * attraction.x + @@ -43,7 +40,7 @@ sf::Vector2f Ball::getForces(State state) { // la force d'attraction, puis application de la norme attraction /= std::sqrt(distanceSquared); attraction *= Ball::ATTRACTION * ( - (objects[i].getCharge() * objects[j].getCharge()) / + (charge * attractive->getCharge()) / distanceSquared ); diff --git a/ball.hpp b/ball.hpp index 05f3748..7e79f62 100644 --- a/ball.hpp +++ b/ball.hpp @@ -11,7 +11,7 @@ protected: /** * Calcule les forces appliquées à l'objet */ - void getForces(State state); + sf::Vector2f getForces(State state); static constexpr float ATTRACTION = 10; static constexpr float MOVE = 10; diff --git a/engine.cpp b/engine.cpp index 35c1b55..5879154 100644 --- a/engine.cpp +++ b/engine.cpp @@ -68,7 +68,7 @@ void Engine::update() { state.objects = objects; // demande la mise à jour de tous les objets du jeu - for (int i = 0; i < objects.size(); i++) { + for (unsigned int i = 0; i < objects.size(); i++) { objects[i]->update(state); } } @@ -80,7 +80,7 @@ void Engine::draw() { // chargement de la file d'affichage des objets std::priority_queue, CompareObjectLayer> display_queue; - for (int i = 0; i < objects.size(); i++) { + for (unsigned int i = 0; i < objects.size(); i++) { display_queue.push(objects[i]); }