Exemplo n.º 1
0
void CRoleSprite::setFlyAnimation(int iDirection)
{
	Vector<CCSpriteFrame* > pArray;
	char str[100] = {0};
	int iBegin, iEnd;
	if(iDirection == STRAIGHT)
	{
		iBegin = 0;
		iEnd = m_iFlyStraightNum;
	}
	else
	{
		iBegin = m_iFlyStraightNum;
		iEnd = m_iFlyStraightNum + m_iFlyLeftNum;
	}

	if(iDirection == RIGHT)
	{
		m_pSprite->setFlipX(true);
	}
	else
	{
		m_pSprite->setFlipX(false);
	}
	for(int i = iBegin; i < iEnd; i++) 
	{
		sprintf(str, "Plane%d_%d.png", m_iType,i);
		CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
		pArray.pushBack(frame);
	}
	CCAnimation *pWalkAnim = CCAnimation::createWithSpriteFrames(pArray, 0.2f);
	CCRepeatForever *pAciton = CCRepeatForever::create(CCAnimate::create(pWalkAnim));
	pAciton->setTag(iDirection);
	m_pSprite->runAction(pAciton);
}
Exemplo n.º 2
0
void GameLayer::playerRun()
{
    // player begin run
    CCSprite *playerSprite = (CCSprite *)this->getChildByTag(PlayerTag);
    if (playerSprite->getActionByTag(PlayerChangeRoadTag)) {
        return;
    }
    
    CCGameMoveBy *moveBy = CCGameMoveBy::create(1.0f, ccp(0.0f, kPlayerRunSpeed));
    CCRepeatForever *moveForever = CCRepeatForever::create(moveBy);
    moveForever->setTag(PlayerRunningTag);
    
    // run forever
    playerSprite->stopActionByTag(PlayerRunningTag);
    if (isSliding) {
        playerSprite->stopActionByTag(PlayerSlidingTag);
        isSliding = false;
    }
    if (isJumpping) {
        playerSprite->stopActionByTag(PlayerJumppingTag);
        isJumpping = false;
    }
    isRunning = true;
    playerSprite->runAction(moveForever);
}
Exemplo n.º 3
0
void CSmeltArmor::showMoveAction( const char* name )
{
	CCNode* pNode = ((CCNode*)m_ui->findWidgetById(name));
	if(pNode->getActionByTag(999) == nullptr)
	{
		CCRepeatForever* pAction = CCRepeatForever::create(CCSequence::createWithTwoActions(CCMoveBy::create(0.7f, ccp(0, 15)), CCMoveBy::create(0.7f, ccp(0, -15))));
		pAction->setTag(999);
		pNode->runAction(pAction);
	}
}
Exemplo n.º 4
0
void Mole::startLoopAnimation()
{
	if(!isUp){
		return;
	}
	CCRepeatForever *repeat = CCRepeatForever::create((CCSequence *)CCSequence::create(
			Utils::getAnimationWithFrames(11,20),
			Utils::getAnimationWithFrames(11,20)->reverse(),
			NULL));
	repeat->setTag(TAG_REPEAT_ANIM);
	this->runAction(repeat);
}
Exemplo n.º 5
0
void Enemy::moveToTarget( ){
   bool lasttile = false;
    cur++;
    if (cur==WayTilesArray->count()) {
        lasttile = true;
    }
    TileData *toTile;
    CCPoint WalktoPosition;
    
    if (!lasttile) {
   toTile = (TileData *)WayTilesArray->objectAtIndex(cur);

    CCPoint _currentTileCoord = toTile->getPosition();
    if (_currentTileCoord.equals(endPos)) {
     //   this->removeSelf();
        return;
    }
   
    
	//CCPoint startPosition = this->getPosition();
    
   WalktoPosition =  mainLayer->positionForTileCoord(_currentTileCoord);

    }else{
        WalktoPosition = getPosition();
        if (curDir==kRight)
            WalktoPosition.x = mainLayer->gameMap->getContentSize().width + mainLayer->gameMap->getTileSize().width/2;
        else if (curDir==kUp)
            WalktoPosition.y=mainLayer->gameMap->getContentSize().height+ mainLayer->gameMap->getTileSize().height/2;
        else if(curDir == kDown)
            WalktoPosition.y=mainLayer->gameMap->getContentSize().height-mainLayer->gameMap->getTileSize().height/2;
        else if (curDir == kLeft)
            WalktoPosition.x = mainLayer->gameMap->getContentSize().width - mainLayer->gameMap->getTileSize().width/2;
    }
    WalktoPosition.y+=10;
    CCMoveTo* moveAction;
    CCCallFunc* moveCallback;
    float moveTime = 32 / speed;
	moveAction = CCMoveTo::create(moveTime, WalktoPosition);
    moveCallback = CCCallFunc::create(this, callfunc_selector(Enemy::moveToTarget));
    if (!lasttile){


    if (toTile->getDirection()!=KUnKnow&&!hasRemoved) {
        curDir = toTile->getDirection();
        CCAnimation *animation = this->createAnimationByDirection(toTile->getDirection());
        CCAnimate *animate = CCAnimate::create(animation);

        CCRepeatForever* forever = CCRepeatForever::create(animate);
        sprite->stopActionByTag(100);
        forever->setTag(100);
        sprite->runAction(forever);
    }
    }
    if (lasttile) {
       // auto doneCallback = CCCallFunc::create(this, callfunc_selector(Enemy::removeSelf));
        this->runAction(CCSequence::create(moveAction, NULL));
    }else
	this->runAction(CCSequence::create(moveAction, moveCallback, NULL));

}
Exemplo n.º 6
0
bool Enemy::initWithMem(const char* filename, int hp, float speed,int gift,CCPoint pos){
	bool bRet = false;
	do
	{
        imageName = (char *)malloc(strlen(filename));
        imageName = strcpy(imageName, filename);
		mainLayer = GameMediator::sharedMediator()->getGameLayer();
		int maxTileWidth = mainLayer->getMaxTileWidth();
		int maxTileHeight = mainLayer->getMaxTileHeight();
        
		//sprite =CCSprite::createWithSpriteFrameName(filename); //CCSprite::create(filename);
        //将图片生成纹理,保存到全局的纹理缓存取
        CCTexture2D *heroTexture=CCTextureCache::sharedTextureCache()->addImage(filename);
        //用纹理创建4幅帧动画
        CCSpriteFrame *frame0,*frame1,*frame2,*frame3;
        //第二个参数表示显示区域的x,y,width,height
        frame0=CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(36*0,48*3,36,48));
        frame1=CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(36*1,48*3,36,48));
        frame2=CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(36*2,48*3,36,48));
        frame3=CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(36*3,48*3,36,48));
        //CCMutableArray<CCSpriteFrame*> *animFramess=new CCMutableArray<CCSpriteFrame*>(4);
        
        CCArray *animFrames=CCArray::create();
        animFrames->addObject(frame0);
        animFrames->addObject(frame1);
        animFrames->addObject(frame2);
        animFrames->addObject(frame3);
        //根据4幅帧生成CCAnimation对象
        CCAnimation *animation=CCAnimation::createWithSpriteFrames(animFrames);
        //创建一个CCSprite用来显示勇士,可以使用Animation中的一帧来作为勇士静止时的画面
        sprite=CCSprite::createWithSpriteFrame(frame0);
        
        addChild(sprite);
        //根据动画模板创建动画
        animation->setDelayPerUnit(0.2f);
        CCAnimate *animate=CCAnimate::create(animation);
        //animate->retain();
        //创建不断重复的动画,并让heroSprite播放
        CCRepeatForever *forever = CCRepeatForever::create(animate);
        forever->setTag(100);
        sprite->runAction(forever);
        
        animFrames->release();
       
		actionSprite = CCSprite::createWithSpriteFrame(frame0);
		actionSprite->retain();
		this->setHP(hp);
		this->setSpeed(speed);
        this->setGift(gift);
        this->totalHP = hp;
        isAimed = false;
        aim = nil;
		int x, y;
		x =-20;// pos.x/2;
		y=  pos.y+10 ;
		startPos = ccp(x,y);
        this->setPosition(startPos);
        
        startPos = ccp(15,pos.y+10);
		x = maxTileWidth  ;
        y = maxTileHeight;
		endPos = ccp(x, y);
        
		hasRemoved = false;
        
		spOpenSteps = CCArray::create();
		spOpenSteps->retain();
        
		spClosedSteps = CCArray::create();
		spClosedSteps->retain();
        
		shortestPath = CCArray::create();
		shortestPath->retain();
        WayTilesArray =  CCArray::create();
        WayTilesArray->retain();
		//attack();
        cur = 0;
		times = 0;
		orgSpeed = speed;
        
		pre = NULL;
        
        
		healthBar = CCProgressTimer::create(CCSprite::create("health_bar_green.png"));
        
		healthBar->setType(kCCProgressTimerTypeBar);
		healthBar->setMidpoint(ccp(0, 0));
		healthBar->setBarChangeRate(ccp(1, 0));
		healthBar->setPercentage(100);
		healthBar->setScale(0.2f);
		healthBar->setPosition(ccp(0,sprite->getContentSize().height* 0.5f));
		this->addChild(healthBar,2);
        CCSprite *redBar = CCSprite::create("health_bar_red.png");
        redBar->setPosition(healthBar->getPosition());
        redBar->setScale(0.2);
        this->addChild(redBar,1);
        scheduleOnce(schedule_selector(Enemy::attack), 0.5f);
       
        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
		bRet = true;
	} while (0);
	return bRet;
}
Exemplo n.º 7
0
void StageMapLayer::SelectStageMapPoint(INT listIndex, BOOL withAnimation)
{
    if( listIndex <= 0 )
    {
        listIndex = 0;
    }
    ASSERT_DEBUG(m_StageMapPointList.size() > listIndex );
    INT oldIndex = m_SelectedStageMapPointIndex;
    
    m_SelectedStageMapPointIndex = listIndex;
    
    const CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    StageMapPoint* stageMapPoint = m_StageMapPointList[listIndex];
    const StageLevel stageLevel = stageMapPoint->GetStageLevel();
    
    StageInfo* stageInfo = StageInfoDictionary::Instance().FindStageInfo(stageLevel);
    
    CCPoint destination = ccp(stageInfo->GetMapPosition().x, stageInfo->GetMapPosition().y)+m_PlayerPositionOffset;
    CCPoint mapDestination = ccp(m_MapBase->getPositionX(), winSize.height*0.5f+(-stageInfo->GetMapPosition().y));
    if( withAnimation == true )
    {
        CCCallFunc* jumpCall = CCCallFunc::create(m_MyPlayer, callfunc_selector(PlayerNode::AnimateWholeJump));
        CCDelayTime* jumpDelay = CCDelayTime::create(m_MyPlayer->GetWholeJumpAnimationPlayTime());
        CCSequence* jump = CCSequence::create(jumpCall, jumpDelay, nullptr);
        CCRepeatForever* repeatJump = CCRepeatForever::create(jump);
        repeatJump->setTag(ActionType_Animation);
        m_MyPlayer->stopActionByTag(ActionType_Animation);
        m_MyPlayer->runAction(repeatJump);
        
        const int StageMapPlayerActionTag = 37;
        this->MoveMyPlayerToSelectedIndex(0.f);
        
        CCMoveTo* moveMap = CCMoveTo::create(1.f, mapDestination);
        moveMap->setTag(StageMapPlayerActionTag);
        m_MapBase->stopActionByTag(StageMapPlayerActionTag);
        m_MapBase->runAction( moveMap );
    }
    else
    {
        m_CurrentMyPlayerStageMapPointIndex = m_SelectedStageMapPointIndex;
        m_MyPlayer->setPosition(destination);
        m_MapBase->setPosition(mapDestination);
        if( stageMapPoint !=nullptr )
        {
            m_MyPlayer->setZOrder(stageMapPoint->getZOrder());
        }

    }
    
    if( stageMapPoint !=nullptr )
    {
        stageMapPoint->SetFloatingMode(false);
    }
    if( oldIndex >= 0 && oldIndex < m_StageMapPointList.size() )
    {
        StageMapPoint* oldStageMapPoint = m_StageMapPointList[oldIndex];
        oldStageMapPoint->SetFloatingMode(true);
    }
    
    // To Do : PopUp Change
    m_MissionBox->Initialize(*stageInfo);
    m_TitleBox->Initialize(*stageInfo);
    
}
Exemplo n.º 8
0
void GameScene::setStatus(int state){
    CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
    CCPoint center = ccp(screenSize.width * 0.5, screenSize.height * 0.5);
    
    GameState = state;
    if (state == GameReady) {
        
        //
        newRecord = false;
        pipeCount = 0;
        //remove pipes if have
        for (int i = pipesArray->count()-1; i >= 0; i--) {
            Pipe *pi = (Pipe*)pipesArray->objectAtIndex(i);
            actionNode->removeChild(pi);
        }
        pipesArray->removeAllObjects();
        
        //score
        score = 0;
        scoreTip->setCount(score);
        
        //show
        stateTipReady->setOpacity(255);
        help->setOpacity(255);
        
        //bg
        CCArray *bgAnimArray = Utils::createAnimArray("bg", 2);
        int bgRand = 0 + rand() % (1 - 0 + 1);
        bg->setDisplayFrame((CCSpriteFrame *)bgAnimArray->objectAtIndex(bgRand));
        
        //bird     
        CCMoveBy *birdMove = CCMoveBy::create(0.5, ccp(0, 10));
        CCRepeatForever *upDown = CCRepeatForever::create(CCSequence::create(birdMove, birdMove->reverse(), NULL));
        upDown->setTag(ActionTagBirdUpDown);
        bird->runAction(upDown);
        bird->setInit();
        bird->setPosition(ccpAdd(center, ccp(-60, 0)));
        bird->setRotation(0);

        //land
        CCAction *landMove = CCRepeatForever::create (CCSequence::create(CCMoveTo::create(48/SpeedLand, ccp(-48, 0)), CCMoveTo::create(0, ccp(0, 0)), NULL));
        landMove->setTag(ActionTagLandMove);
        land->runAction(landMove);
    }
    else if (state == GameRun) {
        //bird cancel upDown
        bird->stopActionByTag(ActionTagBirdUpDown);
        
        //tip and help fade action
        float durFade = 0.1;
        CCFadeOut *fade1 = CCFadeOut::create(durFade);
        CCFadeOut *fade2 = (CCFadeOut*)fade1->copy();
        stateTipReady->runAction(fade1);
        help->runAction(fade2);
        
        this->unscheduleUpdate();
        this->scheduleUpdate();
        this->unschedule(schedule_selector(GameScene::setPipes));
        this->schedule(schedule_selector(GameScene::setPipes), (screenSize.width/2 + 30)/SpeedPipe, kCCRepeatForever, 1);
    }
    else if (state == GameEnd) {
        this->unscheduleUpdate();
        this->unschedule(schedule_selector(GameScene::setPipes));
        //pipe action
        for (int i = 0 ; i < pipesArray->count(); i++) {
            Pipe *pi = (Pipe*)pipesArray->objectAtIndex(i);
            //pi->stopActionByTag(ActionTagPipeMove);
            pi->setAniNodeMoveSpeed(ccp(0, 0));
        }
        
        //land action
        land->stopAllActions();
        
        //layerColor
        color->runAction(CCSequence::create(CCFadeIn::create(0.1), CCFadeOut::create(0.1), NULL));
        
        //actionNode
        actionNode->runAction(CCShake::createWithStrength(0.5, 20, 5));
        
        //best score
        int highScore = GameData::instance()->getGDHighScore();
        if (score > highScore) {
            GameData::instance()->setGDHighScore(score);
            newRecord = true;
        }
        
        //gold
        GameData::instance()->setGDGold(goldCount);
    }
    
}
Exemplo n.º 9
0
void HSBalloonSprite::SetColorType( BalloonColorType type ,float petrifactionTime/* = 0.f*/)
{
    //设置石化球的时候 如果当前是石化状态 就跳过
    if (type == BALLOON_COLOR_Petrifaction && m_BallonColorType == BALLOON_COLOR_Petrifaction)
    {
        return;
    }
    this->SetLastColorType(m_BallonColorType);

	m_BallonColorType = type;

	std::map<BalloonColorType,BalloonTexture2D>::iterator it = m_balloonColorMap.find(m_BallonColorType);
	if (it != m_balloonColorMap.end())
	{
		this->setTexture(it->second.base);
		this->SetLuminousTexture2D(it->second.luminous);
	}
    
#define HS_BOMB_ACTION_TAG 0x2001
    if ( m_BallonColorType == BALLOON_COLOR_Bomb )
    {
        CCRepeatForever* pBombAction = CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleBy::create(0.5f, 1.1f),
                                                                                                CCScaleTo::create(0.5f, 1)));
        pBombAction->setTag(HS_BOMB_ACTION_TAG);
        this->runAction(pBombAction);
        //return;
    }else{
        if (this->getActionByTag(HS_BOMB_ACTION_TAG))
        {
            this->stopActionByTag(HS_BOMB_ACTION_TAG);
        }
    }

	if (m_BallonColorType == BALLOON_COLOR_Petrifaction)
	{
		//HSAssert(petrifactionTime > 2.f,"petrifactionTime > 2.f");
		petrifactionTime < 2.f ? petrifactionTime = 7.f : 0;

		CCDelayTime* pDelayTime = CCDelayTime::create(petrifactionTime /*- 2.f*/);
		CCCallFunc* pCall = CCCallFunc::create(this,callfunc_selector(HSBalloonSprite::CallRemovePetrifactionEffect_FirstTwoSeconds));
		this->runAction(CCSequence::create(pDelayTime,pCall,NULL));
	}

	if (m_BallonColorType == BALLOON_COLOR_Camouflage)
	{
		if (!m_spxCamouflage)
		{
			m_spxCamouflage = SPX_Manager::CreateSprite("SPX/Caisemao.sprite");
			m_spxCamouflage->SetAction(0,1);
			m_spxCamouflage->setPosition(HS_SizeHalf_Point(this->getContentSize()));
			m_spxCamouflage->setVisible(false);
			this->addChild(m_spxCamouflage);
		}
		m_isCamouflage = true;
	}else{
		m_isCamouflage = false;
	}

	if (m_BallonColorType == BALLOON_COLOR_Chameleon)
	{
		if (!m_spxChameleon)
		{
			m_spxChameleon = SPX_Manager::CreateSprite("SPX/Chameleon.sprite");
			m_spxChameleon->SetAction(0,1);
			m_spxChameleon->setPosition(HS_SizeHalf_Point(this->getContentSize()));
			m_spxChameleon->setVisible(false);
			this->addChild(m_spxChameleon);
		}
		m_spxChameleon->setVisible(true);
		m_spxChameleon->SetAction(0);

		CCDelayTime* pDelayTime = CCDelayTime::create(2.f);
		CCCallFunc* pCall = CCCallFunc::create(this,callfunc_selector(HSBalloonSprite::Call_BALLOON_COLOR_Chameleon));
		m_spxChameleon->runAction(CCSequence::create(pDelayTime,pCall,NULL));
	}
}
Exemplo n.º 10
0
////private
void RPGMapRoleSprite::startMove(RPGMapRoleSpriteMoveActTag actTag)
{
    if(this->m_isMoving && this->m_currMoveActTag != actTag)
    {
        this->stopActionByTag(this->m_currMoveActTag);
        this->m_isMoving = false;
    }
    
    if(!this->m_isMoving)
    {
        CCArray *spriteFrames = CCArray::create();
        
        switch (actTag)
        {
            case kRPGMapRoleSpriteMoveActTagUp:
            {
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(9));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(10));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(11));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(10));
                
                this->m_direction = kRPGMapRoleSpriteDirectionUp;
            }
                break;
            case kRPGMapRoleSpriteMoveActTagDown:
            {
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(0));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(1));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(2));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(1));
                
                this->m_direction = kRPGMapRoleSpriteDirectionDown;
            }
                break;
            case kRPGMapRoleSpriteMoveActTagLeft:
            {
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(3));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(4));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(5));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(4));
                
                this->m_direction = kRPGMapRoleSpriteDirectionLeft;
            }
                break;
            case kRPGMapRoleSpriteMoveActTagRight:
            {
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(6));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(7));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(8));
                spriteFrames->addObject(this->m_roleSpriteFrames->objectAtIndex(7));
                
                this->m_direction = kRPGMapRoleSpriteDirectionRight;
            }
                break;
            default:
                break;
        }
        
        CCAnimation *animation = CCAnimation::createWithSpriteFrames(spriteFrames, MOVE_ACT);
        CCRepeatForever *animate = CCRepeatForever::create(CCAnimate::create(animation));
        animate->setTag(actTag);
        this->m_currMoveActTag = actTag;
        
        this->runAction(animate);
        
        this->m_isMoving = true;
    }
}