void HelloWorld::setPlayerPosition(cocos2d::CCPoint position) { CCPoint tileCoord = this->tileCoordForPosition(position); int tileGid = _meta->tileGIDAt(tileCoord); if (tileGid) { CCDictionary<std::string, CCString*> *properties = _tileMap->propertiesForGID(tileGid); if (properties) { CCString *collision = properties->objectForKey("Collidable"); if (collision && (collision->toStdString().compare("True") == 0)) { SimpleAudioEngine::sharedEngine()->playEffect("hit.caf"); return; } CCString *collectable = properties->objectForKey("Collectable"); if (collectable && (collectable->toStdString().compare("True") == 0)) { _meta->removeTileAt(tileCoord); _foreground->removeTileAt(tileCoord); _numCollected++; _hud->numCollectedChanged(_numCollected); SimpleAudioEngine::sharedEngine()->playEffect("pickup.caf"); if (_numCollected == 2) { this->win(); } } } } SimpleAudioEngine::sharedEngine()->playEffect("move.caf"); _player->setPosition(position); }
bool PtMap::checkCollisionForPosition(CCPoint position) { bool collidable = false; position = tileCoordForPosition(position); int tileGID = _metaLayer->tileGIDAt(position); // Collision checking // In previous Versions, this method checked for every eventuality (Water, NPCs, etc) and that was very expensive. // Right now, it only checks for the Collidable property. Every NPC that steps on a tile makes it collidable and passable again after it // leaves. Water is collidable, but reacts on Action and has its own water property. if (tileGID) { CCStringToStringDictionary *properties = _tileMap->propertiesForGID(tileGID); if (properties) { CCString *collision = properties->objectForKey("Collidable"); if (collision && strcmp(collision->toStdString().c_str(),"True") == 0) { // If Collidable is true, return Yes collidable = true; } else { // If not, ... well. collidable = false; } } } return collidable; }
void CCStoreScene::requestProductsCompleted(CCArray* products, CCArray* invalidProductsId) { CCNative::cancelAlert(); CCNative::createAlert("LOAD PRODUCTS COMPLETED", "Load products completed. Check console output", "OK"); CCNative::showAlert(); printf("\n"); for (int i = 0; i < products->count(); ++i) { CCStoreProduct* product = static_cast<CCStoreProduct*>(products->objectAtIndex(i)); printf("PRODUCT ID: %s\n", product->getProductIdentifier().c_str()); printf(" localizedTitle: %s\n", product->getLocalizedTitle().c_str()); printf(" localizedDescription: %s\n", product->getLocalizedDescription().c_str()); printf(" priceLocale: %s\n", product->getPriceLocale().c_str()); printf(" price: %0.2f\n", product->getPrice()); } printf("\n"); if (invalidProductsId->count() > 0) { printf("FOUND INVALID PRODUCTS ID\n"); for (int i = 0; i < invalidProductsId->count(); ++i) { CCString* ccid = static_cast<CCString*>(invalidProductsId->objectAtIndex(i)); printf(" %s\n", ccid->toStdString().c_str()); } } printf("\n"); }
const char * CCButton::titleForState(CCControlState mState) { CCString * mTepNodeInList = (CCString *) (this->titleCCStrings->objectForKey((int)mState)); if (mTepNodeInList != NULL) { return mTepNodeInList->toStdString().c_str(); } return NULL; }
void CCControlButton::setTitleBMFontForState(const char * fntFile, CCControlState state) { CCString * title = this->getTitleForState(state); if (!title) { title = new CCString(); } this->setTitleLabelForState(CCLabelBMFont::labelWithString(title->toStdString().c_str(), fntFile), state); }
void ImageResourceCache::RemoveImage(const char* pKey) { if (!pKey) { return; } std::string key = std::string(pKey); CCString *pFile = pImages->objectForKey(key); if (pFile) { const char *pFileName = pFile->toStdString().c_str(); CCTextureCache::sharedTextureCache()->removeTextureForKey(pFileName); pImages->removeObjectForKey(key); } }
CCTexture2D* ImageResourceCache::GetImage(const char* pKey) { if (!pKey) { return NULL; } std::string key = std::string(pKey); CCString *pFile = pImages->objectForKey(key); if (pFile) { const char *pFileName = pFile->toStdString().c_str(); return CCTextureCache::sharedTextureCache()->addImage(pFileName); } return NULL; }
bool NiStream::getStringattributeValue(mutableDic* dic, std::string key, std::string& value) { if (dic == NULL) return false; CCString* keyValue = static_cast<CCString*>(dic->objectForKey(key.c_str())); if (keyValue == NULL) return false; value = keyValue->toStdString(); return true; }
void CCButton::setTitleForState(const char * mTitle,CCControlState mState) { if (mTitle == NULL) { return; } CCLabelTTF * mTepNode = (CCLabelTTF *) (this->getChildByTag(CCButtonTitleTag)); if (mTepNode != NULL) { mTepNode->setString(mTitle); } else { CCSize mContentSize = this->getContentSize(); mTepNode = CCLabelTTF::labelWithString(mTitle, "Arial", 14); mTepNode->setTag(CCButtonTitleTag); this->setPosition(ccp(mContentSize.width/2.0,mContentSize.height/2.0)); this->addChild(mTepNode, CCButtonZorder2); } CCSize mContentSize = mTepNode->getContentSize(); mContentSize.width += 8; mContentSize.height += 6; this->setContentSize(mContentSize); CCString * mTepNodeInList = (CCString *) (this->titleCCStrings->objectForKey((int)mState)); if (mTepNodeInList != NULL) { std::string mTepString = mTepNodeInList->toStdString(); std::string mTepCompareString(mTitle); if (mTepString.compare(mTepCompareString) == 0) { return; } this->titleCCStrings->removeObjectForKey((int)mState); } //save string CCString * mNormalCCString = new CCString(mTitle); mNormalCCString->autorelease(); this->titleCCStrings->setObject(mNormalCCString,mState); }
CCSprite* WordPuzzleLayer::getImageWithIndex(CCArray* wordIdxArray, int index) { CCString* idxString = (CCString*)wordIdxArray->objectAtIndex(index); // 태호씨 워드스키마를 DBController로 대체 DBController* wordSchema = DBController::sharedDB(); char buf[100]; sprintf(buf, "WHERE words.idx=%s", idxString->m_sString.c_str()); #if (defined PD_IPHONE) || (defined ANDROID_PHONE) wordSchema->queryWithWhereStatementDBWordsSchema(buf); if (wordSchema->fetchDBWordsSchema()) #else wordSchema->queryWithWhereStatement(buf); if (wordSchema->fetch()) #endif { // handle data from database record SqlQuery query( *DBController::sharedDB()->getDB() ); std::ostringstream strStream; CCString *ccStr = (CCString*)wordIdxArray->objectAtIndex(index); strStream << "SELECT soundName,imageName FROM words WHERE words.idx=" << ccStr->toStdString(); SqlResult r = query( strStream.str() ); if (r.empty()) return NULL; #if (defined PD_IPHONE) || (defined ANDROID_PHONE) soundPath = "sound/voice/" + r.fetch(); #else soundPath = "voice/" + r.fetch(); #endif string imageName = r.fetch(); //프레임 애니메이션 생성 코드 CCAnimation *ani = CCAnimation::animation(); char buf[200]; int count = 0; // picturecard/ani/a/abacus_ca_img00.png 형식으로 넘어온다. 뒤에 6글자 잘라서 번호 다시 붙여사용 // 이미지가 존재할 경우에만 화면에 추가 if ( imageName.length() != 0 && imageName != " ") { // DB에는 파일명만저장, 경로 붙여줄것 #if (defined PD_IPHONE) || (defined ANDROID_PHONE) imageName = __CONFIG_IMAGE_PATH_ANIMATION_ "350/" + imageName.substr(0,1) +"/" + imageName; #else imageName = "ani/350/" + imageName.substr(0,1) +"/" + imageName; #endif imageName = imageName.substr(0, imageName.length()-6); } while (1) { sprintf(buf,"%s%02d.png",imageName.c_str(),count); // 첫프레임 대표스프라이트는 직접 add if (count == 0) { sprImage = CCSprite::spriteWithFile(buf); if (sprImage) { sprImage->setAnchorPoint(imageAnchor); sprImage->setScale(imageOriginalScale); sprImage->setPosition(imagePosition); } } // 아이폰의 경우 bundle에 접근하면 되고 // 안드로이드는 zip으로 패키징된 apk에 접근해야한다 #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) if( LCUtil::isFileExistAtBundle(buf) ) #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) if( CCFileUtils::isFileExistInAPK(buf) ) #endif { CCSprite *sprFrame = CCSprite::spriteWithFile(buf); ani->addFrame(CCSpriteFrame::frameWithTexture(sprFrame->getTexture(),sprFrame->getTextureRect())); count++; } else break; } // 프레임이 한장 이상일경우에만 애니 실행 if (count > 1) { ani->setDelay(0.25); aniAction = CCAnimate::actionWithAnimation(ani, true); aniAction->retain(); } else { aniAction = NULL; } return sprImage; } return NULL; }
PtMap::PtMap(std::string mapName) :_tileMap(NULL) ,_bgLayer(NULL) ,_gameObjects(NULL) ,_fgLayer(NULL) ,_extraLayer(NULL) ,_metaLayer(NULL) ,_npcs(NULL) ,_doors(NULL) ,_loadedMap(NULL) ,_mapSize_x(0) ,_mapSize_y(0) { char pTempMap[32] = {0}; sprintf(pTempMap,"%s.tmx",mapName.c_str()); CCLOG("tiledMapWithTMXFile[%s]",pTempMap); _tileMap = CCTMXTiledMap::tiledMapWithTMXFile(pTempMap); //[NSString stringWithFormat:@"%@.tmx",mapName]]; // Load layers and make the meta Layer invisible _bgLayer = _tileMap->layerNamed("bg"); _fgLayer = _tileMap->layerNamed("fg"); _extraLayer = _tileMap->layerNamed("extras"); _metaLayer = _tileMap->layerNamed("meta"); _metaLayer->setIsVisible(true); _gameObjects = _tileMap->objectGroupNamed("go"); // Cycle through all Gameobjects and check their type, sort them into arrays accordingly _npcs = CCArray::arrayWithCapacity(10); _doors = CCArray::arrayWithCapacity(10); for (int i = 0; i < _gameObjects->getObjects()->count(); i += 1) { if (_gameObjects->getObjects()->getObjectAtIndex(i)) { CCString *objectType = _gameObjects->getObjects()->getObjectAtIndex(i)->objectForKey("type"); if (objectType && strcmp(objectType->toStdString().c_str(),"NPC") == 0) { _npcs->addObject(_gameObjects->getObjects()->getObjectAtIndex(i)); } else { if (objectType && strcmp(objectType->toStdString().c_str(),"door") == 0) { _doors->addObject(_gameObjects->getObjects()->getObjectAtIndex(i)); CCLOG("Door count is %i",_doors->count()); } } } } // Set mapsize properties (actual size) _mapSize_x = _tileMap->getTileSize().width * _tileMap->getMapSize().width; _mapSize_y = _tileMap->getTileSize().height * _tileMap->getMapSize().height; // Mapname property CC_SAFE_DELETE(_loadedMap); _loadedMap = new std::string(mapName); }