2 // C++ Implementation: tile
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
16 TileManager* TileManager::instance_ = 0;
17 std::vector<TileGroup>* TileManager::tilegroups_ = 0;
19 TileManager::TileManager()
21 std::string filename = datadir + "images/tilesets/supertux.stgt";
22 load_tileset(filename);
25 void TileManager::load_tileset(std::string filename)
27 lisp_object_t* root_obj = lisp_read_from_file(filename);
30 st_abort("Couldn't load file", filename);
32 if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-tiles") == 0)
34 lisp_object_t* cur = lisp_cdr(root_obj);
37 while(!lisp_nil_p(cur))
39 lisp_object_t* element = lisp_car(cur);
41 if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
43 std::vector<std::string> editor_filenames;
45 Tile* tile = new Tile;
51 tile->fullbox = false;
55 tile->anim_speed = 25;
57 LispReader reader(lisp_cdr(element));
58 assert(reader.read_int("id", &tile->id));
59 reader.read_bool("solid", &tile->solid);
60 reader.read_bool("brick", &tile->brick);
61 reader.read_bool("ice", &tile->ice);
62 reader.read_bool("water", &tile->water);
63 reader.read_bool("fullbox", &tile->fullbox);
64 reader.read_bool("distro", &tile->distro);
65 reader.read_int("data", &tile->data);
66 reader.read_int("anim-speed", &tile->anim_speed);
67 reader.read_int("next-tile", &tile->next_tile);
68 reader.read_string_vector("images", &tile->filenames);
69 reader.read_string_vector("editor-images", &editor_filenames);
71 for(std::vector<std::string>::iterator it = tile->
73 it != tile->filenames.end();
77 tile->images.push_back(cur_image);
78 tile->images[tile->images.size()-1] = new Surface(
79 datadir + "images/tilesets/" + (*it),
82 for(std::vector<std::string>::iterator it = editor_filenames.begin();
83 it != editor_filenames.end();
87 tile->editor_images.push_back(cur_image);
88 tile->editor_images[tile->editor_images.size()-1] = new Surface(
89 datadir + "images/tilesets/" + (*it),
93 if (tile->id + tileset_id >= int(tiles.size())
95 tiles.resize(tile->id + tileset_id+1);
97 tiles[tile->id + tileset_id] = tile;
99 else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
101 LispReader reader(lisp_cdr(element));
102 std::string filename;
103 reader.read_string("file", &filename);
104 filename = datadir + "images/tilesets/" + filename;
105 load_tileset(filename);
107 else if (strcmp(lisp_symbol(lisp_car(element)), "tilegroup") == 0)
111 tilegroups_ = new std::vector<TileGroup>;
112 tilegroups_->push_back(new_);
113 LispReader reader(lisp_cdr(element));
114 tilegroups_->back().name;
115 reader.read_string("name", &tilegroups_->back().name);
116 reader.read_int_vector("tiles", &tilegroups_->back().tiles);
118 else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
120 LispReader reader(lisp_cdr(element));
121 reader.read_int("id", &tileset_id);
126 puts("Unhandled symbol");
139 Tile::draw(float x, float y, unsigned int c, Uint8 alpha)
143 Tile* ptile = TileManager::instance()->get(c);
146 if(ptile->images.size() > 1)
148 ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))]->draw(x,y, alpha);
150 else if (ptile->images.size() == 1)
152 ptile->images[0]->draw(x,y, alpha);
156 //printf("Tile not dravable %u\n", c);