Correcting bugs

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 09ee429e0f
commit 2bb304ccec
  1. BIN
      C++ProjectTemplate
  2. 1
      Meteos.h
  3. 77
      main.cpp

Binary file not shown.

@ -17,6 +17,7 @@ class Meteos : public olc::PixelGameEngine{
std::map<std::string,Renderable> SPRITES; std::map<std::string,Renderable> SPRITES;
bool OnUserCreate()override; bool OnUserCreate()override;
void updateGame(float fElapsedTime); void updateGame(float fElapsedTime);
void handleInput();
void drawGame(float fElapsedTime); void drawGame(float fElapsedTime);
bool OnUserUpdate(float fElapsedTime)override; bool OnUserUpdate(float fElapsedTime)override;
}; };

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

Loading…
Cancel
Save