From: Ingo Ruhnke Date: Wed, 8 Oct 2014 14:28:38 +0000 (+0200) Subject: Added torch code X-Git-Url: https://git.octo.it/?p=supertux.git;a=commitdiff_plain;h=333fb66a9e6ec8e4736fb16bc28f2a5050481d0f Added torch code --- diff --git a/src/object/torch.cpp b/src/object/torch.cpp new file mode 100644 index 000000000..e2c133b82 --- /dev/null +++ b/src/object/torch.cpp @@ -0,0 +1,91 @@ +// SuperTux +// Copyright (C) 2014 Ingo Ruhnke +// +// 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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, see . + +#include "object/torch.hpp" + +#include "object/player.hpp" +#include "sprite/sprite.hpp" +#include "sprite/sprite_manager.hpp" +#include "util/reader.hpp" + +Torch::Torch(const Reader& reader) : + m_torch(), + m_flame(), + m_flame_glow(), + m_flame_light(), + m_burning(true) +{ + reader.get("x", bbox.p1.x); + reader.get("y", bbox.p1.y); + + std::string sprite_name = "images/objects/torch/torch1.sprite"; + reader.get("sprite", sprite_name); + + bbox.p2.x = bbox.p1.x + 50; + bbox.p2.y = bbox.p1.y + 50; + + m_torch = SpriteManager::current()->create(sprite_name); + m_flame = SpriteManager::current()->create("images/objects/torch/flame.sprite"); + m_flame_glow = SpriteManager::current()->create("images/objects/torch/flame_glow.sprite"); + m_flame_glow->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + m_flame_light = SpriteManager::current()->create("images/objects/torch/flame_light.sprite"); + m_flame_light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + set_group(COLGROUP_TOUCHABLE); +} + +void +Torch::draw(DrawingContext& context) +{ + if (m_burning) + { + m_flame->draw(context, get_pos(), LAYER_TILES - 1); + + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + m_flame_light->draw(context, get_pos(), 0); + context.pop_target(); + } + + m_torch->draw(context, get_pos(), LAYER_TILES - 1); + + if (m_burning) + { + m_flame_glow->draw(context, get_pos(), LAYER_TILES - 1); + } +} + +void +Torch::update(float) +{ +} + +HitResponse +Torch::collision(GameObject& other, const CollisionHit& ) +{ + // FIXME: this doesn't work, as bbox is wrong + Player* player = dynamic_cast(&other); + if(player == 0) + { + return ABORT_MOVE; + } + else + { + m_burning = true; + return ABORT_MOVE; + } +} + +/* EOF */ diff --git a/src/object/torch.hpp b/src/object/torch.hpp new file mode 100644 index 000000000..9169efd2c --- /dev/null +++ b/src/object/torch.hpp @@ -0,0 +1,50 @@ +// SuperTux +// Copyright (C) 2014 Ingo Ruhnke +// +// 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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, see . + +#ifndef HEADER_SUPERTUX_OBJECT_TORCH_HPP +#define HEADER_SUPERTUX_OBJECT_TORCH_HPP + +#include + +#include "sprite/sprite_ptr.hpp" +#include "supertux/moving_object.hpp" +#include "util/reader_fwd.hpp" + +class Torch : public MovingObject +{ +public: + Torch(const Reader& reader); + + void draw(DrawingContext& context) override; + void update(float) override; + + HitResponse collision(GameObject& other, const CollisionHit& ); + +private: + SpritePtr m_torch; + SpritePtr m_flame; + SpritePtr m_flame_glow; + SpritePtr m_flame_light; + bool m_burning; + +private: + Torch(const Torch&) = delete; + Torch& operator=(const Torch&) = delete; +}; + +#endif + +/* EOF */ diff --git a/src/supertux/object_factory.cpp b/src/supertux/object_factory.cpp index 3699f3c8f..006060f10 100644 --- a/src/supertux/object_factory.cpp +++ b/src/supertux/object_factory.cpp @@ -88,6 +88,7 @@ #include "object/bullet.hpp" #include "object/camera.hpp" #include "object/candle.hpp" +#include "object/torch.hpp" #include "object/cloud_particle_system.hpp" #include "object/coin.hpp" #include "object/coin_explode.hpp" @@ -263,6 +264,7 @@ ObjectFactory::init_factories() add_factory("spotlight"); add_factory("thunderstorm"); add_factory("tilemap"); + add_factory("torch"); add_factory("trampoline"); add_factory("rustytrampoline"); add_factory("unstable_tile");