generated from AMay/CPlusPlusProjectTemplate
Block matching
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
cd95a546bd
commit
2a50fb0fff
3
Block.h
3
Block.h
@ -12,7 +12,8 @@ enum class BlockColor{
|
||||
LIGHT,
|
||||
DARK,
|
||||
SOUL,
|
||||
TIME
|
||||
TIME,
|
||||
LAUNCHED,
|
||||
};
|
||||
|
||||
class Block{
|
||||
|
||||
@ -5,8 +5,8 @@ extern Meteos*game;
|
||||
Board::Board()
|
||||
:colorHandler({}){}
|
||||
|
||||
Board::Board(vi2d boardSize,float gravity,float spawnRate,std::array<int,10> 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<int,10> 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<boardSize.x;i++) {
|
||||
|
||||
3
Board.h
3
Board.h
@ -39,8 +39,9 @@ class Board{
|
||||
vi2d boardSize;
|
||||
float gravity;
|
||||
float spawnRate;
|
||||
float launchSpd;
|
||||
Board();
|
||||
Board(vi2d boardSize,float gravity,float spawnRate,std::array<int,10> colorRates,Renderable&tileset);
|
||||
Board(vi2d boardSize,float gravity,float launchSpd,float spawnRate,std::array<int,10> colorRates,Renderable&tileset);
|
||||
void spawnBlock(int col);
|
||||
std::vector<Block>&getBlocks(int col);
|
||||
std::vector<BlockClump>&getBlockClumps();
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 759 B After Width: | Height: | Size: 6.1 KiB |
79
main.cpp
79
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::vector<Block*>matchedBlocksX;
|
||||
std::vector<Block*>matchedBlocksY;
|
||||
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<gameBoard.boardSize.x;i++){
|
||||
for (int y=0;y<gameBoard.getBlocks(i).size();y++){
|
||||
Block&b=gameBoard.getBlocks(i)[y];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user