Haywire: Walk towards the player if possible.
authorflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sun, 28 Feb 2010 10:30:54 +0000 (10:30 +0000)
committerflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sun, 28 Feb 2010 10:30:54 +0000 (10:30 +0000)
This is a simple version of the "follow the player" behavior proposed in the
Milestone 2 design document.

git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6446 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/badguy/haywire.cpp

index ebcf3f1..6dff5cc 100644 (file)
@@ -130,6 +130,20 @@ Haywire::active_update(float elapsed_time)
     }
   }
 
+  if (is_exploding && !turn_around_timer.started()) {
+    Player *p = Sector::current()->get_nearest_player (this->get_pos ());
+
+    if (p) {
+      Direction player_dir = LEFT;
+
+      if (p->get_pos ().x > this->get_pos ().x)
+        player_dir = RIGHT;
+
+      if (player_dir != dir)
+        turn_around ();
+    }
+  }
+
   WalkingBadguy::active_update(elapsed_time);
 }