New sound effects
[supertux.git] / src / badguy / flame.cpp
index 0956160..d0406ea 100644 (file)
 
 #include "badguy/flame.hpp"
 
+#include <math.h>
+
 #include "audio/sound_manager.hpp"
-#include "lisp/lisp.hpp"
+#include "math/random_generator.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "object/sprite_particle.hpp"
 #include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
+#include "util/reader.hpp"
 
-#include <math.h>
-
-static const std::string SOUNDFILE = "sounds/flame.wav";
+static const std::string FLAME_SOUND = "sounds/flame.wav";
 
 Flame::Flame(const Reader& reader) :
-  BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), 
-  angle(0), 
-  radius(100), 
+  BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS),
+  angle(0),
+  radius(100),
   speed(2),
+  light(0.0f,0.0f,0.0f),
+  lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")),
   sound_source()
 {
   reader.get("radius", radius);
@@ -36,9 +43,12 @@ Flame::Flame(const Reader& reader) :
   bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
                       start_position.y + sin(angle) * radius));
   countMe = false;
-  sound_manager->preload(SOUNDFILE);
+  SoundManager::current()->preload(FLAME_SOUND);
 
   set_colgroup_active(COLGROUP_TOUCHABLE);
+
+  lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+  lightsprite->set_color(Color(0.21f, 0.13f, 0.08f));
 }
 
 void
@@ -50,12 +60,32 @@ Flame::active_update(float elapsed_time)
   movement = newpos - get_pos();
 
   sound_source->set_position(get_pos());
+
+  if (sprite->get_action() == "fade" && sprite->animation_done()) remove_me();
+}
+
+void
+Flame::draw(DrawingContext& context)
+{
+  //Draw the Sprite.
+  sprite->draw(context, get_pos(), LAYER_OBJECTS);
+  //Draw the light if dark
+  if(true){
+    context.get_light( get_bbox().get_middle(), &light );
+    if (light.red + light.green < 2.0){
+      context.push_target();
+      context.set_target(DrawingContext::LIGHTMAP);
+      sprite->draw(context, get_pos(), layer);
+      lightsprite->draw(context, get_bbox().get_middle(), 0);
+      context.pop_target();
+    }
+  }
 }
 
 void
 Flame::activate()
 {
-  sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
+  sound_source = SoundManager::current()->create_sound_source(FLAME_SOUND);
   sound_source->set_position(get_pos());
   sound_source->set_looping(true);
   sound_source->set_gain(2.0);
@@ -69,11 +99,31 @@ Flame::deactivate()
   sound_source.reset();
 }
 
+
 void
 Flame::kill_fall()
 {
 }
 
-IMPLEMENT_FACTORY(Flame, "flame");
+void
+Flame::freeze()
+{
+  SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
+  sprite->set_action("fade", 1);
+  Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
+                                                                 "default",
+                                                                 bbox.get_middle(), ANCHOR_MIDDLE,
+                                                                 Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2));
+  set_group(COLGROUP_DISABLED);
+
+  // start dead-script
+  run_dead_script();
+}
+
+bool
+Flame::is_freezable() const
+{
+  return true;
+}
 
 /* EOF */