Fixed trailing whitespaces in all(?) source files of supertux, also fixed some svn...
[supertux.git] / src / object / bullet.cpp
index ef7b52f..c761735 100644 (file)
@@ -33,17 +33,21 @@ namespace {
   const float BULLET_STARTING_YM = 0;
 }
 
-Bullet::Bullet(const Vector& pos, float xm, int dir)
-  : life_count(3)
+Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type)
+  : life_count(3), type(type)
 {
-  sprite.reset(sprite_manager->create("images/objects/bullets/firebullet.sprite"));
-  
-  bbox.set_pos(pos);
-  bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
-
   float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
   physic.set_velocity_x(speed + xm);
-  physic.set_velocity_y(BULLET_STARTING_YM);
+
+  if(type == FIRE_BONUS) {
+    sprite.reset(sprite_manager->create("images/objects/bullets/firebullet.sprite"));
+  } else if(type == ICE_BONUS) {
+    life_count = 10;
+    sprite.reset(sprite_manager->create("images/objects/bullets/icebullet.sprite"));
+  }
+
+  bbox.set_pos(pos);
+  bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
 }
 
 Bullet::~Bullet()
@@ -53,14 +57,7 @@ Bullet::~Bullet()
 void
 Bullet::update(float elapsed_time)
 {
-  // @not completely framerate independant :-/
-  physic.set_velocity_y(physic.get_velocity_y() + 50 * elapsed_time);
-
-  if(physic.get_velocity_y() > 900)
-    physic.set_velocity_y(900);
-  else if(physic.get_velocity_y() < -900)
-    physic.set_velocity_y(-900);
-
+  // remove bullet when it's offscreen
   float scroll_x =
     Sector::current()->camera->get_translation().x;
   float scroll_y =
@@ -90,14 +87,22 @@ Bullet::collision_solid(const CollisionHit& hit)
     physic.set_velocity_y(-physic.get_velocity_y());
     life_count--;
   } else if(hit.left || hit.right) {
-    remove_me();
+    if(type == ICE_BONUS) {
+      physic.set_velocity_x(-physic.get_velocity_x());
+      life_count--;
+    } else
+      remove_me();
   }
 }
 
+void
+Bullet::ricochet(GameObject& , const CollisionHit& hit)
+{
+  collision_solid(hit);
+}
+
 HitResponse
 Bullet::collision(GameObject& , const CollisionHit& )
 {
   return FORCE_MOVE;
 }
-
-