Example #1
0
void GamePan::Attack(int direct)
{
	CCNode* fieldNode = m_pCcbNode->getChildByTag(kTagGamePanField);
	for(int i =0;i<fieldNode->getChildrenCount();i++)
	{
		fieldNode->getChildByTag(i);
	}
	
	std::string pinyinStr = Utils::getPinyinStr(answer);//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2);
	std::string answerPinyin = Utils::getPinyinLetter(pinyinStr);
	vector<string> answerArr = Utils::split(answerPinyin);
	vector<string> pinyinArr = Utils::split(_pinyinStr);
	for(int i =0;i<pinyinArr.size();i++)
	{
		string letter = pinyinArr.at(i);
		int pos = -1;
		for(int j =0;j<answerArr.size();j++)
		{
			string tmp = answerArr.at(j);
			if(tmp.compare(letter) == 0)
			{
				pos = i;
			}
		}
		if(i>0 && pos>0)
		{
			CCNode* bar = fieldNode->getChildByTag(i);
			CCMoveTo* moveTo = NULL;
			switch (direct)
			{
			case NPC_ATTACK:
				{
					moveTo = CCMoveTo::create(0.3f,ccp(bar->getPositionX(),bar->getPositionY()-MOVE_STEP));
				}
				break;
			case PLAYER_ATTACK:
				{
					moveTo = CCMoveTo::create(0.3f,ccp(bar->getPositionX(),bar->getPositionY()+MOVE_STEP));
				}
				break;
			}
			bool isMoveAble = true;
			float dis = bar->getPositionY();
			if(dis>=MAX_DISTANCE)
			{
				isMoveAble = false;
			}
			else if(dis<= -MAX_DISTANCE)
			{
				isMoveAble = false;
			}
			if(isMoveAble)
			{
				bar->runAction(moveTo);
			}
		}
	}
	this->runAction(CCSequence::create(CCDelayTime::create(0.35f),CCCallFunc::create(this,callfunc_selector(GamePan::checkWhoWin)),NULL));
	
}
Example #2
0
void CSmeltArmor::initFire()
{
	//获取参考位置
	CCNode* pNode = (CCNode*)m_ui->findWidgetById("fire_circle");
	CCPoint pPos = ccp(pNode->getPositionX()+15, pNode->getPositionY()+75);

	if(m_pFire1 == nullptr)
	{
		CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9010");
		pAnimation->setDelayPerUnit(0.15f);
		m_pFire1 = CCSprite::create("skill/9010.png");
		m_pFire1->setPosition(pPos);
		m_pFire1->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation)));
		m_pFire1->setVisible(false);
		m_pFire1->setScale(1.6f);
		pNode->getParent()->addChild(m_pFire1, pNode->getZOrder());
	}
	if(m_pFire2 == nullptr)
	{
		CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9011");
		pAnimation->setDelayPerUnit(0.15f);
		m_pFire2 = CCSprite::create("skill/9011.png");
		m_pFire2->setPosition(pPos);
		m_pFire2->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation)));
		m_pFire2->setVisible(false);
		m_pFire2->setScale(1.5f);
		pNode->getParent()->addChild(m_pFire2, pNode->getZOrder());
	}
}
Example #3
0
void GamePan::checkWhoWin()
{
	if(isCheckWin)
		return;
	if(!isCheckWin)
		isCheckWin = true;
	CCNode* fieldNode = m_pCcbNode->getChildByTag(kTagGamePanField);
	bool isWin = false;
	for(int i =kTagGamePanFieldLeft ;i<=kTagGamePanFieldRight;i++)
	{
		CCNode* bar = fieldNode->getChildByTag(i);
		float dis = bar->getPositionY();
		if(dis>=MAX_DISTANCE||dis<= -MAX_DISTANCE)
			isWin = true;
		else
		{
			isWin = false;
			break;
		}
	}
	if(isWin)
	{
		showResult();
	}
	else
	{
		createNextPuzzle();
		_isPlayer = !_isPlayer;
		changeSide();
	}
}
Example #4
0
void CCBClippingNode::visit(){
    
    CCNode* hock = this->getChildByTag(htag);
    if (hock==NULL) {
        getStencil()->setPosition(0, 0);
        getStencil()->setScaleX(1);
        getStencil()->setScaleY(1);
        getStencil()->setRotationX(0);
        getStencil()->setRotationY(0);
        getStencil()->setSkewX(0);
        getStencil()->setSkewY(0);
        getStencil()->setAnchorPoint(ccp(0.5, 0.5));
    }else{
        getStencil()->setPosition(hock->getPositionX(),hock->getPositionY());
        getStencil()->setScaleX(hock->getScaleX());
        getStencil()->setScaleY(hock->getScaleY());
        getStencil()->setRotationX(hock->getRotationX());
        getStencil()->setRotationY(hock->getRotationY());
        getStencil()->setSkewX(hock->getSkewX());
        getStencil()->setSkewY(hock->getSkewY());
        getStencil()->setAnchorPoint(hock->getAnchorPoint());
    }
    
    CCClippingNode::visit();
}
Example #5
0
bool NodeInRect::detect()
{
	CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag);
	if (pNode != NULL && abs(pNode->getPositionX() - _origin.x) <= _size.width && abs(pNode->getPositionY() - _origin.y) <= _size.height)
	{
		return true;
	}
    return false;
}
bool CCounter::init(CCArray* presenters, int digit)
{
    _presenters = CCNode::create();
    for (int i = 0; i < 10; i++) {
        CCNode* node = (CCNode*)presenters->objectAtIndex(i);
        int y = node->getContentSize().height*i;
		if (i > 0)
		{
			CCNode* pPreNode = (CCNode*)presenters->objectAtIndex(i - 1);
			y = pPreNode->getPositionY() + pPreNode->getContentSize().height/2 + node->getContentSize().height/2 + 2;
		}
        node->setPosition(CCPointMake(0, y));
        _presenters->addChild(node, 0, i);
    }
    this->addChild(_presenters,0,k_Counter_Action);
    this->setDigit(digit,false);
    return true;
}
void GameScene::setBall() {
	//ボールをバー上に配置する
	if (m_balls->count() <= 0) {
		return;
	}
	BallSprite* ball = dynamic_cast<BallSprite*>(m_balls->objectAtIndex(0));
	CCNode *bar = this->getChildByTag(kTagBar);
//	CCRect rect = bar->boundingBox();
	ball->setPosition(
			ccp(bar->getPositionX(), bar->getPositionY() + bar->getContentSize().height + 10));
//    CCLOG("# setBall #bar.width: %f, height: %f",
//          bar->getContentSize().width, bar->getContentSize().height);
//    CCLOG("# setBall #bar position X: %f, Y: %f",
//          bar->getPositionX(), bar->getPositionY());
//	ball->setPosition(
//			ccp(bar->getPositionX() + bar->getContentSize().width / 2, bar->getPositionY() + bar->getContentSize().height));
	this->addChild(ball);

	m_balls->removeObjectAtIndex(0);
	m_activeballs->addObject(ball);
}
Example #8
0
void E002_C010_P230::_setPositionOutParent(CCNode* child, CCNode* newParent)
{
    CCNode* parent = (CCNode*)child->getParent();
    if (parent && child) {
    
        child->retain();
        
        CCSize parentSize = parent->getContentSize();
        CCPoint parentAnchor = parent->getAnchorPoint();
        
        float posX =  parent->getPositionX() - parentSize.width*parentAnchor.x + child->getPositionX();
        float posY =  parent->getPositionY() - parentSize.height*parentAnchor.y + child->getPositionY();
    
        child->removeFromParentAndCleanup(false);
        child->setPosition(ccp(posX, posY));
        this->addChild(child);
        
        child->release();
    }
    
}
Example #9
0
void CCtrlEdit::doKeyboardShowAction()
{
	if (!isVisible())
	{
		return;
	}

	DLG_HANDLE hHandleDlg = GetTopParent();
	CCMyWndObject* pWndObject = g_objUIMgr.GetWndObj(hHandleDlg);
	if (NULL == pWndObject)
	{
		return;
	}

	CCNode *pHandleNode = dynamic_cast<CCNode*>(pWndObject);
	if (NULL == pHandleNode)
	{
		return;
	}

	CCPoint destPos = getPosition();
	CCRect bgRect(destPos.x, destPos.y, m_nWidth, m_nHeight);

	if (bgRect.origin.y - m_nHeight < m_infoIMEKeyboardNotification.end.origin.y + m_infoIMEKeyboardNotification.end.size.height)
	{
        m_RecordPos.y = pHandleNode->getPositionY();
        m_RecordPos.x = 0;
        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
        
        destPos.x = 0;
        destPos.y = m_infoIMEKeyboardNotification.end.size.height+ visibleSize.height;        


		CCMoveTo* moveTo = CCMoveTo::create(m_infoIMEKeyboardNotification.duration, destPos);		

		pHandleNode->runAction(moveTo);
	}
}
void SpaceBackGround::InitBG(cocos2d::CCNode *layer)
{
    glClearColor(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f);
    m_layer = layer;
    pNode = CCParallaxNodeTile::create();
    m_layer->addChild(pNode);
    
        
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //////////////
    //Adding some comments to test out a git pull request
    //
    //
    bool nasaObjsLoaded = true;
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("spaceBG.plist","spaceBG.png");
    
    float scale = ScreenHelper::getTextureScale();
    float scaleX = ScreenHelper::getTextureScaleX();
    float scaleY = ScreenHelper::getTextureScaleY();
    
    CCSprite *sprite = CCSprite::create("ctm_SpaceGradient_Merged_BG.png");
    sprite->setScaleX(s.width/940.0f);
    sprite->setScaleY(s.width/940.0f);
    pNode->addChild(sprite,0,CCPointMake(1.0f,0.0f),ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,40.0f));
    
    CCSprite *moon;
    switch (RandomInt(0, 7)) {
        default:
        case 0:
            moon = CCSprite::create("ctm_Nasa_Jupitor.png");
            break;
        case 1:
            moon = CCSprite::create("ctm_Nasa_Mars.png");
            break;
        case 2:
            moon = CCSprite::create("ctm_Nasa_Mercury.png");
            break;
        case 3:
            moon = CCSprite::create("ctm_Nasa_Neptune.png");
            break;
        case 4:
            moon = CCSprite::create("ctm_Nasa_Saturn.png");
            break;
        case 5:
            moon = CCSprite::create("ctm_Nasa_Uranus.png");
            break;
        case 6:
            moon = CCSprite::create("ctm_Nasa_Venus.png");
            break;
    }
    moon->setAnchorPoint(ccp(0.5f,0.5f));
    moon->setScale(scale);
    pNode->addChild(moon,0,CCPointMake(1.0f,0.0f),ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,RandomFloat(-200.0f, 100.0f),RandomFloat(-25.0f, 25.0f)));
    
    m_Parallax1 = CCArray::createWithCapacity(4);
    m_Parallax1->retain();
    for(int i = 0; i < 4; i++)
    {
        char temp[64];
        sprintf(temp,"ctm_Moon_%02d.png",i+1);
        sprite = CCSprite::create(temp);
        sprite->setScale(scale);
        m_Parallax1Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i, 53.0f);
        pNode->addChild(sprite,1,CCPointMake(0.90f,0.0f),m_Parallax1Points[i]);
        m_Parallax1->addObject(sprite);
        
    }
    
    if(nasaObjsLoaded)
    {
        m_Parallax2 = CCArray::createWithCapacity(4);
        m_Parallax2->retain();
        m_Parallax3 = CCArray::createWithCapacity(4);
        m_Parallax3->retain();
        
        int last = -1;
        std::vector<int> poster_rand;
        std::vector<int> retro_rand;
        object_vals.clear();
        for(int i = 0; i < 4; i++)
        {

            //head
            char name[64];
            if(last != 0 && RandomInt(0, 100)>90)
            {
                if(poster_rand.size()>0){
                    int new_rand;
                    bool found = false;
                    do{
                        found = false;
                        new_rand = RandomInt(1, 7);
                        for(int j=0; j < poster_rand.size(); j++){
                            int val = poster_rand[j];
                            if(val == new_rand){
                                found = true;
                                break;
                            }
                        }
                    }while(found);
                    poster_rand.push_back(new_rand);
                }else{
                    poster_rand.push_back(RandomInt(1, 7));
                }
                last = 0;
                sprintf(name,"ctm_SpacePoster_%02d.png",poster_rand.back());
                sprite = CCSprite::createWithSpriteFrameName(name);
                sprite->setScale(scale);
                m_Parallax2Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i-192.0f, 103.0f);
                pNode->addChild(sprite,2,CCPointMake(0.90f,0.0f),m_Parallax2Points[i]);
                m_Parallax2->addObject(sprite);
            }
            else
            {
                last = 1;
                if(retro_rand.size()>0){
                    int new_rand;
                    bool found = false;
                    do{
                        found = false;
                        new_rand = RandomInt(1, 6);
                        for(int j=0; j < retro_rand.size(); j++){
                            int val = retro_rand[j];
                            if(val == new_rand){
                                found = true;
                                break;
                            }
                        }
                    }while(found);
                    retro_rand.push_back(new_rand);
                }else{
                    retro_rand.push_back(RandomInt(1, 6));
                }
                sprintf(name,"ctm_space_Retro%02d.png",(RandomInt(1, 6)));
                CCNode *object = getBGObject();
                m_Parallax2Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i-128.0f+object->getPositionX(), 103.0f+object->getPositionY());
                pNode->addChild(object,object->getZOrder(),CCPointMake(0.90f,0.0f),m_Parallax2Points[i]);
                m_Parallax2->addObject(object);
            }
            
            //torch
            CCNode *object = getBGObject();
            m_Parallax3Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i+object->getPositionX(), 103.0f+object->getPositionY());
            pNode->addChild(object,object->getZOrder(),CCPointMake(0.90f,0.0f),m_Parallax3Points[i]);
            m_Parallax3->addObject(object);
        }
        
    }
    else
    {
        m_Parallax2 = NULL;
    }
    
    
    
    m_Track = CCArray::createWithCapacity(4);
    m_Track->retain();
    for(int i = 0; i < 4; i++)
    {
        int r = 2.999f * CCRANDOM_0_1();
        switch(r){
            default:
            case 0:
                sprite = CCSprite::create("Space_Panels_01.png");
                break;
            case 1:
                sprite = CCSprite::create("Space_Panels_02.png");
                break;
            case 2:
                sprite = CCSprite::create("Space_Panels_03.png");
                break;
        }
        sprite->setScaleX(scaleX);
        sprite->setScaleY(scaleY);
        m_TrackPoints[i] = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT);
        m_TrackPoints[i].x += (256.0f*i)*scaleX;
        m_TrackPoints[i].y += -28.0f*scale;
        sprite->setPosition(m_TrackPoints[i]);
        m_layer->addChild(sprite,4);
        m_Track->addObject(sprite);
        
        /*       sprite = CCSprite::create("ctm_256_Front_hazardstripe.png");
         sprite->setScaleX(scaleX);
         sprite->setScaleY(scaleY);
         sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i, 55.0f));
         addChild(sprite,4);
         */
    }
    
    
}