b34e671549944fd4867fb9331d86dbfca5d3c52f
[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 <vector>
25 #include "SDL.h"
26 #include "video/surface.h"
27
28 using namespace SuperTux;
29
30 namespace SuperTux {
31 class LispReader;
32 }
33
34 /**
35 Tile Class
36 */
37 class Tile
38 {
39 public:
40   Tile();
41   ~Tile();
42
43   /// parses the tile and returns it's id number
44   void read(LispReader& reader);
45
46   unsigned int id;
47
48   std::vector<Surface*> images;
49   std::vector<Surface*> editor_images;
50   
51   /// bitset for tileflags
52   enum {
53       /** solid tile that is indestructable by Tux */
54       SOLID     = 0x0001,
55       /** uni-directional solid tile */
56       UNISOLID  = 0x0002,
57       /** a brick that can be destroyed by jumping under it */
58       BRICK     = 0x0004,
59       /** an ice brick that makes tux sliding more than usual */
60       ICE       = 0x0008,
61       /** a water tile in which tux starts to swim */
62       WATER     = 0x0010,
63       /** a tile that hurts the player if he touches it */
64       SPIKE     = 0x0020,
65       /** Bonusbox, content is stored in \a data */
66       FULLBOX   = 0x0040,
67       /** Tile is a coin */
68       COIN      = 0x0080,
69       /** the level should be finished when touching a goaltile.
70        * if data is 0 then the endsequence should be triggered, if data is 1
71        * then we can finish the level instantly.
72        */
73       GOAL      = 0x0100,
74       /** slope tile */
75       SLOPE     = 0x0200
76   };
77
78   /** tile attributes */
79   Uint32 attributes;
80   
81   /** General purpose data attached to a tile (content of a box, type of coin)*/
82   int data;
83
84   /** Id of the tile that is going to replace this tile once it has
85       been collected or jumped at */
86   int next_tile;
87
88   int anim_speed;
89
90   /** Draw a tile on the screen */
91   void draw(DrawingContext& context, const Vector& pos, int layer) const;
92
93   /// returns the width of the tile in pixels
94   int getWidth() const
95   { 
96     if(!images.size())
97       return 0;
98     return images[0]->w;
99   }
100
101   /// returns the height of the tiles in pixels
102   int getHeight() const
103   {
104     if(!images.size())
105       return 0;
106     return images[0]->h;
107   }
108 };
109
110 #endif
111
112 /* EOF */