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; }
void GameScene::makeCards() { //initialize array CCArray* numbers = CCArray::create(); for(int i=1; i <= 25; i++) numbers->addObject(CCInteger::create(i)); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); for(int x =0; x<5; x++) { for(int y=0; y< 5; y++) { int index = rand() % numbers->count(); int number = ((CCInteger*)numbers->objectAtIndex(index))->getValue(); CCSprite* pCard = CCSprite::create("card_frontside.png"); CCSize cardSize = pCard->getContentSize(); pCard->setPosition(ccp(winSize.width*0.5+(x-2)*cardSize.width, winSize.height*0.5+(y-2)*cardSize.height)); pCard->setTag(number); this->addChild(pCard); CCString* fileName = CCString::createWithFormat("%d.png", number) ; CCSprite* pNumber =CCSprite::create(fileName->getCString()); pNumber->setPosition(ccp(cardSize.width * 0.5, cardSize.height * 0.5)); pCard->addChild(pNumber); numbers->removeObjectAtIndex(index); } } }
void ResourceManager::processAfterSingleModleFileDownload() { CCArray* downloadList = (CCArray*)downloadCache->objectForKey(currentModuleName); CCString* filePath = (CCString*)downloadList->objectAtIndex(0); //回调 if (this->delegate) { this->delegate->onSingleFileUpdated(filePath->getCString()); } #if ScriptType ==1 if (this->scriptDelegate) { CCArray* params = CCArray::createWithObject(filePath); CCArray* paramTypes = CCArray::createWithObject(CCString::create("CCString")); LuaUtil::executePeertableFunction(this->scriptDelegate, "onSingleFileUpdated", params, paramTypes, false); } #endif //从updateList中删除 std::string updateListFile = this->fullLocalResourcePath(RMUpdateListFile); JSONObject* updateListObj=JSONObject::createWithFile(updateListFile); updateListObj->remove(filePath->getCString()); //回写updateList FileManager::writeStringToFile(updateListObj->toPrettyString(), updateListFile); //从缓存列表中删除 downloadList->removeObjectAtIndex(0); //检查缓存列表 if (downloadList->count() == 0) { if (this->delegate) { this->delegate->onModuleUpdated(this->currentModuleName); } #if ScriptType ==1 if (this->scriptDelegate) { CCArray* params = CCArray::createWithObject(CCString::create(this->currentModuleName)); CCArray* paramTypes = CCArray::createWithObject(CCString::create("CCString")); LuaUtil::executePeertableFunction(this->scriptDelegate, "onModuleUpdated", params, paramTypes, false); } #endif }else{ this->downloadModuleFile(); } }
void DaojuEngine::daoJuConfirmHitPoint(Point p, int type){ int row = p.y / this->perHeight; int line = p.x / this->perWidth; StarModel* model = this->getModelForLineAndRow(line, row); if (!model) { return; } switch (type) { case 0: { model->type = 2; model->node->sprite->setTexture("image_02.png"); break; } case 1: { CCArray* arr = CCArray::create(); arr->addObject(model); destroySlectedArray(arr,NULL); break; } case 2: { CCArray* arr = CCArray::create(); arr->addObject(model); StarModel* block = getModelForLineAndRow(model->line-1, model->row); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line+1, model->row); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line, model->row-1); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line, model->row+1); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line-1, model->row-1); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line+1, model->row+1); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line+1, model->row-1); if (block) { arr->addObject(block); } block = getModelForLineAndRow(model->line-1, model->row+1); if (block) { arr->addObject(block); } destroySlectedArray(arr,NULL); break; } case 3: { CCArray* nameArray = CCArray::create(); for (int i = 0; i<5; i++) { __String* s = __String::createWithFormat("image_0%d.png",i); nameArray->addObject(s); } for (int i = 0; i<dataSource->count(); i++) { CCArray* lineArr = (CCArray*)dataSource->objectAtIndex(i); for (int j = 0; j<lineArr->count(); j++) { StarModel* model = getModelForLineAndRow(i, j); int type = arc4random()%typeCount; model->type = type; model->line = i; model->row = j; __String* file = (__String*)nameArray->objectAtIndex(model->type); Sprite* bSprite = model->node->sprite; bSprite->setTexture(file->getCString()); } } break; } case 4: { for (int i = 0; i<dataSource->count(); i++) { CCArray* lineArr = (CCArray*)dataSource->objectAtIndex(i); for (int j = 0; j<lineArr->count(); j++) { StarModel* model = getModelForLineAndRow(i, j); if (!model) { return; } int tLine = arc4random()%dataSource->count(); int tRow = arc4random()%(((CCArray*)dataSource->objectAtIndex(tLine))->count()); StarModel* tModel = getModelForLineAndRow(tLine, tRow); if (!tModel) { return; } CCArray* TEMP = NULL; if (tModel) { TEMP = (CCArray*)dataSource->objectAtIndex(model->line); TEMP->removeObjectAtIndex(model->row); TEMP->insertObject(tModel, model->row); TEMP = (CCArray*)dataSource->objectAtIndex(tModel->line); TEMP->removeObjectAtIndex(tModel->row); TEMP->insertObject(model, tModel->row); int temp = model->line; model->line = tModel->line; tModel->line = temp; temp = model->row; model->row = tModel->row; tModel->row = temp; } } } for (int i = 0; i<dataSource->count(); i++) { for (int j = 0; j<((CCArray*)dataSource->objectAtIndex(i))->count(); j++) { StarModel* model = (StarModel*)((CCArray*)dataSource->objectAtIndex(i))->objectAtIndex(j); model->line = i; model->row = j; StarNode* node = model->node; Point p = node->sprite->getPosition(); Point t = ccp((i+ 0.5)*this->perHeight, (j+0.5)*this->perWidth); if (p.x != t.x || p.y != t.y) { CCActionInterval * moveBy = CCMoveBy::create(0.3,Vec2(t.x-p.x, t.y-p.y)); CCActionInterval * actionmoveback= moveBy; node->sprite->runAction(actionmoveback); allNodes->addObject(node); } } } break; } default: break; } }