1 /*
2 * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3 *
4 * Solarus is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Solarus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "solarus/entities/ParallaxScrollingTilePattern.h"
18 #include "solarus/entities/Tileset.h"
19 #include "solarus/graphics/Surface.h"
20
21 namespace Solarus {
22
23 /**
24 * \brief Creates a tile pattern with parallax scrolling.
25 * \param ground Kind of ground of the tile pattern.
26 * \param xy Coordinates of the tile pattern in the tileset.
27 * \param size Size of the tile pattern in the tileset.
28 */
ParallaxScrollingTilePattern(Ground ground,const Point & xy,const Size & size)29 ParallaxScrollingTilePattern::ParallaxScrollingTilePattern(
30 Ground ground, const Point& xy, const Size& size):
31 SimpleTilePattern(ground, xy, size) {
32
33 }
34
35 /**
36 * \brief Draws the tile image on a surface.
37 * \param dst_surface the surface to draw
38 * \param dst_position position where tile pattern should be drawn on dst_surface
39 * \param tileset the tileset of this tile
40 * \param viewport coordinates of the top-left corner of dst_surface relative
41 * to the map (may be used for scrolling tiles)
42 */
draw(const SurfacePtr & dst_surface,const Point & dst_position,const Tileset & tileset,const Point & viewport) const43 void ParallaxScrollingTilePattern::draw(
44 const SurfacePtr& dst_surface,
45 const Point& dst_position,
46 const Tileset& tileset,
47 const Point& viewport
48 ) const {
49 const SurfacePtr& tileset_image = tileset.get_tiles_image();
50 Point dst = dst_position;
51 dst += viewport / ratio;
52 tileset_image->draw_region(position_in_tileset, dst_surface, dst);
53
54 // one day, we can implement several scrolling layers just by changing the ratio
55 }
56
57 /**
58 * \brief Returns whether this tile pattern is animated, i.e. not always displayed
59 * the same way.
60 *
61 * Non-animated tiles may be rendered faster by using intermediate surfaces
62 * that are drawn only once.
63 *
64 * \return true if this tile pattern is animated
65 */
is_animated() const66 bool ParallaxScrollingTilePattern::is_animated() const {
67 return true;
68 }
69
70 /**
71 * \brief Returns whether tiles having this tile pattern are drawn at their
72 * position.
73 *
74 * Usually, this function returns true, and when it is the case, draw() is
75 * called only for tiles that are located in the current viewport.
76 *
77 * However, some tile patterns may want to be drawn even when they are not
78 * in the viewport, typically to make an illusion of movement like parallax
79 * scrolling.
80 *
81 * \return true to if this tile pattern is always drawn at its coordinates
82 */
is_drawn_at_its_position() const83 bool ParallaxScrollingTilePattern::is_drawn_at_its_position() const {
84 return false;
85 }
86
87 }
88
89