From 0a3ec1862fd479295639a38ab4799e4d36e12c13 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 12 Feb 2021 00:45:43 -0500 Subject: Added tile-sized invisible sprites These are used when you want a solid, interactable object that is part of the map instead of sprite animated (e.g. the mailboxes). --- src/game.cpp | 4 +++- src/map.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 8b6ef8f..fcd5f44 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -59,7 +59,9 @@ void Game::loadMap(std::string filename, std::string warpPoint, Direction dir) { int spriteId = emplaceSprite(p.name); getSystem().initSprite(spriteId, p.pos); getSystem().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true); - getSystem().initSprite(spriteId, p.animationFilename); + if (!p.animationFilename.empty()) { + getSystem().initSprite(spriteId, p.animationFilename); + } getSprite(spriteId).interactionScript = p.interactionScript; } diff --git a/src/map.cpp b/src/map.cpp index 8d4aa2d..da382fd 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -99,6 +99,21 @@ Map::Map(std::string_view name) : name_(name) { } triggers_.push_back(std::move(t)); + } else if (object.getType() == "tileSprite") { + Prototype p; + p.name = object.getName(); + p.pos.x() = std::floor(object.getPosition().x / 16) * 16; + p.pos.y() = std::floor(object.getPosition().y / 16) * 16; + p.collisionOffset = { 0, 0 }; + p.collisionSize = { 16, 16 }; + + for (const tmx::Property& property : object.getProperties()) { + if (property.getName() == "interactionScript") { + p.interactionScript = property.getStringValue(); + } + } + + prototypes_.push_back(std::move(p)); } } } -- cgit 1.4.1