Skip to content

Commit

Permalink
PowerUp type support, object versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 committed Jul 17, 2023
1 parent 3dcc414 commit f5c25d8
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/badguy/dispenser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Dispenser::Dispenser(const ReaderMapping& reader) :
// if (badguys.size() <= 0)
// throw std::runtime_error("No badguys in dispenser.");

m_col.m_bbox.set_size(m_sprite->get_current_hitbox_width(), m_sprite->get_current_hitbox_height());
update_hitbox();
m_countMe = false;
}

Expand Down Expand Up @@ -385,8 +385,8 @@ GameObjectTypes
Dispenser::get_types() const
{
return {
{ "cannon", _("cannon") },
{ "dropper", _("dropper") },
{ "cannon", _("cannon") },
{ "point", _("invisible") }
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/dispenser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Dispenser final : public BadGuy,
{
private:
enum DispenserType {
CANNON, DROPPER, POINT
DROPPER, CANNON, POINT
};

public:
Expand Down
17 changes: 17 additions & 0 deletions src/editor/object_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "editor/object_menu.hpp"

#include "editor/editor.hpp"
#include "gui/dialog.hpp"
#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/d_scope.hpp"
Expand All @@ -43,6 +44,12 @@ ObjectMenu::ObjectMenu(GameObject* go, const std::function<bool (GameObject*)>&
}
}

if (!m_object->is_up_to_date())
{
add_hl();
add_entry(MNID_UPDATE, _("Update"));
}

if (m_remove_function)
{
add_hl();
Expand All @@ -62,6 +69,16 @@ ObjectMenu::menu_action(MenuItem& item)
{
switch (item.get_id())
{
case MNID_UPDATE:
Dialog::show_confirmation(_("This will update the object to its latest functionality.") + "\n \n" +
_("Keep in mind this is very likely to break the proper behaviour of the object.") + "\n" +
_("Make sure to re-check any behaviour, related to the object."), [this]() {
m_object->update_version();
m_editor.m_reactivate_request = true;
MenuManager::instance().pop_menu();
});
break;

case MNID_REMOVE:
m_editor.delete_markers();
m_editor.m_reactivate_request = true;
Expand Down
3 changes: 2 additions & 1 deletion src/editor/object_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ class ObjectMenu final : public Menu
{
public:
enum {
MNID_UPDATE,
MNID_REMOVE,
MNID_REMOVEFUNCTION,
MNID_TEST_FROM_HERE,
MNID_OPEN_PARTICLE_EDITOR,
MNID_OPEN_PARTICLE_EDITOR
};

public:
Expand Down
20 changes: 17 additions & 3 deletions src/editor/tip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

Tip::Tip(GameObject& object) :
m_strings(),
m_warnings(),
m_header()
{
auto os = object.get_settings();
Expand All @@ -48,6 +49,10 @@ Tip::Tip(GameObject& object) :
}
}
}

if (!object.is_up_to_date())
m_warnings.push_back(_("This object's current functionality is deprecated.") + "\n" +
_("Updating to get its latest functionality is recommended."));
}

Tip::Tip(std::string text) :
Expand All @@ -68,12 +73,21 @@ Tip::draw(DrawingContext& context, const Vector& pos, const bool align_right)
auto position = pos;
position.y += 35;
context.color().draw_text(Resources::normal_font, m_header, position,
align_right ? ALIGN_RIGHT : ALIGN_LEFT, LAYER_GUI + 10, g_config->labeltextcolor);
align_right ? ALIGN_RIGHT : ALIGN_LEFT, LAYER_GUI + 10, g_config->labeltextcolor);

for (const auto& str : m_strings)
{
position.y += 22;
context.color().draw_text(Resources::normal_font, str, position,
align_right ? ALIGN_RIGHT : ALIGN_LEFT, LAYER_GUI + 10, ColorScheme::Menu::default_color);
}

for (const auto& str : m_strings) {
position.y += 35;
for (const auto& str : m_warnings)
{
position.y += 22;
context.color().draw_text(Resources::normal_font, str, position,
align_right ? ALIGN_RIGHT : ALIGN_LEFT, LAYER_GUI + 10, ColorScheme::Menu::default_color);
align_right ? ALIGN_RIGHT : ALIGN_LEFT, LAYER_GUI + 10, ColorScheme::Menu::warning_color);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/editor/tip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Tip final

private:
std::vector<std::string> m_strings;
std::vector<std::string> m_warnings;
std::string m_header;

private:
Expand Down
18 changes: 9 additions & 9 deletions src/object/bonus_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ BonusBlock::try_open(Player* player)
}
case Content::POTION:
{
Sector::get().add<SpecialRiser>(get_pos(), std::make_unique<PowerUp>(get_pos(), "images/powerups/potions/red-potion.sprite"));
Sector::get().add<SpecialRiser>(get_pos(), std::make_unique<PowerUp>(get_pos(), PowerUp::FLIP));
break;
}
case Content::RAIN:
Expand Down Expand Up @@ -447,25 +447,25 @@ BonusBlock::try_drop(Player *player)

case Content::FIREGROW:
{
drop_growup_bonus(player, "images/powerups/fireflower/fireflower.sprite", direction, countdown);
drop_growup_bonus(player, PowerUp::FIRE, direction, countdown);
break;
}

case Content::ICEGROW:
{
drop_growup_bonus(player, "images/powerups/iceflower/iceflower.sprite", direction, countdown);
drop_growup_bonus(player, PowerUp::ICE, direction, countdown);
break;
}

case Content::AIRGROW:
{
drop_growup_bonus(player, "images/powerups/airflower/airflower.sprite", direction, countdown);
drop_growup_bonus(player, PowerUp::AIR, direction, countdown);
break;
}

case Content::EARTHGROW:
{
drop_growup_bonus(player, "images/powerups/earthflower/earthflower.sprite", direction, countdown);
drop_growup_bonus(player, PowerUp::EARTH, direction, countdown);
break;
}

Expand Down Expand Up @@ -523,7 +523,7 @@ BonusBlock::try_drop(Player *player)
}
case Content::POTION:
{
Sector::get().add<PowerUp>(get_pos() + Vector(0, 32), "images/powerups/potions/red-potion.sprite");
Sector::get().add<PowerUp>(get_pos() + Vector(0, 32), PowerUp::FLIP);
countdown = true;
break;
}
Expand Down Expand Up @@ -570,15 +570,15 @@ BonusBlock::raise_growup_bonus(Player* player, const BonusType& bonus, const Dir
}

void
BonusBlock::drop_growup_bonus(Player* player, const std::string& bonus_sprite_name, const Direction& dir, bool& countdown)
BonusBlock::drop_growup_bonus(Player* player, int type, const Direction& dir, bool& countdown)
{
if (player->get_status().bonus[player->get_id()] == NO_BONUS)
{
Sector::get().add<GrowUp>(get_pos() + Vector(0, 32), dir);
}
else
{
Sector::get().add<PowerUp>(get_pos() + Vector(0, 32), bonus_sprite_name);
Sector::get().add<PowerUp>(get_pos() + Vector(0, 32), type);
}
SoundManager::current()->play("sounds/upgrade.wav", get_pos(), upgrade_sound_gain);
countdown = true;
Expand Down Expand Up @@ -690,7 +690,7 @@ BonusBlock::preload_contents(int d)
break;

case 12: // Red potion
m_object = std::make_unique<PowerUp>(get_pos(), "images/powerups/potions/red-potion.sprite");
m_object = std::make_unique<PowerUp>(get_pos(), PowerUp::FLIP);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/object/bonus_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BonusBlock final : public Block

void preload_contents(int d);
void raise_growup_bonus(Player* player, const BonusType& bonus, const Direction& dir);
void drop_growup_bonus(Player* player, const std::string& bonus_sprite_name, const Direction& dir, bool& countdown);
void drop_growup_bonus(Player* player, int type, const Direction& dir, bool& countdown);

BonusBlock::Content get_content_by_data(int tile_data) const;
BonusBlock::Content get_content_from_string(const std::string& contentstring) const;
Expand Down
6 changes: 6 additions & 0 deletions src/object/moving_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ MovingSprite::on_type_change(int old_type)
change_sprite(get_default_sprite_name());
}

bool
MovingSprite::matches_sprite(const std::string& sprite_file)
{
return m_sprite_name == sprite_file || m_sprite_name == "/" + sprite_file;
}

void
MovingSprite::update_hitbox()
{
Expand Down
1 change: 1 addition & 0 deletions src/object/moving_sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MovingSprite : public MovingObject
const std::string& get_sprite_name() const { return m_sprite_name; }
virtual std::string get_default_sprite_name() const { return m_default_sprite_name; }

bool matches_sprite(const std::string& sprite_file);
void change_sprite(const std::string& new_sprite_name);
void spawn_explosion_sprites(int count, const std::string& sprite_path);

Expand Down
Loading

0 comments on commit f5c25d8

Please sign in to comment.