Multi row column pattern launching completed for BlockClumps

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent a76ccfc48a
commit 4008ec4f5a
  1. 1
      Block.h
  2. BIN
      C++ProjectTemplate
  3. 1
      Meteos.h
  4. 97
      main.cpp

@ -22,6 +22,7 @@ class Block{
BlockColor col;
bool markedForDeletion=false;
bool markedForRemoval=false;
bool addedToLaunchList=false;
Block(vf2d pos,BlockColor col)
:pos(pos),col(col){}
};

Binary file not shown.

@ -14,7 +14,6 @@ class Meteos : public olc::PixelGameEngine{
std::mt19937 gen;
Board gameBoard;
std::map<std::string,Renderable> SPRITES;
bool onlyOnce=false;
bool OnUserCreate()override;
bool OnUserUpdate(float fElapsedTime)override;
};

@ -18,23 +18,20 @@ bool Meteos::OnUserCreate()
gameBoard=Board({10,14},20.f,100.f,-20.f,1.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]);
BlockClump c;
c.addBlock(0,2,BlockColor::RED);
c.addBlock(0,1,BlockColor::RED);
c.addBlock(1,0,BlockColor::RED);
c.addBlock(2,0,BlockColor::RED);
c.addBlock(0,0,BlockColor::RED);
c.y=120;
gameBoard.addClump(c);
return true;
}
bool Meteos::OnUserUpdate(float fElapsedTime)
{
fElapsedTime=std::min(fElapsedTime,1/60.f);
if (!onlyOnce) {
BlockClump c;
c.addBlock(0,2,BlockColor::RED);
c.addBlock(0,1,BlockColor::RED);
c.addBlock(1,0,BlockColor::RED);
c.addBlock(2,0,BlockColor::RED);
c.addBlock(0,0,BlockColor::RED);
c.y=120;
gameBoard.addClump(c);
onlyOnce=true;
}
lastBlockSpawn+=fElapsedTime;
if (lastBlockSpawn>=gameBoard.spawnRate){
lastBlockSpawn-=gameBoard.spawnRate;
@ -117,25 +114,32 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
nextClump:;
}
for (BlockClump&c:gameBoard.getBlockClumps()){
std::vector<int>matchedBlockIDs;
for (Block&b:c.getBlocks()) {
b.addedToLaunchList=false;
}
for (int i=0;i<c.getBlocks().size();i++) {
Block&b=c.getBlocks()[i];
std::vector<int>tempMatchIDsX;
std::vector<int>tempMatchIDsY;
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);
tempMatchIDsX.push_back(i);
tempMatchIDsY.push_back(i);
rightCheck:
float checkX=targetX+12;
float checkY=targetY;
do{
found=false;
for (Block&b2:c.getBlocks()){
if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue;
for (int j=0;j<c.getBlocks().size();j++){
Block&b2=c.getBlocks()[j];
if (i==j)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;
checkX+=12;
matchedBlocksX.push_back(&b2);
tempMatchIDsX.push_back(j);
}
}
}while(found);
@ -144,12 +148,14 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
checkY=targetY;
do{
found=false;
for (Block&b2:c.getBlocks()){
if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue;
for (int j=0;j<c.getBlocks().size();j++){
Block&b2=c.getBlocks()[j];
if (i==j)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;
checkX-=12;
matchedBlocksX.push_back(&b2);
tempMatchIDsX.push_back(j);
}
}
}while(found);
@ -158,12 +164,14 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
checkY=targetY-12;
do{
found=false;
for (Block&b2:c.getBlocks()){
if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue;
for (int j=0;j<c.getBlocks().size();j++){
Block&b2=c.getBlocks()[j];
if (i==j)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(j);
}
}
}while(found);
@ -172,28 +180,44 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
checkY=targetY+12;
do{
found=false;
for (Block&b2:c.getBlocks()){
if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue;
for (int j=0;j<c.getBlocks().size();j++){
Block&b2=c.getBlocks()[j];
if (i==j)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(j);
}
}
}while(found);
if (matchedBlocksX.size()>2) {
for (Block*b2:matchedBlocksX) {
b2->col=BlockColor::LAUNCHED;
if (tempMatchIDsX.size()>2||tempMatchIDsY.size()>2) {
if (tempMatchIDsX.size()>2) {
for (int i:tempMatchIDsX) {
Block&bb=c.getBlocks()[i];
if (!bb.addedToLaunchList) {
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(i);
}
}
}
c.vspeed=gameBoard.launchSpd;
}
if (matchedBlocksY.size()>2) {
for (Block*b2:matchedBlocksY) {
b2->col=BlockColor::LAUNCHED;
if (tempMatchIDsY.size()>2) {
for (int i:tempMatchIDsY) {
Block&bb=c.getBlocks()[i];
if (!bb.addedToLaunchList) {
bb.addedToLaunchList=true;
matchedBlockIDs.push_back(i);
}
}
}
c.vspeed=gameBoard.launchSpd;
}
}
for (int i:matchedBlockIDs) {
Block&b=c.getBlocks()[i];
std::cout<<"Launch Block ("<<b.pos<<")"<<b.addedToLaunchList<<std::endl;
b.col=BlockColor::LAUNCHED;
c.vspeed=gameBoard.launchSpd;
}
}
for (int i=0;i<gameBoard.boardSize.x;i++){
for (Block&b:gameBoard.getBlocks(i)) {
@ -308,6 +332,7 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
gameBoard.removeBlock(i,y--);
continue;
}
b.addedToLaunchList=false;
DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12});
}
}

Loading…
Cancel
Save