Пример #1
0
void HRootLayer::adjustPostionAndScale(CCNode* node, float scaleX, float scaleY) {
    
    for (int i = 0; i < m_pIgnoreNodeArr->count(); i ++) {
        CCNode* node = dynamic_cast<CCNode*>(m_pIgnoreNodeArr->objectAtIndex(i));
        if (node) {
            node->setScaleX(scaleX);
            node->setScaleY(scaleY);
        }
    }
    
    CCArray *children = node->getChildren();
    if (children) {
        for (int i = children->count() - 1; i >= 0; --i) {
            CCNode *child = (CCNode *)children->objectAtIndex(i);
            if (!m_pIgnoreNodeArr->containsObject(child)) {
                
                CCPoint pos = child->getPosition();
                child->setPosition(ccp(pos.x * scaleX, pos.y * scaleY));
                
            }
        }
    }

}
Пример #2
0
void EXZoomController::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent){
    bool multitouch = _touchesDic->count() > 1;
	if (multitouch) {
        CCArray* keys = _touchesDic->allKeys();
        CCTouch *touch1 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString());
		CCTouch *touch2 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(1))->getCString());
        
		CCPoint pt1 = touch1->getLocationInView();
		CCPoint pt2 = touch2->getLocationInView();
		
		endZoom(pt1, pt2);
		
		//which touch remains?
        //		if (touch == touch2)
        //			beginScroll(_node->convertToNodeSpace(touch1->getLocation()));
        //		else
        beginScroll(_node->convertToNodeSpace(touch2->getLocation()));
	} else {
        CCArray* keys = _touchesDic->allKeys();
        CCTouch *touch = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString());
        recordScrollPoint(touch);
		
        CCPoint pt = _node->convertToNodeSpace(touch->getLocation());
		endScroll(pt);
        
        //handle double-tap zooming
        //        if (zoomOnDoubleTap /**&& [touch tapCount] == 2*/)
        //            handleDoubleTapAt(pt);
	}
	
    CCSetIterator iter = pTouches->begin();
    for (; iter != pTouches->end(); iter++){
        CCTouch* pTouch = (CCTouch*)(*iter);
        _touchesDic->removeObjectForKey(CCString::createWithFormat("%d",pTouch->getID())->getCString());
    }
}
CCArray* CollisionEngine::getSurroundingTilesAtPosition(CCPoint position,
		CCTMXLayer *layer) {

	CCPoint plPos = tileCoordForPosition(position);
	CCArray *gids = CCArray::create();

	for (int i = 0; i < 9; i++) {
		int c = i % 3;
		int r = (int) (i / 3);
		CCPoint tilePos = ccp(plPos.x + (c - 1), plPos.y + (r - 1));
		// fall into a hole
		if (tilePos.y > (map->getMapSize().height - 1)) {

			// kill the enemy here

			//this->gameOver(false);
			return NULL;
		}

		int tgid = layer->tileGIDAt(tilePos);

		CCRect tileRect = tileRectFromTileCoords(tilePos);

		CCDictionary *tileDict = CCDictionary::create();

		CCXNumericData *tilePosData = CCXNumericData::create();
		CCXNumericData *tgidData = CCXNumericData::create();
		CCXNumericData *rectOrgXData = CCXNumericData::create();
		CCXNumericData *rectOrgYData = CCXNumericData::create();

		tilePosData->setPoint(tilePos);
		tgidData->setIntValue(tgid);
		rectOrgXData->setFloatValue(tileRect.origin.x);
		rectOrgYData->setFloatValue(tileRect.origin.y);
		tileDict->setObject(tgidData, "gid");
		tileDict->setObject(rectOrgXData, "x");
		tileDict->setObject(rectOrgYData, "y");
		tileDict->setObject(tilePosData, "tilePos");

		gids->addObject(tileDict);
	}

	gids->removeObjectAtIndex(4);
	gids->insertObject(gids->objectAtIndex(2), 6);
	gids->removeObjectAtIndex(2);
	gids->exchangeObjectAtIndex(4, 6);
	gids->exchangeObjectAtIndex(0, 4);

	return gids;

}
static void dictionary_Value(CCDictionary * aDict, const cocos2d::ValueMap & value)
{
    cocos2d::ValueMap::const_iterator beg = value.begin();
    cocos2d::ValueMap::const_iterator end = value.end();
    for (; beg != end; ++beg)
    {
        const std::string & key = (*beg).first;
        const cocos2d::Value & v = (*beg).second;
        if (v.getType() == Value::Type::MAP)
        {
            CCDictionary * d = new CCDictionary();
            d->init();
            dictionary_Value(d, v.asValueMap());
            aDict->setObject(d, key);
            d->release();
        }
        else if (v.getType() == Value::Type::VECTOR)
        {
            CCArray * a = new CCArray();
            a->init();
            array_Value(a, v.asValueVector());
            aDict->setObject(a, key);
            a->release();
        }
        else
        {
            CCString * str = new CCString();
            if (v.getType() == Value::Type::DOUBLE)
                str->initWithFormat("%f", v.asDouble());
            else
                str->initWithFormat("%s", v.asString().c_str());
            aDict->setObject(str, key);
            str->release();
        }
    }
}
Пример #5
0
void CardScene::loadCardsFromXml()
{
	TiXmlDocument doc;

	//list of card for scroll layer init
	CCArray* cardList = CCArray::create();

	if ( doc.LoadFile(CARDS_XML) )
	{
		TiXmlElement* cards_tag = doc.FirstChildElement();
		TiXmlElement* card_tag = cards_tag->FirstChildElement();
		
		while ( card_tag )
		{
			int number = 0; 
			card_tag->QueryIntAttribute("number", &number);

			const char* path = card_tag->Attribute("path");
			const char* description_id = card_tag->Attribute("description_id");

			//TODO: load description from L10n(Localization) file with description_id

			//create card and add to card list
			Card* card = Card::create(number, path, description_id);
			cardList->addObject( card );
			
			card_tag = card_tag->NextSiblingElement();
		}
	}


	m_pScrollList = CCScrollLayer::create(cardList);
	m_pScrollList->setPosition( ccp(0, 0) );
	addChild( m_pScrollList );

}
Пример #6
0
void Obstacle::SpawnCrow(int xOffset)
{
    CCArray *allFrames = new CCArray();
    for (int i = 0 ; i <= 14 ; i++)
    {
        char fn[64];
        sprintf(fn, "Fly00%d.png" , i );
        allFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fn));
    }
    
    CCAnimation *crowAnim = CCAnimation::createWithSpriteFrames(allFrames, 0.04f * 1);
    CCAction *crowAction = CCRepeatForever::create(CCAnimate::create(crowAnim));
    crowAction->retain();
    
    obstacleSprite = CCSprite::createWithSpriteFrameName("Fly000.png");
    obstacleSprite->setPosition(ccp(winSize.width + xOffset * SPAWN_OFFSET  , winSize.height - obstacleSprite->getContentSize().height));
    this->addChild(obstacleSprite);
    
    obstacleSprite->runAction(crowAction);
    moveOnce = true;
