Added launch time

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent b87fbcce50
commit c8e5d4f125
  1. 1
      BlockClump.h
  2. 4
      Board.cpp
  3. 3
      Board.h
  4. BIN
      C++ProjectTemplate
  5. 13
      main.cpp

@ -10,6 +10,7 @@ class BlockClump{
public: public:
float vspeed=0; float vspeed=0;
float landTime=0.f; float landTime=0.f;
float launchTime=0.f;
float y=0; float y=0;
BlockClump(){} BlockClump(){}
std::vector<Block>&getBlocks(); std::vector<Block>&getBlocks();

@ -5,8 +5,8 @@ extern Meteos*game;
Board::Board() Board::Board()
:colorHandler({}){} :colorHandler({}){}
Board::Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float spawnRate,std::array<int,10> colorRates,Renderable&tileset) Board::Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float spawnRate,std::array<int,10> colorRates,Renderable&tileset)
:boardSize(boardSize),gravity(gravity),maxGravity(maxGravity),launchSpd(launchSpd),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){ :boardSize(boardSize),gravity(gravity),maxGravity(maxGravity),launchSpd(launchSpd),launchTime(launchTime),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){
drawOffset={(float)game->ScreenWidth()/2-boardSize.x/2*12,(float)game->ScreenHeight()/2-boardSize.y/2*12}; drawOffset={(float)game->ScreenWidth()/2-boardSize.x/2*12,(float)game->ScreenHeight()/2-boardSize.y/2*12};
yBottom=(boardSize.y-1)*12; yBottom=(boardSize.y-1)*12;
for (int i=0;i<boardSize.x;i++) { for (int i=0;i<boardSize.x;i++) {

@ -41,8 +41,9 @@ class Board{
float maxGravity; float maxGravity;
float spawnRate; float spawnRate;
float launchSpd; float launchSpd;
float launchTime; //How much time a stack rises before beginning descent.
Board(); Board();
Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float spawnRate,std::array<int,10> colorRates,Renderable&tileset); Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float spawnRate,std::array<int,10> colorRates,Renderable&tileset);
void spawnBlock(int col); void spawnBlock(int col);
void addClump(BlockClump&c); void addClump(BlockClump&c);
std::vector<Block>&getBlocks(int col); std::vector<Block>&getBlocks(int col);

Binary file not shown.

@ -12,13 +12,12 @@ bool Meteos::OnUserCreate()
SPRITES["blocks_test.png"].Load("assets/blocks_test.png"); SPRITES["blocks_test.png"].Load("assets/blocks_test.png");
std::random_device rd; //Will be used to obtain a seed for the random number engine 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() gen=std::mt19937(rd()); //Standard mersenne_twister_engine seeded with rd()
gen=std::mt19937(0);
//Seed 0 causes a stacked block in the middle row followed by a giant stack up soon after. //Seed 0 causes a stacked block in the middle row followed by a giant stack up soon after.
randBlockPos=std::uniform_int_distribution<>(0, 9); randBlockPos=std::uniform_int_distribution<>(0, 9);
coinFlip=std::uniform_int_distribution<>(0, 1); coinFlip=std::uniform_int_distribution<>(0, 1);
gameBoard=Board({10,14},0.2f,1.f,-6.f,1.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]); gameBoard=Board({10,14},0.04f,0.7f,-1.f,1.7f,1.0f,{3,0,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]);
return true; return true;
} }
@ -42,7 +41,11 @@ void Meteos::updateGame(float fElapsedTime){
} }
for (int i=0;i<gameBoard.getBlockClumps().size();i++){ for (int i=0;i<gameBoard.getBlockClumps().size();i++){
BlockClump&c=gameBoard.getBlockClumps()[i]; BlockClump&c=gameBoard.getBlockClumps()[i];
c.vspeed+=gameBoard.gravity; if (c.launchTime>0) {
c.launchTime-=fElapsedTime;
} else {
c.vspeed+=gameBoard.gravity;
}
if (c.vspeed>gameBoard.maxGravity){ if (c.vspeed>gameBoard.maxGravity){
c.vspeed=gameBoard.maxGravity; c.vspeed=gameBoard.maxGravity;
} }
@ -205,6 +208,7 @@ void Meteos::updateGame(float fElapsedTime){
Block&b=c.getBlocks()[i]; Block&b=c.getBlocks()[i];
b.col=BlockColor::LAUNCHED; b.col=BlockColor::LAUNCHED;
c.vspeed=gameBoard.launchSpd; c.vspeed=gameBoard.launchSpd;
c.launchTime=gameBoard.launchTime;
} }
} }
std::vector<std::pair<int,int>>matchedBlockIDs; //Col followed by index std::vector<std::pair<int,int>>matchedBlockIDs; //Col followed by index
@ -322,6 +326,7 @@ void Meteos::updateGame(float fElapsedTime){
} }
b.col=BlockColor::LAUNCHED; b.col=BlockColor::LAUNCHED;
c.vspeed=gameBoard.launchSpd; c.vspeed=gameBoard.launchSpd;
c.launchTime=gameBoard.launchTime;
} }
for (std::pair<int,int>&info:matchedBlockIDs) { for (std::pair<int,int>&info:matchedBlockIDs) {
Block&b=gameBoard.getBlocks(info.first)[info.second]; Block&b=gameBoard.getBlocks(info.first)[info.second];

Loading…
Cancel
Save