Skip to content

Commit

Permalink
Replace m_sprite->clone() with a linked sprite in objects
Browse files Browse the repository at this point in the history
Crushers and bricks now use linked sprites, instead of cloning their own sprite and setting actions on its clone.
  • Loading branch information
Vankata453 committed Nov 23, 2024
1 parent a2f4d77 commit 380ea8b
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 216 deletions.
16 changes: 11 additions & 5 deletions data/images/creatures/crusher/corrupted/krosh_corrupt.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
)
)
(action
(name "whites")
(name "left-eye")
(hitbox 16 16 128 128)
(images "krosh_corrupt_whites.png")
(images "krosh_corrupt_eyes.png")
)
(action
(name "lefteye")
(name "right-eye")
(hitbox 16 16 128 128)
(images "krosh_corrupt_eyes.png")
)
(action
(name "righteye")
(name "whites")
(hitbox 16 16 128 128)
(images "krosh_corrupt_eyes.png")
(images "krosh_corrupt_whites.png")
)

(linked-sprites
(left-eye "krosh_corrupt.sprite" "left-eye")
(right-eye "krosh_corrupt.sprite" "right-eye")
(whites "krosh_corrupt.sprite" "whites")
)
)
16 changes: 11 additions & 5 deletions data/images/creatures/crusher/corrupted/krush_corrupt.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
)
)
(action
(name "whites")
(name "left-eye")
(hitbox 8 8 64 64)
(images "krush_corrupt_whites.png")
(images "krush_corrupt_eyes.png")
)
(action
(name "lefteye")
(name "right-eye")
(hitbox 8 8 64 64)
(images "krush_corrupt_eyes.png")
)
(action
(name "righteye")
(name "whites")
(hitbox 8 8 64 64)
(images "krush_corrupt_eyes.png")
(images "krush_corrupt_whites.png")
)

(linked-sprites
(left-eye "krush_corrupt.sprite" "left-eye")
(right-eye "krush_corrupt.sprite" "right-eye")
(whites "krush_corrupt.sprite" "whites")
)
)
18 changes: 12 additions & 6 deletions data/images/creatures/crusher/krosh_ice.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
)
)
(action
(name "whites")
(name "left-eye")
(hitbox 4 4 128 128)
(images "krosh_ice_whites.png")
(images "krosh_ice_lefteye.png")
)
(action
(name "lefteye")
(name "right-eye")
(hitbox 4 4 128 128)
(images "krosh_ice_lefteye.png")
(images "krosh_ice_righteye.png")
)
(action
(name "righteye")
(name "whites")
(hitbox 4 4 128 128)
(images "krosh_ice_righteye.png")
(images "krosh_ice_whites.png")
)

(linked-sprites
(left-eye "krosh_ice.sprite" "left-eye")
(right-eye "krosh_ice.sprite" "right-eye")
(whites "krosh_ice.sprite" "whites")
)
)
18 changes: 12 additions & 6 deletions data/images/creatures/crusher/krosh_rock.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
)
)
(action
(name "whites")
(name "left-eye")
(hitbox 4 4 128 128)
(images "krosh_rock_whites.png")
(images "krosh_rock_lefteye.png")
)
(action
(name "lefteye")
(name "right-eye")
(hitbox 4 4 128 128)
(images "krosh_rock_lefteye.png")
(images "krosh_rock_righteye.png")
)
(action
(name "righteye")
(name "whites")
(hitbox 4 4 128 128)
(images "krosh_rock_righteye.png")
(images "krosh_rock_whites.png")
)

(linked-sprites
(left-eye "krosh_rock.sprite" "left-eye")
(right-eye "krosh_rock.sprite" "right-eye")
(whites "krosh_rock.sprite" "whites")
)
)
18 changes: 12 additions & 6 deletions data/images/creatures/crusher/krush_ice.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
)
)
(action
(name "whites")
(name "left-eye")
(hitbox 3 3 64 64)
(images "krush_ice_whites.png")
(images "krush_ice_lefteye.png")
)
(action
(name "lefteye")
(name "right-eye")
(hitbox 3 3 64 64)
(images "krush_ice_lefteye.png")
(images "krush_ice_righteye.png")
)
(action
(name "righteye")
(name "whites")
(hitbox 3 3 64 64)
(images "krush_ice_righteye.png")
(images "krush_ice_whites.png")
)

(linked-sprites
(left-eye "krush_ice.sprite" "left-eye")
(right-eye "krush_ice.sprite" "right-eye")
(whites "krush_ice.sprite" "whites")
)
)
18 changes: 12 additions & 6 deletions data/images/creatures/crusher/krush_rock.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@
)
)
(action
(name "whites")
(name "left-eye")
(hitbox 3 3 64 64)
(images "krush_rock_whites.png")
(images "krush_rock_lefteye.png")
)
(action
(name "lefteye")
(name "right-eye")
(hitbox 3 3 64 64)
(images "krush_rock_lefteye.png")
(images "krush_rock_righteye.png")
)
(action
(name "righteye")
(name "whites")
(hitbox 3 3 64 64)
(images "krush_rock_righteye.png")
(images "krush_rock_whites.png")
)

(linked-sprites
(left-eye "krush_rock.sprite" "left-eye")
(right-eye "krush_rock.sprite" "right-eye")
(whites "krush_rock.sprite" "whites")
)
)
6 changes: 5 additions & 1 deletion data/images/objects/bonus_block/brick.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@
(name "piece6")
(fps 1)
(images "../../tiles/blocks/brick_piece6.png"))
)

