]> git.localhorst.tv Git - l2e.git/blob - src/map/Area.cpp
added comparison operators to vector template
[l2e.git] / src / map / Area.cpp
1 /*
2  * Area.cpp
3  *
4  *  Created on: Sep 26, 2012
5  *      Author: holy
6  */
7
8 #include "Area.h"
9
10 #include "Tile.h"
11 #include "../graphics/Sprite.h"
12
13 #include <stdexcept>
14
15 using geometry::Vector;
16
17 namespace map {
18
19 Area::Area()
20 : tiles(0)
21 , numTiles(0)
22 , width(0) {
23
24 }
25
26
27 const Tile &Area::TileAt(const geometry::Vector<int> &offset) const {
28         int tileIndex(offset.Y() * width + offset.X());
29         if (tileIndex < numTiles) {
30                 return tiles[tileIndex];
31         } else {
32                 throw std::out_of_range("tile index out of range");
33         }
34 }
35
36
37 void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
38         for (int i(0); i < numTiles; ++i) {
39                 Vector<int> offset(
40                                 inOffset.X() + (i % width) * tileset->Width(),
41                                 inOffset.Y() + (i / width) * tileset->Height());
42                 const Tile &tile(tiles[i]);
43                 tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
44         }
45 }
46
47 }