Block flinging mechanics implemented

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
sigonasr2 2022-12-13 02:24:02 -06:00
parent ebcacc5381
commit fc563a25aa
3 changed files with 26 additions and 1 deletions

View File

@ -13,6 +13,7 @@ class BlockClump{
float launchTime=0.f; float launchTime=0.f;
int combo=0; int combo=0;
float y=0; float y=0;
bool flinged=false;
BlockClump(); BlockClump();
std::vector<Block>&getBlocks(); std::vector<Block>&getBlocks();
void addBlock(int col,BlockColor color); void addBlock(int col,BlockColor color);

Binary file not shown.

View File

@ -98,6 +98,19 @@ void Meteos::handleInput(){
} }
found:; found:;
} }
if (gameBoard.selectedBlock.c==-1&&gameBoard.selectedBlock.col!=-1&&gameBoard.boardSize.y-mouseRow>gameBoard.getBlocks(gameBoard.selectedBlock.col).size()){
//Fling the block upwards.
BlockClump newClump;
Block&targetBlock=gameBoard.getBlocks(gameBoard.selectedBlock.col)[gameBoard.selectedBlock.ind];
newClump.y=targetBlock.pos.y-1;
newClump.launchTime=999999;
newClump.vspeed=gameBoard.launchSpd[0];
newClump.flinged=true;
newClump.addBlock(gameBoard.selectedBlock.col,targetBlock.col);
gameBoard.addClump(newClump);
gameBoard.removeBlock(gameBoard.selectedBlock.col,gameBoard.selectedBlock.ind);
gameBoard.selectedBlock={-1,-1,-1};
}
} }
if (GetMouse(0).bReleased){ if (GetMouse(0).bReleased){
gameBoard.selectedBlock={-1,-1,-1}; gameBoard.selectedBlock={-1,-1,-1};
@ -126,6 +139,10 @@ void Meteos::updateGame(float fElapsedTime){
c.vspeed=gameBoard.maxGravity; c.vspeed=gameBoard.maxGravity;
} }
} }
if (c.flinged&&c.y<12*3){
c.flinged=false;
c.launchTime=0;
}
for (int j=gameBoard.getBlockClumps().size()-1;j>=0;j--) { for (int j=gameBoard.getBlockClumps().size()-1;j>=0;j--) {
if (i==j) continue; if (i==j) continue;
BlockClump&c2=gameBoard.getBlockClumps()[j]; BlockClump&c2=gameBoard.getBlockClumps()[j];
@ -193,7 +210,14 @@ void Meteos::updateGame(float fElapsedTime){
if (overlappingBlocks){ if (overlappingBlocks){
std::cout<<"Block b3 "<<b3.pos<<"!"<<std::endl; std::cout<<"Block b3 "<<b3.pos<<"!"<<std::endl;
} }
c.vspeed=std::min(c.vspeed,c2.vspeed); if (!c.flinged&&!c2.flinged){
c.vspeed=std::min(c.vspeed,c2.vspeed);
}
if (c.flinged||c2.flinged){
c.launchTime=0;
}
c.flinged=false;
c2.flinged=false;
c.combo=std::max(c.combo,c2.combo); c.combo=std::max(c.combo,c2.combo);
c.landTime=std::max(c.landTime,c2.landTime); c.landTime=std::max(c.landTime,c2.landTime);
c.sortBlocks(); c.sortBlocks();