From 8aedeaf12c7dbf35f2f75f1b063b76a4fad06f30 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 6 Jul 2021 10:12:59 -0400 Subject: Added "floating" sprite attribute Sprites with this flag enabled will ignore map collision. --- src/game.cpp | 1 + src/map.cpp | 2 ++ src/map.h | 1 + src/sprite.h | 1 + src/transform_system.cpp | 12 ++++++++---- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index dff8af0..1b2cda9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -88,6 +88,7 @@ void Game::loadMap(std::string filename) { if (!p.backgroundScript.empty()) { backgroundScripts.push_back({spriteId, p.backgroundScript}); } + getSprite(spriteId).floating = p.floating; } for (const Trigger& t : map_->getTriggers()) { diff --git a/src/map.cpp b/src/map.cpp index f28a976..c6729d6 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -123,6 +123,8 @@ Map::Map(std::string_view name) : name_(name) { p.bumpPlayerScript = property.getStringValue(); } else if (property.getName() == "backgroundScript") { p.backgroundScript = property.getStringValue(); + } else if (property.getName() == "floating") { + p.floating = property.getBoolValue(); } } diff --git a/src/map.h b/src/map.h index 48c0223..4019428 100644 --- a/src/map.h +++ b/src/map.h @@ -37,6 +37,7 @@ struct Prototype { MirrorType mirrorType = MirrorType::None; int mirrorAxis = 0; std::string spriteToMirror; + bool floating = false; }; struct Trigger { diff --git a/src/sprite.h b/src/sprite.h index e7cb55b..406053e 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -84,6 +84,7 @@ public: std::string bumpPlayerScript; std::string enclosureZone; bool sliding = false; + bool floating = false; // Animation (internals) bool isAnimated = false; diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 825514f..425d8ea 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp @@ -81,7 +81,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 } if (dirHasDir(dir, Direction::right)) { - if (newTileDR.x() > oldTileDR.x() && + if (!sprite.floating && + newTileDR.x() > oldTileDR.x() && newColDR.x() < mapBounds.w()) { for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { if (map.isBlocked(newTileDR.x(), y)) { @@ -138,7 +139,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 } if (dirHasDir(dir, Direction::left)) { - if (newTileUL.x() < oldTileUL.x() && + if (!sprite.floating && + newTileUL.x() < oldTileUL.x() && newColUL.x() >= 0) { for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { if (map.isBlocked(newTileUL.x(), y)) { @@ -217,7 +219,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 newTileDR = newColDR / map.getTileSize(); if (dirHasDir(dir, Direction::down)) { - if (newTileDR.y() > oldTileDR.y() && + if (!sprite.floating && + newTileDR.y() > oldTileDR.y() && newColDR.y() < mapBounds.h()) { for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { if (map.isBlocked(x, newTileDR.y())) { @@ -274,7 +277,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 } if (dirHasDir(dir, Direction::up)) { - if (newTileUL.y() < oldTileUL.y() && + if (!sprite.floating && + newTileUL.y() < oldTileUL.y() && newColUL.y() >= 0) { for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { if (map.isBlocked(x, newTileUL.y())) { -- cgit 1.4.1