Ejemplo n.º 1
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto name = ui::Text::create(LHLocalizedCString("appname"), Common_Font, 70);
    name->setColor(Color3B(64, 119, 215));
    name->setPosition(Vec2(visibleSize.width/2, visibleSize.height/3*2) );
    this->addChild(name);
    
    auto play = ui::Button::create("blue.png");
    play->setTitleFontSize(40);
    play->setTitleText(LHLocalizedCString("play"));
    play->setPosition(Vec2(name->getPositionX(), visibleSize.height/2));
    play->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->replaceScene(PlayScene::createScene(nullptr));
            CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("pop.wav");
        }
    });
    this->addChild(play);
    
    auto dbt = DeveloperInfo::DevInfoButton("devinfo.png");
    dbt->setPosition(Vec2(visibleSize.width - 80, visibleSize.height - 80));
    this->addChild(dbt);
    
    auto gbt = GuideScene::guideButton("q.png");
    gbt->setPosition(Vec2(dbt->getPosition().x - gbt->getContentSize().width/2*3, visibleSize.height - 80));
    this->addChild(gbt);
    
    if (UserDefault::getInstance()->getBoolForKey("guide", true)) {
        auto gt = ui::Text::create(LHLocalizedCString("guidetext"), Common_Font, 35);
        gt->setColor(Color3B(250, 201, 11));
        gt->setPosition(Vec2(gbt->getPosition().x - gt->getContentSize().width/2 - gbt->getContentSize().width/2 - 2, gbt->getPosition().y));
        
        MoveBy *byl = MoveBy::create(0.4, Vec2(-20, 0));
        MoveBy *byr = MoveBy::create(0.2, Vec2(20, 0));
        Sequence *sq = Sequence::create(byl,byr,NULL);
        RepeatForever *rp = RepeatForever::create(sq);
        gt->runAction(rp);
        
        this->addChild(gt);
        UserDefault::getInstance()->setBoolForKey("guide", false);
    }
    
    return true;
}
Ejemplo n.º 2
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
//    auto bg = Sprite::createWithSpriteFrameName("bg.png");
//    bg->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
//    this->addChild(bg);
    
