#include "walking_badguy.hpp"
#include "log.hpp"
-
+#include "timer.hpp"
WalkingBadguy::WalkingBadguy(const Vector& pos, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer)
- : BadGuy(pos, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
+ : BadGuy(pos, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
{
}
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)
- : 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)
+ : 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)
{
}
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)
- : BadGuy(reader, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
+ : BadGuy(reader, sprite_name, layer), walk_left_action(walk_left_action), walk_right_action(walk_right_action), walk_speed(80), max_drop_height(-1)
{
}
}
void
-WalkingBadguy::activate()
+WalkingBadguy::initialize()
{
+ if(frozen)
+ return;
sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
update_on_ground_flag(hit);
- if (hit.top || hit.bottom) {
- physic.set_velocity_y(0);
+ if (hit.top) {
+ if (physic.get_velocity_y() < 0) physic.set_velocity_y(0);
+ }
+ if (hit.bottom) {
+ if (physic.get_velocity_y() > 0) physic.set_velocity_y(0);
}
-// if ((hit.left && dir == LEFT) || (hit.right && dir == RIGHT)) {
- if (hit.left || hit.right) {
+ if ((hit.left && (hit.slope_normal.y == 0) && (dir == LEFT)) || (hit.right && (hit.slope_normal.y == 0) && (dir == RIGHT))) {
turn_around();
}
WalkingBadguy::collision_badguy(BadGuy& , const CollisionHit& hit)
{
- //if ((hit.left && (dir == LEFT)) || (hit.right && (dir == RIGHT))) {
- if (hit.left || hit.right) {
+ if ((hit.left && (dir == LEFT)) || (hit.right && (dir == RIGHT))) {
turn_around();
}
void
WalkingBadguy::turn_around()
{
+ if(frozen)
+ return;
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
- physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
+ physic.set_velocity_x(-physic.get_velocity_x());
+
+ // if we get dizzy, we fall off the screen
+ if (turn_around_timer.started()) {
+ if (turn_around_counter++ > 10) kill_fall();
+ } else {
+ turn_around_timer.start(1);
+ turn_around_counter = 0;
+ }
+
+}
+
+void
+WalkingBadguy::freeze()
+{
+ BadGuy::freeze();
+ physic.set_velocity_x(0);
+}
+
+void
+WalkingBadguy::unfreeze()
+{
+ BadGuy::unfreeze();
+ WalkingBadguy::initialize();
+}
+
+
+float
+WalkingBadguy::get_velocity_y() const
+{
+ return physic.get_velocity_y();
}
+void
+WalkingBadguy::set_velocity_y(float vy)
+{
+ physic.set_velocity_y(vy);
+}