Haywire: Implemented a first version of the "crazy bomb".
authorflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sun, 28 Feb 2010 09:32:24 +0000 (09:32 +0000)
committerflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sun, 28 Feb 2010 09:32:24 +0000 (09:32 +0000)
Sprites and bode are based on Mr. Bomb, of course. Haywire behaves like Mr.
Bomb until jumped upon. If jumped upon, he will run around (walk with twice the
speed) for five seconds, then explode. While running around Haywire will
iterate through a number of different colors.

When jumped upon - even when already ticking - Haywire is stunned for half a
second. This does not interrupt the explosion timer, though.

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

14 files changed:
data/images/creatures/haywire/haywire.sprite [new file with mode: 0644]
data/images/creatures/haywire/iced-left.png [new file with mode: 0644]
data/images/creatures/haywire/left-0.png [new file with mode: 0644]
data/images/creatures/haywire/left-1.png [new file with mode: 0644]
data/images/creatures/haywire/left-2.png [new file with mode: 0644]
data/images/creatures/haywire/ticking-0.png [new file with mode: 0644]
data/images/creatures/haywire/ticking-1.png [new file with mode: 0644]
data/images/creatures/haywire/ticking-2.png [new file with mode: 0644]
data/images/creatures/haywire/ticking-3.png [new file with mode: 0644]
data/images/creatures/haywire/ticking-4.png [new file with mode: 0644]
data/images/creatures/haywire/ticking-5.png [new file with mode: 0644]
src/badguy/haywire.cpp [new file with mode: 0644]
src/badguy/haywire.hpp [new file with mode: 0644]
src/supertux/object_factory.cpp

