Skip to content

Commit

Permalink
Add Circular Pathed Platforms (SuperTux#1467)
Browse files Browse the repository at this point in the history
* Add circular platforms [ci skip]

* update objects file [ci skip]

* Add to gameobjectfactory

* Add files via upload

* Update objects.stoi

[ci skip]

* quality de la code [ci skip]

* Update objects.stoi

[ci skip]

* Replaced tabs with spaces

Co-authored-by: Zwatotem <zwatotem@gmail.com>
  • Loading branch information
2 people authored and Isaac committed Jul 31, 2020
1 parent 5ebad69 commit aaa56ca
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
Binary file added data/images/engine/editor/circeplatform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions data/images/engine/editor/objects.stoi
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
84 changes: 84 additions & 0 deletions src/object/circleplatform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (C) 2020 Daniel Ward <weluvgoatz@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/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);
}
54 changes: 54 additions & 0 deletions src/object/circleplatform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2020 Daniel Ward <weluvgoatz@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_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 */
2 changes: 2 additions & 0 deletions src/supertux/game_object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -206,6 +207,7 @@ GameObjectFactory::init_factories()
add_factory<Brick>("brick");
add_factory<Camera>("camera");
add_factory<Candle>("candle");
add_factory<CirclePlatform>("circleplatform");
add_factory<CloudParticleSystem>("particles-clouds");
add_factory<Coin>("coin");
add_factory<Decal>("decal");
Expand Down

0 comments on commit aaa56ca

Please sign in to comment.