+TileMap::draw(DrawingContext& context)
+{
+ context.push_transform();
+
+ if(vertical_flip)
+ context.set_drawing_effect(VERTICAL_FLIP);
+ float trans_x = roundf(context.get_translation().x);
+ float trans_y = roundf(context.get_translation().y);
+ context.set_translation(Vector(trans_x * speed, trans_y * speed));
+
+ /** if we don't round here, we'll have a 1 pixel gap on screen sometimes.
+ * I have no idea why */
+ float start_x = roundf(context.get_translation().x);
+ float start_y = roundf(context.get_translation().y);
+ float end_x = std::min(start_x + screen->w, float(width * 32));
+ float end_y = std::min(start_y + screen->h, float(height * 32));
+ start_x -= int(start_x) % 32;
+ start_y -= int(start_y) % 32;
+ int tsx = int(start_x / 32); // tilestartindex x
+ int tsy = int(start_y / 32); // tilestartindex y
+
+ Vector pos;
+ int tx, ty;
+ for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
+ for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
+ const Tile* tile = tilemanager->get(tiles[ty*width + tx]);
+ assert(tile != 0);
+ tile->draw(context, pos, layer);
+ }
+ }
+
+ context.pop_transform();
+}
+
+void
+TileMap::set(int newwidth, int newheight, const std::vector<unsigned int>&newt,
+ int newlayer, bool newsolid)
+{
+ assert(int(newt.size()) == newwidth * newheight);
+
+ width = newwidth;
+ height = newheight;
+
+ tiles.resize(newt.size());
+ tiles = newt;
+
+ layer = newlayer;
+ solid = newsolid;
+ if(solid)
+ flags |= FLAG_SOLID;
+}
+
+void
+TileMap::resize(int new_width, int new_height)