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

Ability to set bonus block coin sprite for coin, coin rain and coin explosion #2546

Merged
merged 6 commits into from
Jul 20, 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
15 changes: 10 additions & 5 deletions src/object/bonus_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ BonusBlock::BonusBlock(const Vector& pos, int tile_data) :
m_custom_sx()
{
m_default_sprite_name = "images/objects/bonus_block/bonusblock.sprite";
m_coin_sprite = "images/objects/coin/coin.sprite";
MatusGuy marked this conversation as resolved.
Show resolved Hide resolved

m_col.m_bbox.set_pos(pos);
m_sprite->set_action("normal");
Expand All @@ -89,6 +90,7 @@ BonusBlock::BonusBlock(const ReaderMapping& mapping) :
m_custom_sx()
{
m_default_sprite_name = "images/objects/bonus_block/bonusblock.sprite";
m_coin_sprite = "images/objects/coin/coin.sprite";

auto iter = mapping.get_iter();
while (iter.next()) {
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
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
24 changes: 13 additions & 11 deletions src/object/coin_explode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

#include "math/random.hpp"
#include "object/coin.hpp"
#include "sprite/sprite_manager.hpp"
MatusGuy marked this conversation as resolved.
Show resolved Hide resolved
#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 +34,16 @@ CoinExplode::update(float )
float mag = 100.0f; // madnitude that coins are to be thrown
float rand = 30.0f; // max variation to be subtracted from magnitide

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 remainder of the coins drop in a determined but appears to be a 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