AUTO-canon always shoots towards tux.
authorWolfgang Becker <uafr@gmx.de>
Sun, 20 Jan 2008 12:34:22 +0000 (12:34 +0000)
committerWolfgang Becker <uafr@gmx.de>
Sun, 20 Jan 2008 12:34:22 +0000 (12:34 +0000)
SVN-Revision: 5285

data/images/creatures/dispenser/dispenser.sprite
data/images/creatures/dispenser/swivel-left.png [new file with mode: 0644]
data/images/creatures/dispenser/swivel-right.png [new file with mode: 0644]
src/badguy/dispenser.cpp
src/badguy/dispenser.hpp

index 7636dfc..cc2f3be 100644 (file)
   (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 (file)
index 0000000..55dccfa
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 (file)
index 0000000..b455c0c
Binary files /dev/null and b/data/images/creatures/dispenser/swivel-right.png differ
index 123e4aa..613f06e 100644 (file)
@@ -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();
+    }
   }
 }
 
index e553d54..95b5cad 100644 (file)
@@ -45,6 +45,8 @@ protected:
   float cycle;
   std::string badguy;
   Timer dispense_timer;
+  bool autotarget;
+  bool swivel;
 };
 
 #endif