diff --git a/src/editor/input_center.cpp b/src/editor/input_center.cpp index 341f89b874..7335dc375a 100644 --- a/src/editor/input_center.cpp +++ b/src/editor/input_center.cpp @@ -29,6 +29,7 @@ #include "math/rectf.hpp" #include "object/ambient_sound.hpp" #include "object/camera.hpp" +#include "object/enemy_blocker.hpp" #include "object/invisible_wall.hpp" #include "object/path.hpp" #include "object/platform.hpp" @@ -316,8 +317,9 @@ EditorInputCenter::mark_object() { auto dc5 = dynamic_cast(dragged_object); auto dc6 = dynamic_cast(dragged_object); auto dc7 = dynamic_cast(dragged_object); + auto dc8 = dynamic_cast(dragged_object); - if (dc1 || dc2 || dc3 || dc4 || dc5 || dc6 || dc7) { + if (dc1 || dc2 || dc3 || dc4 || dc5 || dc6 || dc7 || dc8) { marked_object = dragged_object; dragged_object->edit_bbox(); return; diff --git a/src/object/enemy_blocker.cpp b/src/object/enemy_blocker.cpp new file mode 100644 index 0000000000..cf314291b5 --- /dev/null +++ b/src/object/enemy_blocker.cpp @@ -0,0 +1,80 @@ +// SuperTux +// Copyright (C) 2007 Kovago Zoltan +// +// 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/enemy_blocker.hpp" + +#include "editor/editor.hpp" +#include "badguy/badguy.hpp" +#include "supertux/object_factory.hpp" +#include "util/gettext.hpp" +#include "util/reader_mapping.hpp" +#include "video/drawing_context.hpp" + +EnemyBlocker::EnemyBlocker(const ReaderMapping& lisp): + width(), + height() +{ + if (!lisp.get("name" , name)) name = ""; + if (!lisp.get("x", bbox.p1.x)) bbox.p1.x = 0; + if (!lisp.get("y", bbox.p1.y)) bbox.p1.y = 0; + if (!lisp.get("width", width)) width = 32; + if (!lisp.get("height", height)) height = 32; + + bbox.set_size(width, height); +} + +ObjectSettings +EnemyBlocker::get_settings() { + width = bbox.get_width(); + height = bbox.get_height(); + + ObjectSettings result = MovingObject::get_settings(); + result.options.push_back( ObjectOption(MN_NUMFIELD, _("Width"), &width, "width")); + result.options.push_back( ObjectOption(MN_NUMFIELD, _("Height"), &height, "height")); + + return result; +} + +void +EnemyBlocker::after_editor_set() { + bbox.set_size(width, height); +} + +HitResponse +EnemyBlocker::collision(GameObject& other, const CollisionHit& ) +{ + BadGuy* badguy = dynamic_cast (&other); + + if (badguy == 0) + return ABORT_MOVE; + return FORCE_MOVE; +} + +void +EnemyBlocker::draw(DrawingContext& context) +{ + if (Editor::is_active()) { + context.draw_filled_rect(bbox, Color(0.96f, 0.38f, 0.0f, 0.8f), + 0.0f, LAYER_OBJECTS); + } +} + +void +EnemyBlocker::update(float ) +{ +} + +/* EOF */ diff --git a/src/object/enemy_blocker.hpp b/src/object/enemy_blocker.hpp new file mode 100644 index 0000000000..55c097767e --- /dev/null +++ b/src/object/enemy_blocker.hpp @@ -0,0 +1,51 @@ +// SuperTux +// Copyright (C) 2007 Kovago Zoltan +// +// 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_ENEMY_BLOCKER_HPP +#define HEADER_SUPERTUX_OBJECT_ENEMY_BLOCKER_HPP + +#include "supertux/moving_object.hpp" +#include "util/reader_fwd.hpp" + +/** An object that only solid for badguys. */ +class EnemyBlocker : public MovingObject +{ +public: + EnemyBlocker(const ReaderMapping& lisp); + + HitResponse collision(GameObject& other, const CollisionHit& hit); + + void draw(DrawingContext& context); + + std::string get_class() const { + return "enemy_blocker"; + } + std::string get_display_name() const { + return _("Enemy blocker"); + } + + virtual ObjectSettings get_settings(); + virtual void after_editor_set(); + +private: + void update(float elapsed_time); + + float width, height; +}; + +#endif + +/* EOF */ diff --git a/src/supertux/object_factory.cpp b/src/supertux/object_factory.cpp index d559e29d4b..433c6460eb 100644 --- a/src/supertux/object_factory.cpp +++ b/src/supertux/object_factory.cpp @@ -107,6 +107,7 @@ #include "object/endsequence.hpp" #include "object/endsequence_walkleft.hpp" #include "object/endsequence_walkright.hpp" +#include "object/enemy_blocker.hpp" #include "object/explosion.hpp" #include "object/falling_coin.hpp" #include "object/firefly.hpp" @@ -253,6 +254,7 @@ ObjectFactory::init_factories() add_factory("coin"); add_factory("particles-comets"); add_factory("decal"); + add_factory("enemy_blocker"); add_factory("explosion"); add_factory("firefly"); add_factory("particles-ghosts");