Replaced Ref and RefCounter with std::shared_ptr<>
[supertux.git] / src / badguy / igel.cpp
index cd37105..457b22d 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux - Badguy "Igel"
 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
 //
-//  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 2
-//  of the License, or (at your option) any later version.
+//  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
 //  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, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#include <config.h>
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "igel.hpp"
-#include "object/block.hpp"
-#include "sector.hpp"
+#include "badguy/igel.hpp"
 #include "object/bullet.hpp"
+#include "supertux/sector.hpp"
 
-#include "lisp/writer.hpp"
-#include "object_factory.hpp"
+#include "supertux/object_factory.hpp"
 
 namespace {
-  const float WALKSPEED = 80; /**< speed at which we walk around */
-  const float TURN_RECOVER_TIME = 0.5; /**< seconds before we will again turn around when shot at */
-  const float RANGE_OF_VISION = 256; /**< range in px at which we can see bullets */
-}
 
-Igel::Igel(const lisp::Lisp& reader)
-  : WalkingBadguy(reader, "images/creatures/igel/igel.sprite", "walking-left", "walking-right")
-{
-  walk_speed = WALKSPEED;
-  max_drop_height = 16;
-}
+const float IGEL_SPEED = 80; /**< speed at which we walk around */
+const float TURN_RECOVER_TIME = 0.5; /**< seconds before we will again turn around when shot at */
+const float RANGE_OF_VISION = 256; /**< range in px at which we can see bullets */
+
+} // namespace
 
-Igel::Igel(const Vector& pos, Direction d)
-  : WalkingBadguy(pos, d, "images/creatures/igel/igel.sprite", "walking-left", "walking-right")
+Igel::Igel(const Reader& reader) :
+  WalkingBadguy(reader, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"),
+  turn_recover_timer()
 {
-  walk_speed = WALKSPEED;
+  walk_speed = IGEL_SPEED;
   max_drop_height = 16;
 }
 
-void
-Igel::write(lisp::Writer& writer)
+Igel::Igel(const Vector& pos, Direction d) :
+  WalkingBadguy(pos, d, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"),
+  turn_recover_timer()
 {
-  writer.start_list("igel");
-  WalkingBadguy::write(writer);
-  writer.end_list("igel");
+  walk_speed = IGEL_SPEED;
+  max_drop_height = 16;
 }
 
 void
@@ -71,8 +60,8 @@ Igel::turn_around()
 bool
 Igel::can_see(const MovingObject& o)
 {
-  Rect mb = get_bbox();
-  Rect ob = o.get_bbox();
+  Rectf mb = get_bbox();
+  Rectf ob = o.get_bbox();
 
   bool inReach_left = ((ob.p2.x < mb.p1.x) && (ob.p2.x >= mb.p1.x-((dir == LEFT) ? RANGE_OF_VISION : 0)));
   bool inReach_right = ((ob.p1.x > mb.p2.x) && (ob.p1.x <= mb.p2.x+((dir == RIGHT) ? RANGE_OF_VISION : 0)));
@@ -90,7 +79,7 @@ Igel::active_update(float elapsed_time)
   // check if we see a fire bullet
   Sector* sector = Sector::current();
   for (Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) {
-    Bullet* bullet = dynamic_cast<Bullet*>(*i);
+    Bullet* bullet = dynamic_cast<Bullet*>(i->get());
     if (!bullet) continue;
     if (bullet->get_type() != FIRE_BONUS) continue;
     if (can_see(*bullet)) wants_to_flee = true;
@@ -110,8 +99,9 @@ Igel::active_update(float elapsed_time)
 HitResponse
 Igel::collision_bullet(Bullet& bullet, const CollisionHit& hit)
 {
-  // default reaction if hit on front side
-  if (((dir == LEFT) && hit.left) || ((dir == RIGHT) && hit.right)) {
+  // default reaction if hit on front side or for freeze and unfreeze
+  if (((dir == LEFT) && hit.left) || ((dir == RIGHT) && hit.right) ||
+    (bullet.get_type() == ICE_BONUS) || ((bullet.get_type() == FIRE_BONUS) && (frozen))) {
     return BadGuy::collision_bullet(bullet, hit);
   }
 
@@ -121,10 +111,16 @@ Igel::collision_bullet(Bullet& bullet, const CollisionHit& hit)
 }
 
 bool
+Igel::is_freezable() const
+{
+  return true;
+}
+
+bool
 Igel::collision_squished(GameObject& )
 {
   // this will hurt
   return false;
 }
 
-IMPLEMENT_FACTORY(Igel, "igel")
+/* EOF */