コード例 #1
0
ファイル: GameScene.cpp プロジェクト: momirror/MyAngerBird-
void GameScene::createTargets(int iLevel)
{
//    if(iLevel >= m_pEnemyInfos->count())
//    {
//        iLevel = 0;
//        global::setGameLevel(iLevel);
//        
//        m_popView = new PopUpView("popUpBGg.png", "Yeah", "你已经通关,真厉害~", "OK",menu_selector(GameScene::backToMainMenu), "Cancel",menu_selector(GameScene::backToMainMenu),this);
//        this->addChild(m_popView,20);
//        return;
//    }
    
    CCDictionary * pEnemyNumDic = (CCDictionary*)((CCArray*)m_pEnemyInfos->objectAtIndex(iLevel))->objectAtIndex(0);
    m_iCurrentEnemy = pEnemyNumDic->valueForKey("EnemyNumber")->intValue();
    
    CCArray * pEnemys = (CCArray*)((CCArray*)m_pEnemyInfos->objectAtIndex(iLevel))->objectAtIndex(1);
    
    for(int i = 0;i < pEnemys->count();i++)
    {
        CCDictionary * pEnemyDic = (CCDictionary*)pEnemys->objectAtIndex(i);
        CCString * imageName = (CCString*)pEnemyDic->objectForKey("imageName");
        float positionX = pEnemyDic->valueForKey("positionX")->floatValue();
        float positionY = pEnemyDic->valueForKey("positionY")->floatValue();
        float rotation = pEnemyDic->valueForKey("rotation")->floatValue();
        bool isCircle = pEnemyDic->valueForKey("isCircle")->boolValue();
        bool isStatic = pEnemyDic->valueForKey("isStatic")->boolValue();
        bool isEnemy = pEnemyDic->valueForKey("isEnemy")->boolValue();
        
    //    CCLog("imageName->%s",imageName->getCString());
    //    CCLog("positionX->%f,positionY->%f",positionX,positionY);
        
        createTarget((char*)imageName->getCString(), CCPointMake(positionX, positionY), rotation, isCircle, isStatic, isEnemy);
    }

}
コード例 #2
0
ファイル: GameLayer.cpp プロジェクト: pdpdds/cocos2dx-dev
void GameLayer::loadLevel (int level) {
    
    clearLayer();
    
    _currentLevel = level;
    
    resetLevel();
    
    CCDictionary * levelData = (CCDictionary *) _levels->objectAtIndex(_currentLevel);
    
    int count;
    CCDictionary * data;
    
    //create platforms
    CCArray * platforms = (CCArray *) levelData->objectForKey("platforms");
    Platform * platform;
    count = platforms->count();
    
    for (int i = 0; i < count; i++) {
        platform = (Platform *) _platformPool->objectAtIndex(_platformPoolIndex);
        _platformPoolIndex++;
        if (_platformPoolIndex == _platformPool->count()) _platformPoolIndex = 0;
        
        data = (CCDictionary *) platforms->objectAtIndex(i);
        platform->initPlatform (
                                data->valueForKey("width")->intValue() * TILE,
                                data->valueForKey("angle")->floatValue(),
                                ccp(data->valueForKey("x")->floatValue() * TILE,
                                    data->valueForKey("y")->floatValue() * TILE)
                                );
    }
}
コード例 #3
0
ファイル: LevelMgr.cpp プロジェクト: YameteYY/Cocos2DFishGame
void LevelMgr::Init(CCLayer* layer)
{
	mGameLayer = layer;
	//¶ÁfishInfo
	const char* testPlistPath = "fish/GamePart.plist";
	std::string str1 = CCFileUtils::sharedFileUtils()->fullPathForFilename(testPlistPath);
	CCDictionary* plistDic = CCDictionary::createWithContentsOfFile(str1.c_str());
	mLevelCount = plistDic->count();
	char str[64] = {0};
	for(int i=1;i<=mLevelCount;i++)
	{
		sprintf(str,"level%d",i);
		CCDictionary* levelDic = dynamic_cast<CCDictionary*>(plistDic->objectForKey(str));
		LevelInfo levelInfo;
		strcpy(levelInfo.fishList,levelDic->valueForKey("fish")->getCString());
		strcpy(levelInfo.fishCount,levelDic->valueForKey("fishCount")->getCString());
		levelInfo.time = levelDic->valueForKey("time")->intValue();
		strcpy(levelInfo.music,levelDic->valueForKey("bgMusic")->getCString());
		CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(levelInfo.music); 
		strcpy(levelInfo.background,levelDic->valueForKey("background")->getCString());
		mLevelInfoList.push_back(levelInfo);
	}
	mMainFrame = UIMgr::Instance()->GetMainFrame();
	// Ô¤¼ÓÔØÒôÀÖºÍÒôЧ 
}
コード例 #4
0
ファイル: PaymentCommand.cpp プロジェクト: ourgames/dc208
bool PaymentTstoreCommand::handleRecieve(cocos2d::CCDictionary *dict)
{
    if (dict->valueForKey("cmd")->compare(PAYMENT_TSTORE_COMMAND) != 0)
        return false;
    PayController::getInstance()->setGoldExchangeSaleBoughtFlag(m_itemId, false);
    CCDictionary *params = _dict(dict->objectForKey("params"));
    
    if (m_orderId.compare(params->valueForKey("orderId")->getCString()) != 0) {
        return false;
    }
    
    if (params->objectForKey("errorCode")) {
        callFail(NetResult::createWithFail(params));
        return true;
    }
    
    int status = params->valueForKey("status")->intValue();
    if(CCCommonUtils::payParseData(params))
    {
        auto ret = CCDictionary::create();
        ret->setObject(CCInteger::create(status), "status");
        ret->setObject(CCString::create(m_orderId), "orderId");
        callSuccess(NetResult::createWithSuccess(ret));
    }
    return true;
}
コード例 #5
0
ファイル: LotteryActCommand.cpp プロジェクト: ourgames/dc208
bool LotteryBuyCmd::handleRecieve(CCDictionary* dict)
{
    if (dict->valueForKey("cmd")->compare(LOTTERY_BUY_COMMAND) != 0) {
        return false;
    }
    
    CCDictionary* params = _dict(dict->objectForKey("params"));
    
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0)
    {
        CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
//        return true;
    }
    
    if (params->objectForKey("chip"))
    {
        GlobalData::shared()->resourceInfo.lChip = params->valueForKey("chip")->intValue();
    }
    
    if (params->objectForKey("gold"))
    {
        GlobalData::shared()->playerInfo.gold = params->valueForKey("gold")->intValue();
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_CITY_RESOURCES_UPDATE);
    }
    
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification("BUYCHIPBACK", params);
    
    return true;
}
コード例 #6
0
ファイル: Terrain.cpp プロジェクト: woodpecker-3/bear-game
void Terrain::prepareHillKeyPoint(MyMap* myMap)
{
	CCPoint offsetPosition = myMap->_map->getPosition();

	CCTMXObjectGroup* objGroup = myMap->_map->objectGroupNamed("platform");
	CCDictionary* dict = objGroup->objectNamed("platform");
	/*对象位置**/
	int x = ((CCString*)dict->objectForKey("x"))->intValue();
	int y = ((CCString*)dict->objectForKey("y"))->intValue();
	/*刚体关键点**/
    CCArray* points = (CCArray*)dict->objectForKey("points");
    CCObject* pObj = NULL;
    CCDictionary* point = NULL;
    CCARRAY_FOREACH(points, pObj) {
        point = (CCDictionary*)pObj;
        _hillKeyPoints[_hillKeyPointIndex++] = ccp(
            offsetPosition.x +  x + ((CCString*)point->valueForKey("x"))->intValue(),
            offsetPosition.y +  y - ((CCString*)point->valueForKey("y"))->intValue()
        );
        if (_hillKeyPointIndex >= kMaxPlatformKeyPoints)
        {
            _hillKeyPointIndex = 0;
        }
        _lastHillKeyPoint = ccp(
            x + ((CCString*)point->valueForKey("x"))->intValue(),
            y - ((CCString*)point->valueForKey("y"))->intValue()
        );
    }
コード例 #7
0
ファイル: AlPointFindCommand.cpp プロジェクト: ourgames/dc208
bool AlPointFindCommand::handleRecieve(CCDictionary* dict)
{
    if (dict->valueForKey("cmd")->compare(AL_POINT_FIND) != 0)
        return false;
    CCDictionary* params = _dict(dict->objectForKey("params"));
    if (params->objectForKey("errorCode")) {
        CCCommonUtils::flyText(_lang(params->valueForKey("errorCode")->getCString()));
    } else {
        if (params->objectForKey("targetPoint")) {
            int point = params->valueForKey("targetPoint")->intValue();
            if (point <= 0) {
                if (m_op == 0)
                {
                    if (point == 0)
                    {
                        CCCommonUtils::flyText(_lang("115427"));
                    }
                } else if (m_op == 1) {
                    if (point == 0)
                    {
                        CCCommonUtils::flyText(_lang("115426"));
                    } else if (point == -1) {
                        CCCommonUtils::flyText(_lang("115425"));
                    }
                }
            } else {
                //zym 2015.12.10
                //PopupViewController::getInstance()->removeAllPopupView();
                PopupViewController::getInstance()->forceClearAll();
                auto& info = ToolController::getInstance()->getToolInfoById(ITEM_ALLIANCE_CITY_MOVE);
                if (info.getCNT() <= 0) {
                    return true;
                }
                if (m_op == 0)
                {
                    AllianceManager::getInstance()->goToWorldType = 2;
                } else if (m_op == 1) {
                    AllianceManager::getInstance()->goToWorldType = 3;
                }
                CCPoint pt = WorldController::getPointByIndex(point);
                WorldController::getInstance()->openTargetIndex = point;
                std::string isFirstPopKey = GlobalData::shared()->playerInfo.uid + "isFirstPop";
                int isFirstPop = CCUserDefault::sharedUserDefault()->getIntegerForKey(isFirstPopKey.c_str(),0);
                if(SceneController::getInstance()->currentSceneId == SCENE_ID_WORLD) {
                    WorldMapView::instance()->gotoTilePoint(pt, GlobalData::shared()->playerInfo.selfServerId);
                } else {
                    if (isFirstPop==0) {
                        WorldController::getInstance()->firstInWorld = true;
                        isFirstPop = 1;
                        CCUserDefault::sharedUserDefault()->setIntegerForKey(isFirstPopKey.c_str(), isFirstPop);
                        CCUserDefault::sharedUserDefault()->flush();
                    }
                    SceneController::getInstance()->gotoScene(SCENE_ID_WORLD, false, true, point);
                }
            }
        }
    }
    return true;
}
コード例 #8
0
ファイル: MusicManager.cpp プロジェクト: hyizsg/mytest1st
//private
void HMusicManager::load() {
    //delete by zg
    CCDictionary *dict = NULL; //HFileUtils::loadFromLocal("settings");
    if (dict) {
        m_fBGMusicVolume = dict->valueForKey("musicVolume")->floatValue();
        m_fSoundEffectVolume = dict->valueForKey("effectsVolume")->floatValue();
    }
}
コード例 #9
0
	// TODO: @student : extend the protocol.
	//                  so the receiver can split the package into name and content
	void ClientChatNetPackageDispatcher::dispatchPacket(unsigned char packetIdentifier, NativePacket* nativePacket )
	{
		NetMessageIDTypes eNetMessageID(static_cast<NetMessageIDTypes>(packetIdentifier));
		const bool validMessageId((eNetMessageID > NETMSG_ID_START) && (eNetMessageID < NETMSG_ID_END));
		if(validMessageId == false)	{
			return;
		}

		switch(eNetMessageID)	{
		case NETMSG_ID_CHATLINE:
			{
				const char* message = (const char*)nativePacket->data;
				// skip the packet identifier
				message++;
				if(isEmptyString(message) == true)	{
					getPeer()->log(ELogType_Error, "received an empty chat message");
				}
				else	{
					// TODO: @student : split the packet ...
					ChatMessage chatMessage("---", message);
					addChatMessage(chatMessage);
				}
			}
			break;
		case NETMSG_ID_JSONOBJECT:
			{
				// TODO: @student : this might not be enough ...
				const char* message = (const char*)nativePacket->data;
				// skip the packet identifier
				message++;
				if(isEmptyString(message) == true)	{
					getPeer()->log(ELogType_Error, "received an empty chat message");
				}
				else	{
					SLAString json(message);
					getPeer()->log(ELogType_Info, "received json %s", json.c_str());
					CCDictionary* dictionary = CCJSONConverter::dictionaryFrom(json.c_str());
					getPeer()->log(ELogType_Info, dictionary);
					// DONE: @student : read the relevant dictionary members and pass them to the chat message
					
					CCObject *aMessage = dictionary->objectForKey("message");
					CCDictionary *messDictionary = dynamic_cast<CCDictionary*>(aMessage);
					const CCString *aSender = messDictionary->valueForKey("sender");
					const CCString *aContent = messDictionary->valueForKey("content");
					
					ChatMessage chatMessage(aSender->getCString(), aContent->getCString());
					addChatMessage(chatMessage);
				}
			}
			break;
		default:
			break;
		}
	}
コード例 #10
0
void HelloWorld::setPlayerPosition(CCPoint position)
{
	SimpleAudioEngine::sharedEngine()->playEffect("move.wav");

	CCPoint tileCoord = this->tileCoordForPosition(position);

	int tileGid = mapLayer->tileGIDAt(tileCoord);
	
	if (tileGid)
	{
		
		CCDictionary *properties = map->propertiesForGID(tileGid);
		CCLog("%d\n",tileGid);

		if (properties)
		{
			const CCString *collision = properties->valueForKey("Collidable");
			CCLog("%s\n",collision->getCString());

			if (collision && collision->compare("true") ==0)
			{
				SimpleAudioEngine::sharedEngine()->playEffect("hit.wav");
				return;
			}           
		}

		const CCString *collectable = properties->valueForKey("Collectable");
		if (collectable && collectable->compare("true") ==0)
		{
			count+=1;
			SimpleAudioEngine::sharedEngine()->playEffect("pickup.wav");

			CountLayer *countLayer =(CountLayer *) this->getParent()->getChildByTag(1);

			if(countLayer!=NULL)
			{
				countLayer->countChange(count);
			}
			else
			{
				CCLog("*************error\n");
			}

			mapLayer->removeTileAt(tileCoord);
			foreground->removeTileAt(tileCoord);
		}

	}
	player->setPosition(position);


	//player->setPosition(position);
}
コード例 #11
0
ファイル: LotteryRotateView.cpp プロジェクト: ourgames/dc208
void LotteryRotateView::addRewardsNodeByIndex(int idx){
    
    nodeParticleIdx = idx;
    string iconStr = "";
    
    CCDictionary* dict = dynamic_cast<CCDictionary*>(m_save10Arr->objectAtIndex(idx));
    int dictType = dict->valueForKey("type")->intValue();
    CCDictionary* rewardsDic = _dict(dict->objectForKey("result"));
    if (dictType == 0) {//RESOURCE
        int resType = rewardsDic->valueForKey("type")->intValue();
        iconStr = LotteryController::shared()->getIcon(resType);
    }else if (dictType == 1){//BOX_TIMES
        iconStr = LotteryController::shared()->getIcon(100);
    }else if (dictType == 2){//REWARD
        int resType = rewardsDic->valueForKey("type")->intValue();
        if (resType == 7) {
            CCDictionary* valueDic = _dict(rewardsDic->objectForKey("value"));
            int itemId = valueDic->valueForKey("itemId")->intValue();
            iconStr = CCCommonUtils::getIcon(CC_ITOA(itemId));
        }else{
            iconStr = LotteryController::shared()->getIcon(resType);
        }
    }
    
    auto rewardIcon =CCLoadSprite::createSprite(iconStr.c_str());
    CCCommonUtils::setSpriteMaxSize(rewardIcon, 80);
    if (nodeParticleIdx<5) {
        rewardIcon->setPosition((100*nodeParticleIdx)-200, 45);
    }else{
        rewardIcon->setPosition((100*(nodeParticleIdx-5))-200, -45);
    }
    rewardIcon->setOpacity(0.5);
    CCActionInterval *fadeIn = CCFadeIn::create(0.3);
    rewardIcon->setScale(0.8);
    CCActionInterval *scale1 = CCScaleTo::create(0.1, 1.2);
    CCActionInterval *scale2 = CCScaleTo::create(0.1, 1.0);
    //粒子特效
    CCNode *pNode = CCNode::create();
    pNode->setPosition(rewardIcon->getPosition());
    m_rewardsContainer->addChild(pNode);
    auto func =CCCallFuncO::create(this, callfuncO_selector(LotteryRotateView::addRewardsNodeParticle),pNode);
    rewardIcon->runAction(CCSequence::create(fadeIn,scale1,scale2,func, NULL));
    
    m_rewardsContainer->addChild(rewardIcon);
    
//    string m_itemId="200380";
//    int id = atoi(m_itemId.c_str());
//    CCCommonUtils::flyHintWithDefault("Lottery_wood.png", "", _lang_1("104913", LotteryController::shared()->getLotteryName(id, 100).c_str()),0.5);
    //飘字特效
//    ccColor3B textColor = TEXT_COLOR_YELLOW;
//    CCCommonUtils::flyUiResText("Lottery_wood.png", m_rewardsContainer,ccp(0, 0) ,textColor, floating_type_ui1, 23);
}
コード例 #12
0
CCAction* ParserBezierTo::parseAction(cocos2d::CCDictionary *dict)
{
	float duration = dict->valueForKey("Duration")->floatValue();
	ccBezierConfig config;
	CCDictionary* configDict = (CCDictionary*)dict->objectForKey("BezierConfig");
	config.endPosition = CCPointFromString(configDict->valueForKey("EndPosition")->getCString());
    config.endPosition = pointWithContentScale(config.endPosition);
	config.controlPoint_1 = CCPointFromString(configDict->valueForKey("ControlPoint1")->getCString());
    config.controlPoint_1 = pointWithContentScale(config.controlPoint_1);
	config.controlPoint_2 = CCPointFromString(configDict->valueForKey("ControlPoint2")->getCString());
    config.controlPoint_2 = pointWithContentScale(config.controlPoint_2);
	return CCBezierTo::create(duration, config);
}
コード例 #13
0
void GetFriendListCommand::onGetFriendInfoSuccess(CCObject* pObj)
{
    CCLOGFUNC("");
    CCDictionary* params = dynamic_cast<CCDictionary*>(pObj);
    if (params==NULL || ChatController::getInstance()->m_chatUserInfoDic==NULL) {
        return;
    }
    CCArray* members = dynamic_cast<CCArray*>(params->objectForKey("contactList"));
    string uidStr="";
    string lastUpdateTimeStr="";
    if(members)
    {
        vector<std::string> *uids = new vector<std::string>();
        CCLOGFUNCF("members->count():%d",members->count());
        for (int i=0; i < members->count(); i++) {
            CCDictionary* member = (CCDictionary*)members->objectAtIndex(i);

            string uid=member->valueForKey("uid")->getCString();
            if(uid!="")
            {
                if (ChatController::getInstance()->m_chatUserInfoDic->objectForKey(uid)==NULL) {
                    uids->push_back(uid);
                }
                string time=member->valueForKey("lastUpdateTime")->getCString();
                if (time=="") {
                    time="0";
                }
                
                if(uidStr!="")
                {
                    uidStr.append("_").append(uid);
                    lastUpdateTimeStr.append("_").append(time);
                }
                else
                {
                    uidStr=uid;
                    lastUpdateTimeStr=time;
                }
            }

        }

        CCLOGFUNCF("uidStr:%s",uidStr.c_str());
    }
#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
    if (uidStr!="") {
        ChatServiceCocos2dx::notifyUserUids(uidStr,lastUpdateTimeStr,GET_MUTIUSER_TYPE_FRIEND);
    }
#endif
}
コード例 #14
0
ファイル: GameScene.cpp プロジェクト: shinriyo/expeller
// do not move to Player.h
void Game::setPlayerPosition(CCPoint position, CCFiniteTimeAction* sequence)
{
    CCPoint tileCoord = this->tileCoordForPosition(position);
    int tileGid = _meta->tileGIDAt(tileCoord);
    
    if (tileGid) {
        CCDictionary *properties = _tileMap->propertiesForGID(tileGid);
        if (properties) {
            // obstacle
            CCString *collision = new CCString();
            *collision = *properties->valueForKey("Collidable");
            // Moveable
            CCString *move = new CCString();
            *move = *properties->valueForKey("Moveable");
            // Breakable
            CCString *breakable = new CCString();
            *breakable = *properties->valueForKey("Breakable");
            
            if ((collision && collision->compare("True") == 0) ||
                 (move && move->compare("True") == 0) ||
                 (breakable && breakable->compare("True") == 0)) {
                // 動けない音を出す
                CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("hit.caf");
                this->finishAnimation();
                CCLog("Can't move");
                return;
            }
            
            // item get
            CCString *collectable = new CCString();
            
            *collectable = *properties->valueForKey("Collectable");
            if (collectable && (collectable->compare("True") == 0)) {
                // 取り除く
                _meta->removeTileAt(tileCoord);
                _foreground->removeTileAt(tileCoord);
                _numCollected++;
                _hud->numCollectedChanged(_numCollected);
                CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pickup.caf");
            }
        }
    }
    
    _player->runAction(sequence);
    // not hit only 赤にする
    this->setTileEffect(position);
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("move.caf");
}
コード例 #15
0
ファイル: HelpScene.cpp プロジェクト: Fahy15/Poker
bool HelpScene::init()
{
	if (!Layer::init())
	{
		return false;
	}

	auto size = Director::getInstance()->getWinSize();
	auto visible = Director::getInstance()->getVisibleSize();
	auto origin = Director::getInstance()->getVisibleOrigin();
	//ÉèÖñ³¾°
	auto spriteBK = Sprite::create("background.png");
	spriteBK->setPosition(size.width / 2, size.height / 2);
	spriteBK->setOpacity(75);
	this->addChild(spriteBK, 0);
	//¶ÁÈ¡xml×Ö·û
	CCDictionary* message = CCDictionary::createWithContentsOfFile("chinese.xml");
	auto helpTitleKey = message->valueForKey("helpTitle");
	const char* helpTitle = helpTitleKey->getCString();
	//°ïÖúÐÅÏ¢
	auto helpTitleLabel = Label::createWithTTF(helpTitle, "fonts/newSongTi.ttf", 25);
	helpTitleLabel->setPosition(Point(
		size.width - helpTitleLabel->getContentSize().width,
		size.height - helpTitleLabel->getContentSize().height));
	this->addChild(helpTitleLabel, 1);

	auto helpMessageKey = message->valueForKey("helpMessage");
	const char* helpMessage = helpMessageKey->getCString();
	auto helpMessageLabel = Label::createWithTTF(helpMessage, "fonts/newSongTi.ttf",20);
	helpMessageLabel->setDimensions(300,200);
	helpMessageLabel->enableOutline(Color4B(255, 0, 0, 0), 1);
	//helpMessageLabel->setAnchorPoint(Point(1,1));
	/*helpMessageLabel->setPosition(Point(
		size.width - helpTitleLabel->getContentSize().width,
		size.height - (helpTitleLabel->getContentSize().height*2)));*/
	helpMessageLabel->setPosition(size.width / 2, size.height / 2);
	this->addChild(helpMessageLabel, 1);

	//·µ»Ø°´Å¥
	auto menuItemBack = MenuItemFont::create("Back", CC_CALLBACK_1(HelpScene::gotoMenuCallback, this));
	auto menu = Menu::create(menuItemBack, NULL);
	menu->setPosition(Point::ZERO);
	menuItemBack->setPosition(Point(
		size.width - menuItemBack->getContentSize().width,
		menuItemBack->getContentSize().height));
	this->addChild(menu, 2);
	return true;
}
コード例 #16
0
bool ShowStatusItemCommand::handleRecieve(cocos2d::CCDictionary *dict)
{
    if (dict->valueForKey("cmd")->compare(SHOW_STATUS_ITEM) != 0)
        return false;
    
    CCDictionary *params=_dict(dict->objectForKey("params"));
    
    if (!params) {
        return false;
    }
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0) {
        CCLOG("errocode: '%s'", pStr->getCString());
    }else{
        ToolController::getInstance()->m_statusItems.clear();
        CCArray* arr =  (CCArray*)params->objectForKey("statusItems");
        int num = arr->count();
        for (int i=0; i<num; i++) {
            CCDictionary* dic = (CCDictionary*)arr->objectAtIndex(i);
            dic->retain();
            int type = dic->valueForKey("type2")->intValue();
            ToolController::getInstance()->m_statusItems[type] = dic;  
        }
        callSuccess(NetResult::create());
    }
    return true;
}
コード例 #17
0
bool PrincessRewardCommand::handleRecieve(cocos2d::CCDictionary *dict){
    if (dict->valueForKey("cmd")->compare(PRINCESS_REWARD) != 0)
        return false;
    CCDictionary* params = _dict(dict->objectForKey("params"));
    if(params==NULL) return false;
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0) {;
        CCCommonUtils::flyText(_lang(pStr->getCString()).c_str());
    }else{
        if(params->objectForKey("reward")){
            auto arr = dynamic_cast<CCArray*>(params->objectForKey("reward"));
            if (arr->count() > 0) {
                auto layer = dynamic_cast<ImperialScene*>(SceneController::getInstance()->getCurrentLayerByLevel(LEVEL_SCENE));
                if (layer) {
                    layer->m_princessRwdArr = arr;
                }
                auto dict = dynamic_cast<CCDictionary*>(arr->objectAtIndex(0));
                int type = -1;
                if (dict->objectForKey("type")) {
                    type = dict->valueForKey("type")->intValue();
                }
                CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PrincessRwd, Integer::create(type));
            }
            else
                CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PrincessRwdNull);
        }
        else
            CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PrincessRwdNull);
    }
    return true;
}
コード例 #18
0
ファイル: LevelsManager.cpp プロジェクト: kelyad/SomeTD
Entry LevelsManager::readWayPoints(int entryId, int waysEveryEntry, CCTMXObjectGroup* objects)
{
	Entry entry;
	entry.id = entryId;
	char buffer[64];
	sprintf(buffer, "Entry_%d", entry.id);
	auto entryPair = objects->objectNamed(buffer);
	if(entryPair == NULL)
		return entry;
	entry.pos = CCPoint(entryPair->valueForKey("x")->intValue(), entryPair->valueForKey("y")->intValue());
	
	for (int i = 0; i < waysEveryEntry; ++i)
	{
		std::vector<WayPointEx> way;
		int index = 0;
		while (true)
		{
			sprintf(buffer, "WayPoint_%d_%d_%d", entry.id, i, index);
			CCDictionary *temp = objects->objectNamed(buffer);
			if (temp == NULL) 
				break;
			int x = temp->valueForKey("x")->intValue();
			int y = temp->valueForKey("y")->intValue();
			way.push_back(WayPointEx(x, y, index));
			index++;
		}
		entry.ways.push_back(way);
	}

	return entry;
}
コード例 #19
0
bool HelloWorld::canBuildOnTilePosition(CCPoint pos)
{
//    pos=ccpAdd(pos, ccp(0, 50));
	CCPoint towerLoc = tileCoordForPosition(pos);
	
	int tileGid =_background->tileGIDAt(towerLoc);
	CCDictionary *props = _tileMap->propertiesForGID(tileGid);
	const CCString *type = props->valueForKey("buildable");
	CCString* str=CCString::create("1");
   
    DataModel *m = DataModel::getModel();
     bool occupied = false;
    for (int i=0;i< m->getTowers()->count();i++) {
        Towers *tower=(Towers*)m->getTowers()->objectAtIndex(i);
        CCRect towerRect = CCRectMake(tower->getPosition().x - (tower->getContentSize().width/2),
                                      tower->getPosition().y - (tower->getContentSize().height/2),
                                      tower->getContentSize().width, tower->getContentSize().height);
        if (towerRect.containsPoint(pos)) {
            occupied = true;
        }
    }
    
	if(str->isEqual(type)&&!occupied) {
		return true;
	}
	
	return false;
}
コード例 #20
0
ファイル: texts.cpp プロジェクト: suyu0925/backup
Texts::Texts(World *world, TiledMap *tiledMap)
    : m_world(world)
    , m_tiledMap(tiledMap)
{
    CCTMXObjectGroup *group = m_tiledMap->objectGroup("Texts");
    CCArray *array = group->getObjects();
    if (array && array->count() > 0)
    {
        CCObject *obj = NULL;
        CCARRAY_FOREACH(array, obj)
        {
            CCDictionary *dict = dynamic_cast<CCDictionary *>(obj);
            
            // get position.

            // get size.

            // get text.
            CCObject *textObj = dict->objectForKey("text");
            CCDictionary *text = dynamic_cast<CCDictionary *>(dict->objectForKey("text"));
            CCLOG("%s", text->valueForKey("value")->getCString());

            // create sprite and add it.
            
        }
コード例 #21
0
ファイル: MailBatchCommand.cpp プロジェクト: ourgames/dc208
bool MailBatchDelCommand::handleRecieve(cocos2d::CCDictionary *dict){
    if (dict->valueForKey("cmd")->compare(MAIL_DELETE_BATCH_COMMAND) != 0)
        return false;
    CCDictionary* params = _dict(dict->objectForKey("params"));
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0) {
        CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
        return true;
    }
#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
    if(!MailController::getInstance()->getIsNewMailListEnable())
        MailController::getInstance()->endRemoveAllOpMails(_dict(params->objectForKey("RetObj")));
    else
    {
        ChatServiceCocos2dx::setMutiMailStatusByConfigType(m_uids,3);
    }
#else
    if (ChatServiceCocos2dx::Mail_OC_Native_Enable){
        ChatServiceCocos2dx::deleteingbanchMailsWithMailID(m_uids);
    }else{
         MailController::getInstance()->endRemoveAllOpMails(_dict(params->objectForKey("RetObj")));
    }
   
#endif
    return true;
}
コード例 #22
0
ファイル: ItemStatusView.cpp プロジェクト: ourgames/dc208
CCArray* ItemStatusView::getTypeArray(int type){
    int city_lv = FunBuildController::getInstance()->getMainCityLv();
    auto goodDic = LocalController::shared()->DBXMLManager()->getGroupByKey("goods");
    CCArray* array = CCArray::create();// new CCArray();
   // array->init();
    int num = 0;
    if(goodDic)
    {
        CCDictElement* element;
        CCDICT_FOREACH(goodDic, element)
        {
            CCDictionary* dictInfo = _dict(element->getObject());
            if(type==dictInfo->valueForKey("type2")->intValue() && dictInfo->valueForKey("type")->intValue()==4 && city_lv>=dictInfo->valueForKey("lv")->intValue()){
                array->addObject(dictInfo);
            }
        }
    }
コード例 #23
0
ファイル: LotteryActCommand.cpp プロジェクト: ourgames/dc208
bool LotteryActCommand::handleRecieve2(cocos2d::CCDictionary *dict)
{
    CCDictionary* resourceDic = _dict(dict->objectForKey("resource"));
    if (resourceDic->objectForKey("diamond"))
    {
        GlobalData::shared()->resourceInfo.lDiamond = resourceDic->valueForKey("diamond")->intValue();
    }
    if (resourceDic->objectForKey("gold"))
    {
        GlobalData::shared()->playerInfo.gold = resourceDic->valueForKey("gold")->intValue();
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_CITY_RESOURCES_UPDATE);
    }
    dict->setObject(CCString::createWithFormat("%d", m_position), "position");
    LotteryController::shared()->lotteryAct2CmdBack(dict);
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYACTVIEWCMD2, NetResult::createWithSuccess(dict));
    
    return true;
}
コード例 #24
0
ファイル: AddFriendScene.cpp プロジェクト: crazyit/iGame
void AddFriendScene::didClickButton(CCMessageDialog* dialog,unsigned int index)
{
	if (index == 0)
	{
		CCDictionary *dict = (CCDictionary *)mFriendList->objectAtIndex(selectedindex);
        string encryptedUserInfo(dict->valueForKey("encryptedUserInfo")->getCString());
		this->addFriendRequest(encryptedUserInfo);
	}
}
コード例 #25
0
ファイル: MailListScene.cpp プロジェクト: crazyit/iGame
void MailListScene::didClickButton(CCMessageDialog* dialog,unsigned int index)
{
	if (index == 0)
	{
		CCDictionary *dict = (CCDictionary *)mArrayList->objectAtIndex(selectedindex);
        string encryptedUserInfo(dict->valueForKey("encryptedUserInfo")->getCString());
		this->deleteEntrys();
	}
}
コード例 #26
0
ファイル: LotteryActCommand.cpp プロジェクト: ourgames/dc208
bool Lottery10TimesCommand::handleRecieve(cocos2d::CCDictionary *dict){
    if (dict->valueForKey("cmd")->compare(LOTTERY_10TIMES_COMMAND) != 0) {
        return false;
    }
    LotteryController::shared()->setSendCMD(false);
    CCDictionary* params = _dict(dict->objectForKey("params"));
    
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0)
    {
        CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
        return false;
    }
    CCDictionary* resourceDic = _dict(params->objectForKey("resource"));
    if (resourceDic->objectForKey("chip"))
    {
        GlobalData::shared()->resourceInfo.lChip = resourceDic->valueForKey("chip")->intValue();
    }
    
    if (params->objectForKey("batchResult"))
    {
        CCArray* batchResult = dynamic_cast<CCArray*>(params->objectForKey("batchResult"));
        if(batchResult && batchResult->count()>0){
            for(int i=0;i<batchResult->count();i++){
                CCDictionary* iDict = dynamic_cast<CCDictionary*>(batchResult->objectAtIndex(i));
                if (iDict->valueForKey("type")->intValue()==1) {
                    continue;
                }
                CCDictionary* rewards = _dict(iDict->objectForKey("result"));
                CCArray* arr = CCArray::create();
                arr->addObject(rewards);
                GCMRewardController::getInstance()->retReward2(arr, false);
            }
        }
    }
    if (params->objectForKey("boxTimes"))
    {
        LotteryController::shared()->lotteryInfo.boxTimes = params->valueForKey("boxTimes")->intValue();
    }
