4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 TileManager* TileManager::instance_ = 0;
26 std::vector<TileGroup>* TileManager::tilegroups_ = 0;
28 TileManager::TileManager()
30 std::string filename = datadir + "images/tilesets/supertux.stgt";
31 load_tileset(filename);
34 void TileManager::load_tileset(std::string filename)
36 lisp_object_t* root_obj = lisp_read_from_file(filename);
39 st_abort("Couldn't load file", filename);
41 if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-tiles") == 0)
43 lisp_object_t* cur = lisp_cdr(root_obj);
46 while(!lisp_nil_p(cur))
48 lisp_object_t* element = lisp_car(cur);
50 if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
52 std::vector<std::string> editor_filenames;
54 Tile* tile = new Tile;
60 tile->fullbox = false;
64 tile->anim_speed = 25;
66 LispReader reader(lisp_cdr(element));
67 assert(reader.read_int("id", &tile->id));
68 reader.read_bool("solid", &tile->solid);
69 reader.read_bool("brick", &tile->brick);
70 reader.read_bool("ice", &tile->ice);
71 reader.read_bool("water", &tile->water);
72 reader.read_bool("fullbox", &tile->fullbox);
73 reader.read_bool("distro", &tile->distro);
74 reader.read_int("data", &tile->data);
75 reader.read_int("anim-speed", &tile->anim_speed);
76 reader.read_int("next-tile", &tile->next_tile);
77 reader.read_string_vector("images", &tile->filenames);
78 reader.read_string_vector("editor-images", &editor_filenames);
80 for(std::vector<std::string>::iterator it = tile->
82 it != tile->filenames.end();
86 tile->images.push_back(cur_image);
87 tile->images[tile->images.size()-1] = new Surface(
88 datadir + "images/tilesets/" + (*it),
91 for(std::vector<std::string>::iterator it = editor_filenames.begin();
92 it != editor_filenames.end();
96 tile->editor_images.push_back(cur_image);
97 tile->editor_images[tile->editor_images.size()-1] = new Surface(
98 datadir + "images/tilesets/" + (*it),
102 if (tile->id + tileset_id >= int(tiles.size())
104 tiles.resize(tile->id + tileset_id+1);
106 tiles[tile->id + tileset_id] = tile;
108 else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
110 LispReader reader(lisp_cdr(element));
111 std::string filename;
112 reader.read_string("file", &filename);
113 filename = datadir + "images/tilesets/" + filename;
114 load_tileset(filename);
116 else if (strcmp(lisp_symbol(lisp_car(element)), "tilegroup") == 0)
120 tilegroups_ = new std::vector<TileGroup>;
121 tilegroups_->push_back(new_);
122 LispReader reader(lisp_cdr(element));
123 tilegroups_->back().name;
124 reader.read_string("name", &tilegroups_->back().name);
125 reader.read_int_vector("tiles", &tilegroups_->back().tiles);
127 else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
129 LispReader reader(lisp_cdr(element));
130 reader.read_int("id", &tileset_id);
135 puts("Unhandled symbol");
148 Tile::draw(float x, float y, unsigned int c, Uint8 alpha)
152 Tile* ptile = TileManager::instance()->get(c);
155 if(ptile->images.size() > 1)
157 ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))]->draw(x,y, alpha);
159 else if (ptile->images.size() == 1)
161 ptile->images[0]->draw(x,y, alpha);
165 //printf("Tile not dravable %u\n", c);