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