- readded paralax tiles, not so sure why they disappeared in the first place
[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 "utils/lispreader.h"
26 #include "math/rectangle.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 private:
64   unsigned int id;
65
66   struct ImageSpec {
67     ImageSpec(const std::string& newfile, const Rectangle& newrect)
68       : file(newfile), rect(newrect)
69     { }
70
71     std::string file;
72     Rectangle rect;
73   };
74   std::vector<ImageSpec> imagespecs;
75   std::vector<Surface*> images;
76
77   std::string editor_imagefile;
78   Surface* editor_image;
79   
80   /** tile attributes */
81   Uint32 attributes;
82   
83   /** General purpose data attached to a tile (content of a box, type of coin)*/
84   int data;
85
86   float anim_fps;
87
88 public:
89   ~Tile();
90   
91   /** Draw a tile on the screen */
92   void draw(DrawingContext& context, const Vector& pos, int layer) const;
93
94   Surface* get_editor_image() const;
95
96   unsigned int getID() const
97   { return id; }
98
99   Uint32 getAttributes() const
100   { return attributes; }
101
102   int getData() const
103   { return data; }
104
105   /// returns the width of the tile in pixels
106   int getWidth() const
107   { 
108     if(!images.size())
109       return 0;
110     return images[0]->w;
111   }
112
113   /// returns the height of the tiles in pixels
114   int getHeight() const
115   {
116     if(!images.size())
117       return 0;
118     return images[0]->h;
119   }
120
121 protected:
122   friend class TileManager;
123   Tile();
124
125   void load_images();
126
127   /// parses the tile and returns it's id number
128   void parse(LispReader& reader);
129   void parse_images(lisp_object_t* cur);
130 };
131
132 #endif