From 5e5804d84df402986df86e75bbb5cf692df46a21 Mon Sep 17 00:00:00 2001 From: Savsish Date: Sat, 25 Jun 2016 19:56:21 +0700 Subject: [PATCH 01/10] Create enemy_blocker.cpp --- src/object/enemy_blocker.cpp | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/object/enemy_blocker.cpp diff --git a/src/object/enemy_blocker.cpp b/src/object/enemy_blocker.cpp new file mode 100644 index 0000000000..1e63bd5090 --- /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::collides(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 */ From 9c08402faa4605150b5f5444e11eb54be816332b Mon Sep 17 00:00:00 2001 From: Savsish Date: Sat, 25 Jun 2016 19:58:52 +0700 Subject: [PATCH 02/10] Create enemy_blocker.hpp --- src/object/enemy_blocker.hpp | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/object/enemy_blocker.hpp diff --git a/src/object/enemy_blocker.hpp b/src/object/enemy_blocker.hpp new file mode 100644 index 0000000000..3e15900839 --- /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 collides(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 */ From 6498e8827e20d28024e73d3e2ba5635948645217 Mon Sep 17 00:00:00 2001 From: Savsish Date: Sat, 25 Jun 2016 20:00:16 +0700 Subject: [PATCH 03/10] Update object_factory.cpp --- src/supertux/object_factory.cpp | 2 ++ 1 file changed, 2 insertions(+) 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"); From b6e8e9bda312869db56ed11b5a1ed5696219fcad Mon Sep 17 00:00:00 2001 From: Savsish Date: Sat, 25 Jun 2016 21:24:45 +0700 Subject: [PATCH 04/10] Update enemy_blocker.cpp --- src/object/enemy_blocker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/object/enemy_blocker.cpp b/src/object/enemy_blocker.cpp index 1e63bd5090..cf314291b5 100644 --- a/src/object/enemy_blocker.cpp +++ b/src/object/enemy_blocker.cpp @@ -54,7 +54,7 @@ EnemyBlocker::after_editor_set() { } HitResponse -EnemyBlocker::collides(GameObject& other, const CollisionHit& ) +EnemyBlocker::collision(GameObject& other, const CollisionHit& ) { BadGuy* badguy = dynamic_cast (&other); From 7dbc6271184ff0a42c2a712c817c5f5aa184f082 Mon Sep 17 00:00:00 2001 From: Savsish Date: Sat, 25 Jun 2016 21:25:05 +0700 Subject: [PATCH 05/10] Update enemy_blocker.hpp --- src/object/enemy_blocker.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/object/enemy_blocker.hpp b/src/object/enemy_blocker.hpp index 3e15900839..55c097767e 100644 --- a/src/object/enemy_blocker.hpp +++ b/src/object/enemy_blocker.hpp @@ -26,7 +26,7 @@ class EnemyBlocker : public MovingObject public: EnemyBlocker(const ReaderMapping& lisp); - HitResponse collides(GameObject& other, const CollisionHit& hit); + HitResponse collision(GameObject& other, const CollisionHit& hit); void draw(DrawingContext& context); From cf129443d3129e56d48684d22170771489db60e7 Mon Sep 17 00:00:00 2001 From: Savsish Date: Mon, 8 Aug 2016 15:37:13 +0700 Subject: [PATCH 06/10] Add method "collides" to enemy_blocker.cpp --- src/object/enemy_blocker.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/object/enemy_blocker.cpp b/src/object/enemy_blocker.cpp index cf314291b5..e44d33381a 100644 --- a/src/object/enemy_blocker.cpp +++ b/src/object/enemy_blocker.cpp @@ -53,6 +53,16 @@ EnemyBlocker::after_editor_set() { bbox.set_size(width, height); } +bool +EnemyBlocker::collides(GameObject& other, const CollisionHit& ) +{ + BadGuy* badguy = dynamic_cast (&other); + + if (badguy == 0) + return ABORT_MOVE; + return FORCE_MOVE; +} + HitResponse EnemyBlocker::collision(GameObject& other, const CollisionHit& ) { From 15ea3146bed6993244bb900b24c0312b77291727 Mon Sep 17 00:00:00 2001 From: Savsish Date: Mon, 8 Aug 2016 15:37:46 +0700 Subject: [PATCH 07/10] Add method "collides" to enemy_blocker.hpp --- src/object/enemy_blocker.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/object/enemy_blocker.hpp b/src/object/enemy_blocker.hpp index 55c097767e..73f3f67cfb 100644 --- a/src/object/enemy_blocker.hpp +++ b/src/object/enemy_blocker.hpp @@ -26,6 +26,7 @@ class EnemyBlocker : public MovingObject public: EnemyBlocker(const ReaderMapping& lisp); + virtual bool collides(GameObject& other, const CollisionHit& hit); HitResponse collision(GameObject& other, const CollisionHit& hit); void draw(DrawingContext& context); From ed907ceb48410c8b01e236152eeae93fe95d6170 Mon Sep 17 00:00:00 2001 From: Savsish Date: Mon, 8 Aug 2016 15:44:41 +0700 Subject: [PATCH 08/10] Update input_center.cpp --- src/editor/input_center.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/editor/input_center.cpp b/src/editor/input_center.cpp index d6f5a0ce9f..efb9a20af6 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" @@ -311,8 +312,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; From 37f37694eccdee06fcd38118a20e72f4176b210b Mon Sep 17 00:00:00 2001 From: Savsish Date: Tue, 9 Aug 2016 20:22:04 +0700 Subject: [PATCH 09/10] Reverted changes The build fails for some reason, so using method collision instead. --- src/object/enemy_blocker.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/object/enemy_blocker.cpp b/src/object/enemy_blocker.cpp index e44d33381a..cf314291b5 100644 --- a/src/object/enemy_blocker.cpp +++ b/src/object/enemy_blocker.cpp @@ -53,16 +53,6 @@ EnemyBlocker::after_editor_set() { bbox.set_size(width, height); } -bool -EnemyBlocker::collides(GameObject& other, const CollisionHit& ) -{ - BadGuy* badguy = dynamic_cast (&other); - - if (badguy == 0) - return ABORT_MOVE; - return FORCE_MOVE; -} - HitResponse EnemyBlocker::collision(GameObject& other, const CollisionHit& ) { From 30ccb929105a983bcb800f68624b60588a03a1b6 Mon Sep 17 00:00:00 2001 From: Savsish Date: Tue, 9 Aug 2016 20:22:44 +0700 Subject: [PATCH 10/10] Reverted change in another file --- src/object/enemy_blocker.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/object/enemy_blocker.hpp b/src/object/enemy_blocker.hpp index 73f3f67cfb..55c097767e 100644 --- a/src/object/enemy_blocker.hpp +++ b/src/object/enemy_blocker.hpp @@ -26,7 +26,6 @@ class EnemyBlocker : public MovingObject public: EnemyBlocker(const ReaderMapping& lisp); - virtual bool collides(GameObject& other, const CollisionHit& hit); HitResponse collision(GameObject& other, const CollisionHit& hit); void draw(DrawingContext& context);