diff --git a/C++ProjectTemplate b/C++ProjectTemplate index b574d88..b0d9755 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 3a4ec33..b19aeee 100644 --- a/main.cpp +++ b/main.cpp @@ -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>matchedBlockIDs; //Col followed by index + std::vectormatchedBlockIDs; //Col followed by index for (int i=0;i>tempMatchIDsX; //Col followed by index - std::vector>tempMatchIDsY; //Col followed by index + std::vectortempMatchIDsX; //Col followed by index + std::vectortempMatchIDsY; //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;k0) { + for (int l=0;l0) { + for (int l=0;l0) { + for (int l=0;l0) { + for (int l=0;l2||tempMatchIDsY.size()>2) { if (tempMatchIDsX.size()>2) { - for (std::pair&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&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&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&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