|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#include <random>
|
|
|
|
#include "gameDefines.h"
|
|
|
|
|
|
|
|
Meteos*game;
|
|
|
|
|
|
|
|
bool Meteos::OnUserCreate()
|
|
|
|
{
|
|
|
|
game=this;
|
|
|
|
|
|
|
|
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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Meteos::OnUserUpdate(float fElapsedTime)
|
|
|
|
{
|
|
|
|
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<gameBoard.getBlockClumps().size();i++){
|
|
|
|
BlockClump&c=gameBoard.getBlockClumps()[i];
|
|
|
|
c.vspeed+=gameBoard.gravity*fElapsedTime;
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){
|
|
|
|
Block&b=c.getBlocks()[j];
|
|
|
|
int col=b.pos.x/12;
|
|
|
|
for (int k=0;k<gameBoard.getBlocks(col).size();k++){
|
|
|
|
Block&b2=gameBoard.getBlocks(col)[k];
|
|
|
|
if (c.getBlockPosition(b).y+12>=b2.pos.y&&c.getBlockPosition(b).y<=b2.pos.y+12){
|
|
|
|
c.y=b2.pos.y-12;
|
|
|
|
c.vspeed=0;
|
|
|
|
gameBoard.removeClump(i--);
|
|
|
|
goto nextClump;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getBlockPosition(b).y>=gameBoard.yBottom) {
|
|
|
|
c.y=gameBoard.yBottom;
|
|
|
|
c.vspeed=0;
|
|
|
|
gameBoard.removeClump(i--);
|
|
|
|
goto nextClump;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){
|
|
|
|
Block&b=c.getBlocks()[j];
|
|
|
|
c.y+=c.vspeed*fElapsedTime;
|
|
|
|
FillRectDecal(c.getBlockPosition(b)+gameBoard.drawOffset,{12,12},DARK_GREEN);
|
|
|
|
}
|
|
|
|
nextClump:;
|
|
|
|
}
|
|
|
|
for (int i=0;i<gameBoard.boardSize.x;i++){
|
|
|
|
for (int y=0;y<gameBoard.getBlocks(i).size();y++){
|
|
|
|
Block&b=gameBoard.getBlocks(i)[y];
|
|
|
|
FillRectDecal(b.pos+gameBoard.drawOffset,{12,12},GREEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
Meteos instance;
|
|
|
|
if (instance.Construct(256, 240, 4, 4))
|
|
|
|
instance.Start();
|
|
|
|
return 0;
|
|
|
|
}
|