038d87668f6ebd8840fa298c5c60bca9314595e7
[supertux.git] / src / badguy / walking_badguy.hpp
1 //  SuperTux - WalkingBadguy
2 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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_BADGUY_WALKING_BADGUY_HPP
18 #define HEADER_SUPERTUX_BADGUY_WALKING_BADGUY_HPP
19
20 #include "badguy/badguy.hpp"
21
22 class Timer;
23
24 /**
25  * Base class for Badguys that walk on the floor.
26  */
27 class WalkingBadguy : public BadGuy
28 {
29 public:
30   WalkingBadguy(const Vector& pos, 
31                 const std::string& sprite_name, 
32                 const std::string& walk_left_action, 
33                 const std::string& walk_right_action, 
34                 int layer = LAYER_OBJECTS);
35   WalkingBadguy(const Vector& pos, Direction direction, 
36                 const std::string& sprite_name, 
37                 const std::string& walk_left_action, 
38                 const std::string& walk_right_action, 
39                 int layer = LAYER_OBJECTS);
40   WalkingBadguy(const Reader& reader, 
41                 const std::string& sprite_name, 
42                 const std::string& walk_left_action, 
43                 const std::string& walk_right_action, 
44                 int layer = LAYER_OBJECTS);
45
46   void initialize();
47   void active_update(float elapsed_time);
48   void active_update(float elapsed_time, float target_velocity);
49   void collision_solid(const CollisionHit& hit);
50   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
51   void freeze();
52   void unfreeze();
53
54   float get_velocity_y() const;
55   void set_velocity_y(float vy);
56
57   /**
58    * Adds velocity to the badguy (be careful when using this)
59    */
60   void add_velocity(const Vector& velocity);
61
62   float get_walk_speed (void) const
63   {
64     return (walk_speed);
65   }
66   void  set_walk_speed (float);
67
68 protected:
69   void turn_around();
70
71 protected:
72   std::string walk_left_action;
73   std::string walk_right_action;
74   float walk_speed;
75   int max_drop_height; /**< Maximum height of drop before we will turn around, or -1 to just drop from any ledge */
76   Timer turn_around_timer;
77   int turn_around_counter; /**< counts number of turns since turn_around_timer was started */
78 };
79
80 #endif
81
82 /* EOF */