Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / badguy / mole.cpp
index 765319d..1391d2a 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux - Mole Badguy
 //  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.
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <config.h>
+#include "audio/sound_manager.hpp"
+#include "badguy/mole.hpp"
+#include "badguy/mole_rock.hpp"
+#include "math/random_generator.hpp"
+#include "sprite/sprite.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
 
-#include "mole.hpp"
-#include "mole_rock.hpp"
-#include "tile.hpp"
-#include "object/tilemap.hpp"
-#include "random_generator.hpp"
-#include "log.hpp"
-#include "level.hpp"
+#include <math.h>
 
-static const float IDLE_TIME = 0.2; /**< time to wait before and after throwing */
-static const float THROW_TIME = 4.6; /**< time to spend throwing */
+static const float IDLE_TIME = 0.2f; /**< time to wait before and after throwing */
+static const float THROW_TIME = 4.6f; /**< time to spend throwing */
 static const float THROW_INTERVAL = 1; /**< time between two thrown rocks */
 static const float THROW_VELOCITY = 400; /**< initial velocity of thrown rocks */
 
-Mole::Mole(const lisp::Lisp& reader)
-       : BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING)
+Mole::Mole(const Reader& reader) :
+  BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), 
+  state(PRE_THROWING),
+  timer(),
+  throw_timer()
 {
   physic.enable_gravity(false);
+  sound_manager->preload("sounds/fall.wav");
+  sound_manager->preload("sounds/squish.wav");
+  sound_manager->preload("sounds/dartfire.wav");
 }
 
-Mole::Mole(const Vector& pos)
-       : BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING)
+Mole::Mole(const Vector& pos) :
+  BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), 
+  state(PRE_THROWING),
+  timer(),
+  throw_timer()
 {
   physic.enable_gravity(false);
-}
-
-void
-Mole::write(lisp::Writer& writer)
-{
-  writer.start_list("mole");
-  writer.write_float("x", start_position.x);
-  writer.write_float("y", start_position.y);
-  writer.end_list("mole");
+  sound_manager->preload("sounds/fall.wav");
+  sound_manager->preload("sounds/squish.wav");
+  sound_manager->preload("sounds/dartfire.wav");
 }
 
 void
@@ -64,7 +64,7 @@ Mole::kill_fall()
 {
   set_state(DEAD);
   sound_manager->play("sounds/fall.wav", get_pos());
-  if (countMe) Sector::current()->get_level()->stats.badguys++;
+  run_dead_script();
 }
 
 HitResponse
@@ -74,11 +74,11 @@ Mole::collision_badguy(BadGuy& , const CollisionHit& )
 }
 
 bool
-Mole::collision_squished(Player& )
+Mole::collision_squished(GameObject& )
 {
   set_state(DEAD);
   sound_manager->play("sounds/squish.wav", get_pos());
-  if (countMe) Sector::current()->get_level()->stats.badguys++;
+  run_dead_script();
   return true;
 }
 
@@ -104,26 +104,26 @@ Mole::active_update(float elapsed_time)
   switch (state) {
     case PRE_THROWING:
       if (timer.check()) {
-       set_state(THROWING);
+        set_state(THROWING);
       }
       break;
     case THROWING:
       if (throw_timer.check()) {
         throw_rock();
-       throw_timer.start(THROW_INTERVAL);
+        throw_timer.start(THROW_INTERVAL);
       }
       if (timer.check()) {
-       set_state(POST_THROWING);
+        set_state(POST_THROWING);
       }
       break;
     case POST_THROWING:
       if (timer.check()) {
-       set_state(PEEKING);
+        set_state(PEEKING);
       }
       break;
     case PEEKING:
       if (sprite->animation_done()) {
-       set_state(PRE_THROWING);
+        set_state(PRE_THROWING);
       }
       break;
     case DEAD:
@@ -132,38 +132,39 @@ Mole::active_update(float elapsed_time)
 
 }
 
-void 
+void
 Mole::set_state(MoleState new_state)
 {
   switch (new_state) {
     case PRE_THROWING:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       timer.start(IDLE_TIME);
       break;
     case THROWING:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       timer.start(THROW_TIME);
       throw_timer.start(THROW_INTERVAL);
       break;
     case POST_THROWING:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       timer.start(IDLE_TIME);
       break;
     case PEEKING:
       sprite->set_action("peeking", 1);
-      set_group(COLGROUP_STATIC);
+      set_colgroup_active(COLGROUP_STATIC);
       break;
     case DEAD:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       break;
   }
 
   state = new_state;
 }
 
-IMPLEMENT_FACTORY(Mole, "mole")
+IMPLEMENT_FACTORY(Mole, "mole");
 
+/* EOF */