void Troop::kickOut(Pet* pet) { int index = pet->getIndex(); if (index >= cap) return; CCArray* vlink = (CCArray*)vlinks->objectAtIndex(pet->getVLink()); int v = vlink->indexOfObject(pet); vlink->removeObject(pet); while (vlink->count() > v) { Pet* p = (Pet*)vlink->lastObject(); p->setVLink(index + col); vlink->removeLastObject(); ((CCArray*)vlinks->objectAtIndex(index + col))->insertObject(p, 0); } CCArray* hlink = (CCArray*)hlinks->objectAtIndex(pet->getHLink()); int h = hlink->indexOfObject(pet); hlink->removeObject(pet); while (hlink->count() > h) { Pet* p = (Pet*)hlink->lastObject(); p->setHLink(index + 1); hlink->removeLastObject(); ((CCArray*)hlinks->objectAtIndex(index + 1))->insertObject(p, 0); } pets->replaceObjectAtIndex(index, Pet::createFakePet()); }
bool GameLevelLayer::initWithLevel(int level) { bool bRet = CCLayer::init(); if( bRet == true) { this->currentLevel = level; char levelName[10]; CCDictionary *levelsDict = CCDictionary::createWithContentsOfFile("levels.plist"); memset(levelName, 0, sizeof(levelName) ); sprintf(levelName, "level%d", level); //当前地图关卡的背景数据// CCDictionary *lvlDict = (CCDictionary *) levelsDict->objectForKey(levelName); //背景音乐// const char* bgMusic = lvlDict->valueForKey("music")->getCString(); SimpleAudioEngine::sharedEngine()->playBackgroundMusic(bgMusic, true); SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.25f); CCParallaxNode *pNode = CCParallaxNode::create(); CCArray *backGroundArray = (CCArray *) lvlDict->objectForKey("background"); CCObject *group1 = NULL; CCObject *group2 = NULL; CCARRAY_FOREACH( backGroundArray, group1) { CCArray *nodeArray = (CCArray *)group1; CCARRAY_FOREACH(nodeArray, group2) { CCString* fileName = (CCString *)group2; CCSprite *bgNodeSprite = CCSprite::create(fileName->getCString()); bgNodeSprite->setAnchorPoint( ccp(0.0f, 0.0f) ); int index = nodeArray->indexOfObject(group2); float index2 = (float) backGroundArray->indexOfObject(group1) + 1.0f; float ratio = ( ( 4.0f - index2) / 8.0f); if(index2 == 4.0f) ratio = 0.0f; pNode->addChild(bgNodeSprite, index2 * -1, ccp(ratio, 0.6f), ccp(index * 2048, 30)); }