void Field::addJunk(int nr) { for (auto& block : blocks_) { block.setY(block.getY() + nr); block.setAnimationY(block.getAnimationY() - nr); } if (tetromino_) { tetromino_->moveUp(nr); } std::uniform_int_distribution<int> dist(0, width_ - 1); std::mt19937 colorRandom; std::uniform_int_distribution<int> colorDist(0, 255); for (int i = 0; i < nr; ++i) { int leaveOut = dist(random); for (int x = 0; x < width_; ++x) { if (x != leaveOut) { jngl::Color color(colorDist(colorRandom), colorDist(colorRandom), colorDist(colorRandom)); Block block(x, i, color); block.setAnimationY(-nr); AddBlock(block); } } } }
static void expansionOfKnownRegionsHelper(const cv::Mat &_image, cv::Mat &_trimap, int r, float c) { const cv::Mat_<cv::Vec3b> &image = (const cv::Mat_<cv::Vec3b> &)_image; cv::Mat_<uchar> &trimap = (cv::Mat_<uchar>&)_trimap; int w = image.cols; int h = image.rows; for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) { if (trimap(y, x) != 128) continue; const cv::Vec3b &I = image(y, x); for (int j = y-r; j <= y+r; ++j) for (int i = x-r; i <= x+r; ++i) { if (i < 0 || i >= w || j < 0 || j >= h) continue; if (trimap(j, i) != 0 && trimap(j, i) != 255) continue; const cv::Vec3b &I2 = image(j, i); float pd = sqrt((float)(sqr(x - i) + sqr(y - j))); float cd = colorDist(I, I2); if (pd <= r && cd <= c) { if (trimap(j, i) == 0) trimap(y, x) = 1; else if (trimap(j, i) == 255) trimap(y, x) = 254; } } } for (int x = 0; x < trimap.cols; ++x) for (int y = 0; y < trimap.rows; ++y) { if (trimap(y, x) == 1) trimap(y, x) = 0; else if (trimap(y, x) == 254) trimap(y, x) = 255; } }
Field::Field(int seed) : blockSize_(60), counter_(0), gameOver_(false), score_(0), level_(GetOptions().Get<int>("startLevel")), lines_(0), maxY_(0), pause_(false), control_(new Control{std::make_shared<KeyboardControl>(), std::make_shared<GamepadControl>(0)}), randomSeed(seed), linesCleared(0) { random.seed(seed); NewTetromino(); NewTetromino(); score_ = 0; std::uniform_int_distribution<int> dist(0, width_ - 1); std::mt19937 colorRandom; std::uniform_int_distribution<int> colorDist(0, 255); for (int i = 0; i < GetOptions().Get<int>("startJunks"); ++i) { int leaveOut = dist(random); for (int x = 0; x < width_; ++x) { if (x != leaveOut) { jngl::Color color(colorDist(colorRandom), colorDist(colorRandom), colorDist(colorRandom)); AddBlock(Block(x, i, color)); } } } }
void Player::drawNewCard(int slot, bool mana) { Ability *ab; double cardProbability[] = { 1.0, 1.5, 1.0}; boost::random::discrete_distribution<> cardDist(cardProbability); boost::random::discrete_distribution<> colorDist(m_maxMana); bool done = false; while(!done) { int color = colorDist(RAND); int card = cardDist(RAND); if(mana) card = 2; switch(color) { case 0: // RED switch(card) { case 0: ab = new AbInstantTunnel(AB_INSTANT_TUNNEL); break; case 1: ab = new AbLightningBolt(AB_LIGHTNING_BOLT); break; case 2: ab = new AbSmallManaStream(AB_SMALL_MANA_STREAM, COLOR_RED); break; } break; case 1: // BLUE switch(card) { case 0: ab = new AbBlink(AB_BLINK); break; case 1: ab = new AbBlastTrap(AB_BLAST_TRAP,0); break; case 2: ab = new AbSmallManaStream(AB_SMALL_MANA_STREAM, COLOR_BLUE); break; } break; case 2: // WHITE switch(card) { case 0: ab = new AbSacredNectar(AB_SACRED_NECTAR); break; case 1: ab = new AbDefensiveStance(AB_DEFENSIVE_STANCE); break; case 2: ab = new AbSmallManaStream(AB_SMALL_MANA_STREAM, COLOR_WHITE); break; } break; } done = m_maxMana[ab->m_color] > 0; if(done) { for(unsigned int i=0; i<ab->m_cost.size(); i++) { ManaCost &cost = ab->m_cost[i]; if(m_maxMana[cost.m_color] < cost.m_amount) { done = false; } } } if(!done) { delete ab; } } if(int(m_abilities.size()) > slot) { if(m_abilities[slot] != 0) { delete m_abilities[slot]; } m_abilities[slot] = ab; } else { m_abilities.push_back(ab); } /*if(slot<m_abilities.size() && slot>=0){ if(m_library.size()<=0){ restockLibrary(); } m_abilities[slot] = m_library.back(); m_library.pop_back(); }*/ }
bool xbrz::equalColor(uint32_t col1, uint32_t col2, double luminanceWeight, double equalColorTolerance) { return colorDist(col1, col2, luminanceWeight) < equalColorTolerance; }