#303: Typo fixes from mathnerd314
[supertux.git] / src / tile.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 //  02111-1307, USA.
21 #ifndef TILE_H
22 #define TILE_H
23
24 #include <vector>
25 #include <SDL.h>
26 #include <stdint.h>
27 #include "video/surface.hpp"
28 #include "math/rect.hpp"
29
30 namespace lisp { class Lisp; }
31
32 class TileSet;
33 class DrawingContext;
34
35 /**
36 Tile Class
37 */
38 class Tile
39 {
40 public:
41   /// bitset for tile attributes
42   enum {
43     /** solid tile that is indestructible by Tux */
44     SOLID     = 0x0001,
45     /** uni-directional solid tile */
46     UNISOLID  = 0x0002,
47     /** a brick that can be destroyed by jumping under it */
48     BRICK     = 0x0004,
49     /** the level should be finished when touching a goaltile.
50      * if data is 0 then the endsequence should be triggered, if data is 1
51      * then we can finish the level instantly.
52      */
53     GOAL      = 0x0008,
54     /** slope tile */
55     SLOPE     = 0x0010,
56     /** Bonusbox, content is stored in \a data */
57     FULLBOX   = 0x0020,
58     /** Tile is a coin */
59     COIN      = 0x0040,
60
61     /* interesting flags (the following are passed to gameobjects) */
62     FIRST_INTERESTING_FLAG = 0x0100,
63
64     /** an ice brick that makes tux sliding more than usual */
65     ICE       = 0x0100,
66     /** a water tile in which tux starts to swim */
67     WATER     = 0x0200,
68     /** a tile that hurts the player if he touches it */
69     HURTS     = 0x0400,
70     /** for lava: WATER, HURTS, FIRE */
71     FIRE      = 0x0800
72   };
73
74   /// worldmap flags
75   enum {
76     WORLDMAP_NORTH = 0x0001,
77     WORLDMAP_SOUTH = 0x0002,
78     WORLDMAP_EAST  = 0x0004,
79     WORLDMAP_WEST  = 0x0008,
80         WORLDMAP_DIR_MASK = 0x000f,
81
82     WORLDMAP_STOP  = 0x0010,
83
84     // convenience values ("C" stands for crossroads)
85     WORLDMAP_CNSE  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST,
86     WORLDMAP_CNSW  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_WEST,
87     WORLDMAP_CNEW  = WORLDMAP_NORTH | WORLDMAP_EAST  | WORLDMAP_WEST,
88     WORLDMAP_CSEW  = WORLDMAP_SOUTH | WORLDMAP_EAST  | WORLDMAP_WEST,
89     WORLDMAP_CNSEW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST
90   };
91
92   struct ImageSpec {
93     ImageSpec(const std::string& newfile, const Rect& newrect)
94       : file(newfile), rect(newrect)
95     { }
96
97     std::string file;
98     Rect rect;
99   };
100
101 private:
102   const TileSet         *tileset;
103   std::vector<ImageSpec> imagespecs;
104   std::vector<Surface*>  images;
105
106   /// tile attributes
107   uint32_t attributes;
108
109   /** General purpose data attached to a tile (content of a box, type of coin)*/
110   int data;
111
112   float anim_fps;
113
114 public:
115   ~Tile();
116
117   /** Draw a tile on the screen */
118   void draw(DrawingContext& context, const Vector& pos, int z_pos) const;
119
120   uint32_t getAttributes() const
121   { return attributes; }
122
123   int getData() const
124   { return data; }
125
126   /// returns the width of the tile in pixels
127   int getWidth() const
128   {
129     if(!images.size())
130       return 0;
131     return (int) images[0]->get_width();
132   }
133
134   /// returns the height of the tiles in pixels
135   int getHeight() const
136   {
137     if(!images.size())
138       return 0;
139     return (int) images[0]->get_height();
140   }
141
142 protected:
143   friend class TileSet;
144   Tile(const TileSet *tileset);
145   Tile(const TileSet *tileset, Uint32 attributes, const ImageSpec& imagespec);
146
147   void load_images();
148
149   /// parses the tile and returns it's id number
150   uint32_t parse(const lisp::Lisp& reader);
151   void parse_images(const lisp::Lisp& cur);
152 };
153
154 #endif