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
69  };
70 
72  enum {
73  WORLDMAP_NORTH = 0x0001,
74  WORLDMAP_SOUTH = 0x0002,
75  WORLDMAP_EAST = 0x0004,
76  WORLDMAP_WEST = 0x0008,
77  WORLDMAP_DIR_MASK = 0x000f,
78 
79  WORLDMAP_STOP = 0x0010,
80 
81  // convenience values ("C" stands for crossroads)
82  WORLDMAP_CNSE = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST,
83  WORLDMAP_CNSW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_WEST,
84  WORLDMAP_CNEW = WORLDMAP_NORTH | WORLDMAP_EAST | WORLDMAP_WEST,
85  WORLDMAP_CSEW = WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST,
86  WORLDMAP_CNSEW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST
87  };
88 
89  enum
90  {
91  UNI_DIR_NORTH = 0,
92  UNI_DIR_SOUTH = 1,
93  UNI_DIR_WEST = 2,
94  UNI_DIR_EAST = 3,
95  UNI_DIR_MASK = 3
96  };
97 
98 public:
99  Tile();
100  Tile(const std::vector<SurfacePtr>& images,
101  const std::vector<SurfacePtr>& editor_images,
102  uint32_t attributes, uint32_t data, float fps,
103  const std::string& obj_name = "", const std::string& obj_data = "",
104  bool deprecated = false);
105 
107  void draw(Canvas& canvas, const Vector& pos, int z_pos, const Color& color = Color(1, 1, 1)) const;
108  void draw_debug(Canvas& canvas, const Vector& pos, int z_pos, const Color& color = Color(1.0f, 0.f, 1.0f, 0.5f)) const;
109 
110  SurfacePtr get_current_surface() const;
111  SurfacePtr get_current_editor_surface() const;
112 
113  uint32_t get_attributes() const { return m_attributes; }
114  int get_data() const { return m_data; }
115 
117  bool is_slope() const { return (m_attributes & SLOPE) != 0; }
118 
124  bool is_solid (const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
125 
131  bool is_solid() const { return (m_attributes & SOLID) != 0; }
132 
136  bool is_collisionful(const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
137 
139  bool is_unisolid() const { return (m_attributes & UNISOLID) != 0; }
140 
141  bool is_deprecated() const { return m_deprecated; }
142 
143  const std::string& get_object_name() const { return m_object_name; }
144  const std::string& get_object_data() const { return m_object_data; }
145 
146 private:
149  bool check_movement_unisolid (const Vector& movement) const;
150 
153  bool check_position_unisolid (const Rectf& obj_bbox,
154  const Rectf& tile_bbox) const;
155 
156 private:
157  std::vector<SurfacePtr> m_images;
158  std::vector<SurfacePtr> m_editor_images;
159 
161  uint32_t m_attributes;
162 
164  int m_data;
165 
166  float m_fps;
167 
168  std::string m_object_name;
169  std::string m_object_data;
170 
172  bool m_deprecated;
173 
174 private:
175  Tile(const Tile&) = delete;
176  Tile& operator=(const Tile&) = delete;
177 };
178 
179 #endif
180 
181 /* EOF */
Bonusbox, content is stored in data.
Definition: tile.hpp:54
uni-directional solid tile
Definition: tile.hpp:43
bool is_slope() const
Checks the SLOPE attribute.
Definition: tile.hpp:117
a brick that can be destroyed by jumping under it
Definition: tile.hpp:45
bool is_unisolid() const
Checks the UNISOLID attribute.
Definition: tile.hpp:139
Simple two dimensional vector.
Definition: vector.hpp:24
for lava: WATER, HURTS, FIRE
Definition: tile.hpp:68
a water tile in which tux starts to swim
Definition: tile.hpp:64
slope tile
Definition: tile.hpp:52
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
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
an ice brick that makes tux sliding more than usual
Definition: tile.hpp:62
the level should be finished when touching a goaltile.
Definition: tile.hpp:50
Definition: rectf.hpp:29
solid tile that is indestructible by Tux
Definition: tile.hpp:41
a tile that hurts Tux if he touches it
Definition: tile.hpp:66
Tile is a coin.
Definition: tile.hpp:56
Definition: tile.hpp:32
Definition: color.hpp:25
bool is_solid() const
This version only checks the SOLID flag to determine the solidity of a tile.
Definition: tile.hpp:131
Definition: canvas.hpp:43
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42