1 | // SuperTux - A Jump'n Run |
2 | // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmail.com> |
3 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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_WORLDMAP_TUX_HPP |
19 | #define |
20 | |
21 | #include "sprite/sprite_ptr.hpp" |
22 | #include "supertux/game_object.hpp" |
23 | #include "supertux/player_status.hpp" |
24 | #include "worldmap/worldmap.hpp" |
25 | |
26 | class Controller; |
27 | |
28 | namespace worldmap { |
29 | |
30 | class SpecialTile; |
31 | class SpriteChange; |
32 | class WorldMap; |
33 | |
34 | class Tux final : public GameObject |
35 | { |
36 | public: |
37 | Tux(WorldMap* worldmap); |
38 | |
39 | virtual void draw(DrawingContext& context) override; |
40 | virtual void update(float dt_sec) override; |
41 | virtual bool is_singleton() const override { return true; } |
42 | |
43 | void setup(); /**< called prior to first update */ |
44 | |
45 | void set_direction(Direction dir); |
46 | |
47 | void set_ghost_mode(bool enabled); |
48 | bool get_ghost_mode() const; |
49 | |
50 | bool is_moving() const { return m_moving; } |
51 | Vector get_pos() const; |
52 | Vector get_tile_pos() const { return m_tile_pos; } |
53 | void set_tile_pos(const Vector& p) { m_tile_pos = p; } |
54 | |
55 | void process_special_tile(SpecialTile* special_tile); |
56 | |
57 | private: |
58 | void stop(); |
59 | std::string get_action_prefix_for_bonus(const BonusType& bonus) const; |
60 | bool can_walk(int tile_data, Direction dir) const; /**< check if we can leave a tile (with given "tile_data") in direction "dir" */ |
61 | void update_input_direction(); /**< if controller was pressed, update input_direction */ |
62 | void try_start_walking(); /**< try starting to walk in input_direction */ |
63 | void try_continue_walking(float dt_sec); /**< try to continue walking in current direction */ |
64 | |
65 | void change_sprite(SpriteChange* sc); /**< Uses the given sprite change */ |
66 | |
67 | public: |
68 | Direction m_back_direction; |
69 | |
70 | private: |
71 | WorldMap* m_worldmap; |
72 | SpritePtr m_sprite; |
73 | Controller& m_controller; |
74 | |
75 | Direction m_input_direction; |
76 | Direction m_direction; |
77 | Vector m_tile_pos; |
78 | /** Length by which tux is away from its current tile, length is in |
79 | input_direction direction */ |
80 | float m_offset; |
81 | bool m_moving; |
82 | |
83 | bool m_ghost_mode; |
84 | |
85 | private: |
86 | Tux(const Tux&) = delete; |
87 | Tux& operator=(const Tux&) = delete; |
88 | }; |
89 | |
90 | } // namespace worldmap |
91 | |
92 | #endif |
93 | |
94 | /* EOF */ |
95 | |