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