@ -2,49 +2,37 @@
extern Meteos * game ;
Board : : Board ( vi2d boardSize , float gravity , float spawnRate )
: boardSize ( boardSize ) , gravity ( gravity ) , spawnRate ( spawnRate ) {
Board : : Board ( )
: colorHandler ( { } ) { }
Board : : Board ( vi2d boardSize , float gravity , float spawnRate , std : : array < int , 10 > colorRates , Renderable & tileset )
: boardSize ( boardSize ) , gravity ( gravity ) , 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 + + ) {
cols . push_back ( std : : vector < Block > ( ) ) ;
}
BlockClump c = BlockClump ( ) ;
c . addBlock ( 0 , 0 ) ;
c . addBlock ( 1 , 0 ) ;
c . addBlock ( 2 , 0 ) ;
c . vspeed = - 20 ;
c . y = yBottom - 12 ;
BlockClump c2 = BlockClump ( ) ;
c2 . addBlock ( 0 , 0 ) ;
c2 . addBlock ( 1 , 0 ) ;
c2 . addBlock ( 1 , - 1 ) ;
c2 . addBlock ( 2 , 0 ) ;
c2 . vspeed = 20 ;
c2 . y = 24 ;
clumps . push_back ( c ) ;
clumps . push_back ( c2 ) ;
}
void Board : : spawnBlock ( int col ) {
BlockClump c = BlockClump ( ) ;
c . addBlock ( col ) ;
c . addBlock ( col , colorHandler . getRandomColor ( ) ) ;
for ( int counter = 1 ; game - > coinFlip ( game - > gen ) = = 0 ; counter + + ) {
c . addBlock ( col , - counter ) ;
c . addBlock ( col , - counter , colorHandler . getRandomColor ( ) ) ;
}
if ( game - > coinFlip ( game - > gen ) = = 0 ) {
if ( col > 0 ) {
c . addBlock ( col - 1 ) ;
c . addBlock ( col - 1 , colorHandler . getRandomColor ( ) ) ;
for ( int counter = 1 ; game - > coinFlip ( game - > gen ) = = 0 ; counter + + ) {
c . addBlock ( col - 1 , - counter ) ;
c . addBlock ( col - 1 , - counter , colorHandler . getRandomColor ( ) ) ;
}
}
}
if ( game - > coinFlip ( game - > gen ) = = 0 ) {
if ( col < boardSize . x - 1 ) {
c . addBlock ( col + 1 ) ;
c . addBlock ( col + 1 , colorHandler . getRandomColor ( ) ) ;
for ( int counter = 1 ; game - > coinFlip ( game - > gen ) = = 0 ; counter + + ) {
c . addBlock ( col + 1 , - counter ) ;
c . addBlock ( col + 1 , - counter , colorHandler . getRandomColor ( ) ) ;
}
}
}
@ -84,7 +72,7 @@ void Board::convertClump(int ind){
Block & b2 = c . getBlocks ( ) [ i ] ;
if ( c . getBlockPosition ( b ) . x = = b2 . pos . x ) {
b2 . markedForDeletion = true ;
c2 . addBlock ( b2 . pos ) ;
c2 . addBlock ( b2 . pos , b2 . col ) ;
}
c2 . y = c . y ;
}
@ -96,3 +84,15 @@ void Board::convertClump(int ind){
}
removeClump ( ind ) ;
}
BlockColor ColorDistributor : : getRandomColor ( ) {
int val = range ( game - > gen ) ;
for ( int i = 0 ; i < 10 ; i + + ) {
if ( rangeTable [ i ] . first ! = - 1 & &
rangeTable [ i ] . first < = val & &
rangeTable [ i ] . second > val ) {
return ( BlockColor ) i ;
}
}
return BlockColor : : WHITE ;
}