Skip to content

Commit 09c032f

Browse files
committed
and falling
1 parent 7196df2 commit 09c032f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

JewelBoard.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "utils/utils.h"
1616
#include "utils/log.h"
1717
#include <assert.h>
18+
#include <algorithm>
19+
20+
1821

1922
#include <SDL_events.h>
2023

@@ -119,18 +122,21 @@ void JewelBoard::pureSwap(BoardPos pos, BoardPos pos2)
119122
{
120123
/*getJewel(BoardPos(pos.m_col, pos.m_row + 1)) = jo;
121124
getJewel(BoardPos(pos.m_col, pos.m_row)).resetFalling();*/
122-
125+
std::swap( m_jewels[pos.m_row][pos.m_col], m_jewels[pos2.m_row][pos2.m_col]);
123126
}
124127

125128
void JewelBoard::shiftDown(BoardPos pos)
126129
{
127-
JewelObject &jo = getJewel(pos);
130+
//JewelObject &jo = getJewel(pos);
128131
assert(pos.m_row < BoardPos::NUM_ROWS);
129132
{
130133
BoardPos next = pos.getBelow();
131134
pureSwap(pos, next);
132135
//it will be set to falling again if lower jewel is detected to be empty
133136
getJewel(next).resetFalling();
137+
//resurrect so that it will fall
138+
if (pos.m_row == 0)
139+
getJewel(pos).kill();
134140
}
135141
/* else
136142
{
@@ -175,13 +181,14 @@ void JewelBoard::update()
175181
JewelObject &jo = getJewel(pos);
176182
if(jo.isFallDone())
177183
shiftDown(pos);
178-
if (jo.isFalling() || jo.isDead())
184+
if (pos.m_row > 0 && (jo.isFalling() || jo.isDead()))
179185
{
180-
getJewel(BoardPos(pos.m_col, pos.m_row - 1)).fallStep();
186+
JewelObject &upper = getJewel(BoardPos(pos.m_col, pos.m_row - 1));
187+
upper.fallStep();
181188
}
182189
jo.update();
183190

184-
});
191+
}, true);
185192
}
186193

187194
void JewelBoard::clean()

JewelObject.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void JewelObject::update()
6262
if (m_dyingCounter == m_dyingTime)
6363
{
6464
m_bDead = true;
65+
m_bDying = false;
6566
}
6667
} else if (isFalling())
6768
{
@@ -77,6 +78,10 @@ void JewelObject::setMovement(JewelMove const &m)
7778
}
7879

7980

81+
void JewelObject::resurrect()
82+
{
83+
m_bDying = false;
84+
}
8085

8186
void JewelObject::kill()
8287
{

JewelObject.h

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class JewelObject : public BoardObject
3939

4040
void setMovement(JewelMove const &m);
4141
void kill();
42+
void resurrect();
43+
4244
virtual void doDyingAnimation() override;
4345
bool isFalling() const;
4446
bool isFallDone() const;

0 commit comments

Comments
 (0)