bool TColorMatch::isMatchAt(int subX0,int subY0,int subWidth,int subHeight, int match_x0,int match_y0,frg_TMatchType* out_matchType)const{ if ((match_x0<0)||(match_x0+subWidth>m_ref.width)) return false; if ((match_y0<0)||(match_y0+subHeight>m_ref.height)) return false; if ((match_y0+subHeight<=subY0)||((match_y0<=subY0)&&(match_x0+subWidth<=subX0))){ if (isSameColor(m_ref,subX0,subY0,match_x0,match_y0,subWidth,subHeight,m_colorMask)){ if ((subWidth==kFrg_ClipWidth)&&isSameAlpha(m_ref,subX0,subY0,match_x0,match_y0,subWidth,subHeight)) *out_matchType=kFrg_MatchType_move_bgra_w8; else *out_matchType=kFrg_MatchType_move_bgr; return true; }if (isSameColor_up_down(m_ref,subX0,subY0,match_x0,match_y0,subWidth,subHeight,m_colorMask)){ if ((subWidth==kFrg_ClipWidth)&&isSameAlpha_up_down(m_ref,subX0,subY0,match_x0,match_y0,subWidth,subHeight)) *out_matchType=kFrg_MatchType_up_down_bgra_w8; else *out_matchType=kFrg_MatchType_up_down_bgr; return true; }else if (isSameColor_left_right(m_ref,subX0,subY0,match_x0,match_y0,subWidth,subHeight,m_colorMask)){ if ((subWidth==kFrg_ClipWidth)&&isSameAlpha_left_right(m_ref,subX0,subY0,match_x0,match_y0,subWidth,subHeight)) *out_matchType=kFrg_MatchType_left_right_bgra_w8; else *out_matchType=kFrg_MatchType_left_right_bgr; return true; }else{ return false; } }else{ return false; } }
void LEDStrip::fadeToColorStep() { Color nextFadeColor = getNextFadeColor(); setColor(nextFadeColor); // check if target color has been reached if (isSameColor(targetColor, currentColor)) { shouldFadeToColor = false; return; } }
static bool isSameColor_up_down(const TPixels32Ref& ref,int curX,int curY,int ox,int oy,int sw,int sh,TUInt32 colorMask){ const Color32* pixelLine0=&ref.pixels(curX,curY); const Color32* pixelLine1=&ref.pixels(ox,oy+(sh-1)); for (int y=0;y<sh;++y){ for (int x=0;x<sw;++x){ if (!isSameColor(pixelLine0[x],pixelLine1[x],colorMask)) return false; } pixelLine0=ref.nextLine(pixelLine0); pixelLine1=ref.prevLine(pixelLine1); } return true; }
void LEDStrip::fadeToColor(Color color, byte speed) { // check if color is already set if (isSameColor(color, currentColor)) { shouldFadeToColor = false; return; } targetColor = color; fadeSpeed = speed; shouldFadeToColor = true; // actual fadeing will be performed in multiple fadeToColorStep() calls }
void SceneGame::MoveChess(Touch* touch) { #if 0 Vec2 ptClicked = touch->getLocation(); int row, col; bool bClick = Screen2Plate(ptClicked, row, col); if (!bClick) { return; } int clickid = getChessFromRowCol(row, col); if (clickid != -1) { if (isSameColor(clickid, _selectid)) { _selectid = clickid; Vec2 pt = Plate2Screen(row, col); _selectSprite->setPosition(pt); //_selectSprite->setVisible(true); _selectSprite->setOpacity(255); return; } /*else { _c->at(clickid)->setVisible(false); _c->at(clickid)->_dead = true; }*/ } if (!canMove(_selectid, row, col, clickid)) { return; } recordStep(_selectid, clickid, _c->at(_selectid)->_row, _c->at(_selectid)->_col, row, col); if (clickid != -1) { _c->at(clickid)->setVisible(false); _c->at(clickid)->_dead = true; } _c->at(_selectid)->_row = row; _c->at(_selectid)->_col = col; //_c->at(_selectid)->setPosition(Plate2Screen(row, col)); _c->at(_selectid)->setZOrder(100); MoveTo* moveto = MoveTo::create(1.0f, Plate2Screen(row, col)); CallFuncN* callfuncN = CallFuncN::create(CC_CALLBACK_1(SceneGame::AfterMove,this, (void*)(intptr_t)clickid)); _c->at(_selectid)->runAction(CCSequence::createWithTwoActions(moveto, callfuncN)); FadeOut* fadeout = FadeOut::create(1.0f); MoveTo* SelectMoveto = MoveTo::create(1.0f, _c->at(_selectid)->fromPlate()); Spawn* spawn = Spawn::createWithTwoActions(fadeout, SelectMoveto); _selectSprite->runAction(spawn); _selectid = -1; //_selectSprite->setVisible(false); _bRedTurn = !_bRedTurn; /* if (!_bRedTurn) { //单步智能 Step* step = AI::getStep(this); Chess* moveChess = _c->at(step->moveid); moveChess->_row = step->rowTo; moveChess->_col = step->colTo; _bRedTurn = !_bRedTurn; moveChess->setPosition(moveChess->fromPlate()); if (step->killid != -1) { Chess* killChess = _c->at(step->killid); killChess->_dead = true; killChess->setVisible(false); } _steps->push_back(step); //多步智能 // scheduleOnce(schedule_selector(SceneGame::computerMove), 0.01f); //网络对战 } */ Step* step = *_steps->rbegin(); char buf[4]; buf[0] = 2; buf[1] = step->moveid; buf[2] = step->rowTo; buf[3] = step->colTo; NetBattle::Send(buf, 4); NetBattle::RecvStart(); schedule(schedule_selector(SceneGame::CheckRecv)); #endif Vec2 ptClicked = touch->getLocation(); int row, col; bool bClick = Screen2Plate(ptClicked, row, col); if (!bClick) { return; } int clickid = getChessFromRowCol(row, col); // 如果点击位置没有象棋,那么点击也无效 if (clickid != -1) { // 如果后一次点击的棋子和前一次相同,那么换选择 if (isSameColor(clickid, _selectid)) { _selectid = clickid; // 显示该棋子被选中的效果 Vec2 pt = Plate2Screen(row, col); _selectSprite->setPosition(pt); //_selectSprite->setVisible(true); _selectSprite->setOpacity(255); // 换选择之后,这次点击处理就结束了 return; } } // 判断棋子是否可以移动 if (!canMove(_selectid, row, col, clickid)) { return; } // 可以移动 // 记录移动信息 recordStep(_selectid, clickid, _c->at(_selectid)->_row, _c->at(_selectid)->_col, row, col); // 走棋相关 if (clickid != -1) { // 杀掉 //_s[clickid]->setVisible(false); _c->at(clickid)->_dead = true; } _c->at(_selectid)->_row = row; _c->at(_selectid)->_col = col; // _s[_selectid]->setPosition(Plate2Screen(row, col)); _c->at(_selectid)->setZOrder(100); MoveTo* moveto = MoveTo::create(1.0f, Plate2Screen(row, col)); CallFuncN* callfuncN = CallFuncN::create(CC_CALLBACK_1(SceneGame::AfterMove, this,(void*)(intptr_t)clickid)); _c->at(_selectid)->runAction(Sequence::createWithTwoActions(moveto, callfuncN)); FadeOut* fadeout = FadeOut::create(1.0f); MoveTo* SelectMoveto = MoveTo::create(1.0f, _c->at(_selectid)->fromPlate()); Spawn* spawn = CCSpawn::createWithTwoActions(fadeout, SelectMoveto); _selectSprite->runAction(spawn); _selectid = -1; //_selectSprite->setVisible(false); _bRedTurn = !_bRedTurn; // 发送移动棋子报文 Step* step = *_steps->rbegin(); char buf[4]; buf[0] = 2; buf[1] = step->moveid; buf[2] = step->rowTo; buf[3] = step->colTo; NetBattle::Send(buf, 4); // 接收信息 NetBattle::RecvStart(); schedule(schedule_selector(SceneGame::CheckRecv)); }
void GameStartLayer::moveStone(CCTouch *touch) { CCPoint ptClicked = touch->getLocation(); int row, col; bool bClick = Screen2Plate(ptClicked, row, col); //! 点击在棋子间的空隙点击无效 if (!bClick) { return; } int clickid = getStoneFromRowCol(row, col); if (clickid != -1) { //! 如果颜色相同,更换选中棋子 if (isSameColor(clickid, _selectid)) { _selectid = clickid; CCPoint pt = Plate2Screen(row, col); _selectedSprite->setPosition(pt); _selectedSprite->setVisible(true); return; } //else //{ // //! kill // _s[clickid]->setVisible(false); // _s[clickid]->_dead = true; //} } //! 判断是否可以移动棋子 if (!canMove(_selectid, row, col, clickid)) { return; } recordStep(_selectid, clickid, _s[_selectid]->_proper._row, _s[_selectid]->_proper._col, row, col); //! kill if (clickid != -1) { // 杀掉 _s[clickid]->setVisible(false); _s[clickid]->_dead = true; } //! 移动棋子 _s[_selectid]->_proper._row = row; _s[_selectid]->_proper._col = col; _s[_selectid]->setPosition(Plate2Screen(row, col)); //! 重置属性 _selectid = -1; //_selectedSprite->setVisible(false); _selectedSprite->setPosition(Plate2Screen(row, col)); _bRedTurn = !_bRedTurn; //! 智能移动 if (!_bRedTurn) { //CCDelayTime *delay = CCDelayTime::create(0.01f); //CCCallFunc *ai = CCCallFunc::create(this, callfunc_selector(GameStartLayer::computerMove)); //CCSequence *seq = CCSequence::create(delay, ai, nullptr); //this->runAction(seq); scheduleOnce(schedule_selector(GameStartLayer::computerMove), 0.01f); } }