X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fstalactite.cpp;h=f53a944097c4118b0ac4e729d10b43b9f4c32fc4;hb=0222881aae90660c925ea2733cd8c80be7ac837b;hp=788683ba8ee6fe4dc96768ab4f75e3a01e68a969;hpb=495f8b77cb935fe8eff81bec755efca8e34e8a99;p=supertux.git diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 788683ba8..f53a94409 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -1,18 +1,36 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// 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. + #include -#include "stalactite.h" +#include "stalactite.hpp" +#include "random_generator.hpp" -static const int SHAKE_RANGE = 40; +static const int SHAKE_RANGE_X = 40; static const float SHAKE_TIME = .8; static const float SQUISH_TIME = 2; +static const float SHAKE_RANGE_Y = 400; Stalactite::Stalactite(const lisp::Lisp& lisp) + : BadGuy(lisp, "images/creatures/stalactite/stalactite.sprite"), state(STALACTITE_HANGING) { - lisp.get("x", start_position.x); - lisp.get("y", start_position.y); - bbox.set_size(31.8, 31.8); - sprite = sprite_manager->create("stalactite"); - state = STALACTITE_HANGING; + countMe = false; } void @@ -25,15 +43,18 @@ Stalactite::write(lisp::Writer& writer) } void -Stalactite::active_action(float elapsed_time) +Stalactite::active_update(float elapsed_time) { if(state == STALACTITE_HANGING) { - Player* player = Sector::current()->player; - if(player->get_bbox().p2.x > bbox.p1.x - SHAKE_RANGE - && player->get_bbox().p1.x < bbox.p2.x + SHAKE_RANGE - && player->get_bbox().p2.y > bbox.p1.y) { - timer.start(SHAKE_TIME); - state = STALACTITE_SHAKING; + Player* player = this->get_nearest_player(); + if (player) { + if(player->get_bbox().p2.x > bbox.p1.x - SHAKE_RANGE_X + && player->get_bbox().p1.x < bbox.p2.x + SHAKE_RANGE_X + && player->get_bbox().p2.y > bbox.p1.y + && player->get_bbox().p1.y < bbox.p2.y + SHAKE_RANGE_Y) { + timer.start(SHAKE_TIME); + state = STALACTITE_SHAKING; + } } } else if(state == STALACTITE_SHAKING) { if(timer.check()) { @@ -53,8 +74,9 @@ Stalactite::collision_solid(GameObject& , const CollisionHit& hit) if(state != STALACTITE_FALLING && state != STALACTITE_SQUISHED) return FORCE_MOVE; - if(fabsf(hit.normal.y) > .5) { // hit floor or roof? + if(hit.normal.y < .9) { // hit floor? state = STALACTITE_SQUISHED; + set_group(COLGROUP_MOVING_ONLY_STATIC); physic.set_velocity_y(0); sprite->set_action("squished"); if(!timer.started()) @@ -68,7 +90,7 @@ HitResponse Stalactite::collision_player(Player& player, const CollisionHit& ) { if(state != STALACTITE_SQUISHED) { - player.kill(Player::SHRINK); + player.kill(false); } return FORCE_MOVE; @@ -82,8 +104,11 @@ Stalactite::kill_fall() void Stalactite::draw(DrawingContext& context) { + if(get_state() != STATE_ACTIVE) + return; + if(state == STALACTITE_SHAKING) { - sprite->draw(context, get_pos() + Vector((rand() % 6)-3, 0), LAYER_OBJECTS); + sprite->draw(context, get_pos() + Vector(systemRandom.rand(-3,3), 0), LAYER_OBJECTS); } else { sprite->draw(context, get_pos(), LAYER_OBJECTS); }