#303: Typo fixes from mathnerd314
[supertux.git] / src / object / gameobjs.cpp
index 78adbbe..a0276ed 100644 (file)
 #include "video/drawing_context.hpp"
 #include "camera.hpp"
 #include "main.hpp"
+#include "random_generator.hpp"
 
-BouncyCoin::BouncyCoin(const Vector& pos)
-  : position(pos)
+/** this controls the time over which a bouncy coin fades */
+static const float FADE_TIME = .2f;
+/** this is the total life time of a bouncy coin */
+static const float LIFE_TIME = .5f;
+
+BouncyCoin::BouncyCoin(const Vector& pos, bool emerge)
+  : position(pos), emerge_distance(0)
 {
-  timer.start(.3);
+  timer.start(LIFE_TIME);
   sprite = sprite_manager->create("images/objects/coin/coin.sprite");
-  sprite->set_action("still");
+
+  if(emerge) {
+    emerge_distance = sprite->get_height();
+  }
 }
 
 BouncyCoin::~BouncyCoin()
@@ -52,7 +61,9 @@ BouncyCoin::~BouncyCoin()
 void
 BouncyCoin::update(float elapsed_time)
 {
-  position.y += -200 * elapsed_time;
+  float dist = -200 * elapsed_time;
+  position.y += dist;
+  emerge_distance += dist;
 
   if(timer.check())
     remove_me();
@@ -61,7 +72,25 @@ BouncyCoin::update(float elapsed_time)
 void
 BouncyCoin::draw(DrawingContext& context)
 {
-  sprite->draw(context, position, LAYER_OBJECTS);
+  float time_left = timer.get_timeleft();
+  bool fading = time_left < FADE_TIME;
+  if(fading) {
+    float alpha = time_left/FADE_TIME;
+    context.push_transform();
+    context.set_alpha(alpha);
+  }
+
+  int layer;
+  if(emerge_distance > 0) {
+    layer = LAYER_OBJECTS - 5;
+  } else {
+    layer = LAYER_OBJECTS + 5;
+  }
+  sprite->draw(context, position, layer);
+
+  if(fading) {
+    context.pop_transform();
+  }
 }
 
 //---------------------------------------------------------------------------
@@ -70,7 +99,7 @@ BrokenBrick::BrokenBrick(Sprite* nsprite,
     const Vector& pos, const Vector& nmovement)
   : sprite(new Sprite(*nsprite)), position(pos), movement(nmovement)
 {
-  timer.start(.2);
+  timer.start(.2f);
 }
 
 BrokenBrick::~BrokenBrick()
@@ -91,7 +120,7 @@ void
 BrokenBrick::draw(DrawingContext& context)
 {
   sprite->draw_part(context,
-      Vector(rand() % 16, rand() % 16), Vector(16, 16),
+      Vector(systemRandom.rand(16), systemRandom.rand(16)), Vector(16, 16),
       position, LAYER_OBJECTS + 1);
 }
 
@@ -100,14 +129,14 @@ BrokenBrick::draw(DrawingContext& context)
 FloatingText::FloatingText(const Vector& pos, const std::string& text_)
   : position(pos), text(text_)
 {
-  timer.start(.1);
+  timer.start(.1f);
   position.x -= text.size() * 8;
 }
 
 FloatingText::FloatingText(const Vector& pos, int score)
   : position(pos)
 {
-  timer.start(.1);
+  timer.start(.1f);
 
   // turn int into a string
   char str[10];
@@ -131,7 +160,7 @@ FloatingText::update(float elapsed_time)
 void
 FloatingText::draw(DrawingContext& context)
 {
-  // make an alpha animation when disapearing
+  // make an alpha animation when disappearing
   int alpha;
   if(timer.get_timeleft() < FADING_TIME)
     alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
@@ -141,7 +170,7 @@ FloatingText::draw(DrawingContext& context)
   context.push_transform();
   context.set_alpha(alpha);
 
-  context.draw_text(gold_text, text, position, LEFT_ALLIGN, LAYER_OBJECTS+1);
+  context.draw_text(gold_text, text, position, ALIGN_LEFT, LAYER_OBJECTS+1);
 
   context.pop_transform();
 }
@@ -151,7 +180,7 @@ Sprite *img_smoke_cloud = 0;
 SmokeCloud::SmokeCloud(const Vector& pos)
   : position(pos)
 {
-  timer.start(.3);
+  timer.start(.3f);
   sprite = sprite_manager->create("images/objects/particles/stomp.sprite");
 }
 
@@ -174,4 +203,3 @@ SmokeCloud::draw(DrawingContext& context)
 {
   sprite->draw(context, position, LAYER_OBJECTS+1);
 }
-