diff --git a/Block.h b/Block.h index ebb86ad..a8ad136 100644 --- a/Block.h +++ b/Block.h @@ -20,6 +20,7 @@ class Block{ public: vf2d pos; BlockColor col; + float resetTime=0.0f; bool markedForDeletion=false; bool markedForRemoval=false; bool addedToLaunchList=false; diff --git a/Board.cpp b/Board.cpp index a8ada80..9d5cc8e 100644 --- a/Board.cpp +++ b/Board.cpp @@ -5,8 +5,8 @@ extern Meteos*game; Board::Board() :colorHandler({}){} -Board::Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float spawnRate,std::array colorRates,Renderable&tileset) -:boardSize(boardSize),gravity(gravity),maxGravity(maxGravity),launchSpd(launchSpd),launchTime(launchTime),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){ +Board::Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float landTime,float spawnRate,std::array colorRates,Renderable&tileset) +:boardSize(boardSize),gravity(gravity),maxGravity(maxGravity),launchSpd(launchSpd),launchTime(launchTime),landTime(landTime),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){ drawOffset={(float)game->ScreenWidth()/2-boardSize.x/2*12,(float)game->ScreenHeight()/2-boardSize.y/2*12}; yBottom=(boardSize.y-1)*12; for (int i=0;igameBoard.landTime; clumpsToAdd.push_back(c2); } else { for (int i=0;igameBoard.landTime; b2.pos=c.getBlockPosition(b2); b2.pos.y=(int)(b2.pos.y+1)/12*12; b2.markedForDeletion=true; @@ -105,4 +107,8 @@ BlockColor ColorDistributor::getRandomColor(){ void Board::removeBlock(int col,int ind){ cols[col].erase(cols[col].begin()+ind); +} + +void Board::assignRandomColor(Block&b){ + b.col=colorHandler.getRandomColor(); } \ No newline at end of file diff --git a/Board.h b/Board.h index 7a2a500..a2f9e26 100644 --- a/Board.h +++ b/Board.h @@ -42,8 +42,9 @@ class Board{ float spawnRate; float launchSpd; float launchTime; //How much time a stack rises before beginning descent. + float landTime; Board(); - Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float spawnRate,std::array colorRates,Renderable&tileset); + Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float landTime,float spawnRate,std::array colorRates,Renderable&tileset); void spawnBlock(int col); void addClump(BlockClump&c); std::vector&getBlocks(int col); @@ -51,5 +52,6 @@ class Board{ void convertClump(int ind); void removeClump(int ind); void removeBlock(int col,int ind); + void assignRandomColor(Block&b); }; #endif \ No newline at end of file diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 70335df..17ad190 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/Meteos.h b/Meteos.h index 291e09e..0fbd5b2 100644 --- a/Meteos.h +++ b/Meteos.h @@ -17,7 +17,7 @@ class Meteos : public olc::PixelGameEngine{ std::map SPRITES; bool OnUserCreate()override; void updateGame(float fElapsedTime); - void drawGame(); + void drawGame(float fElapsedTime); bool OnUserUpdate(float fElapsedTime)override; }; #endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 6463178..95a343d 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ bool Meteos::OnUserCreate() randBlockPos=std::uniform_int_distribution<>(0, 9); coinFlip=std::uniform_int_distribution<>(0, 1); - gameBoard=Board({10,14},0.04f,1.2f,-1.f,1.7f,1.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]); + gameBoard=Board({10,14},0.04f,1.2f,-1.f,1.7f,2.0f,1.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]); return true; } @@ -29,7 +29,7 @@ bool Meteos::OnUserUpdate(float fElapsedTime) updateGame(1/60.0f); accumulatedTime=0; } - drawGame(); + drawGame(fElapsedTime); return true; } @@ -43,6 +43,15 @@ void Meteos::updateGame(float fElapsedTime){ BlockClump&c=gameBoard.getBlockClumps()[i]; if (c.launchTime>0) { c.launchTime-=fElapsedTime; + } else + if (c.landTime>0) { + c.landTime-=fElapsedTime; + if (c.landTime<=0) { + c.landTime=0; + for (int j=0;j0) { + b.resetTime-=fElapsedTime; + if (b.resetTime<0) { + b.resetTime=0; + gameBoard.assignRandomColor(b); + } + } DrawPartialDecal(c.getBlockPosition(b)+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12}); } } for (int i=0;i0) { + b.resetTime-=fElapsedTime; + if (b.resetTime<0) { + b.resetTime=0; + gameBoard.assignRandomColor(b); + } + } DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12}); } }