Block matching between two landed clumps fixed up

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 16b1290fe0
commit 4010b52c5b
  1. 18
      Board.cpp
  2. BIN
      C++ProjectTemplate
  3. 81
      main.cpp

@ -17,6 +17,24 @@ maxWarningLevel(maxWarningLevel){
warningFlashingLevel.push_back(0.f); warningFlashingLevel.push_back(0.f);
} }
clumps.reserve(100); clumps.reserve(100);
BlockClump newClump;
BlockClump newClump2;
newClump.addBlock(2,0,BlockColor::WHITE);
newClump.addBlock(1,0,BlockColor::WHITE);
newClump.addBlock(0,0,BlockColor::WHITE);
newClump.addBlock(2,-1,BlockColor::RED);
newClump.addBlock(3,-1,BlockColor::RED);
newClump2.addBlock(4,0,BlockColor::WHITE);
newClump2.addBlock(5,0,BlockColor::WHITE);
newClump2.addBlock(6,0,BlockColor::WHITE);
newClump2.addBlock(7,0,BlockColor::BLUE);
newClump2.addBlock(4,-1,BlockColor::RED);
newClump2.addBlock(5,-1,BlockColor::RED);
newClump.y=100;
newClump2.y=100;
clumps.push_back(newClump);
clumps.push_back(newClump2);
} }
void Board::spawnBlock(int col){ void Board::spawnBlock(int col){

Binary file not shown.

@ -10,6 +10,7 @@ struct BlockMatchingInfo{
int col; int col;
int ind; int ind;
int c=-1; int c=-1;
bool changeToLaunched=true;
}; };
bool Meteos::OnUserCreate() bool Meteos::OnUserCreate()
@ -24,7 +25,7 @@ bool Meteos::OnUserCreate()
coinFlip=std::uniform_int_distribution<>(0, 1); coinFlip=std::uniform_int_distribution<>(0, 1);
comboOverlayOffset=std::uniform_int_distribution<>(-16,16); comboOverlayOffset=std::uniform_int_distribution<>(-16,16);
gameBoard=Board({10,14},0.02f,0.04f,1.2f,0.04f,0.4f,{-1.f,-1.5f,-2.f,-2.5f,-4.f},1.7f,2.0f,0.2f,{3,3,1,2,3,0,0,0,0,0}, gameBoard=Board({10,14},0.02f,0.04f,1.2f,0.04f,0.4f,{-0.2f,-1.5f,-2.f,-2.5f,-4.f},1.7f,2.0f,0.2f,{3,3,1,2,3,0,0,0,0,0},
60*10,SPRITES["blocks_test.png"]); 60*10,SPRITES["blocks_test.png"]);
return true; return true;
@ -121,7 +122,7 @@ void Meteos::updateGame(float fElapsedTime){
lastBlockSpawn+=fElapsedTime; lastBlockSpawn+=fElapsedTime;
if (lastBlockSpawn>=gameBoard.spawnRate){ if (lastBlockSpawn>=gameBoard.spawnRate){
lastBlockSpawn-=gameBoard.spawnRate; lastBlockSpawn-=gameBoard.spawnRate;
gameBoard.spawnBlock(randBlockPos(gen)); //gameBoard.spawnBlock(randBlockPos(gen));
} }
for (int i=gameBoard.getBlockClumps().size()-1;i>=0;i--){ for (int i=gameBoard.getBlockClumps().size()-1;i>=0;i--){
BlockClump&c=gameBoard.getBlockClumps()[i]; BlockClump&c=gameBoard.getBlockClumps()[i];
@ -298,7 +299,7 @@ void Meteos::updateGame(float fElapsedTime){
if (c2.landTime>0){ if (c2.landTime>0){
for (int j=0;j<c2.getBlocks().size();j++){ for (int j=0;j<c2.getBlocks().size();j++){
Block&b2=c2.getBlocks()[j]; Block&b2=c2.getBlocks()[j];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y-c.y==checkY) { if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&c2.getBlockPosition(b2).y-c.y==checkY) {
found=true; found=true;
checkX+=12; checkX+=12;
tempMatchIDsX.push_back({(int)b2.pos.x/12,j,h}); tempMatchIDsX.push_back({(int)b2.pos.x/12,j,h});
@ -332,7 +333,7 @@ void Meteos::updateGame(float fElapsedTime){
if (c2.landTime>0){ if (c2.landTime>0){
for (int j=0;j<c2.getBlocks().size();j++){ for (int j=0;j<c2.getBlocks().size();j++){
Block&b2=c2.getBlocks()[j]; Block&b2=c2.getBlocks()[j];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y-c.y==checkY) { if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&c2.getBlockPosition(b2).y-c.y==checkY) {
found=true; found=true;
checkX-=12; checkX-=12;
tempMatchIDsX.push_back({(int)b2.pos.x/12,j,h}); tempMatchIDsX.push_back({(int)b2.pos.x/12,j,h});
@ -366,7 +367,7 @@ void Meteos::updateGame(float fElapsedTime){
if (c2.landTime>0){ if (c2.landTime>0){
for (int j=0;j<c2.getBlocks().size();j++){ for (int j=0;j<c2.getBlocks().size();j++){
Block&b2=c2.getBlocks()[j]; Block&b2=c2.getBlocks()[j];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y-c.y==checkY) { if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&c2.getBlockPosition(b2).y-c.y==checkY) {
found=true; found=true;
checkY-=12; checkY-=12;
tempMatchIDsY.push_back({(int)b2.pos.x/12,j,h}); tempMatchIDsY.push_back({(int)b2.pos.x/12,j,h});
@ -400,7 +401,7 @@ void Meteos::updateGame(float fElapsedTime){
if (c2.landTime>0){ if (c2.landTime>0){
for (int j=0;j<c2.getBlocks().size();j++){ for (int j=0;j<c2.getBlocks().size();j++){
Block&b2=c2.getBlocks()[j]; Block&b2=c2.getBlocks()[j];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y-c.y==checkY) { if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&c2.getBlockPosition(b2).y-c.y==checkY) {
found=true; found=true;
checkY+=12; checkY+=12;
tempMatchIDsY.push_back({(int)b2.pos.x/12,j,h}); tempMatchIDsY.push_back({(int)b2.pos.x/12,j,h});
@ -415,19 +416,61 @@ void Meteos::updateGame(float fElapsedTime){
if (tempMatchIDsX.size()>2||tempMatchIDsY.size()>2) { if (tempMatchIDsX.size()>2||tempMatchIDsY.size()>2) {
if (tempMatchIDsX.size()>2) { if (tempMatchIDsX.size()>2) {
for (BlockMatchingInfo i:tempMatchIDsX) { for (BlockMatchingInfo i:tempMatchIDsX) {
Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind]; if (i.c!=g){
if (!bb.addedToLaunchList) { for (int j=0;j<gameBoard.getBlockClumps()[i.c].getBlocks().size();j++){
bb.addedToLaunchList=true; Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[j];
matchedBlockIDs.push_back(i); if (!bb.addedToLaunchList&&j!=i.ind) {
for (int k=0;k<tempMatchIDsX.size();k++){
if (tempMatchIDsX[k].c==i.c&&tempMatchIDsX[k].ind==j){
goto skipX;
}
}
bb.addedToLaunchList=true;
matchedBlockIDs.push_back({(int)bb.pos.x/12,j,i.c,false});
skipX:;
}
}
Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind];
if (!bb.addedToLaunchList){
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(i);
}
} else {
Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind];
if (!bb.addedToLaunchList) {
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(i);
}
} }
} }
} }
if (tempMatchIDsY.size()>2) { if (tempMatchIDsY.size()>2) {
for (BlockMatchingInfo i:tempMatchIDsY) { for (BlockMatchingInfo i:tempMatchIDsY) {
Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind]; if (i.c!=g){
if (!bb.addedToLaunchList) { for (int j=0;j<gameBoard.getBlockClumps()[i.c].getBlocks().size();j++){
bb.addedToLaunchList=true; Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[j];
matchedBlockIDs.push_back(i); if (!bb.addedToLaunchList&&j!=i.ind) {
for (int k=0;k<tempMatchIDsY.size();k++){
if (tempMatchIDsY[k].c==i.c&&tempMatchIDsY[k].ind==j){
goto skipY;
}
}
bb.addedToLaunchList=true;
matchedBlockIDs.push_back({(int)bb.pos.x/12,j,i.c,false});
skipY:;
}
}
Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind];
if (!bb.addedToLaunchList){
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(i);
}
} else {
Block&bb=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind];
if (!bb.addedToLaunchList) {
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(i);
}
} }
} }
} }
@ -440,10 +483,16 @@ void Meteos::updateGame(float fElapsedTime){
} else { } else {
Block&b=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind]; Block&b=gameBoard.getBlockClumps()[i.c].getBlocks()[i.ind];
if (!b.markedForRemoval){ if (!b.markedForRemoval){
if (i.changeToLaunched){
b.col=BlockColor::LAUNCHED;
c.addBlock(i.col,(gameBoard.getBlockClumps()[i.c].getBlockPosition(b).y-c.y)/12,BlockColor::LAUNCHED);
} else {
c.addBlock(i.col,(gameBoard.getBlockClumps()[i.c].getBlockPosition(b).y-c.y)/12,b.col);
}
}
if (i.changeToLaunched){
b.col=BlockColor::LAUNCHED; b.col=BlockColor::LAUNCHED;
c.addBlock(i.col,(gameBoard.getBlockClumps()[i.c].getBlockPosition(b).y-c.y)/12,BlockColor::LAUNCHED);
} }
b.col=BlockColor::LAUNCHED;
b.markedForRemoval=true; b.markedForRemoval=true;
} }
} }

Loading…
Cancel
Save