From: Wolfgang Becker Date: Sun, 20 Jan 2008 12:34:22 +0000 (+0000) Subject: AUTO-canon always shoots towards tux. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=13cda6b24b2d8c7ea53d0fbe44dd8fc6aa8cbbec;p=supertux.git AUTO-canon always shoots towards tux. SVN-Revision: 5285 --- diff --git a/data/images/creatures/dispenser/dispenser.sprite b/data/images/creatures/dispenser/dispenser.sprite index 7636dfc8c..cc2f3be84 100644 --- a/data/images/creatures/dispenser/dispenser.sprite +++ b/data/images/creatures/dispenser/dispenser.sprite @@ -23,5 +23,17 @@ (name "broken-right") (hitbox 4 12 55 40) (mirror-action "broken-left")) + + (action + (name "swivel-left") + (hitbox 5 12 55 40) + (images "swivel-right.png" + "swivel-left.png" + "working.png")) + + (action + (name "swivel-right") + (hitbox 4 12 55 40) + (mirror-action "swivel-left")) ) diff --git a/data/images/creatures/dispenser/swivel-left.png b/data/images/creatures/dispenser/swivel-left.png new file mode 100644 index 000000000..55dccfadb Binary files /dev/null and b/data/images/creatures/dispenser/swivel-left.png differ diff --git a/data/images/creatures/dispenser/swivel-right.png b/data/images/creatures/dispenser/swivel-right.png new file mode 100644 index 000000000..b455c0c02 Binary files /dev/null and b/data/images/creatures/dispenser/swivel-right.png differ diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 123e4aa74..613f06ec3 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -35,9 +35,13 @@ Dispenser::Dispenser(const lisp::Lisp& reader) { reader.get("cycle", cycle); reader.get("badguy", badguy); + autotarget = false; + swivel = false; if (badguy == "mrrocket") { - if (start_dir == AUTO) log_warning << "Setting a Dispenser's direction to AUTO is no good idea" << std::endl; sprite->set_action(dir == LEFT ? "working-left" : "working-right"); + if( start_dir == AUTO ){ + autotarget = true; + } } else {sprite->set_action("dropper");} bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); @@ -62,6 +66,9 @@ Dispenser::activate() { if(frozen) return; + if (badguy == "mrrocket") { + sprite->set_action(dir == LEFT ? "working-left" : "working-right"); + } dispense_timer.start(cycle, true); launch_badguy(); } @@ -89,7 +96,27 @@ void Dispenser::active_update(float ) { if (dispense_timer.check()) { - launch_badguy(); + // auto always shoots in Tux's direction + if( autotarget ){ + if( sprite->animation_done()) { + sprite->set_action(dir == LEFT ? "working-left" : "working-right"); + swivel = false; + } + + Player* player = this->get_nearest_player(); + if( player && !swivel ){ + Direction targetdir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT; + if( dir != targetdir ){ // no target: swivel cannon + swivel = true; + dir = targetdir; + sprite->set_action(dir == LEFT ? "swivel-left" : "swivel-right", 1); + } else { // tux in sight: shoot + launch_badguy(); + } + } + } else { + launch_badguy(); + } } } diff --git a/src/badguy/dispenser.hpp b/src/badguy/dispenser.hpp index e553d545d..95b5cad2b 100644 --- a/src/badguy/dispenser.hpp +++ b/src/badguy/dispenser.hpp @@ -45,6 +45,8 @@ protected: float cycle; std::string badguy; Timer dispense_timer; + bool autotarget; + bool swivel; }; #endif