summaryrefslogtreecommitdiff
path: root/src/graphic
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 15:43:26 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 15:43:26 +0000
commitb7170d13fd71fb624c06c4536974a7cd3f77591b (patch)
tree7f7583407e79423b08f98a50d897f6e30ac886dd /src/graphic
parenta120ea5cb0a57c9d3bd8677269bd65cf79dad933 (diff)
downloadmana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.gz
mana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.bz2
mana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.xz
mana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.zip
Rewrote Spriteset to work with Image* instead of BITMAP*
Diffstat (limited to 'src/graphic')
-rw-r--r--src/graphic/graphic.cpp23
-rw-r--r--src/graphic/graphic.h2
-rw-r--r--src/graphic/image.cpp46
-rw-r--r--src/graphic/image.h49
4 files changed, 25 insertions, 95 deletions
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 0e5b9a32..7678506b 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -196,20 +196,21 @@ GraphicEngine::GraphicEngine() {
gui_bitmap = this->buffer;
// Load the sprite sets
- BITMAP *npcbmp = load_bitmap("data/graphic/npcset.bmp", NULL);
- BITMAP *emotionbmp = load_bitmap("data/graphic/emotionset.bmp", NULL);
- BITMAP *tilesetbmp = load_bitmap("data/graphic/tileset.bmp", NULL);
- BITMAP *monsterbitmap = load_bitmap("data/graphic/monsterset.bmp", NULL);
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *npcbmp = resman->getImage("graphic/npcset.bmp");
+ Image *emotionbmp = resman->getImage("graphic/emotionset.bmp");
+ Image *tilesetbmp = resman->getImage("graphic/tileset.bmp");
+ Image *monsterbitmap = resman->getImage("graphic/monsterset.bmp");
if (!npcbmp) error("Unable to load npcset.bmp");
if (!emotionbmp) error("Unable to load emotionset.bmp");
if (!tilesetbmp) error("Unable to load tileset.bmp");
if (!monsterbitmap) error("Unable to load monsterset.bmp");
- npcset = new Spriteset(npcbmp, 50, 80, 0, 0);
- emotionset = new Spriteset(emotionbmp, 19, 19, 0, 0);
- tileset = new Spriteset(tilesetbmp, 32, 32, 0, 0);
- monsterset = new Spriteset(monsterbitmap, 60, 60, 30, 40);
+ npcset = new Spriteset(npcbmp, 50, 80);
+ emotionset = new Spriteset(emotionbmp, 19, 19);
+ tileset = new Spriteset(tilesetbmp, 32, 32);
+ monsterset = new Spriteset(monsterbitmap, 60, 60);
}
GraphicEngine::~GraphicEngine() {
@@ -341,12 +342,12 @@ void GraphicEngine::refresh() {
int mf = node->frame + node->action;
if (node->action == MONSTER_DEAD) {
- monsterset->spriteset[sprnum + 8 * MONSTER_DEAD]->draw(
- buffer, node->text_x, node->text_y);
+ monsterset->spriteset[sprnum + 8 * MONSTER_DEAD]->draw(buffer,
+ node->text_x + 30, node->text_y + 40);
}
else {
monsterset->spriteset[sprnum + 8 * mf]->draw(buffer,
- node->text_x, node->text_y);
+ node->text_x + 30, node->text_y + 40);
}
if (node->action != STAND) {
diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h
index ed62bf79..063410cf 100644
--- a/src/graphic/graphic.h
+++ b/src/graphic/graphic.h
@@ -39,7 +39,7 @@
#include "../gui/inventory.h"
#include "../gui/npc.h"
#include "../gui/status.h"
-#include "../../data/graphic/gfx_data.h"
+#include "../resources/resourcemanager.h"
#include "image.h"
#include <allegro.h>
diff --git a/src/graphic/image.cpp b/src/graphic/image.cpp
index 008c4017..44b611f6 100644
--- a/src/graphic/image.cpp
+++ b/src/graphic/image.cpp
@@ -18,52 +18,20 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * By ElvenProgrammer aka Eugenio Favalli (umperio@users.sourceforge.net)
+ * $Id$
*/
#include "image.h"
-
-// VideoImage
-
-VideoImage::VideoImage(BITMAP *src, int offset_x, int offset_y):
- src(src),
- offset_x(offset_x),
- offset_y(offset_y)
+Spriteset::Spriteset(Image *img, int width, int height)
{
-}
-
-VideoImage::~VideoImage() {
- destroy_bitmap(src);
-}
-
-void VideoImage::draw(BITMAP *dst, int x, int y) {
- //SDL_Rect dst_rect;
- //dst_rect.x = x + offset_x;
- //dst_rect.y = y + offset_y;
- //SDL_BlitSurface(src, NULL, dst, &dst_rect);
-
- masked_blit(src, dst, 0, 0, x + offset_x, y + offset_y, src->w, src->h);
-}
-
-
-// Spriteset
-
-Spriteset::Spriteset(BITMAP *bmp, int width, int height, int offx, int offy)
-{
- /*
- * We're creating sub bitmaps here for plain convenience. With SDL this'll
- * probably need to be done different.
- */
int x, y;
- for (y = 0; y + height <= bmp->h; y += height)
+ for (y = 0; y + height <= img->getHeight(); y += height)
{
- for (x = 0; x + width <= bmp->w; x += width)
+ for (x = 0; x + width <= img->getWidth(); x += width)
{
- spriteset.push_back(new VideoImage(
- create_sub_bitmap(bmp, x, y, width, height),
- offx, offy));
+ spriteset.push_back(img->getSubImage(x, y, width, height));
}
}
}
@@ -74,7 +42,3 @@ Spriteset::~Spriteset()
delete spriteset[i];
}
}
-
-int Spriteset::getProperty(DATAFILE *datafile, int type) {
- return atoi(get_datafile_property(datafile, type));
-}
diff --git a/src/graphic/image.h b/src/graphic/image.h
index 1bc43ef4..b732d4cf 100644
--- a/src/graphic/image.h
+++ b/src/graphic/image.h
@@ -21,42 +21,15 @@
* $Id$
*/
-#ifndef _IMAGE_H
-#define _IMAGE_H
+#ifndef _TMW_SPRITESET_H
+#define _TMW_SPRITESET_H
#include <allegro.h>
#include <string>
#include <vector>
#include <iostream>
#include "../log.h"
-
-/**
- * A video image stored in memory.
- */
-class VideoImage {
- private:
- BITMAP *src;
- int offset_x, offset_y;
-
- public:
- /**
- * Creates a VideoImage
- * @param src is a reference to a BITMAP
- * @param offset_x is the x offset from where to start drawing
- * @param offset_y is the y offset from where to start drawing
- */
- VideoImage(BITMAP *src, int offset_x, int offset_y);
-
- /**
- * Destructor
- */
- virtual ~VideoImage();
-
- /**
- * Draws a sprite
- */
- void draw(BITMAP *dest, int x, int y);
-};
+#include "../resources/image.h"
/**
* Stores a complete set of sprites.
@@ -64,25 +37,17 @@ class VideoImage {
class Spriteset {
public:
// Vector storing the whole spriteset.
- std::vector<VideoImage*> spriteset;
+ std::vector<Image*> spriteset;
/*
- * Cuts the passed bitmap in a grid of sub bitmaps.
+ * Cuts the passed image in a grid of sub images.
*/
- Spriteset::Spriteset(BITMAP *bmp, int w, int h, int offx, int offy);
+ Spriteset::Spriteset(Image *img, int w, int h);
/**
- * Destructor
+ * Destructor.
*/
~Spriteset();
-
- private:
- /**
- * Helper function to get offset
- * @param datafile is a reference to the whole spriteset
- * @param type is the property of the datafile object
- */
- int getProperty(DATAFILE *datafile, int type);
};
#endif