cfddd0217d6439d5732de0f64a0d23d8f491c706
[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 #ifndef TILE_H
21 #define TILE_H
22
23 #include <vector>
24 #include "video/surface.h"
25 #include "math/rect.h"
26 #include "lisp/lisp.h"
27
28 /**
29 Tile Class
30 */
31 class Tile
32 {
33 public:
34   /// bitset for tile attributes
35   enum {
36     /** solid tile that is indestructable by Tux */                         
37     SOLID     = 0x0001,
38     /** uni-directional solid tile */
39     UNISOLID  = 0x0002,
40     /** a brick that can be destroyed by jumping under it */
41     BRICK     = 0x0004,
42     /** an ice brick that makes tux sliding more than usual */
43     ICE       = 0x0008,
44     /** a water tile in which tux starts to swim */                         
45     WATER     = 0x0010,
46     /** a tile that hurts the player if he touches it */
47     SPIKE     = 0x0020,
48     /** Bonusbox, content is stored in \a data */
49     FULLBOX   = 0x0040,
50     /** Tile is a coin */
51     COIN      = 0x0080,
52     /** the level should be finished when touching a goaltile.
53      * if data is 0 then the endsequence should be triggered, if data is 1
54      * then we can finish the level instantly.
55      */
56     GOAL      = 0x0100,
57     /** slope tile */
58     SLOPE     = 0x0200,
59   };
60
61   /// worldmap flags
62   enum {
63     WORLDMAP_NORTH = 0x0001,
64     WORLDMAP_SOUTH = 0x0002,
65     WORLDMAP_EAST  = 0x0004,
66     WORLDMAP_WEST  = 0x0008,
67     
68     WORLDMAP_STOP  = 0x0010
69   };
70   
71 private:
72   unsigned int id;
73
74   struct ImageSpec {
75     ImageSpec(const std::string& newfile, const Rect& newrect)
76       : file(newfile), rect(newrect)
77     { }
78
79     std::string file;
80     Rect rect;
81   };
82   std::vector<ImageSpec> imagespecs;
83   std::vector<Surface*> images;
84
85   std::string editor_imagefile;
86   Surface* editor_image;
87   
88   /** tile attributes */
89   Uint32 attributes;
90   
91   /** General purpose data attached to a tile (content of a box, type of coin)*/
92   int data;
93
94   float anim_fps;
95
96 public:
97   ~Tile();
98   
99   /** Draw a tile on the screen */
100   void draw(DrawingContext& context, const Vector& pos, int layer) const;
101
102   Surface* get_editor_image() const;
103
104   unsigned int getID() const
105   { return id; }
106
107   Uint32 getAttributes() const
108   { return attributes; }
109
110   int getData() const
111   { return data; }
112
113   /// returns the width of the tile in pixels
114   int getWidth() const
115   { 
116     if(!images.size())
117       return 0;
118     return images[0]->w;
119   }
120
121   /// returns the height of the tiles in pixels
122   int getHeight() const
123   {
124     if(!images.size())
125       return 0;
126     return images[0]->h;
127   }
128
129 protected:
130   friend class TileManager;
131   Tile();
132
133   void load_images(const std::string& tilesetpath);
134
135   /// parses the tile and returns it's id number
136   void parse(const lisp::Lisp& reader);
137   void parse_images(const lisp::Lisp& cur);
138 };
139
140 #endif