1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program 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 //  This program 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
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_SCRIPTING_PLAYER_HPP
18 #define HEADER_SUPERTUX_SCRIPTING_PLAYER_HPP
19 
20 #ifndef SCRIPTING_API
21 #include <string>
22 
23 #include "scripting/game_object.hpp"
24 
25 class Player;
26 #endif
27 
28 namespace scripting {
29 
30 class Player final
31 #ifndef SCRIPTING_API
32   : public GameObject<::Player>
33 #endif
34 {
35 #ifndef SCRIPTING_API
36 public:
37   using GameObject::GameObject;
38 
39 private:
40   Player(const Player&) = delete;
41   Player& operator=(const Player&) = delete;
42 #endif
43 
44 public:
45   /**
46    * Set tux bonus.
47    * This can be "grow", "fireflower" or "iceflower" at the moment
48    */
49   bool add_bonus(const std::string& bonus);
50   /**
51    * Replaces the Tux's bonus with another bonus.
52    * This can be "grow", "fireflower" or "iceflower" at the moment
53    */
54   bool set_bonus(const std::string& bonus);
55   /**
56    * Give tux more coins
57    *
58    * If count is a negative amount of coins, that number of coins will be taken
59    * from the player (until the number of coins the player has is 0, when it
60    * will stop changing).
61    */
62   void add_coins(int count);
63   /**
64    * Returns the number of coins the player currently has.
65    */
66   int get_coins() const;
67   /**
68    * Make tux invincible for a short amount of time
69    */
70   void make_invincible();
71   /**
72    * Deactivate user/scripting input for Tux
73    */
74   void deactivate();
75   /**
76    * Give control back to user/scripting
77    */
78   void activate();
79   /**
80    * Make Tux walk
81    */
82   void walk(float speed);
83   /**
84    * Face Tux in the proper direction
85    */
86   void set_dir(bool right);
87   /**
88    * Set player visible or invisible
89    */
90   void set_visible(bool visible);
91   /**
92    * returns true if Tux is currently visible (that is he was not set
93    * invisible by the set_visible method)
94    */
95   bool get_visible() const;
96 
97   /**
98    * Hurts Tux, if completely=true then he will be killed even
99    * if he had grow or fireflower bonus
100    */
101   void kill(bool completely);
102 
103   /**
104    * Switches ghost mode on/off.
105    * Lets Tux float around and through solid objects.
106    */
107   void set_ghost_mode(bool enable);
108 
109   /**
110    * Returns whether ghost mode is currently enabled
111    */
112   bool get_ghost_mode() const;
113 
114   /**
115    * start kick animation
116    */
117   void kick();
118 
119   /**
120    * play cheer animation.
121    * This might need some space and behave in an unpredictable way. Best to use this at level end.
122    */
123   void do_cheer();
124 
125   /**
126    * duck down if possible.
127    * this won't last long as long as input is enabled.
128    */
129   void do_duck();
130 
131   /**
132    * stand back up if possible.
133    */
134   void do_standup();
135 
136   /**
137    * do a backflip if possible.
138    */
139   void do_backflip();
140 
141   /**
142    * jump in the air if possible
143    * sensible values for yspeed are negative - unless we want to jump into the ground of course
144    */
145   void do_jump(float yspeed);
146 
147   /**
148    * Orders the current GameSession to start a sequence
149    */
150   void trigger_sequence(const std::string& sequence_name);
151 
152   /**
153    * Uses a scriptable controller for all user input (or restores controls)
154    */
155   void use_scripting_controller(bool use_or_release);
156 
157   /**
158    * Check whether player is carrying a certain object
159    * @param name Name of the Portable object to check for
160    */
161    bool has_grabbed(const std::string& name) const;
162 
163   /**
164    * Instructs the scriptable controller to press or release a button
165    */
166   void do_scripting_controller(const std::string& control, bool pressed);
167 
168   float get_velocity_x() const;
169   float get_velocity_y() const;
170 
171   /**
172    * Gets the X coordinate of the player.
173    */
174   float get_x() const;
175 
176   /**
177    * Gets the Y coordinate of the player.
178    */
179   float get_y() const;
180 
181   /**
182    * Sets the position of the player to a programmable/variable position.
183    */
184   void set_pos(float x, float y);
185 };
186 
187 } // namespace scripting
188 
189 #endif
190 
191 /* EOF */
192