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
22class Timer;
23
24/** Base class for Badguys that walk on the floor. */
25class WalkingBadguy : public BadGuy
26{
27public:
28 WalkingBadguy(const Vector& pos,
29 const std::string& sprite_name,
30 const std::string& walk_left_action,
31 const std::string& walk_right_action,
32 int layer = LAYER_OBJECTS,
33 const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite");
34 WalkingBadguy(const Vector& pos, Direction direction,
35 const std::string& sprite_name,
36 const std::string& walk_left_action,
37 const std::string& walk_right_action,
38 int layer = LAYER_OBJECTS,
39 const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite");
40 WalkingBadguy(const ReaderMapping& 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 const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite");
46
47 virtual void initialize() override;
48 virtual void active_update(float dt_sec) override;
49 virtual void collision_solid(const CollisionHit& hit) override;
50 virtual HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit) override;
51 virtual void freeze() override;
52 virtual void unfreeze() override;
53
54 void active_update(float dt_sec, float target_velocity);
55
56 float get_velocity_y() const;
57 void set_velocity_y(float vy);
58
59 /** Adds velocity to the badguy (be careful when using this) */
60 void add_velocity(const Vector& velocity);
61
62 float get_walk_speed() const { return walk_speed; }
63 void set_walk_speed (float);
64 bool is_active() const { return BadGuy::is_active(); }
65
66protected:
67 void turn_around();
68
69protected:
70 std::string walk_left_action;
71 std::string walk_right_action;
72 float walk_speed;
73 int max_drop_height; /**< Maximum height of drop before we will turn around, or -1 to just drop from any ledge */
74 Timer turn_around_timer;
75 int turn_around_counter; /**< counts number of turns since turn_around_timer was started */
76
77private:
78 WalkingBadguy(const WalkingBadguy&) = delete;
79 WalkingBadguy& operator=(const WalkingBadguy&) = delete;
80};
81
82#endif
83
84/* EOF */
85