diff --git a/Block.h b/Block.h index adc6a68..d6d343a 100644 --- a/Block.h +++ b/Block.h @@ -12,7 +12,8 @@ enum class BlockColor{ LIGHT, DARK, SOUL, - TIME + TIME, + LAUNCHED, }; class Block{ diff --git a/Board.cpp b/Board.cpp index 09de8e4..367ee56 100644 --- a/Board.cpp +++ b/Board.cpp @@ -5,8 +5,8 @@ extern Meteos*game; Board::Board() :colorHandler({}){} -Board::Board(vi2d boardSize,float gravity,float spawnRate,std::array colorRates,Renderable&tileset) -:boardSize(boardSize),gravity(gravity),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){ +Board::Board(vi2d boardSize,float gravity,float launchSpd,float spawnRate,std::array colorRates,Renderable&tileset) +:boardSize(boardSize),gravity(gravity),launchSpd(launchSpd),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){ drawOffset={(float)game->ScreenWidth()/2-boardSize.x/2*12,(float)game->ScreenHeight()/2-boardSize.y/2*12}; yBottom=(boardSize.y-1)*12; for (int i=0;i colorRates,Renderable&tileset); + Board(vi2d boardSize,float gravity,float launchSpd,float spawnRate,std::array colorRates,Renderable&tileset); void spawnBlock(int col); std::vector&getBlocks(int col); std::vector&getBlockClumps(); diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 7850879..57287cc 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/assets/blocks_test.png b/assets/blocks_test.png index cdaeed6..ad76d15 100644 Binary files a/assets/blocks_test.png and b/assets/blocks_test.png differ diff --git a/main.cpp b/main.cpp index e045e6e..183bc2d 100644 --- a/main.cpp +++ b/main.cpp @@ -16,7 +16,7 @@ bool Meteos::OnUserCreate() randBlockPos=std::uniform_int_distribution<>(0, 9); coinFlip=std::uniform_int_distribution<>(0, 1); - gameBoard=Board({10,14},12.f,3.0f,{3,3,2,3,2,3,0,0,0,0},SPRITES["blocks_test.png"]); + gameBoard=Board({10,14},12.f,-20.f,3.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]); return true; } @@ -102,6 +102,83 @@ bool Meteos::OnUserUpdate(float fElapsedTime) } nextClump:; } + for (BlockClump&c:gameBoard.getBlockClumps()){ + for (Block&b:c.getBlocks()) { + float targetX=b.pos.x; + float targetY=b.pos.y; + bool found=false; + std::vectormatchedBlocksX; + std::vectormatchedBlocksY; + matchedBlocksX.push_back(&b); + matchedBlocksY.push_back(&b); + 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; + if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) { + found=true; + checkX+=12; + matchedBlocksX.push_back(&b2); + } + } + }while(found); + leftCheck: + checkX=targetX-12; + checkY=targetY; + do{ + found=false; + for (Block&b2:c.getBlocks()){ + if (b.pos.x==b2.pos.x&&b.pos.y==b2.pos.y)continue; + if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) { + found=true; + checkX-=12; + matchedBlocksX.push_back(&b2); + } + } + }while(found); + upCheck: + checkX=targetX; + 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; + if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) { + found=true; + checkY-=12; + matchedBlocksY.push_back(&b2); + } + } + }while(found); + downCheck: + checkX=targetX; + 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; + if (b.col==b2.col&&b2.col!=BlockColor::LAUNCHED&&b2.pos.x==checkX&&b2.pos.y==checkY) { + found=true; + checkY+=12; + matchedBlocksY.push_back(&b2); + } + } + }while(found); + if (matchedBlocksX.size()>2) { + for (Block*b2:matchedBlocksX) { + b2->col=BlockColor::LAUNCHED; + } + } + if (matchedBlocksY.size()>2) { + for (Block*b2:matchedBlocksY) { + b2->col=BlockColor::LAUNCHED; + } + } + } + } for (int i=0;i