00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MAP_H
00023 #define MAP_H
00024
00025 #include <list>
00026 #include <vector>
00027
00028 #include "position.h"
00029 #include "properties.h"
00030
00031 class Animation;
00032 class AmbientOverlay;
00033 class Graphics;
00034 class Image;
00035 class MapLayer;
00036 class Particle;
00037 class SimpleAnimation;
00038 class Sprite;
00039 class Tileset;
00040
00041 typedef std::vector<Tileset*> Tilesets;
00042 typedef std::list<Sprite*> Sprites;
00043 typedef Sprites::iterator SpriteIterator;
00044 typedef std::vector<MapLayer*> Layers;
00045
00051 struct MetaTile
00052 {
00056 MetaTile() : whichList(0), blockmask(0) {}
00057
00058
00059 int Fcost;
00060 int Gcost;
00061 int Hcost;
00062 int whichList;
00063 int parentX;
00064 int parentY;
00065 unsigned char blockmask;
00066 };
00067
00071 class TileAnimation
00072 {
00073 public:
00074 TileAnimation(Animation *ani);
00075 ~TileAnimation();
00076 void update(int ticks = 1);
00077 void addAffectedTile(MapLayer *layer, int index)
00078 { mAffected.push_back(std::make_pair(layer, index)); }
00079 private:
00080 std::list<std::pair<MapLayer*, int> > mAffected;
00081 SimpleAnimation *mAnimation;
00082 Image *mLastImage;
00083 };
00084
00089 class MapLayer
00090 {
00091 public:
00097 MapLayer(int x, int y, int width, int height, bool isFringeLayer);
00098
00102 ~MapLayer();
00103
00107 void setTile(int x, int y, Image *img);
00108
00112 void setTile(int index, Image *img) { mTiles[index] = img; }
00113
00117 Image *getTile(int x, int y) const;
00118
00127 void draw(Graphics *graphics,
00128 int startX, int startY,
00129 int endX, int endY,
00130 int scrollX, int scrollY,
00131 const Sprites &sprites) const;
00132
00133 private:
00134 int mX, mY;
00135 int mWidth, mHeight;
00136 bool mIsFringeLayer;
00137 Image **mTiles;
00138 };
00139
00143 class Map : public Properties
00144 {
00145 public:
00146 enum BlockType
00147 {
00148 BLOCKTYPE_NONE = -1,
00149 BLOCKTYPE_WALL,
00150 BLOCKTYPE_CHARACTER,
00151 BLOCKTYPE_MONSTER,
00152 NB_BLOCKTYPES
00153 };
00154
00158 Map(int width, int height, int tileWidth, int tileHeight);
00159
00163 ~Map();
00164
00169 void initializeOverlays();
00170
00174 void update(int ticks = 1);
00175
00184 void draw(Graphics *graphics, int scrollX, int scrollY);
00185
00189 void drawCollision(Graphics *graphics, int scrollX, int scrollY);
00190
00194 void addLayer(MapLayer *layer);
00195
00199 void addTileset(Tileset *tileset);
00200
00204 Tileset* getTilesetWithGid(int gid) const;
00205
00209 MetaTile *getMetaTile(int x, int y) const;
00210
00214 void blockTile(int x, int y, BlockType type);
00215
00220 bool getWalk(int x, int y, char walkmask = BLOCKMASK_WALL) const;
00221
00225 int getWidth() const { return mWidth; }
00226
00230 int getHeight() const { return mHeight; }
00231
00235 int getTileWidth() const { return mTileWidth; }
00236
00240 int getTileHeight() const { return mTileHeight; }
00241
00245 Path findPath(int startX, int startY, int destX, int destY,
00246 unsigned char walkmask, int maxCost = 20);
00247
00251 SpriteIterator addSprite(Sprite *sprite);
00252
00256 void removeSprite(SpriteIterator iterator);
00257
00261 void addParticleEffect(const std::string &effectFile, int x, int y);
00262
00266 void initializeParticleEffects(Particle* particleEngine);
00267
00271 void addAnimation(int gid, TileAnimation *animation)
00272 { mTileAnimations[gid] = animation; }
00273
00277 TileAnimation *getAnimationForGid(int gid);
00278
00279 private:
00283 void drawOverlay(Graphics *graphics, float scrollX, float scrollY,
00284 int detail);
00285
00289 bool contains(int x, int y) const;
00290
00294 static const unsigned char BLOCKMASK_WALL = 0x80;
00295 static const unsigned char BLOCKMASK_CHARACTER = 0x01;
00296 static const unsigned char BLOCKMASK_MONSTER = 0x02;
00297 int *mOccupation[NB_BLOCKTYPES];
00298
00299 int mWidth, mHeight;
00300 int mTileWidth, mTileHeight;
00301 int mMaxTileHeight;
00302 MetaTile *mMetaTiles;
00303 Layers mLayers;
00304 Tilesets mTilesets;
00305 Sprites mSprites;
00306
00307
00308 int mOnClosedList, mOnOpenList;
00309
00310
00311 std::list<AmbientOverlay*> mOverlays;
00312 float mLastScrollX;
00313 float mLastScrollY;
00314
00315
00316 struct ParticleEffectData
00317 {
00318 std::string file;
00319 int x;
00320 int y;
00321 };
00322 std::list<ParticleEffectData> particleEffects;
00323
00324 std::map<int, TileAnimation*> mTileAnimations;
00325 };
00326
00327 #endif