diff --git a/Block.h b/Block.h index 2e3cdd5..e227bff 100644 --- a/Block.h +++ b/Block.h @@ -4,7 +4,6 @@ class Block{ public: - float vspeed; vf2d pos; Block(vf2d pos) :pos(pos){} diff --git a/BlockClump.cpp b/BlockClump.cpp new file mode 100644 index 0000000..25a5dea --- /dev/null +++ b/BlockClump.cpp @@ -0,0 +1,13 @@ +#include "gameDefines.h" + +std::vector&BlockClump::getBlocks(){ + return blocks; +} + +void BlockClump::addBlock(int col){ + blocks.push_back(Block({(float)col*12,0})); +} + +vf2d BlockClump::getBlockPosition(Block&b){ + return {b.pos.x,b.pos.y+y}; +} \ No newline at end of file diff --git a/BlockClump.h b/BlockClump.h new file mode 100644 index 0000000..9eb743d --- /dev/null +++ b/BlockClump.h @@ -0,0 +1,19 @@ +#ifndef BLOCKCLUMP_H +#define BLOCKCLUMP_H +#include "pixelGameEngine.h" + +class Block; + +class BlockClump{ + std::vectorblocks; + public: + float vspeed=0; + float landTime=0.f; + float y=0; + BlockClump(){} + std::vector&getBlocks(); + void addBlock(int col); + //Get a block's position relative to this block clump. + vf2d getBlockPosition(Block&b); +}; +#endif \ No newline at end of file diff --git a/Board.cpp b/Board.cpp index 70fae6d..9806943 100644 --- a/Board.cpp +++ b/Board.cpp @@ -1,5 +1,4 @@ -#include "Board.h" -#include "Meteos.h" +#include "gameDefines.h" extern Meteos*game; @@ -13,10 +12,15 @@ Board::Board(vi2d boardSize,float gravity,float spawnRate) } void Board::spawnBlock(int col){ - Block newBlock=Block({(float)col*12,-120}); - cols[col].push_back(newBlock); + BlockClump c=BlockClump(); + c.addBlock(col); + clumps.push_back(c); } std::vector&Board::getBlocks(int col){ return cols[col]; +} + +std::vector&Board::getBlockClumps(){ + return clumps; } \ No newline at end of file diff --git a/Board.h b/Board.h index 55dd540..db9ccde 100644 --- a/Board.h +++ b/Board.h @@ -1,10 +1,13 @@ #ifndef BOARD_H #define BOARD_H #include "pixelGameEngine.h" -#include "Block.h" + +class Block; +class BlockClump; class Board{ std::vector> cols; + std::vector clumps; public: float yBottom; vf2d drawOffset; @@ -15,5 +18,6 @@ class Board{ Board(vi2d boardSize,float gravity,float spawnRate); void spawnBlock(int col); std::vector&getBlocks(int col); + std::vector&getBlockClumps(); }; #endif \ No newline at end of file diff --git a/C++ProjectTemplate b/C++ProjectTemplate index e666ae6..31d96b2 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/gameDefines.h b/gameDefines.h new file mode 100644 index 0000000..7d4fd7d --- /dev/null +++ b/gameDefines.h @@ -0,0 +1,4 @@ +#include "pixelGameEngine.h" +#include "Meteos.h" +#include "BlockClump.h" +#include "Block.h" \ No newline at end of file diff --git a/main.cpp b/main.cpp index 003a408..f919fc4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,7 @@ #define OLC_PGE_APPLICATION #include "pixelGameEngine.h" -#include "Meteos.h" #include +#include "gameDefines.h" Meteos*game; @@ -25,37 +25,47 @@ bool Meteos::OnUserUpdate(float fElapsedTime) 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) { + 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=0;yy--) { - Block&b2=gameBoard.getBlocks(i)[yy]; - if (b.pos.y+12>b2.pos.y) { - collisionDetected=true; - b.vspeed=0; - b.pos.y=b2.pos.y-12; - break; - } - } - if (!collisionDetected) { - b.pos.y+=b.vspeed*fElapsedTime; + for (int i=0;i=b2.pos.y&&c.getBlockPosition(b).y<=b2.pos.y+12){ + c.y=b2.pos.y-12; + c.vspeed=0; + gameBoard.removeClump(c); + i--; } - } else { - b.vspeed=0; - b.pos.y=gameBoard.yBottom; } + if (c.getBlockPosition(b).y>=gameBoard.yBottom) { + c.y=gameBoard.yBottom; + c.vspeed=0; + gameBoard.removeClump(c); + i--; + } + } + applyVelocity: + for (int j=0;j