コード例 #1
0
bool AllianceAreaPopupView::init(){
    if(!PopupBaseView::init()){
        return false;
    }
    setIsHDPanel(true);
    isMoving = false;
    this->setModelLayerOpacity(0);
    this->setContentSize(CCDirector::sharedDirector()->getWinSize());
    m_picNode = CCNode::create();
    m_picNode->setContentSize(CCSize(_tile_width * 2, _tile_height * 2));
    m_picNode->setAnchorPoint(ccp(0, 0));
    CCPoint testPoint =PopupViewController::getInstance()->getTouchPoint() + ccp(-_tile_width, -_tile_height);
//    m_picNode->setPosition(PopupViewController::getInstance()->getTouchPoint() + ccp(-_tile_width, -_tile_height));
    
    CCPoint tilePoint = WorldController::getInstance()->getPointByIndex(m_tileIndex);
    CCPoint viewPoint = getInLayerPoint(tilePoint);
    viewPoint = viewPoint + ccp(-_tile_width * 1.5, -_tile_height);
    m_picNode->setPosition(viewPoint);
    
    m_cityNode = CCNode::create();
    
 
    /*int mapIndex = 3;
    while (mapIndex >= 0) {
        auto arr = WorldController::getInstance()->getCityPicArr(mapIndex, 0, false ,44996);
        int posX = _tile_width / 2;
        int posY = _tile_height / 2;
        if(mapIndex == 0 || mapIndex == 2){
            posX = _tile_width;
        }
        if(mapIndex == 3){
            posX = _tile_width + posX;
        }
        if(mapIndex == 1 || mapIndex == 3){
            posY = _tile_height;
        }
        if(mapIndex == 2){
            posY = _tile_height + posY;
        }
        auto itMap = arr.begin();
        while (itMap!=arr.end()) {
            std::string picName = (*itMap).pic;
            int addX = (*itMap).x;
            int addY = (*itMap).y;
            auto sprite = CCLoadSprite::createSprite(picName.c_str());
            sprite->setAnchorPoint(ccp(0, 0));
            if (CCCommonUtils::isIosAndroidPad()) {
                m_cityNode->addChild(sprite);
                sprite->setPosition(ccp(posX, posY) - ccp(_tile_width / 2, _tile_height / 2) + ccp(addX, addY));
                
            }
            else {
                m_picNode->addChild(sprite);
                sprite->setPosition(ccp(posX, posY) - ccp(_tile_width / 2, _tile_height / 2) + ccp(addX, addY));
            }
            ++itMap;
        }
        mapIndex--;
    }*/
    auto tower = CCLoadSprite::createSprite("territory_fort.png");
    tower->setPosition(ccp(_tile_width -25, _tile_height + 62));
    m_picNode->addChild(tower);
    
    if (CCCommonUtils::isIosAndroidPad()) {
        m_picNode->addChild(m_cityNode);
        m_cityNode->setScale(WORLD_DEFAULT_HD_SCALE);
        m_cityNode->setPosition(ccp(-_tile_width * (WORLD_DEFAULT_HD_SCALE - 1),-_tile_height * (WORLD_DEFAULT_HD_SCALE - 1)));
    }
    
        CCPointArray* pointArr = CCPointArray::create(3);
        pointArr->addControlPoint(ccp(-70,59));
        pointArr->addControlPoint(ccp(-2,23));
        pointArr->addControlPoint(ccp(66,57));
    CCLoadSprite::doResourceByCommonIndex(507, true);
        for (int i = 0; i < 3; i++) {
            auto bannerSprite = CCFlagWaveSprite::create(CCLoadSprite::loadResource("1212_double.png"));
            if (CCCommonUtils::isIosAndroidPad()) {
                bannerSprite->setScale(0.25);
            }
            else
                bannerSprite->setScale(0.18);
            bannerSprite->setPosition(ccp(_tile_width, _tile_height)+pointArr->getControlPointAtIndex(i) + ccp(12, 20));
            m_picNode->addChild(bannerSprite);
        }
    CCLoadSprite::doResourceByCommonIndex(507, false);
    
    if (CCCommonUtils::isIosAndroidPad()) {
        m_cancelBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("but_blue.png"));
        m_cancelBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onCancelBtnClick), CCControlEventTouchUpInside);
        m_cancelBtn->setPreferredSize(CCSize(160, 70));
        m_cancelBtn->setScaleX(2.1);
        m_cancelBtn->setScaleY(1.7);
        
        m_confirmBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("btn_green3.png"));
        m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("btn_green3.png"),CCControlStateHighlighted);
        m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("Btn_grey.png"),CCControlStateDisabled);
        m_confirmBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onConfirmBtnClick), CCControlEventTouchUpInside);
        m_confirmBtn->setPreferredSize(CCSize(160, 70));
        m_confirmBtn->setScaleX(2.1);
        m_confirmBtn->setScaleY(1.7);
        
        auto bg = CCLoadSprite::createSprite("technology_11.png");
        m_picNode->addChild(bg);

        m_btnLabel = CCLabelIF::create(_lang("115302").c_str());
        m_btnLabel->setFontSize(32);
        m_btnLabel->setColor(ccc3(255, 255, 255));
        m_btnLabel1 = CCLabelIF::create(_lang("115021").c_str());
        m_btnLabel1->setFontSize(32);
        m_btnLabel1->setColor(ccc3(255, 255, 255));
        m_picNode->addChild(m_cancelBtn);
        m_cancelBtn->setPosition(_tile_width - m_cancelBtn->getContentSize().width * m_cancelBtn->getScaleX() / 2 - 15, 0);
        m_picNode->addChild(m_confirmBtn);
        m_confirmBtn->setPosition(_tile_width + m_confirmBtn->getContentSize().width * m_confirmBtn->getScaleX() / 2 + 15, m_cancelBtn->getPositionY());
        m_picNode->addChild(m_btnLabel);
        m_btnLabel->setPosition(m_confirmBtn->getPosition());
        m_picNode->addChild(m_btnLabel1);
        m_btnLabel1->setPosition(m_cancelBtn->getPosition());
        
        bg->setPosition(ccp(_tile_width, m_cancelBtn->getPositionY()));
        bg->setScaleY(8);
        bg->setScaleX(5);
    }
    else {
        m_cancelBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("but_blue.png"));
        CCCommonUtils::setButtonTitleColor(m_cancelBtn, ccc3(255, 255, 255));
        CCCommonUtils::setButtonTitle(m_cancelBtn, _lang("115021").c_str());
        m_cancelBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onCancelBtnClick), CCControlEventTouchUpInside);
        m_cancelBtn->setPreferredSize(CCSize(160, 70));
        
        m_confirmBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("btn_green3.png"));
        m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("btn_green3.png"),CCControlStateHighlighted);
        m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("Btn_grey.png"),CCControlStateDisabled);
        m_confirmBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onConfirmBtnClick), CCControlEventTouchUpInside);
        m_confirmBtn->setPreferredSize(CCSize(160, 70));
        CCCommonUtils::setButtonTitleColor(m_confirmBtn, ccc3(255, 255, 255));
        CCCommonUtils::setButtonTitle(m_confirmBtn, _lang("115302").c_str());
        
        auto bg = CCLoadSprite::createSprite("technology_11.png");
        m_picNode->addChild(bg);
        
        m_iconNode = CCNode::create();
        int num = WorldController::getInstance()->m_bAAreaCost;
        std::string picPath = "";
        //    picPath = "ui_gold.png";
        //
        //
        //    auto sprite = CCLoadSprite::createSprite(picPath.c_str());
        //    m_iconNode->addChild(sprite);
        //    CCCommonUtils::setSpriteMaxSize(sprite, 40);
        
        m_numText = CCLabelIF::create(CC_ITOA(num));
        //    m_btnLabel = CCLabelIF::create(_lang("115302").c_str());
        //    m_btnLabel->setFontSize(22);
        //    m_btnLabel->setColor(ccc3(255, 230, 116));
        m_picNode->addChild(m_cancelBtn);
        m_cancelBtn->setPosition(_tile_width - m_cancelBtn->getContentSize().width / 2 - 15, 0);
        m_picNode->addChild(m_confirmBtn);
        m_confirmBtn->setPosition(_tile_width + m_confirmBtn->getContentSize().width / 2 + 15, m_cancelBtn->getPositionY());
        
        //    m_numBG = CCLoadSprite::createSprite("num_text_bg.png");
        //    m_picNode->addChild(m_numBG);
        //    m_numBG->setScaleX(1.1);
        
        bg->setPosition(ccp(_tile_width, m_cancelBtn->getPositionY()));
        bg->setScaleY(4);
        bg->setScaleX(3);
        m_picNode->addChild(m_iconNode);
        m_iconNode->setPosition(m_confirmBtn->getPositionX() - 30, m_confirmBtn->getPositionY() - 15);
        //    m_picNode->addChild(m_numText);
        //    m_numText->setAnchorPoint(ccp(0, 0.5));
        //    m_numText->setPosition(m_confirmBtn->getPositionX(), m_confirmBtn->getPositionY() - 15);
        //    m_picNode->addChild(m_btnLabel);
        //    m_btnLabel->setPosition(m_confirmBtn->getPositionX(), m_confirmBtn->getPositionY() + 20);
        //    m_numBG->setPosition(ccp(m_confirmBtn->getPositionX(), m_confirmBtn->getPositionY() - 15));
    }
    
    this->addChild(m_picNode, 2);
    m_showNode = CCNode::create();
    this->addChild(m_showNode, 1);
    refreshShowNode(false);
    return true;
}
コード例 #2
0
ファイル: GameScene.cpp プロジェクト: shinriyo/expeller
// Breakable(破壊可能)のタイルを赤にする
void Game::setTileEffect(CCPoint position)
{
    // stage and area
    _hud->setStageLabel(1, 1);
    _hud->setLifeLabel(1);
    
    CCPoint tileCoord = this->tileCoordForPosition(position);
    // キャラクターの上下左右の座標
    CCPointArray *pointArray = CCPointArray::create(4);
    pointArray->addControlPoint(ccp(0,1));
    pointArray->addControlPoint(ccp(-1,0));
    pointArray->addControlPoint(ccp(1,0));
    pointArray->addControlPoint(ccp(0,-1));
    
    for(int i = 0; i < pointArray->count(); i++){
        CCPoint point = pointArray->getControlPointAtIndex(i);
        //CCLog("(%f,%f)", point.x, point.y);
            
        CCPoint tmpTileCoord = ccp(tileCoord.x + point.x, tileCoord.y + point.y);
        if(tmpTileCoord.x < 0 || tmpTileCoord.x > _tileMap->getMapSize().width -1 ||
           tmpTileCoord.y < 0 || tmpTileCoord.y > _tileMap->getMapSize().height - 1)
        {
            continue;
        }

        //CCLog("(%f,%f)", tmpTileCoord.x, tmpTileCoord.y);
        //CCLog("TileX %f, TileY %f", _tileMap->getMapSize().width, _tileMap->getMapSize().height);
        
        int tileGid = _meta->tileGIDAt(tmpTileCoord);
        
        if (tileGid) {
            CCDictionary *properties = _tileMap->propertiesForGID(tileGid);
            if (properties) {
                // obstacle
                CCString *collision = new CCString();
                // Breakableを赤
                *collision = *properties->valueForKey("Breakable");
            
                if (collision && (collision->compare("True") == 0)) {
                    CCSprite *sprite = _background->tileAt(tmpTileCoord);
                    //sprite->setTag(TAPPABLE);
                    // red
                    sprite->setColor(ccRED);
                }
            }
        }
    }
    
    // 白に戻す
    // まず詰める
    /*
      ◯は赤なので変化させない
      |6,0|6,1|6,2|6,3|6,4|6,5|6,6|
      |5,0|5,1|5,2|5,3|5,4|5,5|5,6|
      |4,0|4,1|4,2|◯4,3|4,4|4,5|4,6|
      |3,0|3,1|◯3,2|3,3|◯3,4|3,5|3,6|
      |2,0|2,1|2,2|◯2,3|2,4|2,5|2,6|
      |1,0|1,1|1,2|1,3|1,4|1,5|1,6|
      |0,0|0,1|0,2|0,3|0,4|0,5|0,6|
    */
    CCPointArray *revertPointArray = CCPointArray::create(255);
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            if((i == 3 && j == 2) || (i == 3 && j == 4) ||
               (i == 2 && j == 3) || (i == 4 && j == 3)
            )
            {
                continue;
            }
            revertPointArray->addControlPoint(ccp(-3 + j, -3 + i));
        }
    }

    // 詰めたものから適用
    for(int i = 0; i < revertPointArray->count(); i++) {
        CCPoint point = revertPointArray->getControlPointAtIndex(i);
        //CCLog("(%f,%f)", point.x, point.y);
        
        CCPoint tmpTileCoord = ccp(tileCoord.x + point.x, tileCoord.y + point.y);
        
        // 画面端はエラーになるので適用させない
        if(tmpTileCoord.x < 0 || tmpTileCoord.x > _tileMap->getMapSize().width - 1||
           tmpTileCoord.y < 0 || tmpTileCoord.y > _tileMap->getMapSize().height - 1)
        {
            continue;
        }
        
        //CCLog("(%f,%f)", tmpTileCoord.x, tmpTileCoord.y);
        
        int tileGid = _meta->tileGIDAt(tmpTileCoord);
        
        if (tileGid) {
            CCDictionary *properties = _tileMap->propertiesForGID(tileGid);
            if (properties) {
                // obstacle
                CCString *collision = new CCString();
                // Breakableのみ戻す
                *collision = *properties->valueForKey("Breakable");
                
                if (collision && (collision->compare("True") == 0)) {
                    CCSprite *sprite = _background->tileAt(tmpTileCoord);
                    // 白で塗る
                    sprite->setColor(ccWHITE);
                    //sprite->setTag(NOT_TAPPABLE);
                }
            }
        }
    }
}