Block landing conversion

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 82831c024d
commit 1bf7312b78
  1. 1
      Block.h
  2. 10
      Board.cpp
  3. 4
      Board.h
  4. BIN
      C++ProjectTemplate
  5. 2
      Meteos.h
  6. 29
      main.cpp

@ -20,6 +20,7 @@ class Block{
public:
vf2d pos;
BlockColor col;
float resetTime=0.0f;
bool markedForDeletion=false;
bool markedForRemoval=false;
bool addedToLaunchList=false;

@ -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<int,10> 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<int,10> 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;i<boardSize.x;i++) {
@ -71,11 +71,13 @@ void Board::convertClump(int ind){
}
c2.y=c.y;
}
c2.landTime=game->gameBoard.landTime;
clumpsToAdd.push_back(c2);
} else {
for (int i=0;i<c.getBlocks().size();i++) {
Block&b2=c.getBlocks()[i];
if (c.getBlockPosition(b).x==b2.pos.x) {
b2.resetTime=game->gameBoard.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();
}

@ -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<int,10> colorRates,Renderable&tileset);
Board(vi2d boardSize,float gravity,float maxGravity,float launchSpd,float launchTime,float landTime,float spawnRate,std::array<int,10> colorRates,Renderable&tileset);
void spawnBlock(int col);
void addClump(BlockClump&c);
std::vector<Block>&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

Binary file not shown.

@ -17,7 +17,7 @@ class Meteos : public olc::PixelGameEngine{
std::map<std::string,Renderable> SPRITES;
bool OnUserCreate()override;
void updateGame(float fElapsedTime);
void drawGame();
void drawGame(float fElapsedTime);
bool OnUserUpdate(float fElapsedTime)override;
};
#endif

@ -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;j<c.getBlocks().size();j++){
gameBoard.assignRandomColor(c.getBlocks()[j]);
}
}
} else {
c.vspeed+=gameBoard.gravity;
}
@ -357,7 +366,7 @@ void Meteos::updateGame(float fElapsedTime){
}
}
void Meteos::drawGame(){
void Meteos::drawGame(float fElapsedTime){
Clear(Pixel(32,32,255));
for (int x=-1;x<=gameBoard.boardSize.x;x++){
for (int y=0;y<=gameBoard.boardSize.y;y++){
@ -372,12 +381,26 @@ void Meteos::drawGame(){
BlockClump&c=gameBoard.getBlockClumps()[i];
for (int j=0;j<c.getBlocks().size();j++){
Block&b=c.getBlocks()[j];
if (b.resetTime>0) {
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;i<gameBoard.boardSize.x;i++){
for (int y=0;y<gameBoard.getBlocks(i).size();y++){
Block&b=gameBoard.getBlocks(i)[y];
if (b.resetTime>0) {
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});
}
}

Loading…
Cancel
Save