+Tile::~Tile()
+{
+ for(std::vector<Surface*>::iterator i = images.begin(); i != images.end();
+ ++i) {
+ delete *i;
+ }
+ for(std::vector<Surface*>::iterator i = editor_images.begin();
+ i != editor_images.end(); ++i) {
+ delete *i;
+ }
+}
+
+void
+Tile::read(LispReader& reader)
+{
+ if(!reader.read_uint("id", id)) {
+ throw std::runtime_error("Missing tile-id.");
+ }
+
+ bool value;
+ if(reader.read_bool("solid", value) && value)
+ attributes |= SOLID;
+ if(reader.read_bool("unisolid", value) && value)
+ attributes |= UNISOLID | SOLID;
+ if(reader.read_bool("brick", value) && value)
+ attributes |= BRICK;
+ if(reader.read_bool("ice", value) && value)
+ attributes |= ICE;
+ if(reader.read_bool("water", value) && value)
+ attributes |= WATER;
+ if(reader.read_bool("spike", value) && value)
+ attributes |= SPIKE;
+ if(reader.read_bool("fullbox", value) && value)
+ attributes |= FULLBOX;
+ if(reader.read_bool("distro", value) && value)
+ attributes |= COIN;
+ if(reader.read_bool("coin", value) && value)
+ attributes |= COIN;
+ if(reader.read_bool("goal", value) && value)
+ attributes |= GOAL;
+
+ reader.read_int("data", data);
+ reader.read_float("anim-fps", anim_fps);
+ reader.read_int("next-tile", next_tile);
+
+ if(reader.read_int("slope-type", data)) {
+ attributes |= SOLID | SLOPE;
+ }
+
+ images = create_surfaces(reader.read_lisp("images"));
+ editor_images = create_surfaces(reader.read_lisp("editor-images"));
+}
+
+void
+Tile::draw(DrawingContext& context, const Vector& pos, int layer) const
+{
+ if(images.size() > 1) {
+ size_t frame = size_t(global_time * anim_fps) % images.size();
+ context.draw_surface(images[frame], pos, layer);
+ } else if (images.size() == 1) {
+ context.draw_surface(images[0], pos, layer);
+ }
+}