Corrected block landing snapping issues

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 1bf7312b78
commit 275bc29854
  1. BIN
      C++ProjectTemplate
  2. BIN
      assets/blocks_test.png
  3. 23
      main.cpp

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

@ -17,7 +17,7 @@ bool Meteos::OnUserCreate()
randBlockPos=std::uniform_int_distribution<>(0, 9);
coinFlip=std::uniform_int_distribution<>(0, 1);
gameBoard=Board({10,14},0.04f,1.2f,-1.f,1.7f,2.0f,1.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]);
gameBoard=Board({10,14},0.04f,1.2f,-1.f,1.7f,2.0f,1.0f,{3,3,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]);
return true;
}
@ -49,7 +49,9 @@ void Meteos::updateGame(float fElapsedTime){
if (c.landTime<=0) {
c.landTime=0;
for (int j=0;j<c.getBlocks().size();j++){
gameBoard.assignRandomColor(c.getBlocks()[j]);
if (c.getBlocks()[j].col==BlockColor::LAUNCHED) {
gameBoard.assignRandomColor(c.getBlocks()[j]);
}
}
}
} else {
@ -68,10 +70,11 @@ 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) {
float yDiff=c2.getBlockPosition(b2).y;
float snapYPos=c.getBlockPosition(b3).y;
yDiff-=snapYPos;
c2.y+=yDiff;
float yDiff=(c2.getBlockPosition(b2).y>c.getBlockPosition(b3).y)?
c2.getBlockPosition(b2).y-c.getBlockPosition(b3).y:
c.getBlockPosition(b3).y-c2.getBlockPosition(b2).y;
c2.y+=(c2.getBlockPosition(b2).y>c.getBlockPosition(b3).y)?
yDiff:-yDiff;
float influence=(float)c.getBlocks().size()/(c.getBlocks().size()+c2.getBlocks().size());
int blockCount=c.getBlocks().size();
//Copy every block from one clump to the other
@ -385,7 +388,9 @@ void Meteos::drawGame(float fElapsedTime){
b.resetTime-=fElapsedTime;
if (b.resetTime<0) {
b.resetTime=0;
gameBoard.assignRandomColor(b);
if (b.col==BlockColor::LAUNCHED) {
gameBoard.assignRandomColor(b);
}
}
}
DrawPartialDecal(c.getBlockPosition(b)+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12});
@ -398,7 +403,9 @@ void Meteos::drawGame(float fElapsedTime){
b.resetTime-=fElapsedTime;
if (b.resetTime<0) {
b.resetTime=0;
gameBoard.assignRandomColor(b);
if (b.col==BlockColor::LAUNCHED) {
gameBoard.assignRandomColor(b);
}
}
}
DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12});

Loading…
Cancel
Save