Line::Line(int row,int z,SafeMatrix& matrix,SDL_Surface* (&blocks)[5]) :SurfaceWidget(MATRIX_X,row*BLOCK_DIM+MATRIX_Y,MATRIX_W,BLOCK_DIM,z) { try { surface_=Util::createSurface(BLOCK_DIM*MATRIX_COLS,BLOCK_DIM); } catch(const exception& ex) { throw runtime_error(string("Line::Line(...): ")+ex.what()); } SDL_Rect r; r.x=r.y=0; for(int i=0;i<MATRIX_COLS;i++,r.x+=BLOCK_DIM) { SDL_BlitSurface(blocks[matrix.get(row,i)],0,surface_,&r); matrix.set(row,i,-1); } alpha_=SDL_ALPHA_OPAQUE; SDL_SetAlpha(surface_,SDL_SRCALPHA|SDL_RLEACCEL,alpha_); ticks_=0; }
void Block::putIn(int row,int col,SafeMatrix& matrix) { for(int r=0;r<matrix_.getRows();r++) for(int c=0;c<matrix_.getCols();c++) if(matrix_.get(r,c)>=0 && row+r>=0) matrix.set(row+r,col+c,matrix_.get(r,c)); }
Block::Block(int row,int z,SafeMatrix& matrix) :FallingObject(0,0,0,0,z) { int ro; for(ro=0;ro<row;ro++) { int j; for(j=0;j<MATRIX_COLS && matrix.get(ro,j)==-1;j++); if(j<MATRIX_COLS) break; } if(ro>=row) throw runtime_error("Block::Block(): Block vacio"); int co; for(co=0;co<MATRIX_COLS;co++) { int j; for(j=ro;j<row && matrix.get(j,co)==-1;j++); if(j<row) break; } int cf; for(cf=MATRIX_COLS-1;cf>=co;cf--) { int j; for(j=0;j<row && matrix.get(j,cf)==-1;j++); if(j<row) break; } if(co>cf) throw runtime_error("Block::Block(): Block vacio"); matrix_=SafeMatrix(row-ro,cf-co+1); for(int r=0;r<matrix_.getRows();r++) for(int c=0;c<matrix_.getCols();c++) { matrix_.set(r,c,matrix.get(ro+r,co+c)); matrix.set(ro+r,co+c,-1); } setX(co*BLOCK_DIM+MATRIX_X); setY(ro*BLOCK_DIM+MATRIX_Y); setWidth(matrix_.getCols()*BLOCK_DIM); setHeight(matrix_.getRows()*BLOCK_DIM); //matrix_.print(); rects_.reserve(matrix_.getCols()); refreshRects(); }