summaryrefslogtreecommitdiff
path: root/src/floor_item.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-07 00:12:32 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-07 00:12:32 +0000
commita246c08cef5e4d598fc07a681eb971bfbcf01519 (patch)
treeff1813b11379ddef2c5be627aafcf3329170a293 /src/floor_item.cpp
parent09db562f2fca5c49fa1a92ba0b6dc60db479ae08 (diff)
downloadmana-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/floor_item.cpp')
-rwxr-xr-xsrc/floor_item.cpp72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/floor_item.cpp b/src/floor_item.cpp
index 691c5acd..a1b83a75 100755
--- a/src/floor_item.cpp
+++ b/src/floor_item.cpp
@@ -22,14 +22,52 @@
*/
#include "floor_item.h"
+#include "sprite.h"
+#include "graphic/spriteset.h"
+#include "resources/itemmanager.h"
+#include "resources/iteminfo.h"
#include <list>
-std::list<FloorItem*> floorItems;
+extern Spriteset *itemset;
+
+typedef std::list<FloorItem*> FloorItems;
+FloorItems floorItems;
+
+FloorItem::FloorItem(unsigned int id,
+ unsigned int itemId,
+ unsigned short x,
+ unsigned short y,
+ Map *map):
+ mId(id),
+ mItemId(itemId),
+ mX(x),
+ mY(y),
+ mMap(map)
+{
+ // Retrieve item image using a global itemset and itemDb (alternative?)
+ Image *image = itemset->spriteset[
+ itemDb->getItemInfo(itemId)->getImage() - 1];
+
+ // Create the sprite representing this floor item
+ mSprite = new Sprite(mX * map->getTileWidth(),
+ mY * map->getTileHeight(),
+ image);
+
+ // Add the representative sprite to the map
+ mSpriteIterator = mMap->addSprite(mSprite);
+}
+
+FloorItem::~FloorItem()
+{
+ // Remove and delete the representative sprite
+ mMap->removeSprite(mSpriteIterator);
+ delete mSprite;
+}
void empty_floor_items()
{
- std::list<FloorItem *>::iterator i;
+ FloorItems::iterator i;
for (i = floorItems.begin(); i != floorItems.end(); i++) {
delete (*i);
}
@@ -41,11 +79,14 @@ void add_floor_item(FloorItem *floorItem)
floorItems.push_back(floorItem);
}
-void remove_floor_item(unsigned int int_id)
+void remove_floor_item(unsigned int id)
{
- std::list<FloorItem *>::iterator i;
- for (i = floorItems.begin(); i != floorItems.end(); i++) {
- if ((*i)->getId() == int_id) {
+ FloorItems::iterator i;
+
+ for (i = floorItems.begin(); i != floorItems.end(); i++)
+ {
+ if ((*i)->getId() == id)
+ {
delete (*i);
floorItems.erase(i);
return;
@@ -55,25 +96,34 @@ void remove_floor_item(unsigned int int_id)
unsigned int find_floor_item_by_cor(unsigned short x, unsigned short y)
{
- std::list<FloorItem *>::iterator i;
- for (i = floorItems.begin(); i != floorItems.end(); i++) {
+ FloorItems::iterator i;
+
+ for (i = floorItems.begin(); i != floorItems.end(); i++)
+ {
FloorItem *floorItem = (*i);
+
if (floorItem->getX() == x && floorItem->getY() == y)
{
return floorItem->getId();
}
}
+
return 0;
}
FloorItem *find_floor_item_by_id(unsigned int int_id)
{
- std::list<FloorItem*>::iterator i;
- for (i = floorItems.begin(); i != floorItems.end(); i++) {
+ FloorItems::iterator i;
+
+ for (i = floorItems.begin(); i != floorItems.end(); i++)
+ {
FloorItem *floorItem = (*i);
- if (floorItem->getId() == int_id) {
+
+ if (floorItem->getId() == int_id)
+ {
return floorItem;
}
}
+
return NULL;
}