generated from AMay/CPlusPlusProjectTemplate
Correct bug where blocks landing on the ground would cause giant displacement clumps to suddenly appear
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
1107da21a9
commit
82831c024d
12
Board.cpp
12
Board.cpp
@ -73,9 +73,15 @@ void Board::convertClump(int ind){
|
||||
}
|
||||
clumpsToAdd.push_back(c2);
|
||||
} else {
|
||||
b.pos=c.getBlockPosition(b);
|
||||
b.pos.y=(int)(b.pos.y+1)/12*12;
|
||||
cols[b.pos.x/12].push_back(b);
|
||||
for (int i=0;i<c.getBlocks().size();i++) {
|
||||
Block&b2=c.getBlocks()[i];
|
||||
if (c.getBlockPosition(b).x==b2.pos.x) {
|
||||
b2.pos=c.getBlockPosition(b2);
|
||||
b2.pos.y=(int)(b2.pos.y+1)/12*12;
|
||||
b2.markedForDeletion=true;
|
||||
cols[b.pos.x/12].push_back(b2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (BlockClump&bc:clumpsToAdd) {
|
||||
|
||||
Binary file not shown.
13
main.cpp
13
main.cpp
@ -2,6 +2,7 @@
|
||||
#include "pixelGameEngine.h"
|
||||
#include <random>
|
||||
#include "gameDefines.h"
|
||||
#include <assert.h>
|
||||
|
||||
Meteos*game;
|
||||
|
||||
@ -12,7 +13,7 @@ bool Meteos::OnUserCreate()
|
||||
SPRITES["blocks_test.png"].Load("assets/blocks_test.png");
|
||||
|
||||
std::random_device rd; //Will be used to obtain a seed for the random number engine
|
||||
gen=std::mt19937(rd()); //Standard mersenne_twister_engine seeded with rd()
|
||||
gen=std::mt19937(0); //Standard mersenne_twister_engine seeded with rd()
|
||||
randBlockPos=std::uniform_int_distribution<>(0, 9);
|
||||
coinFlip=std::uniform_int_distribution<>(0, 1);
|
||||
|
||||
@ -24,9 +25,9 @@ bool Meteos::OnUserCreate()
|
||||
bool Meteos::OnUserUpdate(float fElapsedTime)
|
||||
{
|
||||
accumulatedTime+=fElapsedTime;
|
||||
while (accumulatedTime>=1/60.0f) {
|
||||
if (accumulatedTime>=1/60.0f) {
|
||||
updateGame(1/60.0f);
|
||||
accumulatedTime-=1/60.0f;
|
||||
accumulatedTime=0;
|
||||
}
|
||||
drawGame();
|
||||
return true;
|
||||
@ -63,11 +64,16 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
yDiff-=snapYPos;
|
||||
c2.y+=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
|
||||
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);
|
||||
}
|
||||
if (blockCount+c2.getBlocks().size()!=c.getBlocks().size()) {
|
||||
std::cout<<"Block size is: "<<c.getBlocks().size()<<" but expected "<<blockCount+c2.getBlocks().size()<<std::endl;
|
||||
assert(false);
|
||||
}
|
||||
if (c.vspeed>0) {
|
||||
c.vspeed/=4;
|
||||
}
|
||||
@ -75,6 +81,7 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
c2.vspeed/=4;
|
||||
}
|
||||
c.vspeed=c.vspeed*influence+c2.vspeed*(1-influence);
|
||||
c.sortBlocks();
|
||||
gameBoard.removeClump(j--);
|
||||
goto nextClumpCollisionCheck;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user