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

Loading…
Cancel
Save