X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fstalactite.cpp;h=84febaedfdf5852875b36d7e6dd97f7046b919b3;hb=af6086c5e53fd3b38921ff584abe3b621a2aa9f3;hp=f810d7c0d12a0037ea5b28eb6de56a0827f5dfed;hpb=75acd4b141f45e851a492f089aa9ad24a9552409;p=supertux.git diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index f810d7c0d..84febaedf 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -1,12 +1,10 @@ -// $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 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 3 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 @@ -14,38 +12,32 @@ // 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 +// along with this program. If not, see . -#include "stalactite.hpp" +#include "badguy/stalactite.hpp" -#include "random_generator.hpp" -#include "lisp/writer.hpp" -#include "object_factory.hpp" +#include "audio/sound_manager.hpp" +#include "math/random_generator.hpp" +#include "object/bullet.hpp" #include "object/player.hpp" #include "sprite/sprite.hpp" +#include "supertux/object_factory.hpp" static const int SHAKE_RANGE_X = 40; static const float SHAKE_TIME = .8f; -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", LAYER_TILES - 1), state(STALACTITE_HANGING) +Stalactite::Stalactite(const Reader& lisp) : + BadGuy(lisp, "images/creatures/stalactite/stalactite.sprite", LAYER_TILES - 1), + timer(), + state(STALACTITE_HANGING), + shake_delta() { countMe = false; set_colgroup_active(COLGROUP_TOUCHABLE); -} - -void -Stalactite::write(lisp::Writer& writer) -{ - writer.start_list("stalactite"); - writer.write("x", start_position.x); - writer.write("y", start_position.y); - writer.end_list("stalactite"); + SoundManager::current()->preload("sounds/cracking.wav"); + SoundManager::current()->preload("sounds/sizzle.ogg"); + SoundManager::current()->preload("sounds/icecrash.ogg"); } void @@ -55,23 +47,23 @@ Stalactite::active_update(float elapsed_time) 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) { + && 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; + SoundManager::current()->play("sounds/cracking.wav", get_pos()); } } } else if(state == STALACTITE_SHAKING) { + shake_delta = Vector(graphicsRandom.rand(-3,3), 0); if(timer.check()) { state = STALACTITE_FALLING; physic.enable_gravity(true); set_colgroup_active(COLGROUP_MOVING); } - } else if(state == STALACTITE_FALLING || state == STALACTITE_SQUISHED) { + } else if(state == STALACTITE_FALLING) { movement = physic.get_movement(elapsed_time); - if(state == STALACTITE_SQUISHED && timer.check()) - remove_me(); } } @@ -79,10 +71,14 @@ void Stalactite::squish() { state = STALACTITE_SQUISHED; - set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC); + physic.enable_gravity(true); + physic.set_velocity_x(0); + physic.set_velocity_y(0); + set_state(STATE_SQUISHED); sprite->set_action("squished"); - if(!timer.started()) - timer.start(SQUISH_TIME); + SoundManager::current()->play("sounds/icecrash.ogg", get_pos()); + set_group(COLGROUP_MOVING_ONLY_STATIC); + run_dead_script(); } void @@ -97,7 +93,7 @@ Stalactite::collision_solid(const CollisionHit& hit) } HitResponse -Stalactite::collision_player(Player& player) +Stalactite::collision_player(Player& player, const CollisionHit& ) { if(state != STALACTITE_SQUISHED) { player.kill(false); @@ -122,7 +118,20 @@ Stalactite::collision_badguy(BadGuy& other, const CollisionHit& hit) other.kill_fall(); } - remove_me(); + return FORCE_MOVE; +} + +HitResponse +Stalactite::collision_bullet(Bullet& bullet, const CollisionHit& ) +{ + if(state == STALACTITE_HANGING) { + timer.start(SHAKE_TIME); + state = STALACTITE_SHAKING; + bullet.remove_me(); + if(bullet.get_type() == FIRE_BONUS) + SoundManager::current()->play("sounds/sizzle.ogg", get_pos()); + SoundManager::current()->play("sounds/cracking.wav", get_pos()); + } return FORCE_MOVE; } @@ -135,17 +144,13 @@ Stalactite::kill_fall() void Stalactite::draw(DrawingContext& context) { - if(get_state() != STATE_ACTIVE) + if(get_state() == STATE_INIT || get_state() == STATE_INACTIVE) return; - if(state == STALACTITE_SQUISHED) { sprite->draw(context, get_pos(), LAYER_OBJECTS); - return; - } - - if(state == STALACTITE_SHAKING) { - sprite->draw(context, get_pos() + Vector(systemRandom.rand(-3,3), 0), layer); + } else if(state == STALACTITE_SHAKING) { + sprite->draw(context, get_pos() + shake_delta, layer); } else { sprite->draw(context, get_pos(), layer); } @@ -158,4 +163,4 @@ Stalactite::deactivate() remove_me(); } -IMPLEMENT_FACTORY(Stalactite, "stalactite") +/* EOF */