generated from sigonasr2/CPlusPlusProjectTemplate
Corrected block landing snapping issues
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
1bf7312b78
commit
275bc29854
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.6 KiB |
17
main.cpp
17
main.cpp
@ -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,9 +49,11 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
if (c.landTime<=0) {
|
||||
c.landTime=0;
|
||||
for (int j=0;j<c.getBlocks().size();j++){
|
||||
if (c.getBlocks()[j].col==BlockColor::LAUNCHED) {
|
||||
gameBoard.assignRandomColor(c.getBlocks()[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.vspeed+=gameBoard.gravity;
|
||||
}
|
||||
@ -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,9 +388,11 @@ void Meteos::drawGame(float fElapsedTime){
|
||||
b.resetTime-=fElapsedTime;
|
||||
if (b.resetTime<0) {
|
||||
b.resetTime=0;
|
||||
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,9 +403,11 @@ void Meteos::drawGame(float fElapsedTime){
|
||||
b.resetTime-=fElapsedTime;
|
||||
if (b.resetTime<0) {
|
||||
b.resetTime=0;
|
||||
if (b.col==BlockColor::LAUNCHED) {
|
||||
gameBoard.assignRandomColor(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user