- fixed bomb-dup bug (vector increases on add, and this changes I guess, so remove...
[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 <map>
25 #include <vector>
26 #include "texture.h"
27 #include "globals.h"
28 #include "lispreader.h"
29 #include "setup.h"
30
31 /**
32 Tile Class
33 */
34 struct Tile
35 {
36   int id;
37
38   std::vector<Surface*> images;
39   std::vector<Surface*> editor_images;
40   
41   std::vector<std::string>  filenames;
42
43   /** solid tile that is indestructable by Tux */
44   bool solid;
45
46   /** a brick that can be destroyed by jumping under it */
47   bool brick;
48
49   /** FIXME: ? */
50   bool ice;
51
52   /** water */
53   bool water;
54
55   /** Bonusbox, content is stored in \a data */
56   bool fullbox;
57
58   /** Tile is a distro/coin */
59   bool distro;
60
61   /** General purpose data attached to a tile (content of a box, type of coin) */
62   int data;
63
64   /** Id of the tile that is going to replace this tile once it has
65       been collected or jumped at */
66   int next_tile;
67
68   int anim_speed;
69   
70   /** Draw a tile on the screen: */
71   static void draw(float x, float y, unsigned int c, Uint8 alpha = 255);
72 };
73
74 struct TileGroup
75 {
76   std::string name;
77   std::vector<int> tiles;
78 };
79
80 class TileManager
81 {
82  private:
83   TileManager();
84   std::vector<Tile*> tiles;
85   static TileManager* instance_ ;
86   static std::vector<TileGroup>* tilegroups_;
87   void load_tileset(std::string filename);
88   
89  public:
90   static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
91   static std::vector<TileGroup>* tilegroups() { return tilegroups_ ? tilegroups_ : tilegroups_ = new std::vector<TileGroup>; }
92   Tile* get(unsigned int id) {
93     if(id < tiles.size())
94       {
95         return tiles[id]; 
96       }
97     else
98       {
99         // Never return 0, but return the 0th tile instead so that
100         // user code doesn't have to check for NULL pointers all over
101         // the place
102         return tiles[0]; 
103       } 
104   }
105 };
106
107 #endif