Esempio n. 1
0
bool StageMapLayer::init()
{
    if(!CCLayer::init())
        return false;
    
    this->ignoreAnchorPointForPosition(false);
    this->setAnchorPoint(AnchorPointLeftBottom);
    
    this->setTouchEnabled(true);
    this->setTouchMode(kCCTouchesOneByOne);
    
    const CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    // Background
    m_Background = CCSprite::createWithSpriteFrameName("mainscene_background.png");
    m_Background->retain();
    m_Background->cocos2d::CCNode::setPosition(winSize.width / 2, winSize.height / 2);
    
    for(int i=0; i<5; ++i)
    {
        CCString* fileName = CCString::createWithFormat("mainscene_cloud%d.png", i+1);
        m_BackgroundCloud[i] = CCSprite::createWithSpriteFrameName(fileName->getCString());
        m_BackgroundCloud[i]->retain();
        m_Background->addChild(m_BackgroundCloud[i]);
        
        CCPoint initialPosition = CCPointMake(RandomNumberGenerator::Int(0, static_cast<INT>(winSize.width)), RandomNumberGenerator::Int(30.f, INT(winSize.height*0.9f)));
        m_BackgroundCloud[i]->setPosition(initialPosition);
        
            // Cloud Moving Animation
        const CCSize cloudSize = m_BackgroundCloud[i]->getContentSize();
        const float speed = 5+ static_cast<float>(RandomNumberGenerator::Int(0, 25));   // pixel/sec
        const float timeToLeftEnd = (initialPosition.x+cloudSize.width*0.5f)/speed;
        const float timeToRepeatLeft = (winSize.width+cloudSize.width)/speed;
        CCSprite* cloudNode = m_BackgroundCloud[i];
        CCMoveTo* moveToLeftEnd = CCMoveTo::create(timeToLeftEnd, ccp(-cloudSize.width*0.5f, initialPosition.y));
        CCCallFuncL* moveToRightEnd = CCCallFuncL::create([winSize, cloudNode, cloudSize, initialPosition]()
                                                          {
                                                              if( cloudNode )
                                                              {
                                                                  cloudNode->setPosition(ccp(winSize.width+cloudSize.width*0.5f,initialPosition.y));
                                                              }
                                                          });
        CCMoveTo* moveToLeftEndRepeat = CCMoveTo::create(timeToRepeatLeft, ccp(-cloudSize.width*0.5f, initialPosition.y));
        CCSequence* moveToRightAndLeftEnd = CCSequence::create(moveToRightEnd, moveToLeftEndRepeat, nullptr);
        CCRepeat* moveToRightAndLeftEndRepeat = CCRepeat::create(moveToRightAndLeftEnd, 20);
        CCSequence* moveSeq = CCSequence::create(moveToLeftEnd, moveToRightAndLeftEndRepeat, nullptr);
        cloudNode->runAction(moveSeq);
            // End Cloud Moving Animation
    }
    
    m_Top = CCSprite::createWithSpriteFrameName("mainscene_top.png");
    m_Top->retain();
    const CCSize topSpriteSize = m_Top->getContentSize();
    m_Top->setPosition(ccp(winSize.width*0.5f, winSize.height-topSpriteSize.height*0.5f));
    
    m_Bottom = CCSprite::createWithSpriteFrameName("mainscene_bottom.png");
    m_Bottom->retain();
    const CCSize bottomSpriteSize = m_Bottom->getContentSize();
    m_Bottom->setPosition(ccp(winSize.width*0.5f, bottomSpriteSize.height*0.5f));
    //End Background
    this->addChild(m_Background, StageMapLayerDepth_Background);
    this->addChild(m_Top, StageMapLayerDepth_UIComponents);
    this->addChild(m_Bottom, StageMapLayerDepth_UIComponents);
    
    
    // Number Of Carrots
    m_Carrot = CCSprite::createWithSpriteFrameName("mainscene_carrot_stat.png");
    m_Carrot->retain();
    const CCSize carrotSize = m_Carrot->getContentSize();
    m_Carrot->setPosition(ccp( 5.f+carrotSize.width/2.f, winSize.height-carrotSize.height/2.f-5.f));
    this->addChild(m_Carrot, StageMapLayerDepth_UIComponents);
    
    m_Clover = CCSprite::createWithSpriteFrameName("mainscene_clover_stat.png");
    m_Clover->retain();
    const CCSize cloverSize = m_Clover->getContentSize();
    m_Clover->setPosition(ccp( 5.f + carrotSize.width +10.f + cloverSize.width*0.5f, winSize.height-cloverSize.height*0.5f - 5.f));
    this->addChild(m_Clover, StageMapLayerDepth_UIComponents);
    
    User* myUser = GooRoomClient::Instance().GetUser();
    if( myUser != nullptr )
    {
        m_NumberOfCarrots = CCLabelTTF::create(CCString::createWithFormat("%lld",myUser->GetGold())->getCString(), fontList[0].c_str(), 13);
        m_NumberOfCarrots->retain();
        m_NumberOfCarrots->setColor(ccBLACK);
        const CCSize numberOfCarrotsSize = m_NumberOfCarrots->getContentSize();
        m_NumberOfCarrots->setPosition(ccp(5.f+carrotSize.width*0.5f, m_Carrot->getPositionY()-2.f));
        this->addChild(m_NumberOfCarrots, StageMapLayerDepth_UIComponents);
    }
    // END BASE


    m_MapBase = CCNode::create();
    m_MapBase->retain();
    m_MapBase->setContentSize(winSize);
    m_MapBase->setAnchorPoint(AnchorPointMidBottom);
    m_MapBase->setPosition(ccp(winSize.width/2.f, 0.f));
    this->addChild(m_MapBase,StageMapLayerDepth_MapBase);
    
    m_StageInfoBox = CCSprite::createWithSpriteFrameName("stagemap_info_box.png");
    m_StageInfoBox->retain();
    m_StageInfoBox->setAnchorPoint(AnchorPointMid);
    const CCSize stageInfoBoxSize = m_StageInfoBox->getContentSize();
    m_StageInfoBox->setPosition(ccp(winSize.width*0.5f, stageInfoBoxSize.height*0.5f));
    m_Bottom->addChild(m_StageInfoBox,StageMapLayerDepth_UIComponents);

    StageInfoDictionary::Instance().ForEachStageInfo([this](StageInfo* stageInfo)
    {
        this->AddStageMapPoint(*stageInfo);
    });
    
    CharacterData characterData = *CharacterDictionary::Instance().GetCharacterData(GooRoomClient::Instance().GetUser()->GetSelectedCharacterType());
    characterData.SetLevel(GooRoomClient::Instance().GetUser()->GetSelectedCharacterCard().GetLevel());
    m_MyPlayer = PlayerNode::create(characterData, ActorID_None, GooRoomClient::Instance().GetUser()->GetUserName().c_str(), TeamType_None);
    m_MyPlayer->retain();
    m_MyPlayer->setPosition((m_StageMapPointList.front()->getPosition()+m_PlayerPositionOffset));
    m_MyPlayer->setAnchorPoint(CharacterAnchorPoint);
    m_MapBase->addChild(m_MyPlayer);
    
    StageInfo* stageInfo = StageInfoDictionary::Instance().FindStageInfo(0);
    m_MissionBox = MissionBox::create(*stageInfo);
    m_MissionBox->retain();
    m_MissionBox->setAnchorPoint(AnchorPointLeftBottom);
    const CCSize missionBoxSize = m_MissionBox->getContentSize();
    m_MissionBox->setPosition(ccp(missionBoxSize.width*0.5f, missionBoxSize.height*0.5f));
    this->addChild(m_MissionBox, StageMapLayerDepth_UIComponents);
    
    m_TitleBox = TitleBox::create(*stageInfo);
    m_TitleBox->retain();
    m_TitleBox->setAnchorPoint(AnchorPointLeftBottom);
    const CCSize titleBoxSize = m_TitleBox->getContentSize();
    m_TitleBox->setPosition(ccp(winSize.width-titleBoxSize.width*0.5f, titleBoxSize.height*0.5f+5.f));
    this->addChild(m_TitleBox, StageMapLayerDepth_UIComponents);


    // Create Button
    m_CreateStage = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("create_button.png"), CCSprite::createWithSpriteFrameName("create_button_pushed.png"), this, menu_selector(StageMapLayer::OnCreateStageTouch));
    m_CreateStage->retain();
    m_MenuCreateStage = CCMenu::create(m_CreateStage, nullptr);
    m_MenuCreateStage->retain();
    m_MenuCreateStage->setAnchorPoint(AnchorPointMid);
    const CCSize menuItemSize = m_CreateStage->getContentSize();
    m_MenuCreateStage->setPosition(ccp(winSize.width-menuItemSize.width/2.f-40.f, menuItemSize.height/2.f+10.f));
    this->addChild(m_MenuCreateStage, StageMapLayerDepth_UIComponents);
    
    // End Create Button

    // Exit Button
    CCMenuItemSprite* exitButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("exit_button.png"),CCSprite::createWithSpriteFrameName("exit_button_pushed.png"), this, menu_selector(StageMapLayer::OnExitButtonTouch));
    CCMenu* exitMenu = CCMenu::create(exitButton, NULL);
    CCSize exitButtonSize = exitButton->getContentSize();
    exitMenu->setPosition(winSize.width-exitButtonSize.width/2.f-5.f, winSize.height-exitButtonSize.height/2.f-5.f);
    
    this->addChild(exitMenu, StageMapLayerDepth_UIComponents);
    
    // Shop Menu
    {
        CCSprite* shopSprite = CCSprite::createWithSpriteFrameName("mainscene_blank_button.png");
        CCSprite* shopPushedSprite = CCSprite::createWithSpriteFrameName("mainscene_blank_button_pushed.png");
        CCMenuItemSprite* shopButton = CCMenuItemSprite::create(shopSprite, shopPushedSprite, this, menu_selector(StageMapLayer::OnShopButtonTouch));
        CCLabelTTF* shopLabel = CCLabelTTF::create("구르몽 친구들", fontList[0].c_str(), 14);
        shopLabel->setColor(ccBLACK);
        shopLabel->setAnchorPoint(AnchorPointMid);
        const CCSize shopSpriteSize = shopSprite->getContentSize();
        shopLabel->setPosition(ccp(shopSpriteSize.width*0.5f, shopSpriteSize.height*0.5f));
        shopSprite->addChild(shopLabel);
        shopButton->setScale(0.85f);
        
        CCMenu* shopMenu = CCMenu::create(shopButton, nullptr);
        shopMenu->setPosition(ccp(winSize.width-shopSpriteSize.width*0.5f - 5.f, winSize.height-exitButtonSize.height - 5.f -shopSpriteSize.height*0.5f -10.f));
        this->addChild(shopMenu, StageMapLayerDepth_UIComponents);
    }

    
    StageLevel currentStageLevel = GooRoomClient::Instance().GetUser()->GetStageLevel();
    if( currentStageLevel >= m_StageMapPointList.size() )
    {
        currentStageLevel = m_StageMapPointList.size()-1;
    }
    this->SelectStageMapPoint(currentStageLevel-1, false);
    this->SelectStageMapPoint(currentStageLevel, true);
    
    this->scheduleUpdate();
    
    return true;
}
Esempio n. 2
0
void AwaiterInfoNode::OnAwaiterEnter(ActorID actorID)
{
    m_ActorID = actorID;

    m_InviteMenu->setVisible(false);
    m_InviteMenu->setEnabled(false);
    
    Player* player = GooRoomClient::Instance().FindActor(actorID);
    if( player == nullptr )
    {
        return;
    }

    if( m_Background != nullptr )
    {
        m_Background->removeFromParent();
        m_Background->release();
        m_Background = nullptr;
    }
    if( m_ProfileImage != nullptr )
    {
        m_ProfileImage->removeFromParent();
        m_ProfileImage->release();
        m_ProfileImage = nullptr;
    }
    if( m_LevelLabel != nullptr )
    {
        m_LevelLabel->removeFromParent();
        m_LevelLabel->release();
        m_LevelLabel = nullptr;
    }
    if( m_NameLabel != nullptr )
    {
        m_NameLabel->removeFromParent();
        m_NameLabel->release();
        m_NameLabel = nullptr;
    }
    if( m_Character != nullptr )
    {
        m_Character->stopAllActions();
        m_Character->removeFromParent();
        m_Character->release();
        m_Character = nullptr;
    }

    // Background
    if( player->GetTeamType() == TeamType_Beta)
    {
        m_Background = CCSprite::createWithSpriteFrameName("awaiterinfo_blue.png");
    }
    else
    {
        m_Background = CCSprite::createWithSpriteFrameName("awaiterinfo_red.png");
    }
    m_Background->retain();
    
    const CCSize backgroundSize = m_Background->getContentSize();
    m_Background->setPosition(ccp(backgroundSize.width*0.5f, backgroundSize.height*0.5f));
    m_Background->setAnchorPoint(AnchorPointMid);
    this->addChild(m_Background, AwaiterInfoNodeDepth_Background);
    
    // END Background
    
    const CCSize profileImageSize = CCSizeMake(ProfileImageWidth, ProfileImageHeight);
    m_ProfileImage = CCSprite::createWithSpriteFrameName("default_profile_image.png");
    m_ProfileImage->retain();
    m_ProfileImage->setAnchorPoint(AnchorPointMid);
    m_ProfileImage->setPosition(ccp(10.f+profileImageSize.width*0.5f, backgroundSize.height*0.5f));
    CCSize imageSize = m_ProfileImage->getContentSize();
    const float scaleX = profileImageSize.width / imageSize.width;
    const float scaleY = profileImageSize.height / imageSize.height;
    m_ProfileImage->setScaleX(scaleX);
    m_ProfileImage->setScaleY(scaleY);
    this->addChild(m_ProfileImage, AwaiterInfoNodeDepth_Profile);

    cocos2d::extension::CCHttpClient* httpClient = cocos2d::extension::CCHttpClient::getInstance();    
    cocos2d::extension::CCHttpRequest* profileImageRequest = new cocos2d::extension::CCHttpRequest();
    profileImageRequest->setUrl("http://www.roughhands.co.kr/img/roughhands_logo_small.png");
    profileImageRequest->setRequestType(cocos2d::extension::CCHttpRequest::kHttpGet);
    profileImageRequest->setResponseCallback(this, httpresponse_selector(AwaiterInfoNode::OnProfileImageResponse)); // on reponse callback
    httpClient->send(profileImageRequest);
    profileImageRequest->release();

    CCString* levelString = CCString::createWithFormat("Lv.%d", static_cast<INT>(player->GetCharacterCard().GetLevel()));
    m_LevelLabel = CCLabelTTF::create(levelString->getCString(), fontList[0].c_str(), 10.f);
    m_LevelLabel->retain();
    const CCSize levelLabelSize = m_LevelLabel->getContentSize();
    m_LevelLabel->setAnchorPoint(AnchorPointMid);
    m_LevelLabel->setPosition(ccp(m_ProfileImage->getPositionX()+profileImageSize.width*0.5f + 5.f + levelLabelSize.width*0.5f, backgroundSize.height*0.5f));
    this->addChild(m_LevelLabel, AwaiterInfoNodeDepth_Profile);
    
    const CCSize nameLabelSize = CCSizeMake(60.f, 25.f);
    m_NameLabel = CCLabelTTF::create(player->GetPlayerName().c_str(), fontList[0].c_str(), 10.f, nameLabelSize, kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
    m_NameLabel->retain();
    m_NameLabel->setAnchorPoint(AnchorPointMid);
    m_NameLabel->setPosition(ccp(backgroundSize.width-3.f-nameLabelSize.width*0.5f, backgroundSize.height*0.5f));
    this->addChild(m_NameLabel, AwaiterInfoNodeDepth_Profile);

    const CharacterType characterType = player->GetCharacterCard().GetCharacterType();
    CharacterData characterData = *CharacterDictionary::Instance().GetCharacterData(characterType);
    characterData.SetLevel(player->GetCharacterCard().GetLevel());
    
    m_Character = PlayerNode::create(characterData, ActorID_None, player->GetPlayerName().c_str(), player->GetTeamType());
    m_Character->ShowNameTag(false);
    m_Character->ShowGuideArrow(false);
    m_Character->retain();
    m_Character->setScale(0.45f);
    m_Character->setPosition(m_ProfileImage->getPositionX()+profileImageSize.width*0.5f+40.f, -3.f);
    m_Character->AnimateIdle();
    
    this->addChild(m_Character, AwaiterInfoNodeDepth_Background);
    
    if( player == nullptr )
    {
        return;
    }

}