(linked-sprites
(break-particles "brick.sprite")
)
)
32 changes: 3 additions & 29 deletions data/images/objects/bonus_block/brickIce.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,7 @@
(name "normal")
(images "../../tiles/blocks/brick1.png"))

(action
(name "piece1")
(fps 1)
(images "../../tiles/blocks/brick_piece1.png"))

(action
(name "piece2")
(fps 1)
(images "../../tiles/blocks/brick_piece2.png"))

(action
(name "piece3")
(fps 1)
(images "../../tiles/blocks/brick_piece3.png"))

(action
(name "piece4")
(fps 1)
(images "../../tiles/blocks/brick_piece4.png"))

(action
(name "piece5")
(fps 1)
(images "../../tiles/blocks/brick_piece5.png"))

(action
(name "piece6")
(fps 1)
(images "../../tiles/blocks/brick_piece6.png"))
(linked-sprites
(break-particles "brick.sprite")
)
)
32 changes: 3 additions & 29 deletions data/images/objects/bonus_block/brickWeb.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,7 @@
(name "normal")
(images "../../tiles/blocks/brick2.png"))

(action
(name "piece1")
(fps 1)
(images "../../tiles/blocks/brick_piece1.png"))

(action
(name "piece2")
(fps 1)
(images "../../tiles/blocks/brick_piece2.png"))

(action
(name "piece3")
(fps 1)
(images "../../tiles/blocks/brick_piece3.png"))

(action
(name "piece4")
(fps 1)
(images "../../tiles/blocks/brick_piece4.png"))

(action
(name "piece5")
(fps 1)
(images "../../tiles/blocks/brick_piece5.png"))

(action
(name "piece6")
(fps 1)
(images "../../tiles/blocks/brick_piece6.png"))
(linked-sprites
(break-particles "brick.sprite")
)
)
4 changes: 4 additions & 0 deletions data/images/objects/bonus_block/heavy-brick.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@
(name "piece6")
(fps 1)
(images "../../tiles/blocks/brick_piece12.png"))

(linked-sprites
(break-particles "heavy-brick.sprite")
)
)
59 changes: 23 additions & 36 deletions src/badguy/crusher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ Crusher::Crusher(const ReaderMapping& reader) :
// TODO: Add distinct sounds for crusher hitting the ground and hitting Tux.
SoundManager::current()->preload(not_ice() ? "sounds/thud.ogg" : "sounds/brick.wav");
set_state(m_state, true);
after_sprite_set();
}

MovingSprite::LinkedSprites
Crusher::get_linked_sprites()
{
return {
{ "left-eye", m_lefteye },
{ "right-eye", m_righteye },
{ "whites", m_whites }
};
}

GameObjectTypes
Expand Down Expand Up @@ -119,6 +128,13 @@ Crusher::on_type_change(int old_type)
MovingSprite::on_type_change(old_type);
}

void
Crusher::on_sprite_update()
{
MovingSprite::on_sprite_update();
set_state(m_state, true);
}

HitResponse
Crusher::collision(GameObject& other, const CollisionHit& hit)
{
Expand Down Expand Up @@ -472,26 +488,17 @@ Crusher::draw(DrawingContext& context)
const Vector draw_pos = get_pos() + draw_offset;

m_sprite->draw(context.color(), draw_pos, m_layer + 2, m_flip);
if (m_sprite->has_action("whites"))
{
// Draw crusher's eyes slightly behind.
m_lefteye->draw(context.color(), draw_pos + eye_position(false), m_layer + 1, m_flip);
m_righteye->draw(context.color(), draw_pos + eye_position(true), m_layer + 1, m_flip);
// Draw the whites of crusher's eyes even further behind.
m_whites->draw(context.color(), draw_pos, m_layer, m_flip);
}

// Draw crusher's eyes slightly behind.
m_lefteye->draw(context.color(), draw_pos + eye_position(false), m_layer + 1, m_flip);
m_righteye->draw(context.color(), draw_pos + eye_position(true), m_layer + 1, m_flip);
// Draw the whites of crusher's eyes even further behind.
m_whites->draw(context.color(), draw_pos, m_layer, m_flip);

if (m_light_sprite)
m_light_sprite->draw(context.light(), m_col.m_bbox.get_middle() + draw_offset, m_layer + 3);
}

void
Crusher::after_editor_set()
{
MovingSprite::after_editor_set();
after_sprite_set();
}

ObjectSettings
Crusher::get_settings()
{
Expand Down Expand Up @@ -585,26 +592,6 @@ Crusher::set_state(CrusherState state_, bool force)
m_state = state_;
}

void
Crusher::after_sprite_set()
{
if (!m_sprite->has_action("whites"))
{
m_lefteye.reset();
m_righteye.reset();
m_whites.reset();
}
else
{
m_lefteye = m_sprite->clone();
m_lefteye->set_action("lefteye");
m_righteye = m_sprite->clone();
m_righteye->set_action("righteye");
m_whites = m_sprite->clone();
m_whites->set_action("whites");
}
}

Vector
Crusher::eye_position(bool right) const
{
Expand Down
Loading

0 comments on commit 380ea8b

Please sign in to comment.