diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2021-07-06 10:12:59 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2021-07-06 10:12:59 -0400 |
commit | 8aedeaf12c7dbf35f2f75f1b063b76a4fad06f30 (patch) | |
tree | b90a7f804631d1921be64666e5ddc9bce31df371 | |
parent | b57aa99e101c7cf59fd59d2f8df9fe3547d91acc (diff) | |
download | tanetane-8aedeaf12c7dbf35f2f75f1b063b76a4fad06f30.tar.gz tanetane-8aedeaf12c7dbf35f2f75f1b063b76a4fad06f30.tar.bz2 tanetane-8aedeaf12c7dbf35f2f75f1b063b76a4fad06f30.zip |
Added "floating" sprite attribute
Sprites with this flag enabled will ignore map collision.
-rw-r--r-- | src/game.cpp | 1 | ||||
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/sprite.h | 1 | ||||
-rw-r--r-- | 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) { | |||
88 | if (!p.backgroundScript.empty()) { | 88 | if (!p.backgroundScript.empty()) { |
89 | backgroundScripts.push_back({spriteId, p.backgroundScript}); | 89 | backgroundScripts.push_back({spriteId, p.backgroundScript}); |
90 | } | 90 | } |
91 | getSprite(spriteId).floating = p.floating; | ||
91 | } | 92 | } |
92 | 93 | ||
93 | for (const Trigger& t : map_->getTriggers()) { | 94 | 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) { | |||
123 | p.bumpPlayerScript = property.getStringValue(); | 123 | p.bumpPlayerScript = property.getStringValue(); |
124 | } else if (property.getName() == "backgroundScript") { | 124 | } else if (property.getName() == "backgroundScript") { |
125 | p.backgroundScript = property.getStringValue(); | 125 | p.backgroundScript = property.getStringValue(); |
126 | } else if (property.getName() == "floating") { | ||
127 | p.floating = property.getBoolValue(); | ||
126 | } | 128 | } |
127 | } | 129 | } |
128 | 130 | ||
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 { | |||
37 | MirrorType mirrorType = MirrorType::None; | 37 | MirrorType mirrorType = MirrorType::None; |
38 | int mirrorAxis = 0; | 38 | int mirrorAxis = 0; |
39 | std::string spriteToMirror; | 39 | std::string spriteToMirror; |
40 | bool floating = false; | ||
40 | }; | 41 | }; |
41 | 42 | ||
42 | struct Trigger { | 43 | 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: | |||
84 | std::string bumpPlayerScript; | 84 | std::string bumpPlayerScript; |
85 | std::string enclosureZone; | 85 | std::string enclosureZone; |
86 | bool sliding = false; | 86 | bool sliding = false; |
87 | bool floating = false; | ||
87 | 88 | ||
88 | // Animation (internals) | 89 | // Animation (internals) |
89 | bool isAnimated = false; | 90 | 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 | |||
81 | } | 81 | } |
82 | 82 | ||
83 | if (dirHasDir(dir, Direction::right)) { | 83 | if (dirHasDir(dir, Direction::right)) { |
84 | if (newTileDR.x() > oldTileDR.x() && | 84 | if (!sprite.floating && |
85 | newTileDR.x() > oldTileDR.x() && | ||
85 | newColDR.x() < mapBounds.w()) { | 86 | newColDR.x() < mapBounds.w()) { |
86 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { | 87 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { |
87 | if (map.isBlocked(newTileDR.x(), y)) { | 88 | if (map.isBlocked(newTileDR.x(), y)) { |
@@ -138,7 +139,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 | |||
138 | } | 139 | } |
139 | 140 | ||
140 | if (dirHasDir(dir, Direction::left)) { | 141 | if (dirHasDir(dir, Direction::left)) { |
141 | if (newTileUL.x() < oldTileUL.x() && | 142 | if (!sprite.floating && |
143 | newTileUL.x() < oldTileUL.x() && | ||
142 | newColUL.x() >= 0) { | 144 | newColUL.x() >= 0) { |
143 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { | 145 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { |
144 | if (map.isBlocked(newTileUL.x(), y)) { | 146 | if (map.isBlocked(newTileUL.x(), y)) { |
@@ -217,7 +219,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 | |||
217 | newTileDR = newColDR / map.getTileSize(); | 219 | newTileDR = newColDR / map.getTileSize(); |
218 | 220 | ||
219 | if (dirHasDir(dir, Direction::down)) { | 221 | if (dirHasDir(dir, Direction::down)) { |
220 | if (newTileDR.y() > oldTileDR.y() && | 222 | if (!sprite.floating && |
223 | newTileDR.y() > oldTileDR.y() && | ||
221 | newColDR.y() < mapBounds.h()) { | 224 | newColDR.y() < mapBounds.h()) { |
222 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { | 225 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { |
223 | if (map.isBlocked(x, newTileDR.y())) { | 226 | if (map.isBlocked(x, newTileDR.y())) { |
@@ -274,7 +277,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 | |||
274 | } | 277 | } |
275 | 278 | ||
276 | if (dirHasDir(dir, Direction::up)) { | 279 | if (dirHasDir(dir, Direction::up)) { |
277 | if (newTileUL.y() < oldTileUL.y() && | 280 | if (!sprite.floating && |
281 | newTileUL.y() < oldTileUL.y() && | ||
278 | newColUL.y() >= 0) { | 282 | newColUL.y() >= 0) { |
279 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { | 283 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { |
280 | if (map.isBlocked(x, newTileUL.y())) { | 284 | if (map.isBlocked(x, newTileUL.y())) { |