Correction de la collision balle-balle

This commit is contained in:
Mattéo Delabre 2016-03-19 15:33:31 +01:00
parent 5903bf15fa
commit 20d15c6df8
1 changed files with 3 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#include "block.hpp" #include "block.hpp"
#include "constants.hpp" #include "constants.hpp"
#include <array> #include <array>
#include <iostream>
Ball::Ball(float x, float y) : Object(x, y), shape(10) { Ball::Ball(float x, float y) : Object(x, y), shape(10) {
shape.setOrigin(sf::Vector2f(10, 10)); shape.setOrigin(sf::Vector2f(10, 10));
@ -82,7 +83,7 @@ bool Ball::getCollisionInfo(Object& obj, sf::Vector2f& normal, float& depth) {
} }
bool Ball::getCollisionInfo(Ball& obj, sf::Vector2f& normal, float& depth) { bool Ball::getCollisionInfo(Ball& obj, sf::Vector2f& normal, float& depth) {
sf::Vector2f dir = obj.getPosition() - getPosition(); sf::Vector2f dir = getPosition() - obj.getPosition();
float squaredLength = dir.x * dir.x + dir.y * dir.y; float squaredLength = dir.x * dir.x + dir.y * dir.y;
// TODO: supprimer les valeurs magiques // TODO: supprimer les valeurs magiques
@ -106,7 +107,7 @@ bool Ball::getCollisionInfo(Ball& obj, sf::Vector2f& normal, float& depth) {
// TODO: supprimer les valeurs magiques // TODO: supprimer les valeurs magiques
// il y a eu collision // il y a eu collision
depth = 10 - length; depth = 20 - length;
normal = dir / length; normal = dir / length;
return true; return true;
} }