From ddde5ee5c1c5fd7d9614da60ba021405b040d11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Mon, 4 Apr 2016 22:37:37 +0200 Subject: [PATCH] =?UTF-8?q?=C3=89vite=20les=20objets=20superpos=C3=A9s=20d?= =?UTF-8?q?ans=20l'=C3=A9diteur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/editor.cpp b/src/editor.cpp index dd1b2a3..08b56fd 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -43,7 +43,20 @@ void Editor::frame() { std::shared_ptr object = std::shared_ptr(new Block); object->setPosition(position); - objects.push_back(object); + + // avant d'ajouter l'objet, on vérifie qu'il ne soit + // pas superposé à un autre + float overlaps = false; + + for (unsigned int i = 0; i < objects.size(); i++) { + if (objects[i]->getAABB()->intersects(*object->getAABB())) { + overlaps = true; + } + } + + if (!overlaps) { + objects.push_back(object); + } } } }