| 1 | //  SuperTux | 
|---|
| 2 | //  Copyright (C) 2006 Matthias Braun <matze@braunis.de> | 
|---|
| 3 | //  Copyright (C) 2010 Florian Forster <supertux at octo.it> | 
|---|
| 4 | // | 
|---|
| 5 | //  This program is free software: you can redistribute it and/or modify | 
|---|
| 6 | //  it under the terms of the GNU General Public License as published by | 
|---|
| 7 | //  the Free Software Foundation, either version 3 of the License, or | 
|---|
| 8 | //  (at your option) any later version. | 
|---|
| 9 | // | 
|---|
| 10 | //  This program is distributed in the hope that it will be useful, | 
|---|
| 11 | //  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 12 | //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 13 | //  GNU General Public License for more details. | 
|---|
| 14 | // | 
|---|
| 15 | //  You should have received a copy of the GNU General Public License | 
|---|
| 16 | //  along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 17 |  | 
|---|
| 18 | #include "badguy/short_fuse.hpp" | 
|---|
| 19 |  | 
|---|
| 20 | #include "object/bullet.hpp" | 
|---|
| 21 | #include "object/explosion.hpp" | 
|---|
| 22 | #include "object/player.hpp" | 
|---|
| 23 | #include "sprite/sprite_manager.hpp" | 
|---|
| 24 | #include "supertux/sector.hpp" | 
|---|
| 25 | #include "util/reader_mapping.hpp" | 
|---|
| 26 |  | 
|---|
| 27 | ShortFuse::ShortFuse(const ReaderMapping& reader) : | 
|---|
| 28 | WalkingBadguy(reader, "images/creatures/short_fuse/short_fuse.sprite", "left", "right") | 
|---|
| 29 | { | 
|---|
| 30 | walk_speed = 100; | 
|---|
| 31 | max_drop_height = -1; | 
|---|
| 32 |  | 
|---|
| 33 | //Check if we need another sprite | 
|---|
| 34 | if ( !reader.get( "sprite", m_sprite_name ) ){ | 
|---|
| 35 | return; | 
|---|
| 36 | } | 
|---|
| 37 | if (m_sprite_name.empty()) { | 
|---|
| 38 | m_sprite_name = "images/creatures/short_fuse/short_fuse.sprite"; | 
|---|
| 39 | return; | 
|---|
| 40 | } | 
|---|
| 41 | //Replace sprite | 
|---|
| 42 | m_sprite = SpriteManager::current()->create( m_sprite_name ); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | void | 
|---|
| 46 | ShortFuse::explode() | 
|---|
| 47 | { | 
|---|
| 48 | if (!is_valid()) | 
|---|
| 49 | return; | 
|---|
| 50 |  | 
|---|
| 51 | auto& explosion = Sector::get().add<Explosion>(get_bbox().get_middle()); | 
|---|
| 52 | explosion.hurts(false); | 
|---|
| 53 | explosion.pushes(true); | 
|---|
| 54 |  | 
|---|
| 55 | run_dead_script(); | 
|---|
| 56 | remove_me(); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | bool | 
|---|
| 60 | ShortFuse::collision_squished(GameObject& obj) | 
|---|
| 61 | { | 
|---|
| 62 | if (!is_valid ()) | 
|---|
| 63 | return true; | 
|---|
| 64 |  | 
|---|
| 65 | auto player = dynamic_cast<Player*>(&obj); | 
|---|
| 66 | if (player) | 
|---|
| 67 | player->bounce(*this); | 
|---|
| 68 |  | 
|---|
| 69 | explode (); | 
|---|
| 70 |  | 
|---|
| 71 | return true; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | HitResponse | 
|---|
| 75 | ShortFuse::collision_player (Player& player, const CollisionHit&) | 
|---|
| 76 | { | 
|---|
| 77 | player.bounce (*this); | 
|---|
| 78 | explode (); | 
|---|
| 79 | return ABORT_MOVE; | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | HitResponse | 
|---|
| 83 | ShortFuse::collision_bullet (Bullet& bullet, const CollisionHit& ) | 
|---|
| 84 | { | 
|---|
| 85 | // All bullets cause the unstable short fuse to explode | 
|---|
| 86 | bullet.remove_me(); | 
|---|
| 87 | explode(); | 
|---|
| 88 | return ABORT_MOVE; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | void | 
|---|
| 92 | ShortFuse::kill_fall() | 
|---|
| 93 | { | 
|---|
| 94 | explode (); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | void | 
|---|
| 98 | ShortFuse::ignite() | 
|---|
| 99 | { | 
|---|
| 100 | kill_fall(); | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | /* EOF */ | 
|---|
| 104 |  | 
|---|