From 0c2cd251fa0427b19f7c995bc7da7319d2ac80a5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 9 Feb 2021 19:39:30 -0500 Subject: Maps can contain named points of interest called warps --- res/maps/map1.tmx | 5 ++++- src/main.cpp | 2 +- src/map.cpp | 6 ++++++ src/map.h | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/res/maps/map1.tmx b/res/maps/map1.tmx index 6ad312b..d830158 100644 --- a/res/maps/map1.tmx +++ b/res/maps/map1.tmx @@ -1,5 +1,5 @@ - + @@ -771,6 +771,9 @@ + + + diff --git a/src/main.cpp b/src/main.cpp index b1fc373..62c81f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ void loop(Renderer& renderer) { game.setMap(std::move(map)); int lucasSprite = game.emplaceSprite("lucas"); - game.getSystem().initSprite(lucasSprite, {32, 32}); + game.getSystem().initSprite(lucasSprite, game.getMap().getWarpPoint("spawn")); game.getSystem().setUpCollision(lucasSprite, {-8, -8}, {12, 8}); game.getSystem().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt", renderer); game.getSprite(lucasSprite).controllable = true; diff --git a/src/map.cpp b/src/map.cpp index 1a2a250..2214d17 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -78,6 +78,12 @@ Map::Map(std::string_view filename, Renderer& renderer) { } prototypes_.push_back(std::move(p)); + } else if (object.getType() == "warp") { + vec2i point; + point.x() = object.getPosition().x; + point.y() = object.getPosition().y; + + warpPoints_[object.getName()] = std::move(point); } } } diff --git a/src/map.h b/src/map.h index a896b00..7bfb15e 100644 --- a/src/map.h +++ b/src/map.h @@ -1,6 +1,7 @@ #ifndef MAP_H_D95D6D47 #define MAP_H_D95D6D47 +#include #include #include #include @@ -48,6 +49,8 @@ public: const std::vector& getPrototypes() const { return prototypes_; } + const vec2i& getWarpPoint(const std::string& name) const { return warpPoints_.at(name); } + private: vec2i mapSize_; @@ -56,6 +59,7 @@ private: int tilesetTextureId_; int tilesetColumns_; std::vector prototypes_; + std::map warpPoints_; }; #endif /* end of include guard: MAP_H_D95D6D47 */ -- cgit 1.4.1