X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fkamikazesnowball.cpp;h=49ae58239330c3344624cc57a21c9c0fd31b38f4;hb=6492679a300bff2c17505c5d9bc9d333eeba384d;hp=b9cf34ff2a43e3f71e081530149064604efef32b;hpb=058e2f6298d8319c0fe03c5e950a36a8f1f57aba;p=supertux.git diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp index b9cf34ff2..49ae58239 100644 --- a/src/badguy/kamikazesnowball.cpp +++ b/src/badguy/kamikazesnowball.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2008 Wolfgang Becker // -// 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,42 +12,41 @@ // 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 "kamikazesnowball.hpp" +#include "badguy/kamikazesnowball.hpp" -#include "object_factory.hpp" #include "audio/sound_manager.hpp" #include "sprite/sprite.hpp" +#include "supertux/object_factory.hpp" -/* +/* * Kamikaze Snowball will fly in one direction until he hits something. - * On impact he is destroyed, trying to kill what he hit or hit him. + * On impact he is destroyed, trying to kill what he hit or hit him. */ namespace{ - static const float SPEED = 200; + static const float KAMIKAZE_SPEED = 200; const std::string SPLAT_SOUND = "sounds/splat.wav"; } -KamikazeSnowball::KamikazeSnowball(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite") +KamikazeSnowball::KamikazeSnowball(const Reader& reader) : + BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite") { - sound_manager->preload(SPLAT_SOUND); + SoundManager::current()->preload(SPLAT_SOUND); + set_action (dir == LEFT ? "left" : "right", /* loops = */ -1); } KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d) : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite") { - sound_manager->preload(SPLAT_SOUND); + SoundManager::current()->preload(SPLAT_SOUND); + set_action (dir == LEFT ? "left" : "right", /* loops = */ -1); } void KamikazeSnowball::initialize() { - physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); + physic.set_velocity_x(dir == LEFT ? -KAMIKAZE_SPEED : KAMIKAZE_SPEED); physic.enable_gravity(false); sprite->set_action(dir == LEFT ? "left" : "right"); } @@ -67,7 +64,8 @@ KamikazeSnowball::collision_solid(const CollisionHit& hit) { if(hit.top || hit.bottom) { physic.set_velocity_y(0); - } else if(hit.left || hit.right) { + } + if(hit.left || hit.right) { kill_collision(); } } @@ -75,24 +73,26 @@ KamikazeSnowball::collision_solid(const CollisionHit& hit) void KamikazeSnowball::kill_collision() { - sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); - sound_manager->play(SPLAT_SOUND, get_pos()); - physic.set_velocity_x(0); - physic.set_velocity_y(0); - physic.enable_gravity(true); - set_state(STATE_FALLING); + sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); + SoundManager::current()->play(SPLAT_SOUND, get_pos()); + physic.set_velocity_x(0); + physic.set_velocity_y(0); + physic.enable_gravity(true); + set_state(STATE_FALLING); + + run_dead_script(); } HitResponse KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit) { + //Hack to tell if we should die HitResponse response = BadGuy::collision_player(player, hit); - if(response == FORCE_MOVE){ + if(response == FORCE_MOVE) { kill_collision(); - response = ABORT_MOVE; } - return response; -} + return ABORT_MOVE; +} -IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball") +/* EOF */