2 // C++ Implementation: tile
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
15 TileManager* TileManager::instance_ = 0;
17 TileManager::TileManager()
19 std::string filename = datadir + "images/tilesets/supertux.stgt";
20 load_tileset(filename);
23 void TileManager::load_tileset(std::string filename)
25 lisp_object_t* root_obj = lisp_read_from_file(filename);
28 st_abort("Couldn't load file", filename);
30 if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-tiles") == 0)
32 lisp_object_t* cur = lisp_cdr(root_obj);
35 while(!lisp_nil_p(cur))
37 lisp_object_t* element = lisp_car(cur);
39 if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
41 Tile* tile = new Tile;
46 tile->fullbox = false;
52 tile->anim_speed = 25;
54 LispReader reader(lisp_cdr(element));
55 assert(reader.read_int("id", &tile->id));
56 reader.read_bool("solid", &tile->solid);
57 reader.read_bool("brick", &tile->brick);
58 reader.read_bool("ice", &tile->ice);
59 reader.read_bool("fullbox", &tile->fullbox);
60 reader.read_bool("distro", &tile->distro);
61 reader.read_int("data", (int*)&tile->data);
62 reader.read_int("alpha", (int*)&tile->alpha);
63 reader.read_int("anim-speed", &tile->anim_speed);
64 reader.read_int("next-tile", &tile->next_tile);
65 reader.read_int("next-tile2", &tile->next_tile2);
66 reader.read_string_vector("images", &tile->filenames);
68 for(std::vector<std::string>::iterator it = tile->filenames.begin();
69 it != tile->filenames.end();
72 texture_type cur_image;
73 tile->images.push_back(cur_image);
74 texture_load(&tile->images[tile->images.size()-1],
75 datadir + "images/tilesets/" + (*it),
79 if (tile->id + tileset_id >= int(tiles.size()))
80 tiles.resize(tile->id + tileset_id+1);
82 tiles[tile->id + tileset_id] = tile;
84 else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
86 LispReader reader(lisp_cdr(element));
88 reader.read_string("file", &filename);
89 filename = datadir + "images/tilesets/" + filename;
90 load_tileset(filename);
92 else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
94 LispReader reader(lisp_cdr(element));
95 reader.read_int("id", &tileset_id);
100 puts("Unhandled symbol");