diff --git a/Block.h b/Block.h new file mode 100644 index 0000000..e227bff --- /dev/null +++ b/Block.h @@ -0,0 +1,11 @@ +#ifndef BLOCK_H +#define BLOCK_H +#include "pixelGameEngine.h" + +class Block{ + public: + vf2d pos; + Block(vf2d pos) + :pos(pos){} +}; +#endif \ No newline at end of file diff --git a/Board.cpp b/Board.cpp new file mode 100644 index 0000000..8add5df --- /dev/null +++ b/Board.cpp @@ -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}; +} \ No newline at end of file diff --git a/Board.h b/Board.h new file mode 100644 index 0000000..4972ea8 --- /dev/null +++ b/Board.h @@ -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 \ No newline at end of file diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 6814313..ec6bc90 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/Meteos.h b/Meteos.h new file mode 100644 index 0000000..d419432 --- /dev/null +++ b/Meteos.h @@ -0,0 +1,21 @@ +#ifndef METEOS_H +#define METEOS_H +#include "pixelGameEngine.h" +#include "Block.h" +#include "Board.h" +#include + +class Meteos : public olc::PixelGameEngine{ + public: + Meteos(){ + sAppName="Meteos"; + } + std::vector blocks; + float lastBlockSpawn=0.0f; + std::uniform_int_distribution<> randBlockPos; + std::mt19937 gen; + Board gameBoard; + bool OnUserCreate()override; + bool OnUserUpdate(float fElapsedTime)override; +}; +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7860e9e..484829a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,31 +1,49 @@ #define OLC_PGE_APPLICATION #include "pixelGameEngine.h" +#include "Meteos.h" +#include -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; } \ No newline at end of file diff --git a/pixelGameEngine.h b/pixelGameEngine.h index 3005cbe..76f1c27 100644 --- a/pixelGameEngine.h +++ b/pixelGameEngine.h @@ -6243,3 +6243,5 @@ namespace olc // | END OF OLC_PGE_APPLICATION | // O------------------------------------------------------------------------------O + +using namespace olc;