From eb40e3de7226d0005ce0a41c67c9355e675a489b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 25 Sep 2014 18:39:03 +0200 Subject: Add collision layer to maps and prevent movement into blocked areas --- src/model/Map.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/model/Map.cpp') diff --git a/src/model/Map.cpp b/src/model/Map.cpp index 21fbe00..faead6d 100644 --- a/src/model/Map.cpp +++ b/src/model/Map.cpp @@ -39,10 +39,13 @@ std::unique_ptr Map::load(__attribute__((unused)) const std::string &name) for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if (4 <= i && i < 12 && 4 <= j && j < 12) + if (4 <= i && i < 12 && 4 <= j && j < 12) { map->setTileAt(0, i, j, 1); - else + map->setCollisionAt(i, j, EMPTY); + } + else { map->setTileAt(0, i, j, 0); + } if (4 <= i && i < 12 && j == 8) map->setTileAt(1, i, j, 2); @@ -52,7 +55,7 @@ std::unique_ptr Map::load(__attribute__((unused)) const std::string &name) } map->entities.emplace_back("square"); - map->entities.back().moveTo(Model::Position{6, 6}); + map->entities.back().moveTo(map.get(), Model::Position{6, 6}); return map; } -- cgit v1.2.3