use spike flag again and don't replace spikes with objects
[supertux.git] / src / badguy / yeti.cpp
index 2bbf5d7..50aa888 100644 (file)
 //  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>
 
 #include <float.h>
-#include "yeti.h"
-#include "object/camera.h"
-#include "yeti_stalactite.h"
-#include "bouncing_snowball.h"
+#include <sstream>
+#include <memory>
+#include "yeti.hpp"
+#include "object/camera.hpp"
+#include "yeti_stalactite.hpp"
+#include "bouncing_snowball.hpp"
+#include "game_session.hpp"
+#include "scripting/script_interpreter.hpp"
 
 static const float JUMP_VEL1 = 250;
 static const float JUMP_VEL2 = 700;
@@ -41,11 +44,16 @@ Yeti::Yeti(const lisp::Lisp& reader)
   reader.get("y", start_position.y);
   bbox.set_size(80, 120);
   sprite = sprite_manager->create("yeti");
+  sprite->set_action("right");
   state = INIT;
   side = LEFT;
+#if 0
   sound_manager->preload_sound("yeti_gna");
   sound_manager->preload_sound("yeti_roar");
+#endif
   hit_points = INITIAL_HITPOINTS;
+  reader.get("dead-script", dead_script);
+  countMe = false;
 }
 
 Yeti::~Yeti()
@@ -56,14 +64,14 @@ void
 Yeti::draw(DrawingContext& context)
 {
   // we blink when we are safe
-  if(safe_timer.started() && size_t(global_time*40)%2)
+  if(safe_timer.started() && size_t(game_time*40)%2)
     return;
 
   BadGuy::draw(context);
 }
 
 void
-Yeti::active_action(float elapsed_time)
+Yeti::active_update(float elapsed_time)
 {
   switch(state) {
     case INIT:
@@ -81,7 +89,7 @@ Yeti::active_action(float elapsed_time)
     case ANGRY_JUMPING:
       if(timer.check()) {
         // jump
-        sound_manager->play_sound("yeti_gna");
+        sound_manager->play("sounds/yeti_gna.wav");
         physic.set_velocity_y(JUMP_VEL1);
       }
       break;
@@ -133,11 +141,17 @@ Yeti::collision_squished(Player& player)
     return true;
 
   player.bounce(*this);
-  sound_manager->play_sound("yeti_roar");
+  sound_manager->play("sounds/yeti_roar.wav");
   hit_points--;
   if(hit_points <= 0) {
-    sprite->set_action("dead"); 
+    sprite->set_action("dead");
     kill_squished(player);
+
+    // start script
+    if(dead_script != "") {
+      ScriptInterpreter::add_script_object(Sector::current(),
+          "Yeti - dead-script", dead_script);
+    }
   } else {
     safe_timer.start(SAFE_TIME);
   }
@@ -190,10 +204,12 @@ Yeti::collision_solid(GameObject& , const CollisionHit& hit)
     } else if(state == GO_LEFT && !timer.started()) {
       side = LEFT;
       summon_snowball();
+      sprite->set_action("right");
       angry_jumping();
     } else if(state == GO_RIGHT && !timer.started()) {
       side = RIGHT;
       summon_snowball();
+      sprite->set_action("left");
       angry_jumping();
     } else if(state == ANGRY_JUMPING) {
       if(!timer.started()) {