diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 5b3c7a5..74bf3e4 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/Meteos.h b/Meteos.h index 0fbd5b2..4807d86 100644 --- a/Meteos.h +++ b/Meteos.h @@ -17,6 +17,7 @@ class Meteos : public olc::PixelGameEngine{ std::map SPRITES; bool OnUserCreate()override; void updateGame(float fElapsedTime); + void handleInput(); void drawGame(float fElapsedTime); bool OnUserUpdate(float fElapsedTime)override; }; diff --git a/main.cpp b/main.cpp index 84492d3..36026f4 100644 --- a/main.cpp +++ b/main.cpp @@ -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:"<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=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=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){