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 // Copyright (C) 2010 Florian Forster <supertux at octo.it>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (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, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_HPP
20 #define HEADER_SUPERTUX_SUPERTUX_TILE_HPP
21 
22 #include <vector>
23 #include <stdint.h>
24 
25 #include "math/rectf.hpp"
26 #include "video/color.hpp"
27 #include "video/surface_ptr.hpp"
28 
29 class Canvas;
30 class DrawingContext;
31 
32 class Tile final
33 {
34 public:
35  static bool draw_editor_images;
36 
37 public:
39  enum {
41  SOLID = 0x0001,
43  UNISOLID = 0x0002,
45  BRICK = 0x0004, //Marked for removal, DO NOT USE!
50  GOAL = 0x0008, //Marked for removal, DO NOT USE!
52  SLOPE = 0x0010,
54  FULLBOX = 0x0020, //Marked for removal, DO NOT USE!
56  COIN = 0x0040, //Marked for removal, DO NOT USE!
57 
58  /* interesting flags (the following are passed to gameobjects) */
59  FIRST_INTERESTING_FLAG = 0x0100,
60 
62  ICE = 0x0100,
64  WATER = 0x0200,
66  HURTS = 0x0400,
68  FIRE = 0x0800,
70  WALLJUMP = 0x1000
71  };
72 
74  enum {
75  WORLDMAP_NORTH = 0x0001,
76  WORLDMAP_SOUTH = 0x0002,
77  WORLDMAP_EAST = 0x0004,
78  WORLDMAP_WEST = 0x0008,
79  WORLDMAP_DIR_MASK = 0x000f,
80 
81  WORLDMAP_STOP = 0x0010,
82 
83  // convenience values ("C" stands for crossroads)
84  WORLDMAP_CNSE = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST,
85  WORLDMAP_CNSW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_WEST,
86  WORLDMAP_CNEW = WORLDMAP_NORTH | WORLDMAP_EAST | WORLDMAP_WEST,
87  WORLDMAP_CSEW = WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST,
88  WORLDMAP_CNSEW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST
89  };
90 
91  enum
92  {
93  UNI_DIR_NORTH = 0,
94  UNI_DIR_SOUTH = 1,
95  UNI_DIR_WEST = 2,
96  UNI_DIR_EAST = 3,
97  UNI_DIR_MASK = 3
98  };
99 
100 public:
101  Tile();
102  Tile(const std::vector<SurfacePtr>& images,
103  const std::vector<SurfacePtr>& editor_images,
104  uint32_t attributes, uint32_t data, float fps,
105  bool deprecated = false,
106  const std::string& obj_name = "", const std::string& obj_data = "");
107 
109  void draw(Canvas& canvas, const Vector& pos, int z_pos, const Color& color = Color(1, 1, 1)) const;
110  void draw_debug(Canvas& canvas, const Vector& pos, int z_pos, const Color& color = Color(1.0f, 0.f, 1.0f, 0.5f)) const;
111 
112  SurfacePtr get_current_surface() const;
113  SurfacePtr get_current_editor_surface() const;
114 
115  uint32_t get_attributes() const { return m_attributes; }
116  int get_data() const { return m_data; }
117 
119  bool is_slope() const { return (m_attributes & SLOPE) != 0; }
120 
126  bool is_solid (const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
127 
133  bool is_solid() const { return (m_attributes & SOLID) != 0; }
134 
138  bool is_collisionful(const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
139 
141  bool is_unisolid() const { return (m_attributes & UNISOLID) != 0; }
142 
143  bool is_deprecated() const { return m_deprecated; }
144 
145  const std::string& get_object_name() const { return m_object_name; }
146  const std::string& get_object_data() const { return m_object_data; }
147 
148 private:
151  bool check_movement_unisolid (const Vector& movement) const;
152 
155  bool check_position_unisolid (const Rectf& obj_bbox,
156  const Rectf& tile_bbox) const;
157 
158 private:
159  std::vector<SurfacePtr> m_images;
160  std::vector<SurfacePtr> m_editor_images;
161 
163  uint32_t m_attributes;
164 
166  int m_data;
167 
168  float m_fps;
169 
170  std::string m_object_name;
171  std::string m_object_data;
172 
174  bool m_deprecated;
175 
176 private:
177  Tile(const Tile&) = delete;
178  Tile& operator=(const Tile&) = delete;
179 };
180 
181 #endif
182 
183 /* EOF */
solid tile that is indestructible by Tux
Definition: tile.hpp:41
bool is_slope() const
Checks the SLOPE attribute.
Definition: tile.hpp:119
bool is_unisolid() const
Checks the UNISOLID attribute.
Definition: tile.hpp:141
a water tile in which tux starts to swim
Definition: tile.hpp:64
void draw(Canvas &canvas, const Vector &pos, int z_pos, const Color &color=Color(1, 1, 1)) const
Draw a tile on the screen.
Definition: tile.cpp:77
for lava: WATER, HURTS, FIRE
Definition: tile.hpp:68
a brick that can be destroyed by jumping under it
Definition: tile.hpp:45
bool is_collisionful(const Rectf &tile_bbox, const Rectf &position, const Vector &movement) const
Determines whether the tile&#39;s attributes are important to calculate the collisions.
Definition: tile.cpp:496
a walljumping trigger tile
Definition: tile.hpp:70
an ice brick that makes tux sliding more than usual
Definition: tile.hpp:62
uni-directional solid tile
Definition: tile.hpp:43
the level should be finished when touching a goaltile.
Definition: tile.hpp:50
Definition: rectf.hpp:31
Definition: tile.hpp:32
Tile is a coin.
Definition: tile.hpp:56
Definition: color.hpp:26
bool is_solid() const
This version only checks the SOLID flag to determine the solidity of a tile.
Definition: tile.hpp:133
Definition: canvas.hpp:43
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Bonusbox, content is stored in data.
Definition: tile.hpp:54
slope tile
Definition: tile.hpp:52
a tile that hurts Tux if he touches it
Definition: tile.hpp:66