// $Id$
-//
+//
// SuperTux
-// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
#include <config.h>
#include "badguy.hpp"
#include "tile.hpp"
#include "statistics.hpp"
#include "game_session.hpp"
+#include "log.hpp"
+#include "level.hpp"
static const float SQUISH_TIME = 2;
static const float X_OFFSCREEN_DISTANCE = 1600;
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
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;
}
physic.set_velocity_y(0);
set_state(STATE_SQUISHED);
set_group(COLGROUP_MOVING_ONLY_STATIC);
- global_stats.add_points(BADGUYS_KILLED_STAT, 1);
+ if (countMe) Sector::current()->get_level()->stats.badguys++;
player.bounce(*this);
}
BadGuy::kill_fall()
{
sound_manager->play("sounds/fall.wav", get_pos());
- global_stats.add_points(BADGUYS_KILLED_STAT, 1);
+ if (countMe) Sector::current()->get_level()->stats.badguys++;
physic.set_velocity_y(0);
physic.enable_gravity(true);
set_state(STATE_FALLING);
// Watch out there buddy, you might take a sticky end!
return true;
}
+
+bool
+BadGuy::might_fall(int height)
+{
+ // make sure we check for at least a 1-pixel fall
+ assert(height > 0);
+
+ float x1;
+ float x2;
+ float y1 = bbox.p2.y + 1;
+ float y2 = bbox.p2.y + 1 + height;
+ if (dir == LEFT) {
+ x1 = bbox.p1.x - 1;
+ x2 = bbox.p1.x - 1;
+ } else {
+ x1 = bbox.p2.x + 1;
+ x2 = bbox.p2.x + 1;
+ }
+ return Sector::current()->is_free_space(Rect(x1, y1, x2, y2));
+}
+
+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;
+}