//    obstacleSprite->runAction(CCSequence::createWithTwoActions(CCMoveTo::create(1,
//                                                                                ccp( winSize.width - obstacleSprite->getContentSize().width , obstacleSprite->getPosition().y)),
//                                                               CCCallFunc::create(this, callfunc_selector(Obstacle::MoveCrow))));
}
Пример #7
0
void BmVList::ShowContents()
{
	clt->setString(g_chara->m_sName.c_str());

	// <ÊôÐÔ
	CCDictElement*	 pCde = NULL;
	string			 t_name;
	CCLabelBMFont*	 t_clbm = NULL;

	int ti = 0;
	CCDICT_FOREACH(m_cdBmNum,pCde){
		t_name = pCde->getStrKey();
		t_clbm = (CCLabelBMFont*) pCde->getObject();

		string tsMai = CCString::createWithFormat("%d",g_chara->getvalue(t_name))->getCString();
		if(ti > 3 && ti < 14){
			int ti = g_chara->getFixValue(t_name) - g_chara->getvalue(t_name);
			string tsMid;
			ti>0?tsMid="+":tsMid="";
			string tsAto =  CCString::createWithFormat("%d",ti)->getCString();
			t_clbm->removeAllChildren();
			t_clbm->setString((tsMai + tsMid + tsAto).c_str());

			CCArray* pArray = t_clbm->getChildren();
			CCLog(">[BmVList] %s - length:%d", tsMai.c_str(), tsMai.length());
			for(int tfi = tsMai.length(); tfi < pArray->count(); ++tfi){
				CCSprite* tcs = (CCSprite*) pArray->objectAtIndex(tfi);
				tcs->setColor(ccRED);
			}

		}else{
			t_clbm->setString(tsMai.c_str());
		}
		++ti;
		
	}
CCAnimation* AnimationManager::createHeroMovingAnimationByDirection(HeroDirection direction)
{
	CCTexture2D *heroTexture = CCTextureCache::sharedTextureCache()->addImage("Hero_image.png");
	CCSpriteFrame *frame0, *frame1, *frame2;
	CCArray* animFrames ;
	//第二个参数表示显示区域的x, y, width, height,根据direction来确定显示的y坐标
	
	
	frame0 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(eSize*0, eSize*direction, eSize, eSize));
	frame1 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(eSize*1, eSize*direction, eSize, eSize));

	
	 animFrames = new CCArray(2);
	animFrames->addObject(frame0);
	animFrames->addObject(frame1);
	
	

	CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.09f);

	animFrames->release();
	
	return animation;
}
Пример #9
0
//构造函数
Ship::Ship()
{
    this->speed = 220;
    this->bulletSpeed = 900;
    this->HP = 5;
    this->bulletTypeValue = 1;
    this->bulletPowerValue = 1;
    this->throwBombing = false;
    this->canBeAttack = true;
    this->isThrowingBomb = false;
    this->zOrder = 3000;
    this->maxBulletPowerValue = 4;
    this->appearPosition = ccp(160, 60);
    this->hurtColorLife = 0;
    this->active = true;
    this->timeTick = 0;

    this->initWithSpriteFrameName("ship01.png");
    this->setTag(zOrder);
    this->setPosition(this->appearPosition);


    CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    CCSpriteFrame *frame0 = cache->spriteFrameByName("ship01.png");
    CCSpriteFrame *frame1 = cache->spriteFrameByName("ship02.png");
    CCArray *frames = CCArray::createWithCapacity(2);
    frames->addObject(frame0);
    frames->addObject(frame1);
    CCAnimation *animation = CCAnimation::createWithSpriteFrames(frames, 0.1f);
    CCAnimate *animate = CCAnimate::create(animation);
    this->runAction(CCRepeatForever::create(animate));

    this->schedule(schedule_selector(Ship::shoot),0.2f);

    this->born();
}
Пример #10
0
//////////////////////////////////////////////////////////////////////////
//called when level active
//////////////////////////////////////////////////////////////////////////
void LevelLayer::onActiveLayer(sActiveLevelConfig& config)
{
	//
	this->setTouchEnabled(true);
	//
	CCDirector::sharedDirector()->setLevelRenderCameraOffset(ccp(0,0));

	//send active event to children
	CCArray* children = this->getChildren();
	if (children)
	{
		int childrenCount = children->count();
		for (int i = 0; i < childrenCount; ++i)
		{
			CCNode* child = (CCNode* )children->objectAtIndex(i);
			ASSERT(child != NULL, "child is NULL");

			BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
			if (listener)
			{
				listener->HandleLayerActiveEvent(child, &config);
			}			
		}
	}

	if(m_pObjectsLayer != NULL)
	{
		/*CCNode* pNode = getSpriteSeer();
		if(pNode != NULL)
		{
		BaseListener* listener = LevelLayer::sGetListenerByTag(pNode->getTag());
		listener->HandleLayerActiveEvent(pNode, &config);
		}*/

		CCArray* children = m_pObjectsLayer->getChildren();
		if (children)
		{
			int childrenCount = children->count();
			for (int i = 0; i < childrenCount; ++i)
			{
				CCNode* child = (CCNode* )children->objectAtIndex(i);
				ASSERT(child != NULL, "child is NULL");

				BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
				if (listener)
				{
					listener->HandleLayerActiveEvent(child, &config);
				}				
			}
		}

	}

	//get other players
	//OnlineNetworkManager::sShareInstance()->sendGetOtherPlayersMessage();
}
 virtual CCSize tableCellSizeForIndex(CCTableView *table, unsigned int idx)
 {
     if (NULL != table )
     {
         int nHandler = table->getScriptHandler(CCTableView::kTableCellSizeForIndex);
         if (0 != nHandler)
         {
             CCArray* resultArray = CCArray::create();
             if (NULL != resultArray)
             {
                 CCLuaEngine::defaultEngine()->executeTableViewEvent(CCTableView::kTableCellSizeForIndex, table,&idx,resultArray);
                 CCAssert(resultArray->count() == 2, "tableCellSizeForIndex Array count error");
                 CCDouble* width  = dynamic_cast<CCDouble*>(resultArray->objectAtIndex(0));
                 CCDouble* height = dynamic_cast<CCDouble*>(resultArray->objectAtIndex(1));
                 if (NULL != width && NULL != height)
                 {
                     return CCSizeMake((float)width->getValue(), (float)height->getValue());
                 }
             }
         }
     }
     
     return CCSizeMake(0,0);
 }
