Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / worldmap / tux.hpp
1 //  SuperTux -  A Jump'n Run
2 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
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 "worldmap/worldmap.hpp"
22
23 class Sprite;
24
25 namespace WorldMapNS {
26
27 class WorldMap;
28
29 class Tux : public GameObject
30 {
31 public:
32   Direction back_direction;
33 private:
34   WorldMap* worldmap;
35   std::auto_ptr<Sprite> sprite;
36   Controller* controller;
37
38   Direction input_direction;
39   Direction direction;
40   Vector tile_pos;
41   /** Length by which tux is away from its current tile, length is in
42       input_direction direction */
43   float offset;
44   bool  moving;
45
46   bool ghost_mode;
47
48 private:
49   void stop();
50   bool canWalk(int tile_data, Direction dir); /**< check if we can leave a tile (with given "tile_data") in direction "dir" */
51   void updateInputDirection(); /**< if controller was pressed, update input_direction */
52   void tryStartWalking(); /**< try starting to walk in input_direction */
53   void tryContinueWalking(float elapsed_time); /**< try to continue walking in current direction */
54
55 public:
56   Tux(WorldMap* worldmap_);
57   ~Tux();
58
59   void setup(); /**< called prior to first update */
60   void draw(DrawingContext& context);
61   void update(float elapsed_time);
62
63   void set_direction(Direction dir);
64
65   void set_ghost_mode(bool enabled);
66   bool get_ghost_mode();
67
68   bool is_moving() const { return moving; }
69   Vector get_pos();
70   Vector get_tile_pos() const { return tile_pos; }
71   void  set_tile_pos(Vector p) { tile_pos = p; }
72
73 private:
74   Tux(const Tux&);
75   Tux& operator=(const Tux&);
76 };
77
78 } // namespace WorldMapNS
79
80 #endif
81
82 /* EOF */