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