From 580114e08743b0f46b4fb4b33de4ff854fc635e8 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Mon, 16 Apr 2007 19:28:20 +0000 Subject: [PATCH] Walking Badguys that get dizzy fall off the screen SVN-Revision: 4990 --- src/badguy/walking_badguy.cpp | 11 ++++++++++- src/badguy/walking_badguy.hpp | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/badguy/walking_badguy.cpp b/src/badguy/walking_badguy.cpp index a3c05625d..3b8f7ab34 100644 --- a/src/badguy/walking_badguy.cpp +++ b/src/badguy/walking_badguy.cpp @@ -21,7 +21,7 @@ #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) @@ -107,6 +107,15 @@ WalkingBadguy::turn_around() dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action); 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 diff --git a/src/badguy/walking_badguy.hpp b/src/badguy/walking_badguy.hpp index f8afc5071..5d8503988 100644 --- a/src/badguy/walking_badguy.hpp +++ b/src/badguy/walking_badguy.hpp @@ -22,6 +22,8 @@ #include "badguy.hpp" +class Timer; + /** * Baseclass for a Badguy that just walks around. */ @@ -50,6 +52,8 @@ protected: std::string walk_right_action; float walk_speed; int max_drop_height; /**< Maximum height of drop before we will turn around, or -1 to just drop from any ledge */ + Timer turn_around_timer; + int turn_around_counter; /**< counts number of turns since turn_around_timer was started */ }; #endif -- 2.11.0