-
-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix editor not updating direction of badguys, conveyor belts and bump…
…ers (#2556) Fixes the editor not updating sprite actions of badguys, bumpers and conveyor belts upon changing their direction. It also fixes the formatting in all the files I touched - indentation, `m_` prefix for member variables and CRLF → LF.
- Loading branch information
Showing
6 changed files
with
405 additions
and
390 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,93 +1,103 @@ | ||
// Copyright (C) 2020 Daniel Ward <[email protected]> | ||
// | ||
// 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/bumper.hpp" | ||
|
||
#include "audio/sound_manager.hpp" | ||
#include "object/player.hpp" | ||
#include "sprite/sprite.hpp" | ||
#include "sprite/sprite_manager.hpp" | ||
#include "supertux/flip_level_transformer.hpp" | ||
#include "supertux/sector.hpp" | ||
#include "util/reader_mapping.hpp" | ||
|
||
namespace { | ||
const std::string TRAMPOLINE_SOUND = "sounds/trampoline.wav"; | ||
const float BOUNCE_Y = -450.0f; | ||
const float BOUNCE_X = 700.0f; | ||
} | ||
|
||
Bumper::Bumper(const ReaderMapping& reader) : | ||
MovingSprite(reader, "images/objects/trampoline/bumper.sprite", LAYER_OBJECTS, COLGROUP_MOVING), | ||
physic(), | ||
left() | ||
{ | ||
reader.get("left", left); | ||
set_action(left ? "left-normal" : "right-normal"); | ||
physic.enable_gravity(false); | ||
} | ||
|
||
ObjectSettings | ||
Bumper::get_settings() | ||
{ | ||
ObjectSettings result = MovingSprite::get_settings(); | ||
|
||
result.add_bool(_("Facing Left"), &left, "left", false); | ||
|
||
result.reorder({"left", "sprite", "x", "y"}); | ||
|
||
return result; | ||
} | ||
|
||
void | ||
Bumper::update(float dt_sec) | ||
{ | ||
if (m_sprite->animation_done()) | ||
{ | ||
set_action(left ? "left-normal" : "right-normal"); | ||
} | ||
m_col.set_movement(physic.get_movement (dt_sec)); | ||
} | ||
|
||
HitResponse | ||
Bumper::collision(GameObject& other, const CollisionHit& hit) | ||
{ | ||
auto player = dynamic_cast<Player*> (&other); | ||
if (player) | ||
{ | ||
float BOUNCE_DIR = left ? -BOUNCE_X : BOUNCE_X; | ||
player->get_physic().set_velocity(0.f, player->is_swimming() ? 0.f : BOUNCE_Y); | ||
player->sideways_push(BOUNCE_DIR); | ||
SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos()); | ||
set_action((left ? "left-swinging" : "right-swinging"), 1); | ||
} | ||
|
||
auto bumper = dynamic_cast<Bumper*> (&other); | ||
if (bumper) | ||
{ | ||
physic.set_velocity_y(0); | ||
return FORCE_MOVE; | ||
} | ||
return ABORT_MOVE; | ||
} | ||
|
||
void | ||
Bumper::on_flip(float height) | ||
{ | ||
MovingSprite::on_flip(height); | ||
FlipLevelTransformer::transform_flip(m_flip); | ||
} | ||
|
||
/* EOF */ | ||
// Copyright (C) 2020 Daniel Ward <[email protected]> | ||
// | ||
// 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/bumper.hpp" | ||
|
||
#include "audio/sound_manager.hpp" | ||
#include "object/player.hpp" | ||
#include "sprite/sprite.hpp" | ||
#include "sprite/sprite_manager.hpp" | ||
#include "supertux/flip_level_transformer.hpp" | ||
#include "supertux/sector.hpp" | ||
#include "util/reader_mapping.hpp" | ||
|
||
namespace { | ||
const std::string TRAMPOLINE_SOUND = "sounds/trampoline.wav"; | ||
const float BOUNCE_Y = -450.0f; | ||
const float BOUNCE_X = 700.0f; | ||
} | ||
|
||
Bumper::Bumper(const ReaderMapping& reader) : | ||
MovingSprite(reader, "images/objects/trampoline/bumper.sprite", LAYER_OBJECTS, COLGROUP_MOVING), | ||
m_physic(), | ||
m_facing_left() | ||
{ | ||
reader.get("left", m_facing_left); | ||
set_action(m_facing_left ? "left-normal" : "right-normal"); | ||
m_physic.enable_gravity(false); | ||
} | ||
|
||
ObjectSettings | ||
Bumper::get_settings() | ||
{ | ||
ObjectSettings result = MovingSprite::get_settings(); | ||
|
||
result.add_bool(_("Facing Left"), &m_facing_left, "left", false); | ||
result.reorder({"left", "sprite", "x", "y"}); | ||
return result; | ||
} | ||
|
||
void | ||
Bumper::update(float dt_sec) | ||
{ | ||
if (m_sprite->animation_done()) | ||
{ | ||
set_action(m_facing_left ? "left-normal" : "right-normal"); | ||
} | ||
m_col.set_movement(m_physic.get_movement (dt_sec)); | ||
} | ||
|
||
HitResponse | ||
Bumper::collision(GameObject& other, const CollisionHit& hit) | ||
{ | ||
auto player = dynamic_cast<Player*> (&other); | ||
if (player) | ||
{ | ||
float BOUNCE_DIR = m_facing_left ? -BOUNCE_X : BOUNCE_X; | ||
player->get_physic().set_velocity(0.f, player->is_swimming() ? 0.f : BOUNCE_Y); | ||
player->sideways_push(BOUNCE_DIR); | ||
SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos()); | ||
set_action((m_facing_left ? "left-swinging" : "right-swinging"), 1); | ||
} | ||
auto bumper = dynamic_cast<Bumper*> (&other); | ||
if (bumper) | ||
{ | ||
m_physic.set_velocity_y(0); | ||
return FORCE_MOVE; | ||
} | ||
return ABORT_MOVE; | ||
} | ||
|
||
Physic& | ||
Bumper::get_physic() | ||
{ | ||
return m_physic; | ||
} | ||
|
||
void | ||
Bumper::after_editor_set() | ||
{ | ||
MovingSprite::after_editor_set(); | ||
set_action(m_facing_left ? "left-normal" : "right-normal"); | ||
} | ||
|
||
void | ||
Bumper::on_flip(float height) | ||
{ | ||
MovingSprite::on_flip(height); | ||
FlipLevelTransformer::transform_flip(m_flip); | ||
} | ||
|
||
/* 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,56 @@ | ||
// Copyright (C) 2020 Daniel Ward <[email protected]> | ||
// | ||
// 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_BUMPER_HPP | ||
#define HEADER_SUPERTUX_OBJECT_BUMPER_HPP | ||
|
||
#include "object/moving_sprite.hpp" | ||
#include "supertux/physic.hpp" | ||
|
||
class Player; | ||
|
||
class Bumper final : public MovingSprite | ||
{ | ||
public: | ||
Bumper(const ReaderMapping& reader); | ||
|
||
virtual ObjectSettings get_settings() override; | ||
|
||
virtual void update(float dt_sec) override; | ||
virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; | ||
|
||
static std::string class_name() { return "bumper"; } | ||
virtual std::string get_class_name() const override { return class_name(); } | ||
static std::string display_name() { return _("Bumper"); } | ||
virtual std::string get_display_name() const override { return display_name(); } | ||
|
||
virtual void on_flip(float height) override; | ||
|
||
Physic physic; | ||
|
||
private: | ||
bool left; | ||
|
||
private: | ||
Bumper(const Bumper&) = delete; | ||
Bumper& operator=(const Bumper&) = delete; | ||
}; | ||
|
||
#endif | ||
|
||
/* EOF */ | ||
// Copyright (C) 2020 Daniel Ward <[email protected]> | ||
// | ||
// 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_BUMPER_HPP | ||
#define HEADER_SUPERTUX_OBJECT_BUMPER_HPP | ||
|
||
#include "object/moving_sprite.hpp" | ||
|
||
#include "supertux/physic.hpp" | ||
|
||
class Player; | ||
|
||
class Bumper final : public MovingSprite | ||
{ | ||
public: | ||
Bumper(const ReaderMapping& reader); | ||
|
||
virtual ObjectSettings get_settings() override; | ||
|
||
virtual void update(float dt_sec) override; | ||
virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; | ||
|
||
static std::string class_name() { return "bumper"; } | ||
virtual std::string get_class_name() const override { return class_name(); } | ||
static std::string display_name() { return _("Bumper"); } | ||
virtual std::string get_display_name() const override { return display_name(); } | ||
|
||
virtual void after_editor_set() override; | ||
virtual void on_flip(float height) override; | ||
|
||
Physic& get_physic(); | ||
|
||
private: | ||
Physic m_physic; | ||
bool m_facing_left; | ||
|
||
private: | ||
Bumper(const Bumper&) = delete; | ||
Bumper& operator=(const Bumper&) = 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
Oops, something went wrong.