Block matching between clumps and ground blocks

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 12837487c6
commit 1daf3810c7
  1. BIN
      C++ProjectTemplate
  2. 184
      main.cpp

Binary file not shown.

@ -6,6 +6,12 @@
Meteos*game;
struct BlockMatchingInfo{
int col;
int ind;
int c=-1;
};
bool Meteos::OnUserCreate()
{
game=this;
@ -227,15 +233,15 @@ void Meteos::updateGame(float fElapsedTime){
c.launchTime=gameBoard.launchTime;
}
}
std::vector<std::pair<int,int>>matchedBlockIDs; //Col followed by index
std::vector<BlockMatchingInfo>matchedBlockIDs; //Col followed by index
for (int i=0;i<gameBoard.boardSize.x;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
std::vector<BlockMatchingInfo>tempMatchIDsX; //Col followed by index
std::vector<BlockMatchingInfo>tempMatchIDsY; //Col followed by index
float targetX=b.pos.x;
float targetY=b.pos.y;
bool found=false;
@ -251,11 +257,26 @@ void Meteos::updateGame(float fElapsedTime){
Block&b2=gameBoard.getBlocks(i+checkX)[k];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==b.pos.x+checkX*12&&b2.pos.y==checkY) {
found=true;
tempMatchIDsX.push_back({i+checkX,k});
tempMatchIDsX.push_back({(int)(i+checkX),k});
checkX++;
break;
goto outercheck2;
}
}
for (int k=0;k<gameBoard.getBlockClumps().size();k++){
BlockClump&c=gameBoard.getBlockClumps()[k];
if (c.landTime>0) {
for (int l=0;l<c.getBlocks().size();l++){
Block&b2=c.getBlocks()[l];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==b.pos.x+checkX*12&&c.getBlockPosition(b2).y==checkY){
found=true;
tempMatchIDsX.push_back({-1,l,k});
checkX++;
goto outercheck2;
}
}
}
}
outercheck2:;
}
}while(found);
leftBoardCheck:
@ -268,11 +289,26 @@ void Meteos::updateGame(float fElapsedTime){
Block&b2=gameBoard.getBlocks(i+checkX)[k];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==b.pos.x+checkX*12&&b2.pos.y==checkY) {
found=true;
tempMatchIDsX.push_back({i+checkX,k});
tempMatchIDsX.push_back({(int)(i+checkX),k});
checkX--;
break;
goto outercheck3;
}
}
for (int k=0;k<gameBoard.getBlockClumps().size();k++){
BlockClump&c=gameBoard.getBlockClumps()[k];
if (c.landTime>0) {
for (int l=0;l<c.getBlocks().size();l++){
Block&b2=c.getBlocks()[l];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==b.pos.x+checkX*12&&c.getBlockPosition(b2).y==checkY){
found=true;
tempMatchIDsX.push_back({-1,l,k});
checkX--;
goto outercheck3;
}
}
}
}
outercheck3:;
}
}while(found);
upBoardCheck:
@ -287,9 +323,24 @@ void Meteos::updateGame(float fElapsedTime){
found=true;
checkY-=12;
tempMatchIDsY.push_back({i,k});
break;
goto outercheck4;
}
}
for (int k=0;k<gameBoard.getBlockClumps().size();k++){
BlockClump&c=gameBoard.getBlockClumps()[k];
if (c.landTime>0) {
for (int l=0;l<c.getBlocks().size();l++){
Block&b2=c.getBlocks()[l];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&c.getBlockPosition(b2).x==checkX&&c.getBlockPosition(b2).y==checkY){
found=true;
checkY-=12;
tempMatchIDsY.push_back({-1,l,k});
goto outercheck4;
}
}
}
}
outercheck4:;
}while(found);
downBoardCheck:
checkX=targetX;
@ -303,26 +354,59 @@ void Meteos::updateGame(float fElapsedTime){
found=true;
checkY+=12;
tempMatchIDsY.push_back({i,k});
break;
goto outercheck1;
}
}
for (int k=0;k<gameBoard.getBlockClumps().size();k++){
BlockClump&c=gameBoard.getBlockClumps()[k];
if (c.landTime>0) {
for (int l=0;l<c.getBlocks().size();l++){
Block&b2=c.getBlocks()[l];
if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&c.getBlockPosition(b2).x==checkX&&c.getBlockPosition(b2).y==checkY){
found=true;
checkY+=12;
tempMatchIDsY.push_back({-1,l,k});
goto outercheck1;
}
}
}
}
outercheck1:;
}while(found);
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);
for (BlockMatchingInfo&info:tempMatchIDsX) {
if (info.c!=-1) {
BlockClump&c=gameBoard.getBlockClumps()[info.c];
Block&bb=c.getBlocks()[info.ind];
if (!bb.addedToLaunchList){
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(info);
}
} else {
Block&bb=gameBoard.getBlocks(info.col)[info.ind];
if (!bb.addedToLaunchList){
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(info);
}
}
}
}
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);
for (BlockMatchingInfo&info:tempMatchIDsY) {
if (info.c!=-1) {
BlockClump&c=gameBoard.getBlockClumps()[info.c];
Block&bb=c.getBlocks()[info.ind];
if (!bb.addedToLaunchList){
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(info);
}
} else {
Block&bb=gameBoard.getBlocks(info.col)[info.ind];
if (!bb.addedToLaunchList){
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(info);
}
}
}
}
@ -333,23 +417,43 @@ void Meteos::updateGame(float fElapsedTime){
BlockClump c;
bool firstBlock=true;
int baseBlockPos;
for (std::pair<int,int>&info:matchedBlockIDs) {
Block&b=gameBoard.getBlocks(info.first)[info.second];
if (firstBlock) {
baseBlockPos=b.pos.y;
c.y=baseBlockPos-1;
firstBlock=false;
for (BlockMatchingInfo&info:matchedBlockIDs) {
Block*b;
if (info.c!=-1){
b=&gameBoard.getBlockClumps()[info.c].getBlocks()[info.ind];
if (firstBlock) {
baseBlockPos=gameBoard.getBlockClumps()[info.c].getBlockPosition(*b).y;
c.y=baseBlockPos-1;
firstBlock=false;
}
} else {
b=&gameBoard.getBlocks(info.col)[info.ind];
if (firstBlock) {
baseBlockPos=b->pos.y;
c.y=baseBlockPos-1;
firstBlock=false;
}
}
b.col=BlockColor::LAUNCHED;
b->col=BlockColor::LAUNCHED;
c.vspeed=gameBoard.launchSpd;
c.launchTime=gameBoard.launchTime;
}
for (std::pair<int,int>&info:matchedBlockIDs) {
Block&b=gameBoard.getBlocks(info.first)[info.second];
for (Block&b2:gameBoard.getBlocks(b.pos.x/12)) {
if (!b2.markedForRemoval&&b2.pos.y<=b.pos.y) {
c.addBlock(b.pos.x/12,(b2.pos.y-baseBlockPos)/12,b2.col);
b2.markedForRemoval=true;
for (BlockMatchingInfo&info:matchedBlockIDs) {
if (info.c!=-1){
Block&b=gameBoard.getBlockClumps()[info.c].getBlocks()[info.ind];
for (Block&b2:gameBoard.getBlockClumps()[info.c].getBlocks()){
if (!b2.markedForRemoval&&gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y<=gameBoard.getBlockClumps()[info.c].getBlockPosition(b).y){
c.addBlock(b.pos.x/12,(gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y-baseBlockPos)/12,b2.col);
b2.markedForRemoval=true;
}
}
} else {
Block&b=gameBoard.getBlocks(info.col)[info.ind];
for (Block&b2:gameBoard.getBlocks(b.pos.x/12)) {
if (!b2.markedForRemoval&&b2.pos.y<=b.pos.y) {
c.addBlock(b.pos.x/12,(b2.pos.y-baseBlockPos)/12,b2.col);
b2.markedForRemoval=true;
}
}
}
}
@ -357,16 +461,18 @@ void Meteos::updateGame(float fElapsedTime){
}
for (int i=0;i<gameBoard.getBlockClumps().size();i++){ //Resolve BlockClump movements.
BlockClump&c=gameBoard.getBlockClumps()[i];
if (c.vspeed<0) {
for (int j=0;j<c.getBlocks().size();j++){
Block&b=c.getBlocks()[j];
if (c.getBlockPosition(b).y<0){
c.removeBlock(j--);
break;
}
for (int j=0;j<c.getBlocks().size();j++){
Block&b=c.getBlocks()[j];
if (c.vspeed<0&&c.getBlockPosition(b).y<0||b.markedForRemoval){
c.removeBlock(j--);
break;
}
}
c.y+=c.vspeed;
if (c.getBlocks().size()<=0) {
gameBoard.removeClump(i--);
continue;
}
}
for (int i=0;i<gameBoard.boardSize.x;i++){
for (int y=0;y<gameBoard.getBlocks(i).size();y++){

Loading…
Cancel
Save