Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor not updating direction of badguys, conveyor belts and bumpers #2556

Merged
merged 5 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ BadGuy::after_editor_set()
}
else
{
std::string action_str = dir_to_string(m_dir);
std::string action_str = dir_to_string(m_start_dir);

if (m_sprite->has_action("editor-" + action_str)) {
set_action("editor-" + action_str);
Expand Down
196 changes: 103 additions & 93 deletions src/object/bumper.cpp
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 */
109 changes: 56 additions & 53 deletions src/object/bumper.hpp
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"

Vankata453 marked this conversation as resolved.
Show resolved Hide resolved
#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();

Vankata453 marked this conversation as resolved.
Show resolved Hide resolved
private:
Physic m_physic;
bool m_facing_left;

private:
Bumper(const Bumper&) = delete;
Bumper& operator=(const Bumper&) = delete;
};

#endif

/* EOF */
2 changes: 2 additions & 0 deletions src/object/conveyor_belt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ ConveyorBelt::after_editor_set()

if (m_length <= 0)
m_length = 1;
m_sprite->set_action(dir_to_string(m_dir));
update_hitbox();
Vankata453 marked this conversation as resolved.
Show resolved Hide resolved
}

void
Expand Down
Loading
Loading