Added default and cancel button to the Dialog
[supertux.git] / src / object / bullet.cpp
index 2161e3b..46c5260 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "math/random_generator.hpp"
 #include "object/bullet.hpp"
 #include "object/camera.hpp"
+#include "sprite/sprite.hpp"
 #include "sprite/sprite_manager.hpp"
-#include "supertux/main.hpp"
+#include "supertux/globals.hpp"
 #include "supertux/sector.hpp"
 
 namespace {
@@ -25,24 +27,28 @@ const float BULLET_XM = 600;
 const float BULLET_STARTING_YM = 0;
 }
 
-Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type) :
+Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type_) :
   physic(),
-  life_count(3), 
+  life_count(3),
   sprite(),
-  type(type)
+  light(0.0f,0.0f,0.0f),
+  lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")),
+  type(type_)
 {
   float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
   physic.set_velocity_x(speed + xm);
 
   if(type == FIRE_BONUS) {
-    sprite = sprite_manager->create("images/objects/bullets/firebullet.sprite");
-  } else if(type == ICE_BONUS) {
+    sprite = SpriteManager::current()->create("images/objects/bullets/firebullet.sprite");
+    lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+    lightsprite->set_color(Color(0.3f, 0.1f, 0.0f));
+ } else if(type == ICE_BONUS) {
     life_count = 10;
-    sprite = sprite_manager->create("images/objects/bullets/icebullet.sprite");
+    sprite = SpriteManager::current()->create("images/objects/bullets/icebullet.sprite");
   } else {
     log_warning << "Bullet::Bullet called with unknown BonusType" << std::endl;
     life_count = 10;
-    sprite = sprite_manager->create("images/objects/bullets/firebullet.sprite");
+    sprite = SpriteManager::current()->create("images/objects/bullets/firebullet.sprite");
   }
 
   bbox.set_pos(pos);
@@ -56,6 +62,11 @@ Bullet::~Bullet()
 void
 Bullet::update(float elapsed_time)
 {
+  // cause fireball color to flicker randomly
+  if (gameRandom.rand(5) != 0) {
+    lightsprite->set_color(Color(0.3f + gameRandom.rand(10)/100.0f, 0.1f + gameRandom.rand(20)/100.0f, gameRandom.rand(10)/100.0f));
+  } else
+    lightsprite->set_color(Color(0.3f, 0.1f, 0.0f));
   // remove bullet when it's offscreen
   float scroll_x =
     Sector::current()->camera->get_translation().x;
@@ -76,7 +87,19 @@ Bullet::update(float elapsed_time)
 void
 Bullet::draw(DrawingContext& context)
 {
+  //Draw the Sprite.
   sprite->draw(context, get_pos(), LAYER_OBJECTS);
+  //Draw the light if fire and dark
+  if(type == FIRE_BONUS){
+    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_OBJECTS);
+      lightsprite->draw(context, get_bbox().get_middle(), 0);
+      context.pop_target();
+    }
+  }
 }
 
 void