Пример #12
0
void GameScene::operateAllScheduleAndActions(cocos2d::CCNode* node, OperateFlag flag)
{
	if(node->isRunning())
	{
		switch(flag){
		case k_Operate_Pause:
			node->pauseSchedulerAndActions();
			break;
		case k_Operate_Resume:
			node->resumeSchedulerAndActions();
			break;
		default:
			break;
		}
		CCArray* array = node->getChildren();
		if(array != NULL && array->count() > 0)
		{
			CCObject* iterator;
			CCARRAY_FOREACH(array, iterator)
			{
				CCNode* child = (CCNode*)iterator;
				this->operateAllScheduleAndActions(child, flag);
			}
		}
Пример #13
0
int CCLuaEngine::executeAccelerometerEvent(CCLayer* pLayer, CCAcceleration* pAccelerationValue)
{
    m_stack->clean();
    CCLuaValueDict event;
    event["name"] = CCLuaValue::stringValue("changed");
    event["x"] = CCLuaValue::floatValue(pAccelerationValue->x);
    event["y"] = CCLuaValue::floatValue(pAccelerationValue->y);
    event["z"] = CCLuaValue::floatValue(pAccelerationValue->z);
    event["timestamp"] = CCLuaValue::floatValue(pAccelerationValue->timestamp);

    m_stack->pushCCLuaValueDict(event);

    CCArray *listeners = pLayer->getAllScriptEventListeners();
    CCScriptHandlePair *p;
    for (int i = listeners->count() - 1; i >= 0; --i)
    {
        p = dynamic_cast<CCScriptHandlePair*>(listeners->objectAtIndex(i));
        if (p->event != ACCELERATE_EVENT || p->removed) continue;
        m_stack->copyValue(1);
        m_stack->executeFunctionByHandler(p->listener, 1);
        m_stack->settop(1);
    }
    return 0;
}
Пример #14
0
void INSPayment_iOS::loadProducts(inewsoft::ol::LoadProductCallback callback)
{
    if(!this->productTable.empty() && productsState == inewsoft::ol::kProductsStateLoaded)
    {
        callback(true);
        return;
    }
    else if(this->productsState == inewsoft::ol::kProductsStateLoading)
    {
        this->loadProductCallback = callback;
        return;
    }
    
    /// loald product from developer server firstly
    this->productsState = inewsoft::ol::kProductsStateLoading;
    Payment::loadProducts([this, callback](bool succeed){
        if(succeed) {
            INSStore::sharedStore()->registerTransactionObserver(this);
            CCArray* productsId = new CCArray();
            productsId->autorelease();
            
            for(auto iter = this->productTable.begin(); iter != this->productTable.end(); ++iter)
            {
                productsId->addObject(newCCString(iter->second.id.c_str()));
            }
            
            this->loadProductCallback = callback;
            INSStore::sharedStore()->loadProducts(productsId, this);
        }
        else {
            this->productsState = inewsoft::ol::kProductsStateUnload;
            callback(false);
            
        }
    });
}
Пример #15
0
void GameLayer::transTile(GridTile *tileA, GridTile *tileB, SEL_CallFuncND sel)
{
    if (!tileA->getCanPutFruit() || !tileB->getCanPutFruit()) return;
    
    // clear the prompt tiles actions
    if(this->getBLL()->getBox()->getPromptTiles())
    {
        int count = this->getBLL()->getBox()->getPromptTiles()->count();
        for (int i=0; i<count; i++) {
            CCArray* aComb = (CCArray*)this->getBLL()->getBox()->getPromptTiles()->objectAtIndex(i);
            GridTile* aTile = (GridTile*)aComb->objectAtIndex(0);
            GridTile* bTile = (GridTile*)aComb->objectAtIndex(1);
            GridTile* cTile = (GridTile*)aComb->objectAtIndex(2);
            aTile->stopItemActionByTag(kPromptMatchTag);
            bTile->stopItemActionByTag(kPromptMatchTag);
            cTile->stopItemActionByTag(kPromptMatchTag);
            aTile->getFruitItem()->getItemBG()->setScale(kTileScaleFactor);
            bTile->getFruitItem()->getItemBG()->setScale(kTileScaleFactor);
            cTile->getFruitItem()->getItemBG()->setScale(kTileScaleFactor);
        }
    }
    // unschedule prompt time
    this->unschedule(schedule_selector(GameLayer::promptMatch));
    
    this->getBLL()->getBox()->setLock(true);
    CCFiniteTimeAction* actionA = CCSequence::create(CCMoveTo::create(kMoveTileTime, tileB->getFruitItem()->getItemBG()->getPosition()),
                                                     CCCallFuncND::create(this, sel, tileA),
                                                     NULL);
    CCFiniteTimeAction* actionB = CCSequence::create(CCMoveTo::create(kMoveTileTime, tileA->getFruitItem()->getItemBG()->getPosition()),
                                                     CCCallFuncND::create(this, sel, tileB),
                                                     NULL);
    tileA->getFruitItem()->getItemBG()->runAction(actionA);
    tileB->getFruitItem()->getItemBG()->runAction(actionB);
    
    tileA->transWith(tileB);
}
Пример #16
0
void
MCSkillBarItemGroup::init(MCRole *aRole)
{
    MCSkill *skillA = NULL;
    MCSkill *skillB = NULL;
    MCSkill *skillC = NULL;
    MCSkill *skillD = NULL;
    CCArray *skills;
    mc_size_t count;
    
    skills = aRole->getSkills();
    
    count = skills->count();
    /* 主角和佣兵都至少有1个技能 */
    /* skill A */
    skillA = dynamic_cast<MCSkill *>(dynamic_cast<MCSkill *>(skills->objectAtIndex(0))->copy());
    
    /* skill B */
    if (count > 1) {
        skillB = dynamic_cast<MCSkill *>(dynamic_cast<MCSkill *>(skills->objectAtIndex(1))->copy());
    }
    /* skill C */
    if (count > 2) {
        skillC = dynamic_cast<MCSkill *>(dynamic_cast<MCSkill *>(skills->objectAtIndex(2))->copy());
    }
    /* skill D */
    if (count > 3) {
        skillD = dynamic_cast<MCSkill *>(dynamic_cast<MCSkill *>(skills->objectAtIndex(3))->copy());
    }
    
    if (skillA && skillA->masteredForRole(aRole)) {
        skillBarItemA_ = new MCSkillBarItem;
        skillBarItemA_->init(skillA);
    } else {
        skillBarItemA_ = NULL;
    }
    if (skillB && skillB->masteredForRole(aRole)) {
        skillBarItemB_ = new MCSkillBarItem;
        skillBarItemB_->init(skillB);
    } else {
        skillBarItemB_ = NULL;
    }
    if (skillC && skillC->masteredForRole(aRole)) {
        skillBarItemC_ = new MCSkillBarItem;
        skillBarItemC_->init(skillC);
    } else {
        skillBarItemC_ = NULL;
    }
    if (skillD && skillD->masteredForRole(aRole)) {
        skillBarItemD_ = new MCSkillBarItem;
        skillBarItemD_->init(skillD);
    } else {
        skillBarItemD_ = NULL;
    }
}
Пример #17
0
void Runner::initAction()
{
    //init runningAction
    CCArray *animFrames = CCArray::create();
    for (int i = 0; i < 8; i++)
    {
        CCString* name = CCString::createWithFormat("runner%d.png",i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animFrames->addObject(frame);
    }
    CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);
    m_actionRunning =CCRepeatForever::create(CCAnimate::create(animation));
    m_actionRunning->retain();

    // init jumpUpAction
    animFrames = CCArray::create();
    for (int i=0; i<4; i++)
	{
        CCString* name = CCString::createWithFormat("runnerJumpUp%d.png",i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animFrames->addObject(frame);
    }
    animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2);
	m_actionJumpUp = CCAnimate::create(animation);
	m_actionJumpUp->retain();

    // init jumpDownAction
    animFrames->removeAllObjects();
    for (int i=0; i<2; i++)
	{
        CCString *name = CCString::createWithFormat("runnerJumpDown%d.png",i);
        CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animFrames->addObject(frame);
    }
    animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3);
	m_actionJumpDown = CCAnimate::create(animation);
	m_actionJumpDown->retain();

    // init crouchAction
    animFrames->removeAllObjects();
    for (int i=0; i<1; i++)
	{
        CCString *name = CCString::createWithFormat("runnerCrouch%d.png",i);
        CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animFrames->addObject(frame);
    }
    animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3);
	m_actionCrouch = CCAnimate::create(animation);
	m_actionCrouch->retain();
}
//--------------------------------------------------------------------
void img(string name, string frameName, float x, float y) {
	FKCW_Story_Command* cmd = FKCW_Story_Command::create(FKCW_Story_Command::IMG);
	cmd->m_param.img.name = FKCW_Base_Utils::Copy(name.c_str());
	cmd->m_param.img.frameName = FKCW_Base_Utils::Copy(frameName.c_str());
	cmd->m_param.img.x = x;
	cmd->m_param.img.y = y;
	gStoryCommandSet.addObject(cmd);

#ifdef FKCW_STORY_DESIGNER_TOOL
	CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName.c_str());
	if(frame) {
		gUsedSpriteFrameNames.push_back(frameName);
	} else {
		gUsedImageNames.push_back(frameName);
	}
