src/badguy/kamikazesnowball.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2008 Wolfgang Becker <uafr@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "badguy/kamikazesnowball.hpp"
00018 
00019 #include "audio/sound_manager.hpp"
00020 #include "sprite/sprite.hpp"
00021 #include "supertux/object_factory.hpp"
00022 
00023 /* 
00024  * Kamikaze Snowball will fly in one direction until he hits something.
00025  * On impact he is destroyed, trying to kill what he hit or hit him. 
00026  */
00027 namespace{
00028   static const float KAMIKAZE_SPEED = 200;
00029   const std::string SPLAT_SOUND = "sounds/splat.wav";
00030 }
00031 
00032 KamikazeSnowball::KamikazeSnowball(const Reader& reader) :
00033   BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite")
00034 {
00035   sound_manager->preload(SPLAT_SOUND);
00036   set_action (dir == LEFT ? "left" : "right", /* loops = */ -1);
00037 }
00038 
00039 KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d)
00040   : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite")
00041 {
00042   sound_manager->preload(SPLAT_SOUND);
00043   set_action (dir == LEFT ? "left" : "right", /* loops = */ -1);
00044 }
00045 
00046 void
00047 KamikazeSnowball::initialize()
00048 {
00049   physic.set_velocity_x(dir == LEFT ? -KAMIKAZE_SPEED : KAMIKAZE_SPEED);
00050   physic.enable_gravity(false);
00051   sprite->set_action(dir == LEFT ? "left" : "right");
00052 }
00053 
00054 bool
00055 KamikazeSnowball::collision_squished(GameObject& object)
00056 {
00057   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
00058   kill_squished(object);
00059   return true;
00060 }
00061 
00062 void
00063 KamikazeSnowball::collision_solid(const CollisionHit& hit)
00064 {
00065   if(hit.top || hit.bottom) {
00066     physic.set_velocity_y(0);
00067   }
00068   if(hit.left || hit.right) {
00069     kill_collision();
00070   }
00071 }
00072 
00073 void
00074 KamikazeSnowball::kill_collision()
00075 {
00076   sprite->set_action(dir == LEFT ? "collision-left" : "collision-right");
00077   sound_manager->play(SPLAT_SOUND, get_pos());
00078   physic.set_velocity_x(0);
00079   physic.set_velocity_y(0);
00080   physic.enable_gravity(true);
00081   set_state(STATE_FALLING);
00082 
00083   run_dead_script();
00084 }
00085 
00086 HitResponse
00087 KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
00088 {
00089   //Hack to tell if we should die
00090   HitResponse response = BadGuy::collision_player(player, hit);
00091   if(response == FORCE_MOVE) {
00092     kill_collision();
00093   }
00094 
00095   return ABORT_MOVE;
00096 }
00097 
00098 /* EOF */

Generated on Mon Jun 9 03:38:17 2014 for SuperTux by  doxygen 1.5.1