Replaced std::auto_ptr<> with std::unique_ptr<>
[supertux.git] / src / badguy / kugelblitz.cpp
index b3eee37..c1c7742 100644 (file)
@@ -22,6 +22,7 @@
 #include "object/camera.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"
@@ -39,12 +40,17 @@ Kugelblitz::Kugelblitz(const Reader& reader) :
   movement_timer(),
   lifetime(),
   direction(),
-  state()
+  state(),
+  light(0.0f,0.0f,0.0f),
+  lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"))
 {
   reader.get("x", start_position.x);
   sprite->set_action("falling");
   physic.enable_gravity(false);
   countMe = false;
+  
+  lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+  lightsprite->set_color(Color(0.2f, 0.1f, 0.0f));  
 }
 
 void
@@ -105,8 +111,8 @@ Kugelblitz::hit(const CollisionHit& hit)
     sprite->set_action("flying");
     physic.set_velocity_y(0);
     //Set random initial speed and direction
-    direction = systemRandom.rand(2)? 1: -1;
-    int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction;
+    direction = gameRandom.rand(2)? 1: -1;
+    int speed = (BASE_SPEED + (gameRandom.rand(RAND_SPEED))) * direction;
     physic.set_velocity_x(speed);
     movement_timer.start(MOVETIME);
     lifetime.start(LIFETIME);
@@ -128,7 +134,7 @@ Kugelblitz::active_update(float elapsed_time)
     if (groundhit_pos_set) {
       if (movement_timer.check()) {
         if (direction == 1) direction = -1; else direction = 1;
-        int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction;
+        int speed = (BASE_SPEED + (gameRandom.rand(RAND_SPEED))) * direction;
         physic.set_velocity_x(speed);
         movement_timer.start(MOVETIME);
       }
@@ -150,6 +156,22 @@ Kugelblitz::active_update(float elapsed_time)
 }
 
 void
+Kugelblitz::draw(DrawingContext& context)
+{
+  sprite->draw(context, get_pos(), layer);
+  
+  //Only draw light in dark areas
+  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
 Kugelblitz::kill_fall()
 {
 }