|
|
|
@ -35,10 +35,17 @@ bool Meteos::OnUserUpdate(float fElapsedTime) |
|
|
|
|
updateGame(1/60.0f); |
|
|
|
|
accumulatedTime=0; |
|
|
|
|
} |
|
|
|
|
handleInput(); |
|
|
|
|
drawGame(fElapsedTime); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Meteos::handleInput(){ |
|
|
|
|
if (GetMouse(0).bReleased){ |
|
|
|
|
gameBoard.selectedBlock={-1,-1,-1}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
lastBlockSpawn+=fElapsedTime; |
|
|
|
|
if (lastBlockSpawn>=gameBoard.spawnRate){ |
|
|
|
@ -65,29 +72,36 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
if (c2.getBlockPosition(b2).x==c.getBlockPosition(b3).x&& |
|
|
|
|
c2.getBlockPosition(b2).y+12>=c.getBlockPosition(b3).y&& |
|
|
|
|
c2.getBlockPosition(b2).y<=c.getBlockPosition(b3).y+12) { |
|
|
|
|
|
|
|
|
|
c.y=(int)c.y; |
|
|
|
|
c2.y=(int)c2.y; |
|
|
|
|
if (c2.getBlockPosition(b2).y>c.getBlockPosition(b3).y) { |
|
|
|
|
c.y-=12-(c2.getBlockPosition(b2).y-c.getBlockPosition(b3).y); |
|
|
|
|
c.y-=fmod(c.y-c2.y,12); |
|
|
|
|
if (fmod(c2.y-c.y,12)!=0){ |
|
|
|
|
std::cout<<"Difference is not equal to 12!! Value:"<<c2.y-c.y<<std::endl; |
|
|
|
|
std::cout<<"Difference is not divisible by 12!! Value:"<<fmod(c2.y-c.y,12)<<","<<c2.y<<"//"<<c.y<<std::endl; |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
c2.y-=12-(c.getBlockPosition(b3).y-c2.getBlockPosition(b2).y); |
|
|
|
|
if (fmod(c2.y-c.y,12)!=0){ |
|
|
|
|
std::cout<<"Difference is not equal to 12!! Value:"<<c.y-c2.y<<std::endl; |
|
|
|
|
c2.y-=fmod(c.y-c2.y,12); |
|
|
|
|
if (fmod(c.y-c2.y,12)!=0){ |
|
|
|
|
std::cout<<"Difference is not divisible by 12!! Value:"<<fmod(c.y-c2.y,12)<<","<<c.y<<"//"<<c2.y<<std::endl; |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
float influence=(float)c.getBlocks().size()/(c.getBlocks().size()+c2.getBlocks().size()); |
|
|
|
|
int blockCount=c.getBlocks().size(); |
|
|
|
|
int blockCount2=c2.getBlocks().size(); |
|
|
|
|
//Copy every block from one clump to the other
|
|
|
|
|
for (int m=0;m<c2.getBlocks().size();m++) { |
|
|
|
|
Block&b4=c2.getBlocks()[m]; |
|
|
|
|
c.addBlock(b4.pos.x/12,(c2.getBlockPosition(b4).y-c.y)/12,b4.col); |
|
|
|
|
bool exists=false; |
|
|
|
|
if (!exists){ |
|
|
|
|
c.addBlock(b4.pos.x/12,(c2.getBlockPosition(b4).y-c.y)/12,b4.col); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (blockCount+c2.getBlocks().size()!=c.getBlocks().size()) { |
|
|
|
|
std::cout<<"Block size is: "<<c.getBlocks().size()<<" but expected "<<blockCount+c2.getBlocks().size()<<std::endl; |
|
|
|
|
if (blockCount+blockCount2!=c.getBlocks().size()) { |
|
|
|
|
std::cout<<"Block size is: "<<c.getBlocks().size()<<" but expected "<<blockCount+blockCount2<<std::endl; |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
bool overlappingBlocks=false; |
|
|
|
@ -101,6 +115,9 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
assert(!overlappingBlocks); |
|
|
|
|
if (overlappingBlocks){ |
|
|
|
|
std::cout<<"Block b3 "<<b3.pos<<"!"<<std::endl; |
|
|
|
|
} |
|
|
|
|
if (c.vspeed>0) { |
|
|
|
|
c.vspeed/=4; |
|
|
|
|
} |
|
|
|
@ -109,6 +126,9 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
c.vspeed=c.vspeed*influence+c2.vspeed*(1-influence); |
|
|
|
|
c.sortBlocks(); |
|
|
|
|
if (i>=j){ |
|
|
|
|
i--; |
|
|
|
|
} |
|
|
|
|
gameBoard.removeClump(j--); |
|
|
|
|
goto nextClumpCollisionCheck; |
|
|
|
|
} |
|
|
|
@ -116,24 +136,13 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
nextClumpCollisionCheck:; |
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){ |
|
|
|
|
Block&b=c.getBlocks()[j]; |
|
|
|
|
int col=b.pos.x/12; |
|
|
|
|
for (int k=0;k<gameBoard.getBlocks(col).size();k++){ |
|
|
|
|
Block&b2=gameBoard.getBlocks(col)[k]; |
|
|
|
|
if (c.getBlockPosition(b).y+12>=b2.pos.y&&c.getBlockPosition(b).y<=b2.pos.y+12){ |
|
|
|
|
c.y-=c.getBlockPosition(b).y+12-b2.pos.y; |
|
|
|
|
c.vspeed=0; |
|
|
|
|
if (c.landTime>=gameBoard.landTime) { |
|
|
|
|
gameBoard.convertClump(i--); |
|
|
|
|
} else { |
|
|
|
|
c.landTime+=fElapsedTime; |
|
|
|
|
} |
|
|
|
|
goto nextClump; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (c.getBlockPosition(b).y>=gameBoard.yBottom) { |
|
|
|
|
c.y-=c.getBlockPosition(b).y-gameBoard.yBottom; |
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){ |
|
|
|
|
Block&b=c.getBlocks()[j]; |
|
|
|
|
int col=b.pos.x/12; |
|
|
|
|
for (int k=0;k<gameBoard.getBlocks(col).size();k++){ |
|
|
|
|
Block&b2=gameBoard.getBlocks(col)[k]; |
|
|
|
|
if (c.getBlockPosition(b).y+12>=b2.pos.y&&c.getBlockPosition(b).y<=b2.pos.y+12){ |
|
|
|
|
c.y-=c.getBlockPosition(b).y+12-b2.pos.y; |
|
|
|
|
c.vspeed=0; |
|
|
|
|
if (c.landTime>=gameBoard.landTime) { |
|
|
|
|
gameBoard.convertClump(i--); |
|
|
|
@ -143,7 +152,18 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
goto nextClump; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
c.landTime=0; |
|
|
|
|
if (c.getBlockPosition(b).y>=gameBoard.yBottom) { |
|
|
|
|
c.y-=c.getBlockPosition(b).y-gameBoard.yBottom; |
|
|
|
|
c.vspeed=0; |
|
|
|
|
if (c.landTime>=gameBoard.landTime) { |
|
|
|
|
gameBoard.convertClump(i--); |
|
|
|
|
} else { |
|
|
|
|
c.landTime+=fElapsedTime; |
|
|
|
|
} |
|
|
|
|
goto nextClump; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
c.landTime=0; |
|
|
|
|
nextClump:; |
|
|
|
|
} |
|
|
|
|
for (BlockClump&c:gameBoard.getBlockClumps()){ |
|
|
|
@ -464,6 +484,7 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
b2.markedForRemoval=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
b.markedForRemoval=true; |
|
|
|
|
} else { |
|
|
|
|
Block&b=gameBoard.getBlocks(info.col)[info.ind]; |
|
|
|
|
for (Block&b2:gameBoard.getBlocks(b.pos.x/12)) { |
|
|
|
@ -472,6 +493,7 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
b2.markedForRemoval=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
b.markedForRemoval=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
gameBoard.addClump(c); |
|
|
|
@ -573,9 +595,6 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
found:; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetMouse(0).bReleased){ |
|
|
|
|
gameBoard.selectedBlock={-1}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Meteos::drawGame(float fElapsedTime){ |
|
|
|
|