3 // SuperTux - WalkingBadguy
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "walking_badguy.hpp"
26 WalkingBadguy::WalkingBadguy(const Vector& pos, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer)
27 : BadGuy(pos, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
31 WalkingBadguy::WalkingBadguy(const Vector& pos, Direction direction, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer)
32 : BadGuy(pos, direction, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
36 WalkingBadguy::WalkingBadguy(const lisp::Lisp& reader, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer)
37 : BadGuy(reader, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
42 WalkingBadguy::write(lisp::Writer& writer)
44 writer.write_float("x", start_position.x);
45 writer.write_float("y", start_position.y);
49 WalkingBadguy::activate()
53 sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
54 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
55 physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
59 WalkingBadguy::active_update(float elapsed_time)
61 BadGuy::active_update(elapsed_time);
63 if (max_drop_height > -1) {
64 if (on_ground() && might_fall(max_drop_height+1))
73 WalkingBadguy::collision_solid(const CollisionHit& hit)
76 update_on_ground_flag(hit);
79 if (physic.get_velocity_y() < 0) physic.set_velocity_y(0);
82 if (physic.get_velocity_y() > 0) physic.set_velocity_y(0);
85 if ((hit.left && (hit.slope_normal.y == 0) && (dir == LEFT)) || (hit.right && (hit.slope_normal.y == 0) && (dir == RIGHT))) {
92 WalkingBadguy::collision_badguy(BadGuy& , const CollisionHit& hit)
95 if ((hit.left && (dir == LEFT)) || (hit.right && (dir == RIGHT))) {
103 WalkingBadguy::turn_around()
107 dir = dir == LEFT ? RIGHT : LEFT;
108 sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
109 physic.set_velocity_x(-physic.get_velocity_x());
111 // if we get dizzy, we fall off the screen
112 if (turn_around_timer.started()) {
113 if (turn_around_counter++ > 10) kill_fall();
115 turn_around_timer.start(1);
116 turn_around_counter = 0;
122 WalkingBadguy::freeze()
125 physic.set_velocity_x(0);
129 WalkingBadguy::unfreeze()
132 WalkingBadguy::activate();
137 WalkingBadguy::get_velocity_y() const
139 return physic.get_velocity_y();
143 WalkingBadguy::set_velocity_y(float vy)
145 physic.set_velocity_y(vy);