- some resolution fixes
[supertux.git] / src / tile.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
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.
10 //
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.
15 // 
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
19 //  02111-1307, USA.
20
21 #ifndef TILE_H
22 #define TILE_H
23
24 #include <set>
25 #include <map>
26 #include <vector>
27 #include "texture.h"
28 #include "globals.h"
29 #include "lispreader.h"
30 #include "setup.h"
31
32 /**
33 Tile Class
34 */
35 class Tile
36 {
37 public:
38   Tile();
39   ~Tile();
40
41   int id;
42
43   std::vector<Surface*> images;
44   std::vector<Surface*> editor_images;
45   
46   std::vector<std::string>  filenames;
47   std::vector<std::string> editor_filenames;
48   
49   /** solid tile that is indestructable by Tux */
50   bool solid;
51
52   /** a brick that can be destroyed by jumping under it */
53   bool brick;
54
55   /** FIXME: ? */
56   bool ice;
57
58   /** water */
59   bool water;
60
61   /** Bonusbox, content is stored in \a data */
62   bool fullbox;
63
64   /** Tile is a distro/coin */
65   bool distro;
66
67   /** the level should be finished when touching a goaltile.
68    * if data is 0 then the endsequence should be triggered, if data is 1
69    * then we can finish the level instantly.
70    */
71   bool goal;
72
73   /** General purpose data attached to a tile (content of a box, type of coin) */
74   int data;
75
76   /** Id of the tile that is going to replace this tile once it has
77       been collected or jumped at */
78   int next_tile;
79
80   int anim_speed;
81   
82   /** Draw a tile on the screen: */
83   static void draw(float x, float y, unsigned int c, Uint8 alpha = 255);
84   static void draw_stretched(float x, float y, int w, int h, unsigned int c, Uint8 alpha = 255);
85 };
86
87 struct TileGroup
88 {
89   friend bool operator<(const TileGroup& lhs, const TileGroup& rhs)
90   { return lhs.name < rhs.name; };
91   friend bool operator>(const TileGroup& lhs, const TileGroup& rhs)
92   { return lhs.name > rhs.name; };
93
94   std::string name;
95   std::vector<int> tiles;
96 };
97
98 class TileManager
99 {
100  private:
101   TileManager();
102   ~TileManager();
103   
104   std::vector<Tile*> tiles;
105   static TileManager* instance_ ;
106   static std::set<TileGroup>* tilegroups_;
107   void load_tileset(std::string filename);
108
109   std::string current_tileset;
110   
111  public:
112   static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
113   static void destroy_instance() { delete instance_; instance_ = 0; }
114   
115   static std::set<TileGroup>* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set<TileGroup>; }
116   Tile* get(unsigned int id) {
117     if(id < tiles.size())
118       {
119         return tiles[id]; 
120       }
121     else
122       {
123         // Never return 0, but return the 0th tile instead so that
124         // user code doesn't have to check for NULL pointers all over
125         // the place
126         return tiles[0]; 
127       } 
128   }
129 };
130
131 #endif