|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#include "Meteos.h"
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
gameBoard=Board({10,14},6.f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Meteos::OnUserUpdate(float fElapsedTime)
|
|
|
|
{
|
|
|
|
lastBlockSpawn+=fElapsedTime;
|
|
|
|
if (lastBlockSpawn>=5.0f){
|
|
|
|
lastBlockSpawn-=5.0f;
|
|
|
|
blocks.push_back(Block({(float)randBlockPos(gen)*12,0}));
|
|
|
|
}
|
|
|
|
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 (Block&b:blocks) {
|
|
|
|
if (b.pos.y<gameBoard.yBottom) {
|
|
|
|
b.vspeed+=gameBoard.gravity*fElapsedTime;
|
|
|
|
b.pos.y+=b.vspeed*fElapsedTime;
|
|
|
|
} else {
|
|
|
|
b.vspeed=0;
|
|
|
|
b.pos.y=gameBoard.yBottom;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|