fade out console
[supertux.git] / src / badguy / badguy.cpp
index bafa67b..aa772a2 100644 (file)
 #include "tile.hpp"
 #include "statistics.hpp"
 #include "game_session.hpp"
+#include "log.hpp"
 
 static const float SQUISH_TIME = 2;
 static const float X_OFFSCREEN_DISTANCE = 1600;
 static const float Y_OFFSCREEN_DISTANCE = 1200;
 
 BadGuy::BadGuy()
-  : countMe(true), sprite(0), dir(LEFT), state(STATE_INIT)
+  : countMe(true), sprite(0), remove_out_of_bounds(true), dir(LEFT), state(STATE_INIT)
 {
   set_group(COLGROUP_DISABLED);
 }
@@ -61,7 +62,7 @@ BadGuy::draw(DrawingContext& context)
 void
 BadGuy::update(float elapsed_time)
 {
-  if(!Sector::current()->inside(bbox)) {
+  if(!Sector::current()->inside(bbox) && remove_out_of_bounds) {
     remove_me();
     return;
   }
@@ -104,7 +105,7 @@ BadGuy::deactivate()
 void
 BadGuy::save(lisp::Writer& )
 {
-       std::cout << "Warning: tried to write out a generic badguy." << std::endl;
+       log_warning << "tried to write out a generic badguy" << std::endl;
 }
 
 void
@@ -164,21 +165,27 @@ BadGuy::collision_solid(GameObject& , const CollisionHit& )
 }
 
 HitResponse
-BadGuy::collision_player(Player& player, const CollisionHit& )
+BadGuy::collision_player(Player& player, const CollisionHit& hit)
 {
   if(player.is_invincible()) {
     kill_fall();
     return ABORT_MOVE;
   }
+
+  printf("PlayerHit: GT %3.1f PM: %3.1f %3.1f BM: %3.1f %3.1f Hit: %3.1f %3.1f\n",
+          game_time,
+          player.get_movement().x, player.get_movement().y,
+          get_movement().x, get_movement().y,
+          hit.normal.x, hit.normal.y);
   // hit from above?
-  if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y <
+  if(player.get_movement().y /*- get_movement().y*/ > 0 
+          && player.get_bbox().p2.y <
       (get_bbox().p1.y + get_bbox().p2.y) / 2) {
     // if it's not possible to squish us, then this will hurt
-    if(!collision_squished(player))
-      player.kill(Player::SHRINK);
-
-    return FORCE_MOVE;
+    if(collision_squished(player))
+      return ABORT_MOVE;
   }
+
   player.kill(Player::SHRINK);
   return FORCE_MOVE;
 }
@@ -347,3 +354,17 @@ BadGuy::may_fall_off_platform()
   // Watch out there buddy, you might take a sticky end!
   return true;
 }
+
+Player* 
+BadGuy::get_nearest_player()
+{
+  // FIXME: does not really return nearest player
+
+  std::vector<Player*> players = Sector::current()->get_players();
+  for (std::vector<Player*>::iterator playerIter = players.begin(); playerIter != players.end(); ++playerIter) {
+    Player* player = *playerIter;
+    return player;
+  }
+
+  return 0;
+}