Ejemplo n.º 1
0
void CCTMXLayer::parseInternalProperties()
{
    // if cc_vertex=automatic, then tiles will be rendered using vertexz

    CCString *vertexz = propertyNamed("cc_vertexz");
    if( vertexz ) 
    {
        // If "automatic" is on, then parse the "cc_alpha_func" too
        if( vertexz->m_sString == "automatic" )
        {
            m_bUseAutomaticVertexZ = true;
            CCString *alphaFuncVal = propertyNamed("cc_alpha_func");
            float alphaFuncValue = 0.0f;
            if (alphaFuncVal != NULL)
            {
                alphaFuncValue = alphaFuncVal->floatValue();
            }
            setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColorAlphaTest));

            GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), kCCUniformAlphaTestValue);

            // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
            getShaderProgram()->setUniformLocationWith1f(alphaValueLocation, alphaFuncValue);
        }
        else
        {
            m_nVertexZvalue = vertexz->intValue();
        }
    }
}
bool CComponentParameter::getFloatParameter(const string& name, float& value)
{
    CCString* str = dynamic_cast<CCString*>(parameters_->objectForKey(name));
    if (!str)
    {
        return false;
    }
    value = str->floatValue();
    
    return true;
}
Ejemplo n.º 3
0
bool CallbackExplode::doCallback(GameObject * aGameObject,CCDictionary * dic,float dt) {
	if (dic && aGameObject) {
		
		//获得效果本身影响的范围
		CCDictionary * property = (CCDictionary *)aGameObject->getValue(KStrProperty);
		CCString * atkStr = (CCString *)property->objectForKey(KStrATK);
		CCString * atkRangeStr = (CCString *)property->objectForKey(KStrATK_RANGE);
		
		float atk_range_org = (atkRangeStr?atkRangeStr->floatValue():0) * 0.5;
		float atk = atkStr? atkStr->floatValue() : 0;
		
		//获得对应的效果播放的中心点
		CCDictionary * pDict=(CCDictionary *)dic->objectForKey(KStrPosition);
		CCString * paramStr=(CCString *)dic->objectForKey(KStrParam);
		float scale = !paramStr ? 1.0 : paramStr->floatValue();
		float atk_range = scale * atk_range_org;
		
		CCPoint p = GameObject::dict2Point(pDict);
		GameModle * _sharedInstance = GameModle::sharedInstance();
		CCDictionary * objects = _sharedInstance->gameObjectsDict();
		CCDictElement * pDictElement = NULL;
		CCDICT_FOREACH(objects, pDictElement){
			int32_t classid=pDictElement->getIntKey();
			if(KNPCTypeId == GameObject::typeIdOfClassId(classid)){
				CCSet * set=(CCSet*)pDictElement->getObject();
				CCSetIterator iter;
				for (iter = set->begin(); iter != set->end(); ++iter)
				{
					GameObject * tmp=(GameObject *)(*iter);
					if (tmp->isActive()) {
						
						float r = tmp->getContentSize().width * 0.5;
						//检测可以攻击到泡泡
						if(GameObject::isCircleContact(p,atk_range,tmp->getPosition(),r)){
							//处理进入到攻击范围的泡泡
							handleExplode(tmp,NULL,atk,aGameObject);
						}
					}
				}
			}
		}
Ejemplo n.º 4
0
float32 floatValueFromDictionary(CCDictionary * dict, const string & key)
{
	CCString * result = dynamic_cast<CCString *>(dict->objectForKey(key));
	if (result != NULL)
	{
		return result->floatValue();
	}
	else
	{
		return 0.0f;
	}
}
Ejemplo n.º 5
0
// SFEaseRateAction
bool SFEaseRateAction::initWithDictionary(CCDictionary * pDict)
{
	if (!SFActionEase::initWithDictionary(pDict))
	{
		CNLog("error");
		return false;
	}
	
	CCString * pRate = (CCString *)pDict->objectForKey("Rate");
	m_fRate = pRate ? pRate->floatValue() : 0;
	
	return true;
}
Ejemplo n.º 6
0
YHAnimationFrameDefiner::YHAnimationFrameDefiner(CCDictionary * dict)
{
	// index
	CCString * strIndex = dynamic_cast<CCString *>(dict->objectForKey("Index"));
	m_index = strIndex->uintValue();
	
	// Delay units
	CCString * strDelayUnits = dynamic_cast<CCString *>(dict->objectForKey("DelayUnits"));
	m_delayUnit = strDelayUnits != NULL ? strDelayUnits->floatValue() : 1.0f;
	
	// UserData
	m_userInfo = dynamic_cast<CCDictionary *>(dict->objectForKey("UserInfo"));
	CC_SAFE_RETAIN(m_userInfo);
}
Ejemplo n.º 7
0
void User::CatchBug(Bug* bug)
{
	string x = bug->getId();
	if (bugsCatched->objectForKey(x) != NULL)
	{
		CCString* count = (CCString*)bugsCatched->valueForKey(x);
		int increase = count->floatValue() + 1;
		CCString* add = CCString::create(ConvertInt(increase));
		bugsCatched->setObject(add,x);
	}
	else
	{
		CCString* count = CCString::create("1");
		bugsCatched->setObject(count,x);
	}
}
Ejemplo n.º 8
0
void CCTMXLayer::parseInternalProperties()
{
    // if cc_vertex=automatic, then tiles will be rendered using vertexz

    CCString *vertexz = propertyNamed("cc_vertexz");
    if (vertexz) 
    {
        // If "automatic" is on, then parse the "cc_alpha_func" too
        if (vertexz->m_sString == "automatic")
        {
            m_bUseAutomaticVertexZ = true;
            CCString *alphaFuncVal = propertyNamed("cc_alpha_func");
            float alphaFuncValue = 0.0f;
            if (alphaFuncVal != NULL)
            {
                alphaFuncValue = alphaFuncVal->floatValue();
            }
            setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColorAlphaTest));

            GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), kCCUniformAlphaTestValue);

            // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
            getShaderProgram()->setUniformLocationWith1f(alphaValueLocation, alphaFuncValue);
        }
        else
        {
            m_nVertexZvalue = vertexz->intValue();
        }
    }

	// if cc_zorder=automatic, then tiles will be rendered using in row order from top to bottom

	CCString *zorder = propertyNamed("useZOrderbyY");
    if (zorder) 
    {
		m_bUseZOrderByY = true;

		// delete AtlasIndexArray as we no longer can use quads in this mode
		// all tiles will be instantiated as sprites
		if (m_pAtlasIndexArray)
		{
			ccCArrayFree(m_pAtlasIndexArray);
			m_pAtlasIndexArray = NULL;
		}
	}
}
Ejemplo n.º 9
0
void ResourceManager::compareVersion()
{
    //(1)取版本描述文件内的版本号
    CCString* versionStr = CCString::createWithContentsOfFile(RMVersionFile);
    serverResourceVersion = versionStr->floatValue();
    //(3)比对
    versionLatest = (localVersion >= serverResourceVersion);
    if (this->delegate) {
        this->delegate->onVersionCheckCompleted(false);
    }
    
#if ScriptType ==1
    if (this->scriptDelegate) {
        CCArray* params = CCArray::createWithObject(CCBool::create(versionLatest));
        CCArray* paramTypes = CCArray::createWithObject(CCString::create("CCBool"));
        LuaUtil::executePeertableFunction(this->scriptDelegate, "onVersionCheckCompleted", params, paramTypes, false);
    }
#endif
}
Ejemplo n.º 10
0
//=============================================================
//=============================================================
void CC3DCircleListLayer::moveToCenter(CCButton* pButton,bool bActionFlag)
{
    if(!pButton)
        return;
    stopUpdateItemDegree();
    CCString* pFOldDegree = (CCString*)pButton->getUserData();
    float fOldDegree  = pFOldDegree->floatValue();
    m_fLastMoveDegree = 1.5*M_PI - fOldDegree;
    
    if(m_fLastMoveDegree > M_PI)
    {
        m_fLastMoveDegree = - (2*M_PI - m_fLastMoveDegree);
    }
    if(bActionFlag)
    {
        schedule(schedule_selector(CC3DCircleListLayer::updateItemDegree));
    }
    else
    {
        refreshItemWithMoveDegree(m_fLastMoveDegree);
    }
}
Ejemplo n.º 11
0
//=============================================================
//=============================================================
void CC3DCircleListLayer::refreshItemWithMoveDegree(float fMoveDegree)
{
    float fMoveX = getContentSize().width*0.5;
    float fMoveY = getContentSize().height*0.5;
    
    float fScaleMax = 1;
    float fScaleMin = 0.5;
    
    int zOrderMax = 1000;
    
    //    float fCameraDegreeMax = 45;
    //    float fCameraDegreeMin = 0;
    
    for(int i=0;i<m_pButtonArray->count();i++)
    {
        CCButton* pButton = (CCButton*)m_pButtonArray->objectAtIndex(i);
        CCString* pFOldDegree = (CCString*)pButton->getUserData();
        float fOldDegree  = pFOldDegree->floatValue();
        
        fOldDegree = fabsf(fOldDegree);
        float fCurDegree = fOldDegree + fMoveDegree;
        if(fCurDegree < 0)
        {
            fCurDegree = 2*M_PI - fabsf(fCurDegree);
        }
        int nCircleCount = (int)fCurDegree/(2*M_PI);
        fCurDegree = fCurDegree - nCircleCount*(2*M_PI);
        //=============================================================
        //=============================================================
        delete pFOldDegree;
        CCString* pString = new CCString();
        pString->initWithFormat("%f",fabs(fCurDegree));
        pButton->setUserData(pString);
        //=============================================================
        //=============================================================
        //
        //
        //
        //=============================================================
        //=============================================================
        float fCircleX = m_fEllipseA * cosf(fCurDegree);
        float fCircleY = m_fEllipseB * sinf(fCurDegree);
        fCircleX += fMoveX;
        fCircleY += fMoveY;
        CCPoint buttonPos = ccp(fCircleX,fCircleY);
        pButton->setPosition(buttonPos);
        //=============================================================
        //=============================================================
        //
        //
        //
        //=============================================================
        //=============================================================
        float fScaleDegree = fCurDegree - M_PI_2;
        float fScalePercent = (1-cosf(fScaleDegree))/2.0;
        float fScale = fScaleMin + (fScaleMax - fScaleMin)*fScalePercent;
        pButton->setScale(fScale);
        int nOrder = zOrderMax * fScalePercent + 1;
        pButton->setZOrder(nOrder);
        //=============================================================
        //=============================================================
        
        m_pSelectedButton =  getSelectedButton();
        if(m_pSelectedButton)
        {
            if(m_pDelegate)
            {
                int nIndex = m_pSelectedButton->getTag();
                m_pDelegate->onCC3DCircleListLayerSelectIndex(nIndex);
            }
        }
        
        //        //=============================================================
        //        //camera
        //        //=============================================================
        //        int flagMove = 1;
        //        if(buttonPos.x > getContentSize().width*0.5)
        //        {
        //            flagMove = 1;
        //        }
        //        else
        //        {
        //            flagMove = -1;
        //        }
        //        float fCameraDegree = fCameraDegreeMin + (fCameraDegreeMax - fCameraDegreeMin)*(1-fScalePercent);
        //        fCameraDegree *= -flagMove;
        //        float radians = (float)CC_DEGREES_TO_RADIANS(fCameraDegree);
        //        float fSin = sinf(radians) * CCCamera::getZEye();
        //        CCCamera* pCamera = pButton->getCamera();
        //        pCamera->setCenterXYZ(fSin, 0, 0);
        //        //=============================================================
        //        //=============================================================
    }
}