diff --git a/data/images/engine/editor/circeplatform.png b/data/images/engine/editor/circeplatform.png new file mode 100644 index 00000000000..364e9c5b1d7 Binary files /dev/null and b/data/images/engine/editor/circeplatform.png differ diff --git a/data/images/engine/editor/objects.stoi b/data/images/engine/editor/objects.stoi index 2a1f044a7e8..c56515b30bd 100644 --- a/data/images/engine/editor/objects.stoi +++ b/data/images/engine/editor/objects.stoi @@ -219,6 +219,9 @@ (object (class "bicycle-platform") (icon "images/engine/editor/bicycleplatform.png")) + (object + (class "circleplatform") + (icon "images/engine/editor/circeplatform.png")) (object (class "hurting_platform") (icon "images/objects/sawblade/default-0.png")) diff --git a/src/object/circleplatform.cpp b/src/object/circleplatform.cpp new file mode 100644 index 00000000000..6cdd0835c07 --- /dev/null +++ b/src/object/circleplatform.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2020 Daniel Ward +// +// 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/circleplatform.hpp" + +#include "editor/editor.hpp" +#include "math/util.hpp" +#include "util/reader_mapping.hpp" +#include "util/writer.hpp" + +CirclePlatform::CirclePlatform(const ReaderMapping& reader) : + MovingSprite(reader, "images/objects/platforms/icebridge1.png", LAYER_OBJECTS, COLGROUP_STATIC), + start_position(m_col.m_bbox.p1()), + angle(0.0), + radius(), + speed(), + timer(), + time(0.0) +{ + reader.get("radius", radius, 100.0f); + reader.get("speed", speed, 2.0f); + reader.get("time", time, 0.0f); + if (!Editor::is_active()) + { + m_col.m_bbox.set_pos(Vector(start_position.x + cosf(angle) * radius, + start_position.y + sinf(angle) * radius)); + initialize(); + } +} + +HitResponse +CirclePlatform::collision(GameObject& other, const CollisionHit& ) +{ + return FORCE_MOVE; +} + +ObjectSettings +CirclePlatform::get_settings() +{ + ObjectSettings result = MovingSprite::get_settings(); + + result.add_float(_("Radius"), &radius, "radius", 100.0f); + result.add_float(_("Speed"), &speed, "speed", 2.0f); + result.add_float(_("Delay"), &time, "time", 0.0f); + + result.reorder({"radius", "speed", "time", "sprite", "x", "y"}); + + return result; +} + +void +CirclePlatform::update(float dt_sec) +{ + if (timer.get_timeleft() <= 0.00f) + { + time = 0; + timer.stop(); + angle = fmodf(angle + dt_sec * speed, math::TAU); + if (!Editor::is_active()) + { + Vector newpos(start_position.x + cosf(angle) * radius, + start_position.y + sinf(angle) * radius); + m_col.m_movement = newpos - get_pos(); + } + } +} + +void +CirclePlatform::initialize() +{ + timer.start(time); +} diff --git a/src/object/circleplatform.hpp b/src/object/circleplatform.hpp new file mode 100644 index 00000000000..5b4814599ed --- /dev/null +++ b/src/object/circleplatform.hpp @@ -0,0 +1,54 @@ +// Copyright (C) 2020 Daniel Ward +// +// 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_CIRCLEPLATFORM_HPP +#define HEADER_SUPERTUX_OBJECT_CIRCLEPLATFORM_HPP + +#include "object/moving_sprite.hpp" +#include "supertux/timer.hpp" + +class CirclePlatform : public MovingSprite +{ +public: + CirclePlatform(const ReaderMapping& reader); + + virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; + virtual ObjectSettings get_settings() override; + virtual void update(float dt_sec) override; + + virtual std::string get_class() const override { return "circleplatform"; } + virtual std::string get_display_name() const override { return _("Circular Platform"); } + +private: + virtual void initialize(); + +protected: + Vector start_position; + float angle; + float radius; + float speed; + + Timer timer; + float time; + + +private: + CirclePlatform(const CirclePlatform&) = delete; + CirclePlatform& operator=(const CirclePlatform&) = delete; +}; + +#endif + +/* EOF */ diff --git a/src/supertux/game_object_factory.cpp b/src/supertux/game_object_factory.cpp index 64c7a598bac..0a19dc799be 100644 --- a/src/supertux/game_object_factory.cpp +++ b/src/supertux/game_object_factory.cpp @@ -76,6 +76,7 @@ #include "object/brick.hpp" #include "object/camera.hpp" #include "object/candle.hpp" +#include "object/circleplatform.hpp" #include "object/cloud_particle_system.hpp" #include "object/coin.hpp" #include "object/decal.hpp" @@ -206,6 +207,7 @@ GameObjectFactory::init_factories() add_factory("brick"); add_factory("camera"); add_factory("candle"); + add_factory("circleplatform"); add_factory("particles-clouds"); add_factory("coin"); add_factory("decal");