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
27 #include "screen/texture.h"
29 #include "lispreader.h"
44 /// parses the tile and returns it's id number
45 int read(LispReader& reader);
49 std::vector<Surface*> images;
50 std::vector<Surface*> editor_images;
52 /// bitset for tileflags
54 /** solid tile that is indestructable by Tux */
56 /** uni-directional solid tile */
58 /** a brick that can be destroyed by jumping under it */
60 /** an ice brick that makes tux sliding more than usual */
62 /** a water tile in which tux starts to swim */
64 /** a tile that hurts the player if he touches it */
66 /** Bonusbox, content is stored in \a data */
70 /** the level should be finished when touching a goaltile.
71 * if data is 0 then the endsequence should be triggered, if data is 1
72 * then we can finish the level instantly.
77 /** tile attributes */
80 /** General purpose data attached to a tile (content of a box, type of coin)*/
83 /** Id of the tile that is going to replace this tile once it has
84 been collected or jumped at */
89 /** Draw a tile on the screen: */
90 static void draw(const Vector& pos, unsigned int c, Uint8 alpha = 255);
92 /// returns the width of the tile in pixels
100 /// returns the height of the tiles in pixels
101 int getHeight() const
111 friend bool operator<(const TileGroup& lhs, const TileGroup& rhs)
112 { return lhs.name < rhs.name; };
113 friend bool operator>(const TileGroup& lhs, const TileGroup& rhs)
114 { return lhs.name > rhs.name; };
117 std::vector<int> tiles;
126 std::vector<Tile*> tiles;
127 static TileManager* instance_ ;
128 static std::set<TileGroup>* tilegroups_;
129 void load_tileset(std::string filename);
131 std::string current_tileset;
134 static TileManager* instance()
135 { return instance_ ? instance_ : instance_ = new TileManager(); }
136 static void destroy_instance()
137 { delete instance_; instance_ = 0; }
139 void draw_tile(DrawingContext& context, unsigned int id,
140 const Vector& pos, int layer);
142 static std::set<TileGroup>* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set<TileGroup>; }
143 Tile* get(unsigned int id) {
144 if(id < tiles.size())
150 // Never return 0, but return the 0th tile instead so that
151 // user code doesn't have to check for NULL pointers all over