Added a common set of bridge funcs for Leveleditor and Sector to create game objects.
[supertux.git] / src / object / coin.cpp
index 04beb66..359b452 100644 (file)
@@ -5,7 +5,10 @@
 #include "video/drawing_context.h"
 #include "special/sprite_manager.h"
 #include "player.h"
+#include "sector.h"
 #include "scene.h"
+#include "gameobjs.h"
+#include "statistics.h"
 
 Coin::Coin(const Vector& pos)
 {
@@ -30,15 +33,23 @@ Coin::draw(DrawingContext& context)
   sprite->draw(context, get_pos(), LAYER_TILES);
 }
 
+void
+Coin::collect()
+{
+  Sector::current()->player->get_status().incCoins();
+  Sector::current()->add_object(new BouncyCoin(get_pos()));
+  global_stats.add_points(COINS_COLLECTED_STAT, 1);
+  remove_me();
+}
+
 HitResponse
-Coin::collision(GameObject& other, const CollisionHit& hit)
+Coin::collision(GameObject& other, const CollisionHit& )
 {
   Player* player = dynamic_cast<Player*>(&other);
   if(player == 0)
     return ABORT_MOVE;
 
-  player->get_status().incCoins();
-  remove_me();
+  collect();
   return ABORT_MOVE;
 }