generated from sigonasr2/CPlusPlusProjectTemplate
parent
e77690f7e0
commit
0a5ebfd622
@ -0,0 +1,11 @@ |
||||
#ifndef BLOCK_H |
||||
#define BLOCK_H |
||||
#include "pixelGameEngine.h" |
||||
|
||||
class Block{ |
||||
public: |
||||
vf2d pos; |
||||
Block(vf2d pos) |
||||
:pos(pos){} |
||||
}; |
||||
#endif |
@ -0,0 +1,9 @@ |
||||
#include "Board.h" |
||||
#include "Meteos.h" |
||||
|
||||
extern Meteos*game; |
||||
|
||||
Board::Board(vi2d boardSize,float gravity) |
||||
:boardSize(boardSize),gravity(gravity){ |
||||
drawOffset={(float)game->ScreenWidth()/2-boardSize.x/2*12,(float)game->ScreenHeight()/2-boardSize.y/2*12}; |
||||
} |
@ -0,0 +1,13 @@ |
||||
#ifndef BOARD_H |
||||
#define BOARD_H |
||||
#include "pixelGameEngine.h" |
||||
|
||||
class Board{ |
||||
public: |
||||
vf2d drawOffset; |
||||
vi2d boardSize; |
||||
float gravity; |
||||
Board(){} |
||||
Board(vi2d boardSize,float gravity); |
||||
}; |
||||
#endif |
Binary file not shown.
@ -0,0 +1,21 @@ |
||||
#ifndef METEOS_H |
||||
#define METEOS_H |
||||
#include "pixelGameEngine.h" |
||||
#include "Block.h" |
||||
#include "Board.h" |
||||
#include <random> |
||||
|
||||
class Meteos : public olc::PixelGameEngine{ |
||||
public: |
||||
Meteos(){ |
||||
sAppName="Meteos"; |
||||
} |
||||
std::vector<Block> blocks; |
||||
float lastBlockSpawn=0.0f; |
||||
std::uniform_int_distribution<> randBlockPos; |
||||
std::mt19937 gen; |
||||
Board gameBoard; |
||||
bool OnUserCreate()override; |
||||
bool OnUserUpdate(float fElapsedTime)override; |
||||
}; |
||||
#endif |
@ -1,31 +1,49 @@ |
||||
#define OLC_PGE_APPLICATION |
||||
#include "pixelGameEngine.h" |
||||
#include "Meteos.h" |
||||
#include <random> |
||||
|
||||
class Meteos : public olc::PixelGameEngine |
||||
Meteos*game; |
||||
|
||||
bool Meteos::OnUserCreate() |
||||
{ |
||||
public: |
||||
Meteos() |
||||
{ |
||||
sAppName = "Meteos"; |
||||
} |
||||
game=this; |
||||
|
||||
bool OnUserCreate() override |
||||
{ |
||||
|
||||
return true; |
||||
} |
||||
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},0.1f); |
||||
return true; |
||||
} |
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override |
||||
{ |
||||
|
||||
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) { |
||||
FillRectDecal(b.pos+gameBoard.drawOffset,{12,12},GREEN); |
||||
} |
||||
}; |
||||
return true; |
||||
} |
||||
|
||||
int main() |
||||
{ |
||||
Meteos game; |
||||
if (game.Construct(256, 240, 4, 4)) |
||||
game.Start(); |
||||
Meteos instance; |
||||
if (instance.Construct(256, 240, 4, 4)) |
||||
instance.Start(); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue