diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-10-07 00:12:32 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-10-07 00:12:32 +0000 |
commit | a246c08cef5e4d598fc07a681eb971bfbcf01519 (patch) | |
tree | ff1813b11379ddef2c5be627aafcf3329170a293 /src/map.cpp | |
parent | 09db562f2fca5c49fa1a92ba0b6dc60db479ae08 (diff) | |
download | mana-a246c08cef5e4d598fc07a681eb971bfbcf01519.tar.gz mana-a246c08cef5e4d598fc07a681eb971bfbcf01519.tar.bz2 mana-a246c08cef5e4d598fc07a681eb971bfbcf01519.tar.xz mana-a246c08cef5e4d598fc07a681eb971bfbcf01519.zip |
Modified finding NPC as by timonator's suggestion in order to allow NPCs to be
clicked on their heads too. Also made start to tile engine improvement by
adding the Sprite class that is now used by the floor items for being displayed
on the map. Finally added documentation to Item class and splitted out
Properties class from Map.
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/map.cpp b/src/map.cpp index 583a01be..3237b54a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -26,6 +26,7 @@ #include "being.h" #include "graphics.h" #include "resources/image.h" +#include "sprite.h" #include <queue> @@ -85,9 +86,22 @@ Map::addTileset(Tileset *tileset) tilesets.push_back(tileset); } +bool spriteCompare(const Sprite *a, const Sprite *b) +{ + return a->getY() < b->getY(); +} + void Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) { + // If drawing the fringe layer, make sure sprites are sorted + Sprites::iterator si; + if (layer == 1) + { + mSprites.sort(spriteCompare); + si = mSprites.begin(); + } + int startX = scrollX / 32; int startY = scrollY / 32; int endX = (graphics->getWidth() + scrollX + 31) / 32; @@ -100,6 +114,17 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) for (int y = startY; y < endY; y++) { + // If drawing the fringe layer, make sure all sprites above this row of + // tiles have been drawn + if (layer == 1) + { + while (si != mSprites.end() && (*si)->getY() < y * 32) + { + (*si)->draw(graphics, -scrollX, -scrollY); + si++; + } + } + for (int x = startX; x < endX; x++) { Image *img = getTile(x, y, layer); @@ -220,29 +245,17 @@ Map::getMetaTile(int x, int y) return &metaTiles[x + y * mWidth]; } -std::string -Map::getProperty(const std::string &name) -{ - std::map<std::string,std::string>::iterator i = properties.find(name); - - if (i != properties.end()) - { - return (*i).second; - } - - return ""; -} - -bool -Map::hasProperty(const std::string &name) +Sprites::iterator +Map::addSprite(Sprite *sprite) { - return (properties.find(name) != properties.end()); + mSprites.push_front(sprite); + return mSprites.begin(); } void -Map::setProperty(const std::string &name, const std::string &value) +Map::removeSprite(Sprites::iterator iterator) { - properties[name] = value; + mSprites.erase(iterator); } std::list<PATH_NODE> |