supertux
tux.hpp
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 HEADER_SUPERTUX_WORLDMAP_TUX_HPP
20 
21 #include "supertux/game_object.hpp"
22 
23 #include "sprite/sprite_ptr.hpp"
24 #include "supertux/player_status.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:
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  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(Tux)); }
43 
44  void setup();
46  void set_direction(Direction dir);
47 
48  void set_ghost_mode(bool enabled);
49  bool get_ghost_mode() const;
50 
51  bool is_moving() const { return m_moving; }
52  Vector get_pos() const;
53  Vector get_axis() const;
54  Vector get_tile_pos() const { return m_tile_pos; }
55  void set_initial_pos(const Vector& pos) { m_initial_tile_pos = pos / 32.f; }
56  void set_tile_pos(const Vector& pos) { m_tile_pos = pos; }
57 
58  void process_special_tile(SpecialTile* special_tile);
59 
60 private:
61  void stop();
62  std::string get_action_prefix_for_bonus(const BonusType& bonus) const;
63  bool can_walk(int tile_data, Direction dir) const;
64  void update_input_direction();
65  void try_start_walking();
66  void try_continue_walking(float dt_sec);
68  void change_sprite(SpriteChange* sc);
70 public:
71  Direction m_back_direction;
72 
73 private:
74  WorldMap* m_worldmap;
75  SpritePtr m_sprite;
76  Controller& m_controller;
77 
78  Direction m_input_direction;
79  Direction m_direction;
80  Vector m_initial_tile_pos;
81  Vector m_tile_pos;
84  float m_offset;
85  bool m_moving;
86 
87  bool m_ghost_mode;
88 
89 private:
90  Tux(const Tux&) = delete;
91  Tux& operator=(const Tux&) = delete;
92 };
93 
94 } // namespace worldmap
95 
96 #endif
97 
98 /* EOF */
Definition: controller.hpp:57
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: tux.hpp:42
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: tux.cpp:58
Definition: object_settings.hpp:32
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void setup()
called prior to first update
Definition: tux.cpp:373
Definition: tux.hpp:34
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: tux.cpp:361
Definition: special_tile.hpp:28
Definition: sprite_change.hpp:27
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
virtual bool is_singleton() const override
If true only a single object of this type is allowed in a given GameObjectManager.
Definition: tux.hpp:41
Definition: worldmap.hpp:33