//    auto panel = Sprite::create("panel.png");
//    panel->setPosition(bg->getPosition());
//    panel->setScaleX(1.5);
//    panel->setScaleY(2);
//    this->addChild(panel);
    
    float margin = 40.0f;
    
    auto appname = cocos2d::ui::Text::create(LHLocalizedCString("appname"), Common_Font, 50);
    appname->setColor(Color3B::BLACK);
    appname->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + appname->getContentSize().height/2 + margin + origin.y));
    this->addChild(appname);
    
    auto play = ui::Button::create("play.png");
    play->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 - play->getContentSize().height/2 - margin + origin.y));
    play->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->replaceScene(PlayScene::createScene(nullptr));
        }
    });
    this->addChild(play);
    
    auto debt = DeveloperInfo::DevInfoButton("devinfo.png");
    debt->setPosition(Vec2(appname->getPositionX() + appname->getContentSize().width/2 + 40, appname->getPositionY() + appname->getContentSize().height/2 + 20));
    this->addChild(debt);
    
    auto leader = LHLeaderBoard::defaultButton("lb.png");
    leader->setPosition(Vec2(visibleSize.width/3*2 + origin.x, visibleSize.height/4 + origin.y));
    this->addChild(leader);
    
    auto goReview = ui::Button::create("goreview.png");
    goReview->setPosition(Vec2(visibleSize.width/3 + origin.x, visibleSize.height/4 + origin.y));
    goReview->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            ThirdPartyHelper::goReview();
        }
    });
    this->addChild(goReview);
    
    return true;
}
Ejemplo n.º 3
0
bool GameOverScene::initDict(cocos2d::CCDictionary *dic)
{
    
    ThirdPartyHelper::setAd(SET_AD_SHOW);
    
    Size vs = Director::getInstance()->getVisibleSize();
    Vec2 vo = Director::getInstance()->getVisibleOrigin();
    godelay = 0;
    
    CCInteger *score = (CCInteger*)dic->objectForKey("score");
    
    auto bg = Sprite::createWithSpriteFrameName("bg.png");
    bg->setPosition(Vec2(vs.width/2 + vo.x, vs.height/2 + vo.y));
    this->addChild(bg);
    
    auto panel = Sprite::create("panel.png");
    panel->setPosition(bg->getPosition());
    panel->setScaleX(2);
    panel->setScaleY(3.5);
    this->addChild(panel);
    
    auto gameover = ui::Text::create(LHLocalizedCString("gameover"), Common_Font, 70);
    gameover->setPosition(Vec2(vs.width/2 + vo.x, vs.height/3*2 + vo.y));
    gameover->setColor(Color3B::BLACK);
    this->addChild(gameover);
    show(gameover);
    
    int best = UserDefault::getInstance()->getIntegerForKey("best", 0);
    
    auto scorelabel = ui::Text::create(StringUtils::format("%s   %d",LHLocalizedCString("level"),score->getValue()-1), Common_Font, 50);
    scorelabel->setPosition(Vec2(vs.width/2 + vo.x, vs.height/2+scorelabel->getContentSize().height/2 + + vo.y));
    scorelabel->setColor(Color3B::BLACK);
    this->addChild(scorelabel);
    show(scorelabel);
    
    auto bestlabel = ui::Text::create(StringUtils::format("%s   %d",LHLocalizedCString("best"),best), Common_Font, 50);
    bestlabel->setPosition(Vec2(vs.width/2 + vo.x, vs.height/2-bestlabel->getContentSize().height/2+ vo.y));
    bestlabel->setColor(Color3B::BLACK);
    this->addChild(bestlabel);
    show(bestlabel);
    
    float by = vs.height/6 + vo.y;
    float fs = 40;
    
    auto replay = ui::Button::create("replay.png");
    replay->setTitleFontSize(fs);
    replay->setPosition(Vec2(vs.width/2+ vo.x, vs.height/3+ vo.y));
    replay->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->replaceScene(PlayScene::createScene(nullptr));
        }
    });
    this->addChild(replay);
    show(replay);
    
    auto back = ui::Button::create("back.png");
    back->setPosition(Vec2(vs.width/4 + vo.x, by));
    back->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->replaceScene(HelloWorld::createScene());
        }
    });
    this->addChild(back);
    show(back);
    
    auto share = LHShareButton::defaultButton("share.png","LuckyGame");
    share->setPosition(Vec2(vs.width/2 + vo.x, by));
    this->addChild(share);
    show(share);
    
    std::string lb = "lb.png";
    auto leader = LHLeaderBoard::defaultButton(lb);
    leader->setPosition(Vec2(vs.width/4*3 + vo.x, by));
    this->addChild(leader);
    show(leader);
    
	return true;
}
Ejemplo n.º 4
0
void LDZGameLayer::initLevel(int level){
    
    Size vs = Director::getInstance()->getVisibleSize();
    Vec2 vo = Director::getInstance()->getVisibleOrigin();
    
    _mode = MODE_BEGAIN;
    
    TMXTiledMap *map = TMXTiledMap::create("back.tmx");
    _map = map;
    _mapSize = Size(map->getMapSize().width * map->getTileSize().width , map->getMapSize().height * map->getTileSize().height);
    map->setPosition(Vec2(0, 0));
    this->addChild(map);
    
    //main char
    _mainC = Sprite::createWithSpriteFrameName("1.png");
    _mainC->setPosition(_mapSize.width/2, _mainC->getContentSize().height/2 + 10);
    this->addChild(_mainC,1);
    
    //progress
    auto progress = ProgressTimer::create(Sprite::createWithSpriteFrameName("tempb.png"));
    float progx = _mapSize.width/2 - _mainC->getContentSize().width/2 - progress->getContentSize().width/2 - 5;
    float progy = _mainC->getContentSize().height/2 + 10;
    progress->setPosition( progx, progy);
    progress->setType(cocos2d::ProgressTimer::Type::BAR);
    progress->setBarChangeRate(Vec2(0, 1));
    progress->setMidpoint(Vec2(0, 0));
    auto progback = Sprite::createWithSpriteFrameName("temp.png");
    progback->setPosition(progx, progy);
    this->addChild(progback);
    this->addChild(progress,1);
    progress->setVisible(false);
    progback->setVisible(false);
    _powerProg = progress;
    _powerProgBack = progback;
    
    //limit
    float height = 50 + arc4random()%100;
    float uy = _mapSize.height/3 + _mapSize.height/3*2*CCRANDOM_0_1() - 5;
    float dy = uy - height;
    _upLimit = Sprite::createWithSpriteFrameName("limit.png");
    _upLimit->setPosition(_mapSize.width/2, uy);
    this->addChild(_upLimit);
    _downLimit = Sprite::createWithSpriteFrameName("limit.png");
    _downLimit->setPosition(_mapSize.width/2, dy);
    this->addChild(_downLimit);
    
    //guide
    auto gt = ui::Text::create(LHLocalizedCString("guidetext"), Common_Font, 25);
    gt->setColor(Color3B::RED);
    gt->setPosition(Vec2(_mainC->getPosition().x , _mainC->getBoundingBox().getMaxY() + gt->getContentSize().height/2));
    this->addChild(gt);
    auto bl = Blink::create(1, 1);
    auto rp = RepeatForever::create(bl);
    gt->runAction(rp);
    
    auto da = Sprite::create("da.png");
    da->setScaleY(height/da->getContentSize().height);
    da->setPosition(Vec2(_mainC->getPosition().x,_downLimit->getPositionY()+height/2));
    this->addChild(da);
    
    auto lis = EventListenerTouchOneByOne::create();
    lis->onTouchBegan = [this,gt,progress,progback,da](Touch* tmpTouch, Event*){
        if (_mode == MODE_VIEW) {
            Vec2 loca = tmpTouch->getLocation();
            loca = this->convertToNodeSpace(loca);
            if (_mainC->getBoundingBox().containsPoint(loca)) {
                CallFunc *call = CallFunc::create([this](){
                    _mode = MODE_POWER;
                    this->scheduleUpdate();
                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("wiso.wav");
                });
                
                float focusMargin = 20;
                this->focusOn(_mainC->getPosition(), _mainC->getContentSize().height + focusMargin, true , call);
                _mode = MODE_BEGAIN;
                
                gt->removeFromParent();
                da->removeFromParent();
                
                progress->setVisible(true);
                progback->setVisible(true);
                progress->setPercentage(0);
            }
        }else if (_mode == MODE_POWER_END){
            _mode = MODE_POWER;
        }
        
        return true;
    };
    lis->onTouchMoved = [this](Touch* tmpTouch, Event*){
        Vec2 cu = tmpTouch->getLocation();
        Vec2 last = tmpTouch->getPreviousLocation();
        if (_mode == MODE_VIEW) {
            float toy = _focusCenter.y + (last.y - cu.y);
            if (toy+_focusLen/2 > _upLimit->getPositionY() + 20) {
                toy = _upLimit->getPositionY()+20 - _focusLen/2;
            }
            this->focusOn(Vec2(_focusCenter.x , toy),_focusLen, false);
        }else if (_mode == MODE_POWER){
            float dy = fabsf(cu.y - last.y);
            _powerProg->setPercentage(_powerProg->getPercentage()+dy/(_powerProg->getPercentage()+1)/MOVE_FACTOR);
        }
    };
    lis->onTouchEnded = [this](Touch*, Event*){
        if (_mode == MODE_POWER) {
            _mode = MODE_POWER_END;
            _powerCount = 0.1f;
        }
    };
    this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(lis, this);
    
    focusOn(Vec2(_mapSize.width/2,(uy - height/2)), vs.width, false);
    auto dl2 = DelayTime::create(1);
    CallFunc *call = CallFunc::create([this](){
        auto tmpcall = CallFunc::create([this](){
            _mode = MODE_VIEW;
        });
        this->focusOn(_mainC->getPosition(), _focusLen, true , tmpcall);
    });
    auto sq = Sequence::create(dl2,call, NULL);
    this->runAction(sq);
}