diff --git a/Board.cpp b/Board.cpp index 67efb03..366edb0 100644 --- a/Board.cpp +++ b/Board.cpp @@ -5,8 +5,10 @@ extern Meteos*game; Board::Board() :colorHandler({}){} -Board::Board(vi2d boardSize,float blockWeight,float gravity,float maxGravity,float comboGravity,float comboMaxGravity,std::vector launchSpd,float launchTime,float landTime,float spawnRate,std::array colorRates,Renderable&tileset) -:boardSize(boardSize),blockWeight(blockWeight),gravity(gravity),maxGravity(maxGravity),comboGravity(comboGravity),comboMaxGravity(comboMaxGravity),launchSpd(launchSpd),launchTime(launchTime),landTime(landTime),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()){ +Board::Board(vi2d boardSize,float blockWeight,float gravity,float maxGravity,float comboGravity,float comboMaxGravity,std::vector launchSpd,float launchTime,float landTime,float spawnRate,std::array colorRates, + int maxWarningLevel,Renderable&tileset) +:boardSize(boardSize),blockWeight(blockWeight),gravity(gravity),maxGravity(maxGravity),comboGravity(comboGravity),comboMaxGravity(comboMaxGravity),launchSpd(launchSpd),launchTime(launchTime),landTime(landTime),spawnRate(spawnRate),colorHandler(colorRates),tileset(tileset.Decal()), +maxWarningLevel(maxWarningLevel){ 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.assignRandomColor(b2); } - cols[b.pos.x/12].push_back(b2); + if (cols[b.pos.x/12].size()gameBoard.boardSize.y){ + cols[b.pos.x/12].push_back(b2); + } } } } diff --git a/Board.h b/Board.h index 7413686..b7b3f56 100644 --- a/Board.h +++ b/Board.h @@ -57,7 +57,8 @@ class Board{ int maxWarningLevel=0; std::vector warningFlashingLevel; Board(); - Board(vi2d boardSize,float blockWeight,float gravity,float maxGravity,float launchedGravity,float launchedMaxGravity,std::vector launchSpd,float launchTime,float landTime,float spawnRate,std::array colorRates,Renderable&tileset); + Board(vi2d boardSize,float blockWeight,float gravity,float maxGravity,float launchedGravity,float launchedMaxGravity,std::vector launchSpd,float launchTime,float landTime,float spawnRate,std::array colorRates, + int maxWarningLevel,Renderable&tileset); void spawnBlock(int col); void addClump(BlockClump&c); std::vector&getBlocks(int col); diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 3329b7c..d53fbee 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 449eab4..53fc47d 100644 --- a/main.cpp +++ b/main.cpp @@ -24,7 +24,8 @@ bool Meteos::OnUserCreate() coinFlip=std::uniform_int_distribution<>(0, 1); comboOverlayOffset=std::uniform_int_distribution<>(-16,16); - gameBoard=Board({10,14},0.02f,0.04f,1.2f,0.04f,0.4f,{-1.f,-1.5f,-2.f,-2.5f,-4.f},1.7f,2.0f,1.0f,{3,3,1,2,3,0,0,0,0,0},SPRITES["blocks_test.png"]); + gameBoard=Board({10,14},0.02f,0.04f,1.2f,0.04f,0.4f,{-1.f,-1.5f,-2.f,-2.5f,-4.f},1.7f,2.0f,1.0f,{3,3,1,2,3,0,0,0,0,0}, + 60*10,SPRITES["blocks_test.png"]); return true; } @@ -614,7 +615,15 @@ void Meteos::updateGame(float fElapsedTime){ continue; } } + bool noWarning=true; for (int i=0;i=gameBoard.boardSize.y){ + gameBoard.warningFlashingLevel[i]+=fElapsedTime; + gameBoard.warningLevel++; + noWarning=false; + } else { + gameBoard.warningFlashingLevel[i]=0; + } for (int y=gameBoard.getBlocks(i).size()-1;y>=0;y--){ Block&b=gameBoard.getBlocks(i)[y]; b.addedToLaunchList=false; @@ -624,6 +633,22 @@ void Meteos::updateGame(float fElapsedTime){ } } } + if (noWarning){ + gameBoard.warningLevel=0; + } else + if (gameBoard.warningLevel>=gameBoard.maxWarningLevel){ + //Planet crashes! For now we just clear all blocks and clumps on the board. + while (gameBoard.getBlockClumps().size()>0){ + gameBoard.removeClump(0); + } + for (int i=0;i0){ + gameBoard.removeBlock(i,0); + } + } + gameBoard.warningLevel=0; + goto invalidatedExit; + } //Invalidate the selected block if something is strange about it. if (gameBoard.selectedBlock.col!=-1){ if (gameBoard.selectedBlock.c!=-1){ @@ -674,6 +699,9 @@ void Meteos::drawGame(float fElapsedTime,bool debugView){ Block&b=gameBoard.getBlocks(i)[y]; DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12},{1,1},gameBoard.selectedBlock.col!=-1&&gameBoard.selectedBlock.c==-1&&gameBoard.selectedBlock.col==i&&gameBoard.selectedBlock.ind==y?Pixel(GREY.r,GREY.g,GREY.b,alpha):Pixel(WHITE.r,WHITE.g,WHITE.b,alpha)); } + if (gameBoard.warningFlashingLevel[i]>0){ + FillRectDecal({gameBoard.drawOffset.x+i*12,gameBoard.drawOffset.y},{12,(float)gameBoard.boardSize.y*12},Pixel(255,64,64,std::abs(sin(gameBoard.warningFlashingLevel[i]*M_PI))*128)); + } } for (int i=0;i