Added torch code
authorIngo Ruhnke <grumbel@gmail.com>
Wed, 8 Oct 2014 14:28:38 +0000 (16:28 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Wed, 8 Oct 2014 14:28:38 +0000 (16:28 +0200)
src/object/torch.cpp [new file with mode: 0644]
src/object/torch.hpp [new file with mode: 0644]
src/supertux/object_factory.cpp

diff --git a/src/object/torch.cpp b/src/object/torch.cpp
new file mode 100644 (file)
index 0000000..e2c133b
--- /dev/null
@@ -0,0 +1,91 @@
+//  SuperTux
+//  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+//  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 <http://www.gnu.org/licenses/>.
+
+#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<Player*>(&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 (file)
index 0000000..9169efd
--- /dev/null
@@ -0,0 +1,50 @@
+//  SuperTux
+//  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+//  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 <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_OBJECT_TORCH_HPP
+#define HEADER_SUPERTUX_OBJECT_TORCH_HPP
+
+#include <memory>
+
+#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 */
index 3699f3c..006060f 100644 (file)
@@ -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>("spotlight");
   add_factory<Thunderstorm>("thunderstorm");
   add_factory<TileMap>("tilemap");
+  add_factory<Torch>("torch");
   add_factory<Trampoline>("trampoline");
   add_factory<RustyTrampoline>("rustytrampoline");
   add_factory<UnstableTile>("unstable_tile");