0fd809c43a11b00a30e8b18d0e95ce3eefff197b
[supertux.git] / src / tile.h
1 //
2 // C++ Interface: tile
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #ifndef TILE_H
13 #define TILE_H
14
15 #include <vector>
16 #include "texture.h"
17 #include "globals.h"
18 #include "lispreader.h"
19 #include "setup.h"
20
21 /**
22 Tile Class
23 */
24 struct Tile
25 {
26   int id;
27
28   std::vector<texture_type> images;
29   std::vector<std::string>  filenames;
30
31   /** solid tile that is indestructable by Tux */
32   bool solid;
33
34   /** a brick that can be destroyed by jumping under it */
35   bool brick;
36
37   /** FIXME: ? */
38   bool ice;
39
40   /** Bonusbox, content is stored in \a data */
41   bool fullbox;
42
43   /** Tile is a distro/coin */
44   bool distro;
45
46   /** General purpose data attached to a tile (content of a box, type of coin) */
47   int data;
48
49   /** Id of the tile that is going to replace this tile once it has
50       been collected or jumped at */
51   int next_tile;
52
53   int anim_speed;
54 };
55
56 struct TileGroup
57 {
58   std::string name;
59   std::vector<int> tiles;
60 };
61
62 class TileManager
63 {
64  private:
65   TileManager();
66   std::vector<Tile*> tiles;
67   static TileManager* instance_ ;
68   static std::vector<TileGroup>* tilegroups_;
69   void load_tileset(std::string filename);
70   
71  public:
72   static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
73   static std::vector<TileGroup>* tilegroups() { return tilegroups_ ? tilegroups_ : tilegroups_ = new std::vector<TileGroup>; }
74   Tile* get(unsigned int id) {
75     if(id < tiles.size())
76       {
77         return tiles[id]; 
78       }
79     else
80       {
81         // Never return 0, but return the 0th tile instead so that
82         // user code doesn't have to check for NULL pointers all over
83         // the place
84         return tiles[0]; 
85       } 
86   }
87 };
88
89
90
91 #endif