generated from sigonasr2/CPlusPlusProjectTemplate
Proper block clump separation
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
268d071e9b
commit
2dad7fc3a3
1
Block.h
1
Block.h
@ -5,6 +5,7 @@
|
|||||||
class Block{
|
class Block{
|
||||||
public:
|
public:
|
||||||
vf2d pos;
|
vf2d pos;
|
||||||
|
bool markedForDeletion=false;
|
||||||
Block(vf2d pos)
|
Block(vf2d pos)
|
||||||
:pos(pos){}
|
:pos(pos){}
|
||||||
};
|
};
|
||||||
|
32
Board.cpp
32
Board.cpp
@ -37,9 +37,35 @@ std::vector<BlockClump>&Board::getBlockClumps(){
|
|||||||
|
|
||||||
void Board::removeClump(int ind){
|
void Board::removeClump(int ind){
|
||||||
BlockClump&c=clumps[ind];
|
BlockClump&c=clumps[ind];
|
||||||
for (Block b:c.getBlocks()){
|
for (Block&b:c.getBlocks()){
|
||||||
cols[b.pos.x/12].push_back(b);
|
if (b.markedForDeletion) continue;
|
||||||
cols[b.pos.x/12][cols[b.pos.x/12].size()-1].pos=c.getBlockPosition(b);
|
vf2d relativePos=b.pos;
|
||||||
|
b.pos=c.getBlockPosition(b);
|
||||||
|
bool emptyAirBelow=true;
|
||||||
|
for (int i=0;i<cols[b.pos.x/12].size();i++) {
|
||||||
|
Block&b2=cols[b.pos.x/12][i];
|
||||||
|
if (b.pos.y+12>=b2.pos.y&&b.pos.y<=b2.pos.y+12) {
|
||||||
|
emptyAirBelow=false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (b.pos.y>=yBottom) {
|
||||||
|
emptyAirBelow=false;
|
||||||
|
}
|
||||||
|
if (emptyAirBelow) {
|
||||||
|
BlockClump c2;
|
||||||
|
for (int i=0;i<c.getBlocks().size();i++) {
|
||||||
|
Block&b2=c.getBlocks()[i];
|
||||||
|
if (b.pos.x==b2.pos.x) {
|
||||||
|
b2.markedForDeletion=true;
|
||||||
|
c2.addBlock(relativePos);
|
||||||
|
}
|
||||||
|
c2.y=c.y;
|
||||||
|
}
|
||||||
|
clumps.push_back(c2);
|
||||||
|
} else {
|
||||||
|
cols[b.pos.x/12].push_back(b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
clumps.erase(clumps.begin()+ind);
|
clumps.erase(clumps.begin()+ind);
|
||||||
}
|
}
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user