Skip to content

Commit b4424e9

Browse files
authored
Fix bonusblock terrible sound (#3404)
fixes #3350 fixes #3359
1 parent 54a3823 commit b4424e9

File tree

5 files changed

+75
-51
lines changed

5 files changed

+75
-51
lines changed

src/collision/collision_hit.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@ class CollisionHit final
5757
bool crush;
5858

5959
Vector slope_normal;
60+
61+
inline bool has_direction() const {
62+
return left || right || top || bottom;
63+
}
64+
65+
inline bool is_vertical() const {
66+
return top || bottom;
67+
}
68+
69+
inline bool is_horizontal() const {
70+
return left || right;
71+
}
6072
};

src/object/block.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ Block::Block(const ReaderMapping& mapping, const std::string& sprite_file) :
6565
}
6666

6767
HitResponse
68-
Block::collision(MovingObject& other, const CollisionHit& )
68+
Block::collision(MovingObject& other, const CollisionHit& hit_)
6969
{
70+
if (!hit_.has_direction()) {
71+
return FORCE_MOVE;
72+
}
73+
7074
auto player = dynamic_cast<Player*> (&other);
7175
if (player)
7276
{

src/object/bonus_block.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -300,37 +300,40 @@ BonusBlock::hit(Player& player)
300300
HitResponse
301301
BonusBlock::collision(MovingObject& other, const CollisionHit& hit_)
302302
{
303-
auto player = dynamic_cast<Player*> (&other);
304-
if (player) {
305-
if (player->m_does_buttjump ||
306-
(player->is_swimboosting() && player->get_bbox().get_bottom() < m_col.m_bbox.get_top() + SHIFT_DELTA))
307-
{
308-
try_drop(player);
303+
if (hit_.has_direction()) {
304+
auto player = dynamic_cast<Player*> (&other);
305+
if (player) {
306+
if (player->m_does_buttjump ||
307+
(player->is_swimboosting() && player->get_bbox().get_bottom() < m_col.m_bbox.get_top() + SHIFT_DELTA))
308+
{
309+
try_drop(player);
310+
}
309311
}
310-
}
311312

312-
auto badguy = dynamic_cast<BadGuy*> (&other);
313-
if (badguy) {
314-
// Hit contains no information for collisions with blocks.
315-
// Badguy's bottom has to be below the top of the block
316-
// SHIFT_DELTA is required to slide over one tile gaps.
317-
if ( badguy->can_break() && ( badguy->get_bbox().get_bottom() > m_col.m_bbox.get_top() + SHIFT_DELTA ) ) {
318-
try_open(player);
313+
auto badguy = dynamic_cast<BadGuy*> (&other);
314+
if (badguy) {
315+
// Hit contains no information for collisions with blocks.
316+
// Badguy's bottom has to be below the top of the block
317+
// SHIFT_DELTA is required to slide over one tile gaps.
318+
if ( badguy->can_break() && ( badguy->get_bbox().get_bottom() > m_col.m_bbox.get_top() + SHIFT_DELTA ) ) {
319+
try_open(player);
320+
}
319321
}
320-
}
321-
322-
auto crusher = dynamic_cast<Crusher*> (&other);
323-
if (crusher)
324-
{
325-
try_open(player);
326-
}
327322

328-
auto portable = dynamic_cast<Portable*> (&other);
329-
if (portable && !badguy) {
330-
if (other.get_bbox().get_top() > m_col.m_bbox.get_bottom() - SHIFT_DELTA) {
323+
auto crusher = dynamic_cast<Crusher*> (&other);
324+
if (crusher)
325+
{
331326
try_open(player);
332327
}
328+
329+
auto portable = dynamic_cast<Portable*> (&other);
330+
if (portable && !badguy) {
331+
if (other.get_bbox().get_top() > m_col.m_bbox.get_bottom() - SHIFT_DELTA) {
332+
try_open(player);
333+
}
334+
}
333335
}
336+
334337
return Block::collision(other, hit_);
335338
}
336339

src/object/brick.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,36 @@ Brick::hit(Player& player)
8585
HitResponse
8686
Brick::collision(MovingObject& other, const CollisionHit& hit)
8787
{
88-
auto player = dynamic_cast<Player*> (&other);
89-
if (player && player->m_does_buttjump) try_break(player);
90-
91-
auto badguy = dynamic_cast<BadGuy*> (&other);
92-
if (badguy) {
93-
// Hit contains no information for collisions with blocks.
94-
// Badguy's bottom has to be below the top of the brick
95-
// SHIFT_DELTA is required to slide over one tile gaps.
96-
if ( badguy->can_break() && ( badguy->get_bbox().get_bottom() > m_col.m_bbox.get_top() + SHIFT_DELTA ) ) {
97-
try_break(nullptr);
88+
if (hit.has_direction()) {
89+
auto player = dynamic_cast<Player*> (&other);
90+
if (player && player->m_does_buttjump) try_break(player);
91+
92+
auto badguy = dynamic_cast<BadGuy*> (&other);
93+
if (badguy) {
94+
// Hit contains no information for collisions with blocks.
95+
// Badguy's bottom has to be below the top of the brick
96+
// SHIFT_DELTA is required to slide over one tile gaps.
97+
if ( badguy->can_break() && ( badguy->get_bbox().get_bottom() > m_col.m_bbox.get_top() + SHIFT_DELTA ) ) {
98+
try_break(nullptr);
99+
}
98100
}
99-
}
100-
auto portable = dynamic_cast<Portable*> (&other);
101-
if (portable && !badguy) {
102-
if (other.get_bbox().get_top() > m_col.m_bbox.get_bottom() - SHIFT_DELTA) {
101+
auto portable = dynamic_cast<Portable*> (&other);
102+
if (portable && !badguy) {
103+
if (other.get_bbox().get_top() > m_col.m_bbox.get_bottom() - SHIFT_DELTA) {
104+
try_break(nullptr);
105+
}
106+
}
107+
108+
auto explosion = dynamic_cast<Explosion*> (&other);
109+
if (explosion && explosion->hurts()) {
103110
try_break(nullptr);
104111
}
105-
}
106112

107-
auto explosion = dynamic_cast<Explosion*> (&other);
108-
if (explosion && explosion->hurts()) {
109-
try_break(nullptr);
113+
auto crusher = dynamic_cast<Crusher*> (&other);
114+
if (crusher && crusher->get_state() == Crusher::CRUSHING && m_coin_counter == 0)
115+
try_break(nullptr);
110116
}
111117

112-
auto crusher = dynamic_cast<Crusher*> (&other);
113-
if (crusher && crusher->get_state() == Crusher::CRUSHING && m_coin_counter == 0)
114-
try_break(nullptr);
115-
116118
return Block::collision(other, hit);
117119
}
118120

src/object/infoblock.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,14 @@ InfoBlock::hit(Player& player)
125125
HitResponse
126126
InfoBlock::collision(MovingObject& other, const CollisionHit& hit_)
127127
{
128-
auto player = dynamic_cast<Player*> (&other);
129-
if (player && player->m_does_buttjump)
130-
{
131-
InfoBlock::hit(*player);
128+
if (hit_.has_direction()) {
129+
auto player = dynamic_cast<Player*> (&other);
130+
if (player && player->m_does_buttjump)
131+
{
132+
InfoBlock::hit(*player);
133+
}
132134
}
135+
133136
return Block::collision(other, hit_);
134137
}
135138

0 commit comments

Comments
 (0)