#endif
}
Пример #19
0
bool SGEquipCard::selfCanAdv()
{
    bool ret = true;

    bool flag = true;

    //读取将要转生这个装备卡牌
    SGEquipmentDataModel *model = SGStaticDataManager::shareStatic()->getEquipById(getItemId());

    //装备的需要材料组id
    int materialDependId = model->getMaterialDependencyId();


    //根据装备datamodel里的MaterialDependency获取依赖材料的数据
    //=-1标示已经到最顶级
    if(materialDependId ==-1)
        return false;
    SGMaterialDependencyDataModel *depend = SGStaticDataManager::shareStatic()->getMaterialDependencyById(materialDependId);
    CCString *condition = depend->getMaterialDependCondition();
    //每个条件 materialId:materialNum
    CCArray *conditionGroup = split(condition->getCString(), ";");


    //切分每个分组条件,将内部的条件再次进行切分
    for (int i = 0; i < conditionGroup->count(); i++)
    {
        CCString *temp = static_cast<CCString *>(conditionGroup->objectAtIndex(i));
        //冒号切分
        CCArray *tempConditon = split(temp->getCString(), ",");

        //需要的材料id
        int materialId = static_cast<CCString *>(tempConditon->objectAtIndex(0))->intValue();
        //需要的材料的数量
        int needMaterialNum = static_cast<CCString *>(tempConditon->objectAtIndex(1))->intValue();

        SGMaterialCard *materialCard = SGPlayerInfo::sharePlayerInfo()->getMaterialCardByItemId(materialId);
        if(materialCard)
        {
            if(materialCard->getMaterialCurrNum() < needMaterialNum)
            {
                ret = false;
                break;
            }
        }
        else {
            ret = false;
            break;
        }
    }

    return ret;

}
Пример #20
0
void RequestList::refreshList()
{
    this->unscheduleUpdate();
    
    if (_fbIncomingRequestList != NULL)
    {
        _fbIncomingRequestList->release();
    }
    
    _fbIncomingRequestList = NULL;
    _fbIncomingRequestList = CCArray::create();
    _fbIncomingRequestList->retain();
    
    CCDictionary* completedDictionary = EziFBIncomingRequestManager::sharedManager()->getCompletedRequest();
    
    if (completedDictionary)
    {
        CCArray* completedKeys = completedDictionary->allKeys();
        
        if (completedKeys)
        {
            for (int i=0; i<completedKeys->count(); i++)
            {
                CCString *cKey = (CCString*)completedKeys->objectAtIndex(i);
                _fbIncomingRequestList->addObject(completedDictionary->objectForKey(cKey->getCString()));
            }
        }
    }
    
    CCDictionary* pendingDictionary = EziFBIncomingRequestManager::sharedManager()->getPendingRequests();
    
    if (pendingDictionary)
    {
        CCArray* pendingKeys = pendingDictionary->allKeys();
        
        if (pendingKeys)
        {
            for (int i=0; i<pendingKeys->count(); i++)
            {
                CCString *pKey = (CCString*)pendingKeys->objectAtIndex(i);
                _fbIncomingRequestList->addObject(pendingDictionary->objectForKey(pKey->getCString()));
            }
        }
    }
    
    
    
    
    mPhotoLoadIndex = this->numberOfCellsInTableView(mTableView);
    mReadyForNextDownload = true;
    this->scheduleUpdate();
}
Пример #21
0
void img(string name, string frameName, float x, float y) {
    CCStoryCommand* cmd = CCStoryCommand::create(CCStoryCommand::IMG);
    cmd->m_param.img.name = CCUtils::copy(name.c_str());
    cmd->m_param.img.frameName = CCUtils::copy(frameName.c_str());
    cmd->m_param.img.x = x;
    cmd->m_param.img.y = y;
    gStoryCommandSet.addObject(cmd);
    
    // for designer
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
    CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName.c_str());
    if(frame) {
        gUsedSpriteFrameNames.push_back(frameName);
    } else {
        gUsedImageNames.push_back(frameName);
    }
