#include "AllHeader.h" USING_NS_CC; Scene* LevelComplite::createScene() { // 'scene' is an autorelease object Scene *scene = Scene::create(); // 'layer' is an autorelease object LevelComplite *layer = LevelComplite::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool LevelComplite::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } lastCoin=BridgeClass::getCoin(); auto touchesListinor=EventListenerTouchOneByOne::create(); touchesListinor->onTouchBegan=CC_CALLBACK_2(LevelComplite::onTouchBegan, this); touchesListinor->onTouchMoved=CC_CALLBACK_2(LevelComplite::onTouchMoved, this); touchesListinor->onTouchEnded=CC_CALLBACK_2(LevelComplite::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchesListinor, this); auto keybackListinor=EventListenerKeyboard::create(); keybackListinor->onKeyReleased=CC_CALLBACK_2(LevelComplite::onKeyReleased,this); _eventDispatcher->addEventListenerWithSceneGraphPriority(keybackListinor, this); Sprite *sp=Sprite::create(__String::createWithFormat("%d.jpg",(whichView*10)+subLavel+1)->getCString()); sp->setPosition(Vec2(384*x_scale,512*y_scale)); sp->setScale(y_scale); this->addChild(sp); if(whichView==0) { ParticleSystemQuad *Particle=ParticleSystemQuad::create("bgParticle1.plist"); Particle->setPosition(Vec2(38*x_scale,1100*y_scale)); Particle->setScale(av_scale); this->addChild(Particle); } else { ParticleSystemQuad *Particle=ParticleSystemQuad::create("bgParticle.plist"); Particle->setPosition(Vec2(384*x_scale,1100*y_scale)); Particle->setScale(av_scale); this->addChild(Particle); } auto open=createSprite(this,"map_1 title_open.png",381*x_scale,(938+400)*y_scale); open->setScale(0.7*x_scale); open->runAction(EaseBackOut::create(MoveBy::create(1, Vec2(0, -400*y_scale)))); auto lbl= createLabelWithBMFont(open, nameArray[whichView][subLavel].c_str(),"font.fnt", 384,230-48.00, 40, 0); lbl->setAnchorPoint(Vec2(0.5, 1)); lbl->setAlignment(TextHAlignment::CENTER); lbl->setMaxLineWidth(500); imageShop=createSprite(this,"btn_shop.png",Vec2(665.00*x_scale,(1024-885.00)*y_scale), 0, 0); imageShop->setScale(0); lblCoin=createLabel(imageShop,__String::createWithFormat("%d",BridgeClass::getCoin())->getCString(),"AmsiPro-Ultra.ttf", 52.28,(64-32.52), 30, Color3B::WHITE, 0); lblCoin->setMaxLineWidth(105); imageBack=createSprite(this,"btn_back.png",42.00*x_scale,(1024-44.00)*y_scale); imageBack->setScale(0); imageLevel=createSprite(this,"btn_level.png",726.50*x_scale,(1024-44.00)*y_scale); imageLevel->setScale(0); imageExtra=createSprite(this,"btn_extra.png",53.00*x_scale,(1024-884.50)*y_scale); imageExtra->setScale(0); lblExtra=createLabel(imageExtra,__String::createWithFormat("%d",extraWordCount)->getCString(),"CALIBRIB.TTF", 41.33 , 91-43.62, 20, Color3B(170,65,233), 0); imageNext=createSprite(this, "btn_next_level.png", 384.00*x_scale , (1024-855.00)*y_scale); imageNext->setScale(0); imageNext->setRotation(30); auto sp1=createSprite(this, "chest_highlight.png", Vec2(384.53*x_scale , (1024-417.86)*y_scale),0,0); sp1->setScale(0); sp1->runAction(RepeatForever::create(RotateBy::create(10, 360))); imageBox=createSprite(this, "chest_1.png", 453.00*x_scale , (1024-371.00)*y_scale); imageBox->setScale(0); AddParticle(imageBox,"magicGlow.plist", Vec2(190,186),false,true); imageProgressBack=createSprite(this, "progress_bar.png", 384.00*x_scale , (1024-736.00)*y_scale); imageProgressBack->setScale(0); progress=ProgressTimer::create(Sprite::create("progress_bar_fill.png")); progress->setPosition(Vec2(384.00*x_scale , (1024-736.00)*y_scale)); progress->setMidpoint(Vec2(0, 0.5)); progress->setType(ProgressTimer::Type::BAR); progress->setBarChangeRate(Vec2(1, 0)); this->addChild(progress); progress->setOpacity(0); int progressRate= UserDefault::getInstance()->getIntegerForKey(__String::createWithFormat("progress_%d_%d",whichView,subLavel)->getCString(),0); progress->setPercentage(progressRate); if(UserDefault::getInstance()->getBoolForKey(__String::createWithFormat("isLevelUnlock%d",whichLevel+1)->getCString())==false) { if(whichLevel%100==0) { int lastLevel; for (int i=0; i<10; i++) { if(UserDefault::getInstance()->getBoolForKey(__String::createWithFormat("isMapUnlock%d",i)->getCString())==true) { lastLevel=i; } } UserDefault::getInstance()->setBoolForKey(__String::createWithFormat("isMapUnlock%d",lastLevel+1)->getCString(),true); UserDefault::getInstance()->flush(); } progressRate=progressRate+(100/(int)subLevelCount[subLavel]); UserDefault::getInstance()->setIntegerForKey(__String::createWithFormat("progress_%d_%d",whichView,subLavel)->getCString(), progressRate); UserDefault::getInstance()->setBoolForKey(__String::createWithFormat("isLevelUnlock%d",whichLevel+1)->getCString(),true); UserDefault::getInstance()->flush(); float delay=2.0f; for (int i=0;igetPosition(); c.controlPoint_2=Vec2(362*x_scale,303*y_scale); c.endPosition=Vec2(686*x_scale,134*y_scale); auto sp=createSprite(this,"coin.png",imageExtra->getPosition(),0,100); sp->setScale(0); delay+=(0.2)*i; sp->runAction(Sequence::create(DelayTime::create(2+(0.2*i)),ScaleTo::create(0.1, 1*x_scale),Spawn::create(BezierTo::create(1, c),CCSoundAction::create("collect_coin.mp3",0.72),NULL),RemoveSelf::create(),NULL)); BridgeClass::AddCoin(1); } if(progressRate>=100) { this->runAction(Sequence::create(DelayTime::create(0.1),CCSoundAction::create("leveldone.mp3", 4), NULL)); imageBox->runAction(Sequence::create(DelayTime::create(2.5),CCImageChange::create("chest_1.png",.1),CCImageChange::create("chest_2.png",.1),CCImageChange::create("chest_3.png",.1),CCImageChange::create("chest_4.png",.1),CCTagChange::create(10), NULL)); if(UserDefault::getInstance()->getBoolForKey("isBoxHint")==false) { UserDefault::getInstance()->setBoolForKey("isBoxHint", true); UserDefault::getInstance()->flush(); auto sp=createSprite(this,"hand.png", Vec2(426,580),0,1000); sp->setOpacity(0); sp->runAction(RepeatForever::create(Sequence::create(DelayTime::create(3),FadeIn::create(0.2),FadeOut::create(0.2), NULL))); } } else { imageNext->runAction(Sequence::create(DelayTime::create(delay),EaseOut::create(ScaleTo::create(0.3, 1.3*x_scale), 1),EaseOut::create(ScaleTo::create(0.3, 1*x_scale), 1), NULL)); imageNext->runAction(Sequence::create(DelayTime::create(delay),RotateTo::create(0.3, -50),RotateTo::create(0.2, 0), NULL)); } } else { float delay=2.0f; for (int i=0;igetPosition(); c.controlPoint_2=Vec2(362*x_scale,303*y_scale); c.endPosition=Vec2(686*x_scale,134*y_scale); auto sp=createSprite(this,"coin.png",imageExtra->getPosition(),0,100); sp->setScale(0); delay+=(0.2)*i; sp->runAction(Sequence::create(DelayTime::create(2+(0.2*i)),ScaleTo::create(0.1, 1*x_scale),Spawn::create(BezierTo::create(1, c),CCSoundAction::create("collect_coin.mp3",0.72),NULL),RemoveSelf::create(),NULL)); BridgeClass::AddCoin(1); } if(progress->getPercentage()>=100) imageBox->setTexture("chest_5.png"); imageNext->runAction(Sequence::create(DelayTime::create(delay),EaseOut::create(ScaleTo::create(0.3, 1.3*x_scale), 1),EaseOut::create(ScaleTo::create(0.3, 1*y_scale), 1), NULL)); imageNext->runAction(Sequence::create(DelayTime::create(delay),RotateTo::create(0.3, -50),RotateTo::create(0.2, 0), NULL)); } if(extraWordCount>0) { imageNext->stopAllActions(); } createLabelWithBMFont(imageProgressBack, __String::createWithFormat("MAP %d/%d",(progressRate*subLevelCount[subLavel])/100,subLevelCount[subLavel])->getCString(),"font.fnt", 279,66,30, 0)->enableShadow(); imageProgressBack->runAction(Sequence::create(DelayTime::create(1),ScaleTo::create(0.2, 1), NULL)); progress->runAction(Sequence::create(DelayTime::create(1),FadeIn::create(0.2), NULL)); progress->runAction(Sequence::create(DelayTime::create(1.3),ProgressTo::create(0.5, progressRate), NULL)); sp1->runAction(Sequence::create(DelayTime::create(1.3),ScaleTo::create(0.3, 1.3*x_scale),ScaleTo::create(0.3, 1*x_scale), NULL)); imageBox->runAction(Sequence::create(DelayTime::create(1.3),ScaleTo::create(0.3, 1.3*x_scale),ScaleTo::create(0.3, 1*x_scale), NULL)); imageExtra->runAction(Sequence::create(DelayTime::create(1.4),ScaleTo::create(0.3, 1.3*x_scale),ScaleTo::create(0.3, 1*x_scale), NULL)); imageShop->runAction(Sequence::create(DelayTime::create(1.4),ScaleTo::create(0.3, 1.3*x_scale),ScaleTo::create(0.3, 1*x_scale), NULL)); imageLevel->runAction(Sequence::create(DelayTime::create(1.4),ScaleTo::create(0.3, 1.3*x_scale),ScaleTo::create(0.3, 1*x_scale), NULL)); imageBack->runAction(Sequence::create(DelayTime::create(1.4),ScaleTo::create(0.3, 1.3*x_scale),ScaleTo::create(0.3, 1*x_scale), NULL)); extraWordCount=0; lblExtra->runAction(Sequence::create(DelayTime::create(1),CCStringChange::create(""), NULL)); whichLevel++; int lastLevel=0; for (int i=0; i<=subLavel; i++) { lastLevel+=subLevelCount[i]; } if(whichLevel>lastLevel) subLavel++; if(subLavel>9) { subLavel=0; whichView++; } UserDefault::getInstance()->setIntegerForKey("currentSelectedLevel", whichLevel); UserDefault::getInstance()->setIntegerForKey("currentSelectedSubLavel", subLavel); UserDefault::getInstance()->setIntegerForKey("currentSelectedWhichView", whichView); UserDefault::getInstance()->flush(); time_t now=time(0) ; tm *ltm = localtime(&now); if(UserDefault::getInstance()->getBoolForKey("isRate")==false && ltm->tm_mday%3==0) { RattingPopup *objRate=RattingPopup::create(); this->addChild(objRate,5000,5000); objRate->setScale(0); objRate->imageLater->setScale(0); objRate->imageRate->setScale(0); objRate->runAction(Sequence::create(DelayTime::create(0.2), ScaleTo::create(0.5, 1.2*av_scale),ScaleTo::create(0.3, 1*av_scale), NULL)); objRate->imageLater->runAction(Sequence::create(DelayTime::create(0.8), ScaleTo::create(0.5, 1.2),ScaleTo::create(0.5, 1), NULL)); objRate->imageRate->runAction(Sequence::create(DelayTime::create(1), ScaleTo::create(0.5, 1.2),ScaleTo::create(0.5, 1), NULL)); } scheduleUpdate(); return true; } void LevelComplite::coinCollect() { for (int i=0;i<10;i++) { ccBezierConfig c; c.controlPoint_1=Vec2(452*x_scale,639*y_scale); c.controlPoint_2=Vec2(684*x_scale,828*y_scale); c.endPosition=Vec2(686*x_scale,134*y_scale); auto sp=createSprite(this,"coin.png",Vec2(452*x_scale,639*y_scale),0,100); sp->runAction(Sequence::create(DelayTime::create((0.2*i)),Spawn::create(BezierTo::create(1, c),CCSoundAction::create("collect_coin.mp3",0.72),NULL),RemoveSelf::create(),NULL)); BridgeClass::AddCoin(1); } imageNext->runAction(Sequence::create(DelayTime::create(1.4),EaseOut::create(ScaleTo::create(0.3, 1.3*x_scale), 1),EaseOut::create(ScaleTo::create(0.3, 1*y_scale), 1), NULL)); imageNext->runAction(Sequence::create(DelayTime::create(1.4),RotateTo::create(0.3, -50),RotateTo::create(0.2, 0), NULL)); } void LevelComplite::update(float dt) { if(BridgeClass::getCoin()>lastCoin) { lastCoin++; if(lastCoinsetString(__String::createWithFormat("%d",lastCoin)->getCString()); else lblCoin->setString(__String::createWithFormat("%d",BridgeClass::getCoin())->getCString()); if(lblCoin->getNumberOfRunningActions()==0) lblCoin->runAction(Sequence::create(ScaleTo::create(0.1, 1.1),ScaleTo::create(0.1,1),NULL)); } } bool LevelComplite::onTouchBegan(Touch* touch, Event* event) { location=touch->getLocationInView(); location=Director::getInstance()->convertToGL(location); location=this->convertToNodeSpace(location); if(this->getChildByTag(5000)) return true; if(imageShop->getBoundingBox().containsPoint(location)) { SimpleAudioEngine::getInstance()->playEffect(TAP_SOUND); ScaleInOutEffectOnce(imageShop); ShopScreen *shop=ShopScreen::create(); this->addChild(shop,5000,5000); shop->setPositionY(1024); shop->runAction(EaseBackOut::create(MoveTo::create(0.5, Vec2(0,0)))); } if(imageBack->getBoundingBox().containsPoint(location) && imageBack->getNumberOfRunningActions()==0) { SimpleAudioEngine::getInstance()->playEffect(TAP_SOUND); sdkbox::PluginAdMob::removeListener(); sdkbox::PluginUnityAds::removeListener(); sdkbox::PluginChartboost::removeListener(); ScaleInOutEffectOnce(imageBack); Director::getInstance()->replaceScene(TransitionFade::create(0.5, MapSubView::createScene())); } if(imageLevel->getBoundingBox().containsPoint(location) && imageLevel->getNumberOfRunningActions()==0) { SimpleAudioEngine::getInstance()->playEffect(TAP_SOUND); sdkbox::PluginAdMob::removeListener(); sdkbox::PluginUnityAds::removeListener(); sdkbox::PluginChartboost::removeListener(); ScaleInOutEffectOnce(imageLevel); Director::getInstance()->replaceScene(TransitionFade::create(0.5, MapView::createScene())); } if(imageBox->getBoundingBox().containsPoint(location) && imageBox->getTag()==10 ) { imageBox->setTag(0); imageBox->runAction(Sequence::create(CCImageChange::create("chest_5.png", 0),CallFunc::create(CC_CALLBACK_0(LevelComplite::coinCollect, this)), NULL)); this->runAction(Sequence::create(DelayTime::create(0.1),CCSoundAction::create("collect_coin.mp3", 0.72), NULL)); } if(imageNext->getBoundingBox().containsPoint(location)&& imageNext->getNumberOfRunningActions()==0) { SimpleAudioEngine::getInstance()->playEffect(TAP_SOUND); sdkbox::PluginAdMob::removeListener(); sdkbox::PluginUnityAds::removeListener(); sdkbox::PluginChartboost::removeListener(); ScaleInOutEffectOnce(imageNext); if(whichLevel>1000) { whichLevel=1; whichView=0; subLavel=0; UserDefault::getInstance()->setIntegerForKey("currentSelectedLevel", whichLevel); UserDefault::getInstance()->setIntegerForKey("currentSelectedSubLavel", subLavel); UserDefault::getInstance()->setIntegerForKey("currentSelectedWhichView", whichView); UserDefault::getInstance()->flush(); Director::getInstance()->replaceScene(TransitionFade::create(0.5, MainScreen::createScene())); } else Director::getInstance()->replaceScene(TransitionFade::create(0.5, PlayAreaWord::createScene())); } return true; } void LevelComplite::onTouchMoved(Touch *touch, Event *pEvent) { location=touch->getLocationInView(); location=Director::getInstance()->convertToGL(location); location=this->convertToNodeSpace(location); if(node) node->setPosition(location); } void LevelComplite::onTouchEnded(Touch *touch, Event *pEvent) { location=touch->getLocationInView(); location=Director::getInstance()->convertToGL(location); location=this->convertToNodeSpace(location); // CCLOG("====================================="); CCLOG("Vec2(%2.0f,%2.0f)",location.x,location.y); } void LevelComplite::onKeyReleased(EventKeyboard::KeyCode keyCode, cocos2d::Event *event) { if(EventKeyboard::KeyCode::KEY_ESCAPE==keyCode) { } } void LevelComplite::TouchOn() { _eventDispatcher->setEnabled(true); } void LevelComplite::TouchOff() { _eventDispatcher->setEnabled(false); }