Launches on the floor

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 0749e7264e
commit fe94a9d39c
  1. 1
      Block.h
  2. 10
      BlockClump.cpp
  3. 1
      BlockClump.h
  4. 8
      Board.cpp
  5. 2
      Board.h
  6. BIN
      C++ProjectTemplate
  7. 93
      main.cpp

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

@ -16,6 +16,16 @@ void BlockClump::addBlock(vf2d offset,BlockColor color){
blocks.push_back(Block(offset,color));
}
void BlockClump::addBlockOnTopOf(int col,BlockColor color){
int highestY=999999;
for (Block&b:blocks) {
if (b.pos.x/12==col&&b.pos.y<=highestY) {
highestY=b.pos.y;
}
}
addBlock(col,(highestY==999999)?0:highestY/12-1,color);
}
vf2d BlockClump::getBlockPosition(Block&b){
return {b.pos.x,b.pos.y+y};
}

@ -16,6 +16,7 @@ class BlockClump{
void addBlock(int col,BlockColor color);
void addBlock(int col,int row,BlockColor color);
void addBlock(vf2d offset,BlockColor color);
void addBlockOnTopOf(int col,BlockColor color);
//Get a block's position relative to this block clump.
vf2d getBlockPosition(Block&b);
};

@ -21,6 +21,10 @@ void Board::spawnBlock(int col){
clumps.push_back(c);
}
void Board::addClump(BlockClump&c){
clumps.push_back(c);
}
std::vector<Block>&Board::getBlocks(int col){
return cols[col];
}
@ -77,4 +81,8 @@ BlockColor ColorDistributor::getRandomColor(){
}
}
return BlockColor::WHITE;
}
void Board::removeBlock(int col,int ind){
cols[col].erase(cols[col].begin()+ind);
}

@ -44,9 +44,11 @@ class Board{
Board();
Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float spawnRate,std::array<int,10> colorRates,Renderable&tileset);
void spawnBlock(int col);
void addClump(BlockClump&c);
std::vector<Block>&getBlocks(int col);
std::vector<BlockClump>&getBlockClumps();
void convertClump(int ind);
void removeClump(int ind);
void removeBlock(int col,int ind);
};
#endif

Binary file not shown.

@ -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},20.f,100.f,-20.f,1.0f,{3,3,2,3,2,0,0,0,0,0},SPRITES["blocks_test.png"]);
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"]);
return true;
}
@ -185,8 +185,99 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
}
}
for (int i=0;i<gameBoard.boardSize.x;i++){
for (Block&b:gameBoard.getBlocks(i)) {
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);
rightCheckGrounded:
float checkX=targetX+12;
float checkY=targetY;
do{
found=false;
for (Block&b2:gameBoard.getBlocks(i)){
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);
leftCheckGrounded:
checkX=targetX-12;
checkY=targetY;
do{
found=false;
for (Block&b2:gameBoard.getBlocks(i)){
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);
upCheckGrounded:
checkX=targetX;
checkY=targetY-12;
do{
found=false;
for (Block&b2:gameBoard.getBlocks(i)){
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);
downCheckGrounded:
checkX=targetX;
checkY=targetY+12;
do{
found=false;
for (Block&b2:gameBoard.getBlocks(i)){
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||matchedBlocksY.size()>2) {
BlockClump c;
c.y=b.pos.y-1;
if (matchedBlocksX.size()>2) {
for (Block*b2:matchedBlocksX) {
b2->col=BlockColor::LAUNCHED;
c.addBlockOnTopOf(b2->pos.x/12,b2->col);
b2->markedForRemoval=true;
}
c.vspeed=gameBoard.launchSpd;
}
if (matchedBlocksY.size()>2) {
for (int i=0;i<matchedBlocksY.size();i++) {
Block*b2=matchedBlocksY[i];
b2->col=BlockColor::LAUNCHED;
c.addBlockOnTopOf(b2->pos.x/12,b2->col);
b2->markedForRemoval=true;
}
c.vspeed=gameBoard.launchSpd;
}
gameBoard.addClump(c);
}
}
for (int y=0;y<gameBoard.getBlocks(i).size();y++){
Block&b=gameBoard.getBlocks(i)[y];
if (b.markedForRemoval){
gameBoard.removeBlock(i,y--);
continue;
}
DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12});
}
}

Loading…
Cancel
Save