Getting there...

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 4008ec4f5a
commit 9c2786a735
  1. BIN
      C++ProjectTemplate
  2. 125
      main.cpp

Binary file not shown.

@ -220,112 +220,129 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
} }
} }
for (int i=0;i<gameBoard.boardSize.x;i++){ for (int i=0;i<gameBoard.boardSize.x;i++){
std::vector<std::pair<int,int>>matchedBlockIDs; //Col followed by index
for (Block&b:gameBoard.getBlocks(i)) { for (Block&b:gameBoard.getBlocks(i)) {
b.addedToLaunchList=false;
}
for (int j=0;j<gameBoard.getBlocks(i).size();j++) {
Block&b=gameBoard.getBlocks(i)[j];
std::vector<std::pair<int,int>>tempMatchIDsX; //Col followed by index
std::vector<std::pair<int,int>>tempMatchIDsY; //Col followed by index
float targetX=b.pos.x; float targetX=b.pos.x;
float targetY=b.pos.y; float targetY=b.pos.y;
bool found=false; bool found=false;
std::vector<Block*>matchedBlocksX; tempMatchIDsX.push_back({i,j});
std::vector<Block*>matchedBlocksY; tempMatchIDsY.push_back({i,j});
matchedBlocksX.push_back(&b); rightBoardCheck:
matchedBlocksY.push_back(&b);
rightCheckGrounded:
float checkX=1; float checkX=1;
float checkY=targetY; float checkY=targetY;
do{ do{
found=false; found=false;
if (i+checkX<gameBoard.boardSize.x) { if (i+checkX<gameBoard.boardSize.x) {
for (Block&b2:gameBoard.getBlocks(i+checkX)){ for (int k=0;k<gameBoard.getBlocks(i+checkX).size();k++){
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==b.pos.x+checkX*12&&b2.pos.y==checkY) { Block&b2=gameBoard.getBlocks(i+checkX)[k];
if (j==k)continue;
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX*12&&b2.pos.y==checkY) {
found=true; found=true;
checkX++; std::cout<<"Found match @ ("<<checkX*12<<","<<checkY<<") Block ("<<b2.pos<<")"<<b2.addedToLaunchList<<std::endl;
matchedBlocksX.push_back(&b2); checkX+=12;
tempMatchIDsX.push_back({i+checkX,k});
} }
} }
} }
}while(found); }while(found);
leftCheckGrounded: leftBoardCheck:
checkX=-1; checkX=-1;
checkY=targetY; checkY=targetY;
do{ do{
found=false; found=false;
if (i+checkX>=0) { if (i+checkX>=0) {
for (Block&b2:gameBoard.getBlocks(i+checkX)){ for (int k=0;k<gameBoard.getBlocks(i+checkX).size();k++){
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==b.pos.x+checkX*12&&b2.pos.y==checkY) { Block&b2=gameBoard.getBlocks(i+checkX)[k];
if (j==k)continue;
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX*12&&b2.pos.y==checkY) {
found=true; found=true;
checkX--; std::cout<<"Found match @ ("<<checkX*12<<","<<checkY<<") Block ("<<b2.pos<<")"<<b2.addedToLaunchList<<std::endl;
matchedBlocksX.push_back(&b2); checkX-=12;
tempMatchIDsX.push_back({i+checkX,k});
} }
} }
} }
}while(found); }while(found);
upCheckGrounded: upBoardCheck:
checkX=targetX; checkX=targetX;
checkY=targetY-12; checkY=targetY-12;
do{ do{
found=false; found=false;
for (Block&b2:gameBoard.getBlocks(i)){ for (int k=0;k<gameBoard.getBlocks(i).size();k++){
if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue; Block&b2=gameBoard.getBlocks(i)[k];
if (j==k)continue;
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) { if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) {
found=true; found=true;
std::cout<<"Found match @ ("<<checkX<<","<<checkY<<") Block ("<<b2.pos<<")"<<b2.addedToLaunchList<<std::endl;
checkY-=12; checkY-=12;
matchedBlocksY.push_back(&b2); tempMatchIDsY.push_back({i,k});
} }
} }
}while(found); }while(found);
downCheckGrounded: downBoardCheck:
checkX=targetX; checkX=targetX;
checkY=targetY+12; checkY=targetY+12;
do{ do{
found=false; found=false;
for (Block&b2:gameBoard.getBlocks(i)){ for (int k=0;k<gameBoard.getBlocks(i).size();k++){
if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue; Block&b2=gameBoard.getBlocks(i)[k];
if (j==k)continue;
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) { if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) {
found=true; found=true;
std::cout<<"Found match @ ("<<checkX<<","<<checkY<<") Block ("<<b2.pos<<")"<<b2.addedToLaunchList<<std::endl;
checkY+=12; checkY+=12;
matchedBlocksY.push_back(&b2); tempMatchIDsY.push_back({i,k});
} }
} }
}while(found); }while(found);
if (matchedBlocksX.size()>2||matchedBlocksY.size()>2) { if (tempMatchIDsX.size()>2||tempMatchIDsY.size()>2) {
BlockClump c; if (tempMatchIDsX.size()>2) {
c.y=b.pos.y-1; for (std::pair<int,int>&info:tempMatchIDsX) {
if (matchedBlocksX.size()>2) { Block&bb=gameBoard.getBlocks(info.first)[info.second];
for (Block*b2:matchedBlocksX) { if (!bb.addedToLaunchList) {
b2->col=BlockColor::LAUNCHED; bb.addedToLaunchList=true;
c.addBlockOnTopOf(b2->pos.x/12,b2->col); matchedBlockIDs.push_back(info);
b2->markedForRemoval=true;
}
for (Block*b2:matchedBlocksX) {
for (Block&b3:gameBoard.getBlocks(b2->pos.x/12)) {
if (!b3.markedForRemoval&&b3.pos.y<b2->pos.y) {
c.addBlockOnTopOf(b2->pos.x/12,b3.col);
b3.markedForRemoval=true;
}
} }
} }
c.vspeed=gameBoard.launchSpd;
} }
if (matchedBlocksY.size()>2) { if (tempMatchIDsY.size()>2) {
for (int i=0;i<matchedBlocksY.size();i++) { for (std::pair<int,int>&info:tempMatchIDsY) {
Block*b2=matchedBlocksY[i]; Block&bb=gameBoard.getBlocks(info.first)[info.second];
b2->col=BlockColor::LAUNCHED; if (!bb.addedToLaunchList) {
c.addBlockOnTopOf(b2->pos.x/12,b2->col); bb.addedToLaunchList=true;
b2->markedForRemoval=true; matchedBlockIDs.push_back(info);
}
for (int i=0;i<matchedBlocksY.size();i++) {
Block*b2=matchedBlocksY[i];
for (Block&b3:gameBoard.getBlocks(b2->pos.x/12)) {
if (!b3.markedForRemoval&&b3.pos.y<b2->pos.y) {
c.addBlockOnTopOf(b2->pos.x/12,b3.col);
b3.markedForRemoval=true;
}
} }
} }
c.vspeed=gameBoard.launchSpd;
} }
gameBoard.addClump(c);
} }
} }
if (matchedBlockIDs.size()>0) {
BlockClump c;
bool firstBlock=true;
for (std::pair<int,int>&info:matchedBlockIDs) {
Block&b=gameBoard.getBlocks(info.first)[info.second];
if (firstBlock) {
c.y=b.pos.y-1;
firstBlock=false;
}
std::cout<<"Launch Block ("<<b.pos<<")"<<b.addedToLaunchList<<std::endl;
b.col=BlockColor::LAUNCHED;
for (Block&b2:gameBoard.getBlocks(b.pos.x/12)) {
if (!b2.markedForRemoval&&b2.pos.y<=b.pos.y) {
c.addBlockOnTopOf(b.pos.x/12,b2.col);
b2.markedForRemoval=true;
}
}
c.vspeed=gameBoard.launchSpd;
}
gameBoard.addClump(c);
}
for (int y=0;y<gameBoard.getBlocks(i).size();y++){ for (int y=0;y<gameBoard.getBlocks(i).size();y++){
Block&b=gameBoard.getBlocks(i)[y]; Block&b=gameBoard.getBlocks(i)[y];
if (b.markedForRemoval){ if (b.markedForRemoval){

Loading…
Cancel
Save