Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bruhmoent authored Jul 21, 2023
2 parents afb014f + b132c25 commit 43464dc
Show file tree
Hide file tree
Showing 34 changed files with 182 additions and 125 deletions.
13 changes: 9 additions & 4 deletions src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ Editor::test_level(const std::optional<std::pair<std::string, Vector>>& test_pos
}
else
{
GameManager::current()->start_worldmap(*current_world, "", m_autosave_levelfile);
GameManager::current()->start_worldmap(*current_world, m_autosave_levelfile, test_pos);
}
}

Expand Down Expand Up @@ -404,13 +404,19 @@ Editor::update_keyboard(const Controller& controller)
return;
}


if (!MenuManager::instance().has_dialog())
if (MenuManager::instance().current_menu() == nullptr)
{
if (controller.pressed(Control::ESCAPE)) {
esc_press();
return;
}
if (controller.pressed(Control::DEBUG_MENU) && g_config->developer_mode)
{
m_enabled = false;
m_overlay_widget->delete_markers();
MenuManager::instance().set_menu(MenuStorage::DEBUG_MENU);
return;
}
if (controller.hold(Control::LEFT)) {
scroll({ -m_scroll_speed, 0.0f });
}
Expand Down Expand Up @@ -682,7 +688,6 @@ Editor::setup()
m_enabled = true;
m_toolbox_widget->update_mouse_icon();
}

}

void
Expand Down
19 changes: 12 additions & 7 deletions src/object/bonus_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ BonusBlock::BonusBlock(const Vector& pos, int tile_data) :
m_hit_counter(1),
m_script(),
m_lightsprite(),
m_custom_sx()
m_custom_sx(),
m_coin_sprite("images/objects/coin/coin.sprite")
{
m_default_sprite_name = "images/objects/bonus_block/bonusblock.sprite";

Expand All @@ -86,7 +87,8 @@ BonusBlock::BonusBlock(const ReaderMapping& mapping) :
m_hit_counter(1),
m_script(),
m_lightsprite(),
m_custom_sx()
m_custom_sx(),
m_coin_sprite("images/objects/coin/coin.sprite")
{
m_default_sprite_name = "images/objects/bonus_block/bonusblock.sprite";

Expand Down Expand Up @@ -138,6 +140,8 @@ BonusBlock::BonusBlock(const ReaderMapping& mapping) :
}
}
}
} else if (token == "coin-sprite") {
iter.get(m_coin_sprite);
} else if (token == "custom-contents") {
// Handled elsewhere.
} else {
Expand Down Expand Up @@ -219,8 +223,9 @@ BonusBlock::get_settings()
"1up", "custom", "script", "light", "light-on", "trampoline", "portabletrampoline", "rain", "explode", "rock", "potion"},
static_cast<int>(Content::COIN), "contents");
result.add_sexp(_("Custom Content"), "custom-contents", m_custom_sx);
result.add_sprite(_("Coin sprite"), &m_coin_sprite, "coin-sprite", "images/objects/coin/coin.sprite");

result.reorder({"script", "count", "contents", "sprite", "x", "y"});
result.reorder({"script", "count", "contents", "coin-sprite", "sprite", "x", "y"});

