| 1 | // SuperTux |
| 2 | // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com> |
| 3 | // Copyright (C) 2017 M. Teufel <mteufel@supertux.org> |
| 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 "object/torch.hpp" |
| 19 | |
| 20 | #include "object/player.hpp" |
| 21 | #include "sprite/sprite.hpp" |
| 22 | #include "sprite/sprite_manager.hpp" |
| 23 | #include "util/reader_mapping.hpp" |
| 24 | |
| 25 | Torch::Torch(const ReaderMapping& reader) : |
| 26 | MovingObject(reader), |
| 27 | ExposedObject<Torch, scripting::Torch>(this), |
| 28 | m_torch(), |
| 29 | m_flame(SpriteManager::current()->create("images/objects/torch/flame.sprite" )), |
| 30 | m_flame_glow(SpriteManager::current()->create("images/objects/torch/flame_glow.sprite" )), |
| 31 | m_flame_light(SpriteManager::current()->create("images/objects/torch/flame_light.sprite" )), |
| 32 | m_burning(true), |
| 33 | sprite_name("images/objects/torch/torch1.sprite" ) |
| 34 | { |
| 35 | reader.get("x" , m_col.m_bbox.get_left()); |
| 36 | reader.get("y" , m_col.m_bbox.get_top()); |
| 37 | |
| 38 | reader.get("sprite" , sprite_name); |
| 39 | reader.get("burning" , m_burning, true); |
| 40 | |
| 41 | m_torch = SpriteManager::current()->create(sprite_name); |
| 42 | m_col.m_bbox.set_size(static_cast<float>(m_torch->get_width()), |
| 43 | static_cast<float>(m_torch->get_height())); |
| 44 | m_flame_glow->set_blend(Blend::ADD); |
| 45 | m_flame_light->set_blend(Blend::ADD); |
| 46 | set_group(COLGROUP_TOUCHABLE); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | Torch::draw(DrawingContext& context) |
| 51 | { |
| 52 | if (m_burning) |
| 53 | { |
| 54 | m_flame->draw(context.color(), get_pos(), LAYER_TILES - 1); |
| 55 | |
| 56 | m_flame_light->draw(context.light(), get_pos(), 0); |
| 57 | } |
| 58 | |
| 59 | m_torch->draw(context.color(), get_pos(), LAYER_TILES - 1); |
| 60 | |
| 61 | if (m_burning) |
| 62 | { |
| 63 | m_flame_glow->draw(context.color(), get_pos(), LAYER_TILES - 1); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | Torch::update(float) |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | HitResponse |
| 73 | Torch::collision(GameObject& other, const CollisionHit& ) |
| 74 | { |
| 75 | auto player = dynamic_cast<Player*>(&other); |
| 76 | if (player != nullptr && !m_burning) |
| 77 | { |
| 78 | m_burning = true; |
| 79 | } |
| 80 | return ABORT_MOVE; |
| 81 | } |
| 82 | |
| 83 | ObjectSettings |
| 84 | Torch::get_settings() |
| 85 | { |
| 86 | ObjectSettings result = MovingObject::get_settings(); |
| 87 | |
| 88 | result.add_bool(_("Burning" ), &m_burning, "burning" , true); |
| 89 | result.add_sprite(_("Sprite" ), &sprite_name, "sprite" , std::string("images/objects/torch/torch1.sprite" )); |
| 90 | |
| 91 | result.reorder({"sprite" , "x" , "y" }); |
| 92 | |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | void Torch::after_editor_set() |
| 97 | { |
| 98 | m_torch = SpriteManager::current()->create(sprite_name); |
| 99 | } |
| 100 | |
| 101 | bool |
| 102 | Torch::get_burning() const |
| 103 | { |
| 104 | return m_burning; |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | Torch::set_burning(bool burning_) |
| 109 | { |
| 110 | m_burning = burning_; |
| 111 | } |
| 112 | |
| 113 | /* EOF */ |
| 114 | |