-
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Circular Pathed Platforms (#1467)
* 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
1 parent
f79790a
commit 70f01c2
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters