| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2011 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D 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 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #ifndef TRACKTILE_HPP |
| 17 | #define TRACKTILE_HPP |
| 18 | |
| 19 | #include "../common/tracktilebase.hpp" |
| 20 | #include <MCSurface> |
| 21 | |
| 22 | //! The track tile used in the game. |
| 23 | class TrackTile : public TrackTileBase |
| 24 | { |
| 25 | public: |
| 26 | //! All possible types. |
| 27 | enum class TileType |
| 28 | { |
| 29 | None = 0, |
| 30 | Bridge, |
| 31 | Corner90, |
| 32 | Corner45Left, |
| 33 | Corner45Right, |
| 34 | Straight, |
| 35 | Straight45Male, |
| 36 | Straight45Female, |
| 37 | Grass, |
| 38 | Sand, |
| 39 | SandGrassStraight, |
| 40 | SandGrassCorner, |
| 41 | SandGrassCorner2, |
| 42 | Finish |
| 43 | }; |
| 44 | |
| 45 | /*! Constructor. |
| 46 | * \see TrackTileBase. */ |
| 47 | TrackTile(QPointF location, QPoint matrixLocation, const QString & type = "", TileType typeEnum = TileType::None); |
| 48 | |
| 49 | //! Destructor |
| 50 | virtual ~TrackTile() override; |
| 51 | |
| 52 | //! Set the orientation in XY-plane in degrees when loading |
| 53 | //! a track. |
| 54 | void setRotation(int rotation); |
| 55 | |
| 56 | //! Set the renderable surface object corresponding to the track tile. |
| 57 | void setSurface(MCSurfacePtr surface); |
| 58 | |
| 59 | //! Get the corresponding surface. |
| 60 | MCSurfacePtr surface() const; |
| 61 | |
| 62 | //! Set the renderable surface object corresponding to the preview of track tile. |
| 63 | void setPreviewSurface(MCSurfacePtr surface); |
| 64 | |
| 65 | //! Get the corresponding preview surface. |
| 66 | MCSurfacePtr previewSurface() const; |
| 67 | |
| 68 | //! Get the orientation in XY-plane in degrees. |
| 69 | int rotation() const; |
| 70 | |
| 71 | //! Get the type as an enum (performance optimization). |
| 72 | TileType tileTypeEnum() const; |
| 73 | |
| 74 | //! Set the type as an enum (performance optimization). |
| 75 | void setTileTypeEnum(TileType type); |
| 76 | |
| 77 | //! Returns true if the tile needs a separate asphalt background. |
| 78 | bool hasAsphalt() const; |
| 79 | |
| 80 | private: |
| 81 | //! Disable the string-based type getter. Use tileTypeEnum() instead. |
| 82 | const QString & tileType() const; |
| 83 | |
| 84 | int m_rotation; |
| 85 | |
| 86 | MCSurfacePtr m_surface; |
| 87 | |
| 88 | MCSurfacePtr m_previewSurface; |
| 89 | |
| 90 | TileType m_typeEnum; |
| 91 | |
| 92 | bool m_hasAsphalt; |
| 93 | }; |
| 94 | |
| 95 | using TrackTileS = std::shared_ptr<TrackTile>; |
| 96 | |
| 97 | #endif // TRACKTILE_HPP |