Skip to content

Commit

Permalink
Change default type for WeakBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 committed Jul 26, 2023
1 parent 6dfb4d4 commit 2c2c2cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
32 changes: 21 additions & 11 deletions src/object/weak_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@
#include "util/reader_mapping.hpp"

WeakBlock::WeakBlock(const ReaderMapping& mapping) :
MovingSprite(mapping, "images/objects/weak_block/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL),
MovingSprite(mapping, "images/objects/weak_block/meltbox.sprite", LAYER_TILES, COLGROUP_STATIC),
state(STATE_NORMAL),
linked(true),
lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
{
parse_type(mapping);
mapping.get("linked", linked);

// Older levels utilize hardcoded behaviour from the current sprite.
if (get_version() == 1)
{
// The object was set to the "meltbox" (ICE) sprite, if it's not linked.
// The default sprite was previously the HAY one, so we do the opposite check here.
if (linked)
m_type = HAY;

on_type_change();
}
else
{
parse_type(mapping);
}

lightsprite->set_blend(Blend::ADD);
lightsprite->set_color(Color(0.3f, 0.2f, 0.1f));

// Older levels utilize hardcoded behaviour from the chosen sprite
if (get_version() == 1)
if (matches_sprite("images/objects/weak_block/meltbox.sprite"))
m_type = ICE;

if (m_type == HAY)
SoundManager::current()->preload("sounds/fire.ogg"); // TODO: Use own sound?
else
Expand All @@ -59,8 +69,8 @@ GameObjectTypes
WeakBlock::get_types() const
{
return {
{ "hay", _("Hay") },
{ "ice", _("Ice") }
{ "ice", _("Ice") },
{ "hay", _("Hay") }
};
}

Expand All @@ -69,8 +79,8 @@ WeakBlock::get_default_sprite_name() const
{
switch (m_type)
{
case ICE:
return "images/objects/weak_block/meltbox.sprite";
case HAY:
return "images/objects/weak_block/strawbox.sprite";
default:
return m_default_sprite_name;
}
Expand Down
6 changes: 3 additions & 3 deletions src/object/weak_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WeakBlock final : public MovingSprite
private:
virtual HitResponse collision_bullet(Bullet& bullet, const CollisionHit& hit);

void on_type_change(int old_type) override;
void on_type_change(int old_type = -1) override;

private:
/** called by self when hit by a bullet */
Expand All @@ -58,8 +58,8 @@ class WeakBlock final : public MovingSprite

private:
enum Type {
HAY,
ICE
ICE,
HAY
};

enum State {
Expand Down

0 comments on commit 2c2c2cb

Please sign in to comment.