diff --git a/data/images/creatures/haywire/haywire.sprite b/data/images/creatures/haywire/haywire.sprite
new file mode 100644 (file)
index 0000000..14ec197
--- /dev/null
@@ -0,0 +1,43 @@
+(supertux-sprite
+ (action
+  (name "left")
+  (fps 10.0)
+  (hitbox 5 8 32 32)
+  (images "left-0.png"
+          "left-1.png"
+          "left-2.png"
+          "left-1.png"))
+
+ (action
+  (name "right")
+  (fps 10.0)
+  (hitbox 5 8 32 32)
+  (mirror-action "left"))
+ (action
+  (name "iced-left")
+  (hitbox 3 12 31.8 31.8)
+  (images "iced-left.png"))
+ (action
+  (name "iced-right")
+  (hitbox 7 12 31.8 31.8)
+  (mirror-action "iced-left"))
+
+ (action
+  (name "ticking-left")
+  (fps 10.0)
+  (hitbox 5 8 32 32)
+  (images "ticking-0.png"
+          "ticking-1.png"
+          "ticking-2.png"
+          "ticking-3.png"
+          "ticking-4.png"
+          "ticking-5.png"))
+
+ (action
+  (name "ticking-right")
+  (fps 10.0)
+  (hitbox 5 8 32 32)
+  (mirror-action "ticking-left"))
+)
diff --git a/data/images/creatures/haywire/iced-left.png b/data/images/creatures/haywire/iced-left.png
new file mode 100644 (file)
index 0000000..d6021ba
Binary files /dev/null and b/data/images/creatures/haywire/iced-left.png differ
diff --git a/data/images/creatures/haywire/left-0.png b/data/images/creatures/haywire/left-0.png
new file mode 100644 (file)
index 0000000..ca50a01
Binary files /dev/null and b/data/images/creatures/haywire/left-0.png differ
diff --git a/data/images/creatures/haywire/left-1.png b/data/images/creatures/haywire/left-1.png
new file mode 100644 (file)
index 0000000..ee83bdc
Binary files /dev/null and b/data/images/creatures/haywire/left-1.png differ
diff --git a/data/images/creatures/haywire/left-2.png b/data/images/creatures/haywire/left-2.png
new file mode 100644 (file)
index 0000000..47f4cbf
Binary files /dev/null and b/data/images/creatures/haywire/left-2.png differ
diff --git a/data/images/creatures/haywire/ticking-0.png b/data/images/creatures/haywire/ticking-0.png
new file mode 100644 (file)
index 0000000..56cf415
Binary files /dev/null and b/data/images/creatures/haywire/ticking-0.png differ
diff --git a/data/images/creatures/haywire/ticking-1.png b/data/images/creatures/haywire/ticking-1.png
new file mode 100644 (file)
index 0000000..9e7912a
Binary files /dev/null and b/data/images/creatures/haywire/ticking-1.png differ
diff --git a/data/images/creatures/haywire/ticking-2.png b/data/images/creatures/haywire/ticking-2.png
new file mode 100644 (file)
index 0000000..e61c8f4
Binary files /dev/null and b/data/images/creatures/haywire/ticking-2.png differ
diff --git a/data/images/creatures/haywire/ticking-3.png b/data/images/creatures/haywire/ticking-3.png
new file mode 100644 (file)
index 0000000..bcbad97
Binary files /dev/null and b/data/images/creatures/haywire/ticking-3.png differ
diff --git a/data/images/creatures/haywire/ticking-4.png b/data/images/creatures/haywire/ticking-4.png
new file mode 100644 (file)
index 0000000..a1215f9
Binary files /dev/null and b/data/images/creatures/haywire/ticking-4.png differ
diff --git a/data/images/creatures/haywire/ticking-5.png b/data/images/creatures/haywire/ticking-5.png
new file mode 100644 (file)
index 0000000..ec3abc9
Binary files /dev/null and b/data/images/creatures/haywire/ticking-5.png differ
diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp
new file mode 100644 (file)
index 0000000..ebcf3f1
--- /dev/null
@@ -0,0 +1,162 @@
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//  Copyright (C) 2010 Florian Forster <supertux at octo.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "audio/sound_manager.hpp"
+#include "badguy/bomb.hpp"
+#include "badguy/haywire.hpp"
+#include "object/explosion.hpp"
+#include "object/player.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
+#include "util/reader.hpp"
+
+#define TIME_EXPLOSION 5.0
+#define TIME_STUNNED   0.5
+
+Haywire::Haywire(const Reader& reader) :
+  WalkingBadguy(reader, "images/creatures/haywire/haywire.sprite", "left", "right"),
+  is_exploding(false),
+  is_stunned(false)
+{
+  walk_speed = 80;
+  max_drop_height = 16;
+
+  //Prevent stutter when Tux jumps on Mr Bomb
+  sound_manager->preload("sounds/explosion.wav");
+
+  //Check if we need another sprite
+  if( !reader.get( "sprite", sprite_name ) ){
+    return;
+  }
+  if( sprite_name == "" ){
+    sprite_name = "images/creatures/haywire/haywire.sprite";
+    return;
+  }
+  //Replace sprite
+  sprite = sprite_manager->create( sprite_name );
+}
+
+/* Haywire created by a dispenser always gets default sprite atm.*/
+Haywire::Haywire(const Vector& pos, Direction d) :
+  WalkingBadguy(pos, d, "images/creatures/haywire/haywire.sprite", "left", "right"),
+  is_exploding(false),
+  is_stunned(false)
+{
+  walk_speed = 80;
+  max_drop_height = 16;
+  sound_manager->preload("sounds/explosion.wav");
+}
+
+HitResponse
+Haywire::collision(GameObject& object, const CollisionHit& hit)
+{
+  return WalkingBadguy::collision(object, hit);
+}
+
+HitResponse
+Haywire::collision_player(Player& player, const CollisionHit& hit)
+{
+  return WalkingBadguy::collision_player(player, hit);
+}
+
+bool
+Haywire::collision_squished(GameObject& object)
+{
+  Player* player = dynamic_cast<Player*>(&object);
+  if (player && player->is_invincible()) {
+    player->bounce (*this);
+    kill_fall();
+    return true;
+  }
+
+  if (is_stunned) {
+    player->bounce (*this);
+    return true;
+  }
+
+  if (!is_exploding) {
+    set_action ((dir == LEFT) ? "ticking-left" : "ticking-right", /* loops = */ -1);
+    walk_left_action = "ticking-left";
+    walk_right_action = "ticking-right";
+    set_walk_speed (160);
+    time_until_explosion = TIME_EXPLOSION;
+    is_exploding = true;
+  }
+
+  time_stunned = TIME_STUNNED;
+  is_stunned = true;
+
+  player->bounce (*this);
+  return true;
+}
+
+void
+Haywire::active_update(float elapsed_time)
+{
+  if (is_exploding) {
+    if (elapsed_time >= time_until_explosion) {
+      kill_fall ();
+      return;
+    }
+    else
+      time_until_explosion -= elapsed_time;
+  }
+
+  if (is_stunned) {
+    if (time_stunned > elapsed_time) {
+      time_stunned -= elapsed_time;
+      return;
+    }
+    else { /* if (time_stunned <= elapsed_time) */
+      elapsed_time -= time_stunned;
+      time_stunned = 0.0;
+      is_stunned = false;
+    }
+  }
+
+  WalkingBadguy::active_update(elapsed_time);
+}
+
+void
+Haywire::kill_fall()
+{
+  if(is_valid()) {
+    remove_me();
+    Explosion* explosion = new Explosion(get_bbox().get_middle());
+    Sector::current()->add_object(explosion);
+  }
+
+  run_dead_script();
+}
+
+void
+Haywire::freeze()
+{
+  WalkingBadguy::freeze();
+  sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
+}
+
+bool
+Haywire::is_freezable() const
+{
+  return true;
+}
+
+/* vim: set sw=2 sts=2 et : */
+/* EOF */
diff --git a/src/badguy/haywire.hpp b/src/badguy/haywire.hpp
new file mode 100644 (file)
index 0000000..7acb3cf
--- /dev/null
@@ -0,0 +1,50 @@
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//  Copyright (C) 2010 Florian Forster <supertux at octo.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_BADGUY_HAYWIRE_HPP
+#define HEADER_SUPERTUX_BADGUY_HAYWIRE_HPP
+
+#include "badguy/walking_badguy.hpp"
+
+class Haywire : public WalkingBadguy
+{
+public:
+  Haywire(const Reader& reader);
+  Haywire(const Vector& pos, Direction d);
+
+  void kill_fall();
+  HitResponse collision(GameObject& object, const CollisionHit& hit);
+  HitResponse collision_player(Player& player, const CollisionHit& hit);
+
+  void active_update(float elapsed_time);
+
+  void freeze();
+  bool is_freezable() const;
+
+protected:
+  bool collision_squished(GameObject& object);
+
+private:
+  bool is_exploding;
+  float time_until_explosion;
+  bool is_stunned;
+  float time_stunned;
+};
+
+#endif /* HEADER_SUPERTUX_BADGUY_HAYWIRE_HPP */
+
+/* EOF */
index 669bdf4..5ee076e 100644 (file)
@@ -36,6 +36,7 @@
 #include "badguy/flame.hpp"
 #include "badguy/flyingsnowball.hpp"
 #include "badguy/ghosttree.hpp"
+#include "badguy/haywire.hpp"
 #include "badguy/igel.hpp"
 #include "badguy/jumpy.hpp"
 #include "badguy/kamikazesnowball.hpp"
@@ -182,6 +183,7 @@ ObjectFactory::init_factories()
   add_factory<Flame>("flame");
   add_factory<FlyingSnowBall>("flyingsnowball");
   add_factory<GhostTree>("ghosttree");
+  add_factory<Haywire>("haywire");
   add_factory<Igel>("igel");
   add_factory<Jumpy>("jumpy");
   add_factory<KamikazeSnowball>("kamikazesnowball");