| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "flooritem.h" |
| 23 |
|
| 24 |
#include "graphics.h" |
| 25 |
#include "item.h" |
| 26 |
#include "map.h" |
| 27 |
|
| 28 |
#include "resources/image.h" |
| 29 |
|
| 30 |
FloorItem::FloorItem(int id, |
| 31 |
int itemId, |
| 32 |
int x, |
| 33 |
int y, |
| 34 |
Map *map): |
| 35 |
mId(id), |
| 36 |
mX(x), |
| 37 |
mY(y), |
| 38 |
mMap(map), |
| 39 |
mAlpha(1.0f) |
| 40 |
{ |
| 41 |
// Create a corresponding item instance |
| 42 |
mItem = new Item(itemId); |
| 43 |
|
| 44 |
// Add ourselves to the map |
| 45 |
mMapSprite = mMap->addSprite(this); |
| 46 |
} |
| 47 |
|
| 48 |
FloorItem::~FloorItem() |
| 49 |
{ |
| 50 |
// Remove ourselves from the map |
| 51 |
mMap->removeSprite(mMapSprite); |
| 52 |
|
| 53 |
delete mItem; |
| 54 |
} |
| 55 |
|
| 56 |
int FloorItem::getItemId() const |
| 57 |
{ |
| 58 |
return mItem->getId(); |
| 59 |
} |
| 60 |
|
| 61 |
Item *FloorItem::getItem() const |
| 62 |
{ |
| 63 |
return mItem; |
| 64 |
} |
| 65 |
|
| 66 |
void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const |
| 67 |
{ |
| 68 |
if (mItem) |
| 69 |
{ |
| 70 |
Image *image = mItem->getDrawImage(); |
| 71 |
|
| 72 |
if (image) |
| 73 |
if (mAlpha != image->getAlpha()) |
| 74 |
image->setAlpha(mAlpha); |
| 75 |
|
| 76 |
graphics->drawImage(image, mX * 32 + offsetX, mY * 32 + offsetY); |
| 77 |
} |
| 78 |
} |