]> git.localhorst.tv Git - l2e.git/blob - src/map/Map.h
b751d5ece04f97b33a431b6f8df78e8024ba24e7
[l2e.git] / src / map / Map.h
1 /*
2   * Map.h
3  *
4  *  Created on: Sep 29, 2012
5  *      Author: holy
6  */
7
8 #ifndef MAP_MAP_H_
9 #define MAP_MAP_H_
10
11 #include "Entity.h"
12 #include "fwd.h"
13 #include "../geometry/Vector.h"
14 #include "../graphics/fwd.h"
15
16 #include <SDL.h>
17
18 namespace map {
19
20 /// Represents a single map in the game.
21 /// Maps are made up of uniform areas of tiles.
22 /// The looks of a tile is defined by the Tileset() sprite with Tile::Offset()
23 /// as the column and row in the sprite.
24 /// Maps can be propulated with triggers and entities. Those are or use with
25 /// MapState and are not handled by the map itself.
26 /// Positions are expressed either as pixel or tile coordinates depending on
27 /// function purpose with (0|0) being the top left corner and positive values
28 /// extending to the right and down respectively.
29 class Map {
30
31 public:
32         Map();
33         ~Map() { }
34
35 public:
36         /// The sprite used as the tileset.
37         const graphics::Sprite *Tileset() const { return tileset; }
38         /// Returns the Area at given pixel coordinates or 0 if off the map.
39         Area *AreaAt(const geometry::Vector<int> &);
40         const Area *AreaAt(const geometry::Vector<int> &) const;
41         /// Returns the Tile at given pixel coordinates or 0 if off the map.
42         Tile *TileAt(const geometry::Vector<int> &);
43         const Tile *TileAt(const geometry::Vector<int> &) const;
44         /// Returns the Trigger at given pixel coordinates or 0 if off the map.
45         /// Multiple triggers are not supported. The first one found is returned.
46         Trigger *TriggerAt(const geometry::Vector<int> &);
47         /// The battle background image for this map if neither the tile nor the
48         /// area has one specified.
49         SDL_Surface *BattleBackgroundAt(const geometry::Vector<int> &);
50         /// Convert coordinates pixel to tile.
51         geometry::Vector<int> TileCoordinates(const geometry::Vector<int> &) const;
52
53         Entity *EntitiesBegin() { return entities; }
54         Entity *EntitiesEnd() { return entities + numEntities; }
55
56         /// Render the map.
57         /// Entities are not rendered by this function.
58         void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
59         /// Render a debugging overlay that includes collision and trigger
60         /// information.
61         void RenderDebug(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
62
63         static void CreateTypeDescription();
64         static void Construct(void *);
65
66 private:
67         const graphics::Sprite *tileset;
68         SDL_Surface *battlebg;
69         Area *areas;
70         int numAreas;
71         Trigger *triggers;
72         int numTriggers;
73         Entity *entities;
74         int numEntities;
75         int width;
76
77 };
78
79 }
80
81 #endif /* MAP_MAP_H_ */