#endif
}
Пример #22
0
void Hero::stop()
{
    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    CCArray* animFrames = CCArray::create();
    CCSpriteFrame* frame;
    char str[20] = {0};
    int item_no = options->getItem();
    switch (item_no) {
        case item_Pencil:
                frame = cache->spriteFrameByName("char_pencil.png");
                animFrames->addObject(frame);
            break;
        case item_Fish:
            for (int i = 1; i <= 5; i++) {
                sprintf(str, "char_fish_%d.png",i);
                CCSpriteFrame* frame = cache->spriteFrameByName(str);
                animFrames->addObject(frame);
            }
            break;
        case item_JewishStar:
            frame = cache->spriteFrameByName("char_star.png");
            animFrames->addObject(frame);
            break;
        case item_LightBulb:
            frame = cache->spriteFrameByName("char_bulb.png");
            animFrames->addObject(frame);
            break;
        case item_Matzah:
            frame = cache->spriteFrameByName("char_matzah.png");
            animFrames->addObject(frame);
            break;
        case item_MatzahBall:
            frame = cache->spriteFrameByName("char_matzahball.png");
            animFrames->addObject(frame);
            break;
        default:
            break;
    }
    
    CCAnimation* stopanimation= CCAnimation::createWithSpriteFrames(animFrames, 0.2f);
    CCAnimate* ani = CCAnimate::create(stopanimation);
    CCRepeatForever* runani = CCRepeatForever::create(ani);
    this->stopAllActions();
    this->runAction(runani);
}
Пример #23
0
json_t* NDKHelper::GetJsonFromCCObject(CCObject* obj)
{
    if (dynamic_cast<CCDictionary*>(obj))
    {
        CCDictionary *mainDict = (CCDictionary*)obj;
        CCArray *allKeys = mainDict->allKeys();
        json_t* jsonDict = json_object();
        
        if(allKeys == NULL ) return jsonDict;
        for (unsigned int i = 0; i < allKeys->count(); i++)
        {
            const char *key = ((CCString*)allKeys->objectAtIndex(i))->getCString();
            json_object_set_new(jsonDict,
                                key,
                                NDKHelper::GetJsonFromCCObject(mainDict->objectForKey(key)));
        }
        
        return jsonDict;
    }
    else if (dynamic_cast<CCArray*>(obj))
    {
        CCArray* mainArray = (CCArray*)obj;
        json_t* jsonArray = json_array();
        
        for (unsigned int i = 0; i < mainArray->count(); i++)
        {
            json_array_append_new(jsonArray,
                                  NDKHelper::GetJsonFromCCObject(mainArray->objectAtIndex(i)));
        }
        
        return jsonArray;
    }
    else if (dynamic_cast<CCString*>(obj))
    {
        CCString* mainString = (CCString*)obj;
        json_t* jsonString = json_string(mainString->getCString());
        
        return jsonString;
    }
	else if(dynamic_cast<CCInteger*>(obj)) 
	{
		CCInteger *mainInteger = (CCInteger*) obj;
		json_t* jsonString = json_integer(mainInteger->getValue());

		return jsonString;
	}
    
    return NULL;
}
Пример #24
0
EditorSprite* EditorLayer::findTouchSprite( cocos2d::CCTouch *pTouch )
{
	CCPoint pos = m_containerLayer->convertTouchToNodeSpace(pTouch);
	pos = pTouch->getLocation();
	CCLOG("position x = %.0f, y = %.0f", pos.x, pos.y);


	CCArray* arraySprites = new CCArray();
	arraySprites->init();

	for (unsigned int i=0; i<m_arraySprite->count(); i++)
	{
		EditorSprite* pEditorSprite = (EditorSprite*)m_arraySprite->objectAtIndex(i);
		if (!pEditorSprite->isTransparentInPoint(pos))
		{
			arraySprites->addObject(pEditorSprite);
		}
	}

	EditorSprite* pRet = NULL;
	if (arraySprites->count() > 0)
	{
		pRet = (EditorSprite*)arraySprites->objectAtIndex(0);
	}
	for (unsigned int i=0; i<arraySprites->count(); i++)
	{
		EditorSprite* pEditorSprite = (EditorSprite*)arraySprites->objectAtIndex(i);
		if (pEditorSprite->getOrderForAdd() > pRet->getOrderForAdd())
		{
			pRet = pEditorSprite;
		}
	}

	arraySprites->removeAllObjects();
	delete arraySprites;

	return pRet;
}
Пример #25
0
CCArray* TestScene::next(TileObject *u, TileObject **tileArray, cocos2d::CCSize mapSize){
    CCArray* nextArray = new CCArray;
    nextArray->autorelease();
    int x = u->getXCoord();
    int y = u->getYCoord();
    // left
    int x1, y1;
    x1 = x - 1;
    y1 = y;
    if ( (x1 >= 0 && x1 < mapSize.width) &&
        (y1 >= 0 && y1 < mapSize.height) &&
        (tileArray[x1][y1].getWall() % 2) == 0) {
        TileObject* tile = &tileArray[x1][y1];
        nextArray->addObject(tile);
    }
    
    //up
    x1 = x;
    y1 = y -1;
    if ( (x1 >= 0 && x1 < mapSize.width) &&
        (y1 >= 0 && y1 < mapSize.height) &&
        tileArray[x1][y1].getWall() < 2 ) {
        TileObject* tile = &tileArray[x1][y1];
        nextArray->addObject(tile);
    }
    
    //right
    x1 = x + 1;
    y1 = y;
    if ( (x1 >= 0 && x1 < mapSize.width) &&
        (y1 >= 0 && y1 < mapSize.height) &&
        (u->getWall() % 2) == 0 ) {
        TileObject* tile = &tileArray[x1][y1];
        nextArray->addObject(tile);
    }
    
    //down
    x1 = x;
    y1 = y + 1;
    if ( (x1 >= 0 && x1 < mapSize.width) &&
        (y1 >= 0 && y1 < mapSize.height) &&
        (u->getWall() < 2) ) {
        TileObject* tile = &tileArray[x1][y1];
        nextArray->addObject(tile);
    }
    return nextArray;
}
Пример #26
0
void CGameLevel::InitBottomLayer()
{
    
    CCArray * ccbNameArr = CCArray::create();
    CCArray * loaderArr = CCArray::create();
    
    ccbNameArr->addObject(CCString::create("LevelBottomLayer"));
    ccbNameArr->addObject(CCString::create("MenuTopBarLayer"));
    
    loaderArr->addObject(LevelBottomLayerLoader::loader());
    loaderArr->addObject(MenuTopBarLayerLoader::loader());
    
    LevelBottomLayer * layer = (LevelBottomLayer*)CCBManager::LoadCCBByNameAndLoader(ccbNameArr, loaderArr);
    layer->SetDelegate(this);
    addChild(layer);
    ShowLayer(layer);
}
Пример #27
0
//public
void RPGStartSceneLayer::goToMapScene()
{
    CCArray *loadTextures = CCArray::create();
    loadTextures->addObject(CCString::create("map.png"));
    loadTextures->addObject(CCString::create("main.png"));
    loadTextures->addObject(CCString::create("joystick.png"));
    loadTextures->addObject(CCString::create("actor4_0.png"));
    loadTextures->addObject(CCString::create("actor111.png"));
    loadTextures->addObject(CCString::create("actor113.png"));
    loadTextures->addObject(CCString::create("actor114.png"));
    loadTextures->addObject(CCString::create("actor115.png"));
    loadTextures->addObject(CCString::create("actor117.png"));
    loadTextures->addObject(CCString::create("actor120.png"));
    
    CCMenu *mainMenu = (CCMenu*)this->getChildByTag(kRPGStartSceneLayerTagMainMenu);
    mainMenu->setEnabled(false);
    
    CCScene *s = RPGLoadingSceneLayer::scene(loadTextures, NULL, "single_map");
    CCTransitionFade *t = CCTransitionFade::create(GAME_SCENE, s);
    CCDirector::sharedDirector()->replaceScene(t);
}
Пример #28
0
void linkInputLabels()
{
    GraphicLayer* layer = GraphicLayer::sharedLayer();
    CCArray* children = layer->getChildren();
    if(children != NULL)
    {
        for(int i = 0 ; i < children->count(); i++)
        {
            RawObject* child = (RawObject*)children->objectAtIndex(i);
            //Force actualization of content size and fontSize after everything is loaded because the nodeToWorldTransform is only right after
            if(isKindOfClass(child, InputLabel))
            {
                InputLabel* input = (InputLabel*)child;
                child->getNode()->setContentSize(child->getNode()->getContentSize());
                if(input->getOriginalInfos() != NULL)
                {
                    input->setFontSize(input->getOriginalInfos()->getFontSize());
                }
            }
            if((isKindOfClass(child, DropDownList)) && child->getEventInfos()->objectForKey("LinkTo") != NULL && isKindOfClass(child->getEventInfos()->objectForKey("LinkTo"), CCString))
            {
                DropDownList* dropDownList = (DropDownList*)child;
                if(dropDownList->getLinkTo() == NULL)
                {
                    CCString* linkTo = (CCString*)child->getEventInfos()->objectForKey("LinkTo");
                    CCArray* matchs = layer->allObjectsWithName(linkTo);
                    for(long j = 0; j < matchs->count(); j++)
                    {
                        RawObject* match = (RawObject*)matchs->objectAtIndex(j);
                        if(isKindOfClass(match, LabelTTF))
                        {
                            dropDownList->setLinkTo((LabelTTF*)match);
                            j = matchs->count();
                        }
                    }
                }
            }
        }
    }
}
Пример #29
0
    void textHandler(void *ctx, const char *ch, int len)
    {
        CC_UNUSED_PARAM(ctx);
        if (m_tState == SAX_NONE)
        {
            return;
        }

        CCSAXState curState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
        CCString *pText = new CCString();
        pText->m_sString = std::string((char*)ch,0,len);

        switch(m_tState)
        {
        case SAX_KEY:
            m_sCurKey = pText->m_sString;
            break;
        case SAX_INT:
        case SAX_REAL:
        case SAX_STRING:
            {
                if (SAX_ARRAY == curState)
                {
                    m_pArray->addObject(pText);
                }
                else if (SAX_DICT == curState)
                {
                    CCAssert(!m_sCurKey.empty(), "not found key : <integet/real>");
                    m_pCurDict->setObject(pText, m_sCurKey);
                }
                break;
            }
        default:
            break;
        }
        pText->release();
    }
Пример #30
0
//////////////////////////////////////////////////////////////////////////
//called when level de-active
//////////////////////////////////////////////////////////////////////////
void LevelLayer::onDeactiveLayer()
{
	this->setTouchEnabled(false);	

	//send de-active event to children
	CCArray* children = this->getChildren();
	if (children)
	{
		int childrenCount = children->count();
		for (int i = 0; i < childrenCount; ++i)
		{
			CCNode* child = (CCNode* )children->objectAtIndex(i);
			ASSERT(child != NULL, "child is NULL");

			BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
			if (listener)
			{
				listener->HandleLayerDeactiveEvent(child);
			}			
		}
	}	

	//send de-active event to children
	if(getObjectLayer())
	{
		CCArray* children = this->getObjectLayer()->getChildren();
		if (children)
		{
			int childrenCount = children->count();
			for (int i = 0; i < childrenCount; ++i)
			{
				CCNode* child = (CCNode* )children->objectAtIndex(i);
				ASSERT(child != NULL, "child is NULL");

				BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
				if (listener)
				{
					listener->HandleLayerDeactiveEvent(child);
				}				
			}
		}	
	}
	
}