supertux
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 
25 class WalkingBadguy : public BadGuy
26 {
27 public:
28  enum class LedgeBehavior
29  {
30  STRICT,
31  SMART,
32  NORMAL,
33  FALL
34  };
35 
36 public:
37  WalkingBadguy(const Vector& pos,
38  const std::string& sprite_name,
39  const std::string& walk_left_action,
40  const std::string& walk_right_action,
41  int layer = LAYER_OBJECTS,
42  const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite");
43  WalkingBadguy(const Vector& pos, Direction direction,
44  const std::string& sprite_name,
45  const std::string& walk_left_action,
46  const std::string& walk_right_action,
47  int layer = LAYER_OBJECTS,
48  const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite");
49  WalkingBadguy(const ReaderMapping& reader,
50  const std::string& sprite_name,
51  const std::string& walk_left_action,
52  const std::string& walk_right_action,
53  int layer = LAYER_OBJECTS,
54  const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite");
55  virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(WalkingBadguy)); }
56 
57  virtual void initialize() override;
58  virtual void active_update(float dt_sec) override;
59  virtual void collision_solid(const CollisionHit& hit) override;
60  virtual HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit) override;
61  virtual void freeze() override;
62  virtual void unfreeze(bool melt = true) override;
63 
64  void active_update(float dt_sec, float target_velocity, float modifier = 1.f);
66  void override_stay_on_platform() { m_stay_on_platform_overridden = true; }
67 
68  float get_velocity_x() const { return m_physic.get_velocity_x(); }
69  float get_velocity_y() const { return m_physic.get_velocity_y(); }
70  void set_velocity_y(float vy);
71 
73  void add_velocity(const Vector& velocity);
74 
75  float get_walk_speed() const { return walk_speed; }
76  void set_walk_speed (float);
77  bool is_active() const { return BadGuy::is_active(); }
78 
80  void set_ledge_behavior(LedgeBehavior behavior);
81 
82 protected:
83  void turn_around();
84 
85 protected:
86  static const int s_normal_max_drop_height = 600;
87 
88 protected:
89  std::string walk_left_action;
90  std::string walk_right_action;
91  float walk_speed;
93  Timer turn_around_timer;
95  bool m_stay_on_platform_overridden;
96 
97 private:
98  WalkingBadguy(const WalkingBadguy&) = delete;
99  WalkingBadguy& operator=(const WalkingBadguy&) = delete;
100 };
101 
102 #endif
103 
104 /* EOF */
int turn_around_counter
counts number of turns since turn_around_timer was started
Definition: walking_badguy.hpp:94
LedgeBehavior
Definition: walking_badguy.hpp:28
Base class for moving sprites that can hurt the Player.
Definition: badguy.hpp:38
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: badguy.hpp:71
Fall off any ledge, unless the ledge is too tall (600px) or the ledge falls offscreen.
virtual void collision_solid(const CollisionHit &hit) override
Called when the badguy collided with solid ground.
Definition: walking_badguy.cpp:180
void set_ledge_behavior(LedgeBehavior behavior)
Set max_drop_height depending on the given behavior.
Definition: walking_badguy.cpp:93
bool is_active() const
Returns true if we were in STATE_ACTIVE at the beginning of the last call to update() ...
Definition: badguy.cpp:879
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: walking_badguy.hpp:55
virtual void active_update(float dt_sec) override
called each frame when the badguy is activated.
Definition: walking_badguy.cpp:174
virtual HitResponse collision_badguy(BadGuy &badguy, const CollisionHit &hit) override
Called when the badguy collided with another badguy.
Definition: walking_badguy.cpp:207
Base class for Badguys that walk on the floor.
Definition: walking_badguy.hpp:25
virtual void freeze() override
Called when hit by an ice bullet, and is_freezable() returns true.
Definition: walking_badguy.cpp:246
Do not fall off any ledge at all.
void add_velocity(const Vector &velocity)
Adds velocity to the badguy (be careful when using this)
Definition: walking_badguy.cpp:116
Do not fall off any ledge, but still go down slopes.
virtual void initialize() override
called immediately before the first call to initialize
Definition: walking_badguy.cpp:76
void override_stay_on_platform()
used by objects that should make badguys not turn around when they are walking on them ...
Definition: walking_badguy.hpp:66
virtual void unfreeze(bool melt=true) override
Called to unfreeze the badguy.
Definition: walking_badguy.cpp:252
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
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:32
int max_drop_height
Maximum height of drop before we will turn around, or -1 to just drop from any ledge.
Definition: walking_badguy.hpp:92
This class collects data about a collision.
Definition: collision_hit.hpp:44