[cppcheck] Part 1: Performance
[supertux.git] / src / object / infoblock.cpp
index 3d262df..d81fc93 100644 (file)
 #include "video/drawing_context.hpp"
 #include "sprite/sprite.hpp"
 
-namespace {
-const float SCROLL_DELAY = 0.5;
-const float SCROLL_DISTANCE = 16;
-const float WIDTH = 400;
-const float HEIGHT = 200;
-}
-
 InfoBlock::InfoBlock(const Reader& lisp) :
-  Block(sprite_manager->create("images/objects/bonus_block/infoblock.sprite")), 
+  Block(SpriteManager::current()->create("images/objects/bonus_block/infoblock.sprite")),
   message(),
-  shown_pct(0), 
+  shown_pct(0),
   dest_pct(0),
   lines(),
   lines_height()
@@ -60,7 +53,7 @@ InfoBlock::InfoBlock(const Reader& lisp) :
 
 InfoBlock::~InfoBlock()
 {
-  for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); i++) {
+  for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); ++i) {
     delete *i;
   }
 }
@@ -80,8 +73,8 @@ InfoBlock::hit(Player& player)
     // first hide all other InfoBlocks' messages in same sector
     Sector* parent = Sector::current();
     if (!parent) return;
-    for (Sector::GameObjects::iterator i = parent->gameobjects.begin(); i != parent->gameobjects.end(); i++) {
-      InfoBlock* block = dynamic_cast<InfoBlock*>(*i);
+    for (Sector::GameObjects::iterator i = parent->gameobjects.begin(); i != parent->gameobjects.end(); ++i) {
+      InfoBlock* block = dynamic_cast<InfoBlock*>(i->get());
       if (!block) continue;
       if (block != this) block->hide_message();
     }
@@ -94,6 +87,18 @@ InfoBlock::hit(Player& player)
   }
 }
 
+HitResponse
+InfoBlock::collision(GameObject& other, const CollisionHit& hit_)
+{
+  Player* player = dynamic_cast<Player*> (&other);
+  if (player)
+  {
+    if (player->does_buttjump)
+      InfoBlock::hit(*player);
+  }
+  return Block::collision(other, hit_);
+}
+
 Player*
 InfoBlock::get_nearest_player()
 {
@@ -115,7 +120,7 @@ InfoBlock::update(float delta)
 
   if (delta == 0) return;
 
-  // hide message if player is too far away or above infoblock
+  // hide message if player is too far away
   if (dest_pct > 0) {
     Player* player = get_nearest_player();
     if (player) {
@@ -123,7 +128,7 @@ InfoBlock::update(float delta)
       Vector p2 = player->get_pos() + (player->get_bbox().p2 - player->get_bbox().p1) / 2;
       Vector dist = (p2 - p1);
       float d = dist.norm();
-      if (d > 128 || dist.y < 0) dest_pct = 0;
+      if (d > 128) dest_pct = 0;
     }
   }