//    LotteryController::shared()->lotteryActCmdBack(dict);
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYACTVIEWCMD10, NetResult::createWithSuccess(params));
    
    return true;
}
コード例 #27
0
ファイル: LotteryActCommand.cpp プロジェクト: ourgames/dc208
bool LotteryUseChestCommand::handleRecieve(cocos2d::CCDictionary *dict){
    if (dict->valueForKey("cmd")->compare(LOTTERY_USECHEST_COMMAND) != 0) {
        return false;
    }
    CCDictionary* params = _dict(dict->objectForKey("params"));
    
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0)
    {
        CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
        return false;
    }
    if (params->objectForKey("boxTimes")) {
        LotteryController::shared()->lotteryInfo.boxTimes = params->valueForKey("boxTimes")->intValue();
    }
    
    if (params->objectForKey("lottery")) {
        LotteryController::shared()->lotteryInfo.rewardSort.clear();
        string lottery = params->valueForKey("lottery")->getCString();
        if (lottery.length() > 0)
        {
            vector<string> lotVec;
            CCCommonUtils::splitString(lottery, "|", lotVec);
            vector<string> strVec;
            for (int i = 0; i < lotVec.size(); i++)
            {
                strVec.clear();
                CCCommonUtils::splitString(lotVec.at(i), ":", strVec);
                LotteryController::shared()->setRewardInfo(i, strVec);
            }
        }
        LotteryController::shared()->lotteryInfo.type = 2;
        LotteryController::shared()->lotteryInfo.hasResetReward = false;
        
        CCUserDefault::sharedUserDefault()->setStringForKey(LOTTERY_REWARD_INFO, lottery);
        CCUserDefault::sharedUserDefault()->setStringForKey(LotteryAct2ShowView_PREVIEW_REWARD, "");
        CCUserDefault::sharedUserDefault()->setStringForKey(LotteryAct2ShowView_PREVIEW_REWARD0, "");
        CCUserDefault::sharedUserDefault()->setStringForKey(LOTTERYACT2_PREVIEW_REWARD, "");
        CCUserDefault::sharedUserDefault()->flush();
        
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERY_USE_CHEST);
    }
    return true;
}
コード例 #28
0
ファイル: LotteryActCommand.cpp プロジェクト: ourgames/dc208
bool LotteryActCommand::handleRecieve1(cocos2d::CCDictionary *dict)
{
    CCDictionary* resourceDic = _dict(dict->objectForKey("resource"));
    
    if (resourceDic->objectForKey("chip"))
    {
        GlobalData::shared()->resourceInfo.lChip = resourceDic->valueForKey("chip")->intValue();
    }
    if (resourceDic->objectForKey("gold"))
    {
        GlobalData::shared()->playerInfo.gold = resourceDic->valueForKey("gold")->intValue();
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_CITY_RESOURCES_UPDATE);
    }
    
    LotteryController::shared()->lotteryActCmdBack(dict);
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYACTVIEWCMD, NetResult::createWithSuccess(dict));
    
    return true;
}
コード例 #29
0
bool RPGMapSceneLayer::doMoving(cocos2d::CCPoint targetPoint)
{
    //这里的逻辑跟RPGMapNPCRoleSprite::autoMove类似
    
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer);
    CCTMXObjectGroup *obstaclesObjects = bgMap->objectGroupNamed("obstacles");
    
    targetPoint = ccpAdd(player->getPosition(), targetPoint);
    
    //地图上的障碍物
    for (int i = 0; i < obstaclesObjects->getObjects()->count(); i++)
    {
        CCDictionary *obstaclesObject = (CCDictionary*)obstaclesObjects->getObjects()->objectAtIndex(i);
        const CCString *x = obstaclesObject->valueForKey("x");
        const CCString *y = obstaclesObject->valueForKey("y");
        const CCString *width = obstaclesObject->valueForKey("width");
        const CCString *height = obstaclesObject->valueForKey("height");
        
        CCRect obstaclesRect = CCRectMake(stringToNumber<float>(x->getCString()), stringToNumber<float>(y->getCString()), stringToNumber<float>(width->getCString()), stringToNumber<float>(height->getCString()));
        
        if(obstaclesRect.containsPoint(targetPoint))
            return false;
    }
    
    //NPC或Player
    for (int i = 0; i < bgMap->getChildren()->count(); i++)
    {
        CCObject *item = bgMap->getChildren()->objectAtIndex(i);
        if(dynamic_cast<RPGMapRoleSprite*>(item) != NULL)
        {
            //如果为非player的对象才会执行里面的判断
            if(item != player)
            {
                if(((RPGMapRoleSprite*)item)->boundingBox().containsPoint(targetPoint))
                    return false;
            }
        }
    }
    
    return true;
}
コード例 #30
0
ファイル: GameSprite.cpp プロジェクト: thevinh/Maze
int GameSprite::getWallProperty(int tileGid, cocos2d::CCTMXTiledMap *tileMap){
    CCDictionary *properties = tileMap->propertiesForGID(tileGid);
    if (properties) {
        CCString *wall = new CCString();
        *wall = *properties->valueForKey("Wall");
        CCString abc = *wall;
        CCLog("%d", abc.intValue());
        return abc.intValue();
    }
    return -1;
}