Ejemplo n.º 1
0
void SkillButton::cool(float time) {
    ProgressTimer *prog = static_cast<ProgressTimer *>(this->getChildByTag(PROGRESS_TAG));
    //判断之前是否已经设置了冷却效�?
    if (!prog) {
        prog = ProgressTimer::create(Sprite::create("image/1.png"));
        prog->setType( ProgressTimer::Type::RADIAL);
        prog->setTag(PROGRESS_TAG);
        this->addChild(prog);
        prog->setAnchorPoint(Vec2(0.f, 0.f));
        prog->setPosition(0.f, 0.f);
        prog->setScale(this->getContentSize().width / prog->getContentSize().width); //调整到和图标一样大�?
    }

    auto to1 = Sequence::createWithTwoActions(ProgressTo::create(0, 100.f),
                                              ProgressTo::create(time, 0.f));
    prog->runAction(to1);
}
ProgressTimer* TransitionProgressRadialCW::progressTimerNodeWithRenderTexture(RenderTexture* texture)
{
    Size size = Director::getInstance()->getWinSize();
    
    ProgressTimer* node = ProgressTimer::create(texture->getSprite());
    
    // but it is flipped upside down so we flip the sprite
    node->getSprite()->setFlippedY(true);
    node->setType( ProgressTimer::Type::RADIAL );
    
    //    Return the radial type that we want to use
    node->setReverseDirection(true);
    node->setPercentage(100);
    node->setPosition(Vector2(size.width/2, size.height/2));
    node->setAnchorPoint(Vector2(0.5f,0.5f));
    
    return node;
}
ProgressTimer* TransitionProgressOutIn::progressTimerNodeWithRenderTexture(RenderTexture* texture)
{    
    Size size = Director::getInstance()->getWinSize();
    
    ProgressTimer* node = ProgressTimer::create(texture->getSprite());
    
    // but it is flipped upside down so we flip the sprite
    node->getSprite()->setFlippedY(true);
    node->setType( ProgressTimer::Type::BAR );
    
    node->setMidpoint(Vector2(0.5f, 0.5f));
    node->setBarChangeRate(Vector2(1, 1));
    
    node->setPercentage(100);
    node->setPosition(Vector2(size.width/2, size.height/2));
    node->setAnchorPoint(Vector2(0.5f,0.5f));
    
    return node;
}
Ejemplo n.º 4
0
void SkillItem::onSkillStarted()
{
    this->setEnabled(false);
    
    ProgressTo *to1 = ProgressTo::create(getSkillCDTime(), 100);
    ProgressTimer *sprite = ProgressTimer::create(Sprite::create(this->getDisableIcon().c_str()));
    sprite->setType(ProgressTimer::Type::RADIAL);
    
    auto tint = Sequence::create(TintTo::create(getSkillCDTime(), 60, 255, 180),
                                 NULL);

    
    sprite->setPosition(Point(getContentSize().width / 2, getContentSize().height / 2));
    sprite->setBarChangeRate(Point(0, 1));
    addChild(sprite, 0, SKILL_ITEM_CHILD_TAG);
    sprite->runAction(Sequence::create(Spawn::create(to1, tint, NULL),CallFunc::create( CC_CALLBACK_0( SkillItem::onSkillCDFinished, this)) ,NULL) );


}
Ejemplo n.º 5
0
bool skillCd::init()
{
	if (!Layer::init())
		return false;
	Size visibleSize = Director::getInstance()->getVisibleSize();

	ProgressTo *to = ProgressTo::create(3.0f, 100);
	
	Sprite *skill_icon = Sprite::create("icon.png");
	ProgressTimer *skill = ProgressTimer::create(skill_icon);
	skill->setType(kCCProgressTimerTypeRadial);
	skill->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	addChild(skill);

	Sprite *skill_icon_back = skill_icon;
	skill_icon_back->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	skill_icon_back->setOpacity(100);
	addChild(skill_icon_back);
	skill->runAction(to);
	return true;
}
Ejemplo n.º 6
0
bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    

    _tileMap = TMXTiledMap::create("ai_map.tmx");
    //_tileMap->initWithTMXFile("ai_map.tmx");
    _background = _tileMap->getLayer("Background");
    
    _foreground_1 = _tileMap->getLayer("Foreground_1");
    _foreground_2 = _tileMap->getLayer("Foreground_2");
    _meta = _tileMap->getLayer("Meta");
    _meta->setVisible(false);
    
    this->addChild(_tileMap);
    
    
    TMXObjectGroup *objectGroup = _tileMap->getObjectGroup("Objects");
    CCASSERT(NULL != objectGroup, "SpawnPoint object not found");
    auto spawnPoint = objectGroup->getObject("SpawnPoint");
    CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
    //CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
    
    //int x = ((CCString)spawnPoint.valueForKey("x")).intValue();
    //int y = ((CCString)spawnPoint.valueForKey("y")).intValue();
    int x = spawnPoint["x"].asInt();
    int y = spawnPoint["y"].asInt();
    
    // player
    _player = Sprite::create("egg.png");
    _player->setTag(5);
    _player->setPosition(x,y);
    addChild(_player);
    setViewPointCenter(_player->getPosition());
    
    // patrol enemy
    searching_enemy = Enemys::createWithLayer(this);
    searching_enemy->setGameLayer(this);
    auto enemy = objectGroup->getObject("EnemySpawn1");
    int x_1 = enemy["x"].asInt();
    int y_1 = enemy["y"].asInt();
    addEnemyAtPos(Point(x_1,y_1));
    _enemies.pushBack(searching_enemy);
    
    // archer
    archer = Sprite::create("Kiwi.png");
    archer->setPosition(positionForTileCoord(Point(12, 4)));
    archer->setTag(23);
    archer->setScale(1.0);
    this->addChild(archer,1);
    _enemies.pushBack(archer);
    
    //boss
    boss = Sprite::create("patrol.png");
    boss->setPosition(positionForTileCoord(Point(26,9)));
    boss->setTag(26);
    boss->setScale(1.7);
    this->addChild(boss);

    _enemies.pushBack(boss);
    
    //a princess
    princess = Sprite::create("Princess.png");
    princess->setPosition(positionForTileCoord(Point(28, 10)));
    princess->setScale(0.6);
    this->addChild(princess);
    
    
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan     = [&](Touch* touch, Event* unused_event)->bool { return true;  };
    listener->onTouchEnded     = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    // a pause button
    auto pauseItem = MenuItemImage::create("pause.png","",CC_CALLBACK_1(HelloWorld::onPause, this));
    auto menu = Menu::create(pauseItem,NULL);
    
    pauseItem->setScale(0.2);
    pauseItem->setPosition(positionForTileCoord(Point(27, 1)));
    
    menu->setPosition(Point::ZERO);
    this->addChild(menu,1,5);

    // add background music
    //CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("SummerNight.wav");
    
    // navigation button:up, down, left and right and an attacking button
    auto left_btn = Sprite::create("left.png");
    left_btn->setScale(0.3);
    left_btn->setPosition(Point(100, 125));
    left_btn->setTag(TAG_LEFT);
    this->addChild(left_btn,1);
    
    auto right_btn = Sprite::create("right.png");
    right_btn->setScale(0.3);
    right_btn->setPosition(Point(250, 125));
    right_btn->setTag(TAG_RIGHT);
    this->addChild(right_btn,1);
    
    auto up_btn = Sprite::create("up.png");
    up_btn->setScale(0.3);
    up_btn->setPosition(Point(175, 200));
    up_btn->setTag(TAG_UP);
    this->addChild(up_btn,1);
    
    auto down_btn = Sprite::create("down.png");
    down_btn->setScale(0.3);
    down_btn->setPosition(Point(175, 50));
    down_btn->setTag(TAG_DOWN);
    this->addChild(down_btn,1);

    auto attack_btn = Sprite::create("attack.png");
    attack_btn->setScale(0.5);
    attack_btn->setPosition(positionForTileCoord(Point(25,16)));
    attack_btn->setTag(ATTACK);
    this->addChild(attack_btn,1);
    
    //hero hp
    Sprite *heroEmHP = Sprite::create("empty.png");
    heroEmHP->setPosition(Point(150, 600));
    heroEmHP->setScale(1.5);
    this->addChild(heroEmHP);
    Sprite* heroFuHP = Sprite::create("full.png");
    ProgressTimer *pBlood = ProgressTimer::create(heroFuHP);
    pBlood->setType(kCCProgressTimerTypeBar);
    pBlood->setMidpoint(Point(0, 0));
    pBlood->setBarChangeRate(Point(1, 0));
    pBlood->setPercentage(100.0f);
    pBlood->setPosition(Point(150, 600));
    pBlood->setScale(1.5);
    this->addChild(pBlood, 1, 6);
    auto hero =Sprite::create("hero.png");
    hero->setPosition(Point(50, 600));
    hero->setScale(0.3);
    this->addChild(hero);
    
    //patrol monster hp
    Sprite *enEmHP = Sprite::create("empty.png");
    enEmHP->setPosition(Point(150, 550));
    enEmHP->setScale(1.5);
    this->addChild(enEmHP,1,7);
    Sprite* enFuHP = Sprite::create("full.png");
    ProgressTimer *enpBlood = ProgressTimer::create(enFuHP);
    enpBlood->setType(kCCProgressTimerTypeBar);
    enpBlood->setMidpoint(Point(0, 0));
    enpBlood->setBarChangeRate(Point(1, 0));
    enpBlood->setPercentage(100.0f);
    enpBlood->setPosition(Point(150, 550));
    enpBlood->setScale(1.5);
    this->addChild(enpBlood, 1,8);
    auto monster = Sprite::create("monster.png");
    monster->setPosition(Point(50,550));
    monster->setScale(0.1);
    monster->setTag(9);
    this->addChild(monster);

    //archer
    Sprite *arEmHP = Sprite::create("empty.png");
    arEmHP->setPosition(Point(350, 600));
    arEmHP->setScale(1.5);
    this->addChild(arEmHP,1,10);
    Sprite* arFuHP = Sprite::create("full.png");
    ProgressTimer *arpBlood = ProgressTimer::create(arFuHP);
    arpBlood->setType(kCCProgressTimerTypeBar);
    arpBlood->setMidpoint(Point(0, 0));
    arpBlood->setBarChangeRate(Point(1, 0));
    arpBlood->setPercentage(100.0f);
    arpBlood->setPosition(Point(350, 600));
    arpBlood->setScale(1.5);
    this->addChild(arpBlood, 1,11);
    auto armonster = Sprite::create("archer_icon.png");
    armonster->setPosition(Point(250,600));
    armonster->setScale(0.1);
    armonster->setTag(12);
    this->addChild(armonster);

    //boss
    Sprite *boEmHP = Sprite::create("empty.png");
    boEmHP->setPosition(Point(350, 550));
    boEmHP->setScale(1.5);
    this->addChild(boEmHP,1,13);
    Sprite* boFuHP = Sprite::create("full.png");
    ProgressTimer *bopBlood = ProgressTimer::create(boFuHP);
    bopBlood->setType(kCCProgressTimerTypeBar);
    bopBlood->setMidpoint(Point(0, 0));
    bopBlood->setBarChangeRate(Point(1, 0));
    bopBlood->setPercentage(100.0f);
    bopBlood->setPosition(Point(350, 550));
    bopBlood->setScale(1.5);
    this->addChild(bopBlood, 1,14);
    auto bomonster = Sprite::create("boss_icon.png");
    bomonster->setPosition(Point(250,550));
    bomonster->setScale(0.2);
    bomonster->setTag(15);
    this->addChild(bomonster);

    this->schedule(schedule_selector(HelloWorld::shooting), 2.5f);
    this->schedule(schedule_selector(HelloWorld::bulletCollision));
    this->schedule(schedule_selector(HelloWorld::getPrincess));
    this->schedule(schedule_selector(HelloWorld::bossAttacking),1.0f);
    return true;
}
Ejemplo n.º 7
0
void GameScene::addTouchListener()
{
    
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = [this](Touch* t,Event* e)->bool{
        auto menuCoo = menu->convertToNodeSpace(t->getLocation());
        Rect oldAABB =  buttonCoco->getBoundingBox();
        Vec2 oldVec = oldAABB.origin;
        Vec2 newVec = oldVec-buttonCoco->getContentSize()/2;
        Rect newAABB(newVec.x,newVec.y,oldAABB.size.width,oldAABB.size.height);
        
        if(mpProgressTimer->getPercentage()==100.0f&&newAABB.containsPoint(menuCoo)){
            isMagic = true;
            coco->playAnimation(BaseSprite::State::magic);
            if(!eff){
             eff = EffSprite::create("pfca/effect/eff_point_Coco_ult.fca", "effect/eff_point_Coco_ult");
            this->addChild(eff);
            }
            eff->setVisible(true);
            eff->setPosition(0-_director->getWinSize().width/2,0);
            eff->playAnimation(BaseSprite::State::magic,CallFunc::create(CC_CALLBACK_0(GameScene::effectCallback, this)));
            
            mpProgressTimer->setPercentage(0.f);
            
        }
        
        return true;
    };
    
    auto hurtLisener = EventListenerCustom::create("hurt", [this](EventCustom* e)->void{
      
        auto hurtObject = (BaseSprite*)e->getUserData();
        Label* l = nullptr;
       ProgressTimer* hp = nullptr;
        if(hurtObject==boss){
            l = l1;
            hp = effectHpProgressTimer[0];
            
        }else{
            l  = l2;
            hp = effectHpProgressTimer[1];
        }
        if(dynamic_cast<TreeBoss*>(hurtObject)){
            l->setPosition(hurtObject->getPosition()+Vec2(_director->getWinSize().width/2,_director->getWinSize().height/2+200));
            hp->setPosition(hurtObject->getPosition()+Vec2(_director->getWinSize().width/2,_director->getWinSize().height/2+180));
            
        }
        else{
              l->setPosition(hurtObject->getPosition()+Vec2(_director->getWinSize().width/2,_director->getWinSize().height/2+100));
            hp->setPosition(hurtObject->getPosition()+Vec2(_director->getWinSize().width/2,_director->getWinSize().height/2+130));
        }
       
        hp->setPercentage((hurtObject->getProperty().curLife/hurtObject->getProperty().maxLife)*100);

        
        
        l->setString("-"+Value((int)hurtObject->getCurHurt()).asString());
        if(!l->getParent()){
           
            this->addChild(l,3);
        }
        if(!hp->getParent()){
            this->addChild(hp,3);
        }
        hp->setVisible(true);
        if(!l->isVisible()){
            l->setVisible(true);
            l->setOpacity(255);
        }
        auto move = MoveBy::create(0.5f, Vec2(0,20));
        auto fade = FadeOut::create(0.5f);
        
        l->runAction(Sequence::create(move, fade,CallFunc::create(std::bind(&GameScene::lableCallback, this,l)),nullptr));
        
        hp->runAction(Sequence::create(DelayTime::create(1.0f),CallFuncN::create([](Node* n){
            n->setVisible(false);
        }), NULL));
    });
    
    
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener,buttonCoco);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(hurtLisener,this);
    
    
}