Hacked together a "coin losing" effect when Tux is killed.
authorOndřej Hošek <ondra.hosek@gmail.com>
Wed, 12 Apr 2006 18:59:59 +0000 (18:59 +0000)
committerOndřej Hošek <ondra.hosek@gmail.com>
Wed, 12 Apr 2006 18:59:59 +0000 (18:59 +0000)
SVN-Revision: 3320

src/object/player.cpp
src/object/player.hpp

index 01167e1..f453f50 100644 (file)
@@ -100,6 +100,33 @@ TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
     feet->draw(context, pos, layer-2);
 }
 
+FallingCoin::FallingCoin(const Vector& start_position, const int vel_x)
+{
+  pos = start_position;
+  sprite = sprite_manager->create("images/objects/coin/coin.sprite");
+  physic.set_velocity_y(800);
+  physic.set_velocity_x(vel_x);
+}
+
+FallingCoin::~FallingCoin()
+{
+  delete sprite;
+}
+
+void
+FallingCoin::draw(DrawingContext& context)
+{
+  sprite->draw(context, pos, LAYER_OBJECTS + 5);
+}
+
+void
+FallingCoin::update(float elapsed_time)
+{
+  pos += physic.get_movement(elapsed_time);
+  if (pos.y > SCREEN_HEIGHT)
+    remove_me();
+}
+
 Player::Player(PlayerStatus* _player_status)
   : player_status(_player_status), grabbed_object(0)
 {
@@ -856,6 +883,13 @@ Player::kill(HurtMode mode)
     }
   else
     {
+      srand(time(0));
+      int i;
+      for (i = 0; (i < 5) && (i < player_status->coins); i++)
+      {
+        // the numbers: starting x, starting y, velocity y
+        Sector::current()->add_object(new FallingCoin(get_pos() + Vector(rand()%5, rand()%50 - 32), rand()%200 - 100));
+      }
       physic.enable_gravity(true);
       physic.set_acceleration(0, 0);
       physic.set_velocity(0, 700);
index eb5ab8a..d7326cd 100644 (file)
@@ -34,6 +34,7 @@
 #include "display_effect.hpp"
 #include "script_interface.hpp"
 #include "console.hpp"
+#include "coin.hpp"
 
 class BadGuy;
 class Portable;
@@ -79,6 +80,20 @@ extern TuxBodyParts* big_tux;
 extern TuxBodyParts* fire_tux;
 extern TuxBodyParts* ice_tux;
 
+class FallingCoin : public GameObject
+{
+public:
+  FallingCoin(const Vector& start_position, const int x_vel);
+  ~FallingCoin();
+
+  void draw(DrawingContext& context);
+  void update(float elapsed_time);
+private:
+  Vector  pos;
+  Sprite* sprite;
+  Physic  physic;
+};
+
 class Player : public MovingObject, public Scripting::Player, public ScriptInterface
 {
 public: