#define OLC_PGE_APPLICATION #include "pixelGameEngine.h" #include #include "gameDefines.h" Meteos*game; bool Meteos::OnUserCreate() { game=this; 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() randBlockPos=std::uniform_int_distribution<>(0, 9); coinFlip=std::uniform_int_distribution<>(0, 1); gameBoard=Board({10,14},12.f,3.0f,{3,3,2,3,2,3,0,0,0,0},SPRITES["blocks_test.png"]); return true; } bool Meteos::OnUserUpdate(float fElapsedTime) { fElapsedTime=std::min(fElapsedTime,1/60.f); lastBlockSpawn+=fElapsedTime; if (lastBlockSpawn>=3.0f){ lastBlockSpawn-=3.0f; gameBoard.spawnBlock(randBlockPos(gen)); } Clear(Pixel(32,32,255)); for (int x=-1;x<=gameBoard.boardSize.x;x++){ for (int y=0;y<=gameBoard.boardSize.y;y++){ if (x==-1||x==10||y==14){ FillRectDecal({(float)(gameBoard.drawOffset.x+x*12),(float)(gameBoard.drawOffset.y+y*12)},{12,12},Pixel(0,0,0,255)); } else { DrawRectDecal({(float)(gameBoard.drawOffset.x+x*12),(float)(gameBoard.drawOffset.y+y*12)},{12,12},Pixel(255,255,255,64)); } } } for (int i=0;i=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 influence=(float)c.getBlocks().size()/(c.getBlocks().size()+c2.getBlocks().size()); //Copy every block from one clump to the other for (int m=0;m0) { c.vspeed/=4; } if (c2.vspeed>0) { c2.vspeed/=4; } c.vspeed=c.vspeed*influence+c2.vspeed*(1-influence); gameBoard.removeClump(j--); goto nextClumpCollisionCheck; } } } } nextClumpCollisionCheck:; for (int j=0;j=b2.pos.y&&c.getBlockPosition(b).y<=b2.pos.y+12){ c.y=b2.pos.y-12; c.vspeed=0; gameBoard.convertClump(i--); goto nextClump; } } if (c.getBlockPosition(b).y>=gameBoard.yBottom) { c.y=gameBoard.yBottom; c.vspeed=0; gameBoard.convertClump(i--); goto nextClump; } } c.y+=c.vspeed*fElapsedTime; for (int j=0;j