return result;
}
Expand Down Expand Up @@ -289,7 +294,7 @@ BonusBlock::try_open(Player* player)
switch (m_contents) {
case Content::COIN:
{
Sector::get().add<BouncyCoin>(get_pos(), true);
Sector::get().add<BouncyCoin>(get_pos(), true, m_coin_sprite);
SoundManager::current()->play("sounds/coin.wav", get_pos());
player->get_status().add_coins(1, false);
if (m_hit_counter != 0 && !m_parent_dispenser)
Expand Down Expand Up @@ -379,13 +384,13 @@ BonusBlock::try_open(Player* player)
}
case Content::RAIN:
{
Sector::get().add<CoinRain>(get_pos(), true, !m_parent_dispenser);
Sector::get().add<CoinRain>(get_pos(), true, !m_parent_dispenser, m_coin_sprite);
play_upgrade_sound = true;
break;
}
case Content::EXPLODE:
{
Sector::get().add<CoinExplode>(get_pos() + Vector (0, -40), !m_parent_dispenser);
Sector::get().add<CoinExplode>(get_pos() + Vector (0, -40), !m_parent_dispenser, m_coin_sprite);
play_upgrade_sound = true;
break;
}
Expand Down Expand Up @@ -529,7 +534,7 @@ BonusBlock::try_drop(Player *player)
}
case Content::EXPLODE:
{
Sector::get().add<CoinExplode>(get_pos() + Vector (0, 40), !m_parent_dispenser);
Sector::get().add<CoinExplode>(get_pos() + Vector (0, 40), !m_parent_dispenser, m_coin_sprite);
play_upgrade_sound = true;
countdown = true;
break;
Expand Down
1 change: 1 addition & 0 deletions src/object/bonus_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class BonusBlock final : public Block
std::string m_script;
SurfacePtr m_lightsprite;
sexp::Value m_custom_sx;
std::string m_coin_sprite;

private:
BonusBlock(const BonusBlock&) = delete;
Expand Down
13 changes: 2 additions & 11 deletions src/object/brick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ HitResponse
Brick::collision(GameObject& other, const CollisionHit& hit)
{
auto player = dynamic_cast<Player*> (&other);
if (player) {
if (player->m_does_buttjump) try_break(player);
if (player->is_stone() && player->get_velocity().y >= 280) try_break(player); // stoneform breaks through bricks
}
if (player && player->m_does_buttjump) try_break(player);

auto badguy = dynamic_cast<BadGuy*> (&other);
if (badguy) {
Expand Down Expand Up @@ -166,13 +163,7 @@ HitResponse
HeavyBrick::collision(GameObject& other, const CollisionHit& hit)
{
auto player = dynamic_cast<Player*>(&other);
if (player)
{
if (player->is_stone() && player->get_velocity().y >= 280)
try_break(player);
else if (player->m_does_buttjump)
ricochet(&other);
}
if (player && player->m_does_buttjump) ricochet(&other);

auto crusher = dynamic_cast<Crusher*> (&other);
if (crusher)
Expand Down
8 changes: 4 additions & 4 deletions src/object/coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "util/reader_mapping.hpp"
#include "util/writer.hpp"

Coin::Coin(const Vector& pos, bool count_stats) :
MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_OBJECTS - 1, COLGROUP_TOUCHABLE),
Coin::Coin(const Vector& pos, bool count_stats, const std::string& sprite_path) :
MovingSprite(pos, sprite_path, LAYER_OBJECTS - 1, COLGROUP_TOUCHABLE),
PathObject(),
m_offset(0.0f, 0.0f),
m_from_tilemap(false),
Expand Down Expand Up @@ -210,8 +210,8 @@ Coin::collision(GameObject& other, const CollisionHit& )
}

/* The following defines a coin subject to gravity. */
HeavyCoin::HeavyCoin(const Vector& pos, const Vector& init_velocity, bool count_stats) :
Coin(pos, count_stats),
HeavyCoin::HeavyCoin(const Vector& pos, const Vector& init_velocity, bool count_stats, const std::string& sprite_path) :
Coin(pos, count_stats, sprite_path),
m_physic(),
m_last_hit()
{
Expand Down
6 changes: 4 additions & 2 deletions src/object/coin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Coin : public MovingSprite,
friend class HeavyCoin;

public:
Coin(const Vector& pos, bool count_stats = true);
Coin(const Vector& pos, bool count_stats = true,
const std::string& sprite_path = "images/objects/coin/coin.sprite");
Coin(const ReaderMapping& reader, bool count_stats = true);
virtual void finish_construction() override;

Expand Down Expand Up @@ -73,7 +74,8 @@ friend class HeavyCoin;
class HeavyCoin final : public Coin
{
public:
HeavyCoin(const Vector& pos, const Vector& init_velocity, bool count_stats = true);
HeavyCoin(const Vector& pos, const Vector& init_velocity, bool count_stats = true,
const std::string& sprite_path = "images/objects/coin/coin.sprite");
HeavyCoin(const ReaderMapping& reader, bool count_stats = true);

virtual void update(float dt_sec) override;
Expand Down
23 changes: 12 additions & 11 deletions src/object/coin_explode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#include "object/coin.hpp"
#include "supertux/sector.hpp"

CoinExplode::CoinExplode(const Vector& pos, bool count_stats) :
CoinExplode::CoinExplode(const Vector& pos, bool count_stats, const std::string& sprite) :
m_sprite(sprite),
position(pos),
m_count_stats(count_stats)
{
Expand All @@ -32,16 +33,16 @@ CoinExplode::update(float )
float mag = 100.0f; // Magnitude at which coins are thrown.
float rand = 30.0f; // Max variation to be subtracted from the magnitude.

Sector::get().add<HeavyCoin>(position, Vector(2.5, -4.5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(2, -5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(1.5, -5.5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(1, -6) * (mag+gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(0.5, -6.5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(-2.5, -4.5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(-2, -5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(-1.5, -5.5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(-1, -6) * (mag+gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(-0.5, -6.5) * (mag - gameRandom.randf(rand)), m_count_stats);
Sector::get().add<HeavyCoin>(position, Vector(2.5, -4.5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(2, -5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(1.5, -5.5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(1, -6) * (mag+gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(0.5, -6.5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(-2.5, -4.5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(-2, -5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(-1.5, -5.5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(-1, -6) * (mag+gameRandom.randf(rand)), m_count_stats, m_sprite);
Sector::get().add<HeavyCoin>(position, Vector(-0.5, -6.5) * (mag - gameRandom.randf(rand)), m_count_stats, m_sprite);

remove_me();
}
Expand Down
4 changes: 3 additions & 1 deletion src/object/coin_explode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
class CoinExplode final : public GameObject
{
public:
CoinExplode(const Vector& pos, bool count_stats = true);
CoinExplode(const Vector& pos, bool count_stats = true,
const std::string& sprite_path = "images/objects/coin/coin.sprite");
virtual void update(float dt_sec) override;
virtual void draw(DrawingContext& context) override;
virtual bool is_saveable() const override {
return false;
}

private:
std::string m_sprite;
Vector position;
const bool m_count_stats;
};
Expand Down
9 changes: 5 additions & 4 deletions src/object/coin_rain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

static const float DROP_TIME = .1f; // Time duration between "drops" of coin rain.

CoinRain::CoinRain(const Vector& pos, bool emerge, bool count_stats) :
sprite(SpriteManager::current()->create("images/objects/coin/coin.sprite")),
CoinRain::CoinRain(const Vector& pos, bool emerge, bool count_stats, const std::string& sprite_path) :
sprite(SpriteManager::current()->create(sprite_path)),
m_sprite_path(sprite_path),
position(pos),
emerge_distance(0),
timer(),
Expand All @@ -50,7 +51,7 @@ CoinRain::update(float dt_sec)
else if (counter==0){
drop = gameRandom.rand(10);
Sector::get().add<HeavyCoin>(Vector(position.x + 32.0f * static_cast<float>((drop < 5) ? -drop - 1 : drop - 4), -32.0f),
Vector(0, 0), m_count_stats);
Vector(0, 0), m_count_stats, m_sprite_path);
counter++;
timer.start(DROP_TIME);
} // Finally, the remaining coins drop in a determined but seemingly random order.
Expand All @@ -59,7 +60,7 @@ CoinRain::update(float dt_sec)
drop += 7;
if (drop >= 10) drop -=10;
Sector::get().add<HeavyCoin>(Vector(position.x + 32.0f * static_cast<float>((drop < 5) ? -drop - 1 : drop - 4), -32.0f),
Vector(0, 0), m_count_stats);
Vector(0, 0), m_count_stats, m_sprite_path);
counter++;
timer.start(DROP_TIME);
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/object/coin_rain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
class CoinRain final : public GameObject
{
public:
CoinRain(const Vector& pos, bool emerge=false, bool count_stats = true);
CoinRain(const Vector& pos, bool emerge=false, bool count_stats = true,
const std::string& sprite_path = "images/objects/coin/coin.sprite");
virtual void update(float dt_sec) override;
virtual void draw(DrawingContext& context) override;
virtual bool is_saveable() const override {
Expand All @@ -34,6 +35,7 @@ class CoinRain final : public GameObject

private:
SpritePtr sprite;
std::string m_sprite_path;
Vector position;
float emerge_distance;
Timer timer;
Expand Down
20 changes: 15 additions & 5 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,19 +745,29 @@ Player::update(float dt_sec)
}
}

if (m_does_buttjump)
if (m_does_buttjump || (m_stone && m_physic.get_velocity_y() > 30.f && !m_coyote_timer.started()))
{
Rectf downbox = get_bbox().grown(-1.f);
downbox.set_bottom(get_bbox().get_bottom() + 16.f);
for (auto& brick : Sector::get().get_objects_by_type<Brick>()) {
if (downbox.contains(brick.get_bbox()) && brick.get_class_name() != "heavy-brick") {
// stoneform breaks through any kind of bricks
if (downbox.contains(brick.get_bbox()) && (m_stone || !dynamic_cast<HeavyBrick*>(&brick)))
brick.try_break(this, is_big());
}
}
for (auto& badguy : Sector::get().get_objects_by_type<BadGuy>()) {
if (downbox.contains(badguy.get_bbox()) && badguy.is_snipable()) {
if (downbox.contains(badguy.get_bbox()) && badguy.is_snipable())
badguy.kill_fall();
}
}
}

// break bricks above without stopping
if (m_stone && m_physic.get_velocity_y() < 30.f)
{
Rectf topbox = get_bbox().grown(-1.f);
topbox.set_top(get_bbox().get_top() - 16.f);
for (auto& brick : Sector::get().get_objects_by_type<Brick>()) {
if (topbox.contains(brick.get_bbox()))
brick.try_break(this, is_big());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/scripting/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class BadGuy
{
#ifndef SCRIPTING_API
public:
BadGuy(UID uid, ::GameObjectManager& parent) :
GameObject<::BadGuy>(uid, parent)
BadGuy(const ::GameObject& object) :
GameObject<::BadGuy>(object)
{}

private:
Expand Down
8 changes: 4 additions & 4 deletions src/scripting/dispenser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class Dispenser final : public scripting::BadGuy
{
#ifndef SCRIPTING_API
public:
Dispenser(UID uid, ::GameObjectManager& parent) :
GameObject<::BadGuy>(uid, parent),
GameObject<::Dispenser>(uid, parent),
BadGuy(uid, parent)
Dispenser(const ::GameObject& object) :
GameObject<::BadGuy>(object),
GameObject<::Dispenser>(object),
BadGuy(object)
{}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/floating_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace scripting {

FloatingImage::FloatingImage(const std::string& spritefile) :
GameObject(get_game_object_manager().add<::FloatingImage>(spritefile).get_uid(), get_game_object_manager())
GameObject(get_sector().add<::FloatingImage>(spritefile))
{
}

Expand Down
10 changes: 5 additions & 5 deletions src/scripting/game_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

#include "scripting/game_object.hpp"

#include "supertux/d_scope.hpp"
#include "supertux/sector.hpp"

namespace scripting {

::GameObjectManager& get_game_object_manager()
::Sector& get_sector()
{
if (d_gameobject_manager)
return *d_gameobject_manager.get();
if (::Sector::current())
return ::Sector::get();

throw std::runtime_error("Unable to perform scripting GameObject action: No active GameObjectManager.");
throw std::runtime_error("Unable to perform scripting action: No active Sector.");
}

} // namespace scripting
Expand Down
Loading

0 comments on commit 43464dc

Please sign in to comment.