465c559957e65cc9702d70a90e3c471d9d5dee9c
[supertux.git] / src / supertux / tile.hpp
1 //  SuperTux
2 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
5 //  This program is free software: you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation, either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_TILE_HPP
20
21 #include <vector>
22 #include <stdint.h>
23
24 #include "math/rectf.hpp"
25 #include "video/surface.hpp"
26 #include "util/reader_fwd.hpp"
27
28 class DrawingContext;
29
30 class Tile
31 {
32 public:
33   static bool draw_editor_images;
34   /// bitset for tile attributes
35   enum {
36     /** solid tile that is indestructible by Tux */
37     SOLID     = 0x0001,
38     /** uni-directional solid tile */
39     UNISOLID  = 0x0002,
40     /** a brick that can be destroyed by jumping under it */
41     BRICK     = 0x0004,
42     /** the level should be finished when touching a goaltile.
43      * if data is 0 then the endsequence should be triggered, if data is 1
44      * then we can finish the level instantly.
45      */
46     GOAL      = 0x0008,
47     /** slope tile */
48     SLOPE     = 0x0010,
49     /** Bonusbox, content is stored in \a data */
50     FULLBOX   = 0x0020,
51     /** Tile is a coin */
52     COIN      = 0x0040,
53
54     /* interesting flags (the following are passed to gameobjects) */
55     FIRST_INTERESTING_FLAG = 0x0100,
56
57     /** an ice brick that makes tux sliding more than usual */
58     ICE       = 0x0100,
59     /** a water tile in which tux starts to swim */
60     WATER     = 0x0200,
61     /** a tile that hurts the player if he touches it */
62     HURTS     = 0x0400,
63     /** for lava: WATER, HURTS, FIRE */
64     FIRE      = 0x0800
65   };
66
67   /// worldmap flags
68   enum {
69     WORLDMAP_NORTH = 0x0001,
70     WORLDMAP_SOUTH = 0x0002,
71     WORLDMAP_EAST  = 0x0004,
72     WORLDMAP_WEST  = 0x0008,
73     WORLDMAP_DIR_MASK = 0x000f,
74
75     WORLDMAP_STOP  = 0x0010,
76
77     // convenience values ("C" stands for crossroads)
78     WORLDMAP_CNSE  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST,
79     WORLDMAP_CNSW  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_WEST,
80     WORLDMAP_CNEW  = WORLDMAP_NORTH | WORLDMAP_EAST  | WORLDMAP_WEST,
81     WORLDMAP_CSEW  = WORLDMAP_SOUTH | WORLDMAP_EAST  | WORLDMAP_WEST,
82     WORLDMAP_CNSEW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST
83   };
84
85   struct ImageSpec {
86     ImageSpec(const std::string& newfile, const Rectf& newrect)
87       : file(newfile), rect(newrect)
88     { }
89
90     std::string file;
91     Rectf rect;
92   };
93
94 private:
95   std::vector<ImageSpec> imagespecs;
96   std::vector<SurfacePtr>  images;
97   std::vector<ImageSpec> editor_imagespecs;
98   std::vector<SurfacePtr>  editor_images;
99
100   /// tile attributes
101   uint32_t attributes;
102
103   /** General purpose data attached to a tile (content of a box, type of coin)*/
104   int data;
105
106   float fps;
107
108 public:
109   Tile();
110   Tile(const std::vector<ImageSpec>& images, const std::vector<ImageSpec>& editor_images,
111        uint32_t attributes, uint32_t data, float fps);
112   ~Tile();
113
114   /** load Surfaces, if not already loaded */
115   void load_images();
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   bool is_slope (void) const
127   {
128     return ((attributes & SLOPE) != 0);
129   }
130
131   bool is_unisolid (void) const
132   {
133     return ((attributes & UNISOLID) != 0);
134   }
135
136   void print_debug(int id) const;
137
138 private:
139   //Correct small oddities in attributes that naive people
140   //might miss (and rebuke them for it)
141   void correct_attributes();
142
143 private:
144   Tile(const Tile&);
145   Tile& operator=(const Tile&);
146 };
147
148 #endif
149
150 /* EOF */