Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MainScene.h"
- #include "GoalLayer.h"
- #include "ClockLayer.h"
- #include "StartScene.h"
- #include "ScrollLayer.h"
- #include "SimpleAudioEngine.h"
- #include "cocos2d.h"
- #include "util/SaveData.h"
- #include "util/WebView.h"
- #include "util/NativeLauncher.h"
- #include "util/LocalizedString.h"
- using namespace CocosDenshion;
- using namespace cocos2d;
- using namespace std;
- #define WH Director::getInstance()->getWinSize().height
- #define WW Director::getInstance()->getWinSize().width
- #define VW Director::getInstance()->getVisibleSize().width
- #define VH Director::getInstance()->getVisibleSize().height
- #define VX Director::getInstance()->getVisibleOrigin().x
- #define VY Director::getInstance()->getVisibleOrigin().y
- Scene* Main::createScene() {
- auto scene = Scene::create();
- auto layer = Main::create();
- scene->addChild(layer);
- return scene;
- }
- bool Main::init() {
- if (!Layer::init()) {
- return false;
- }
- FIXRATE=VH/320;
- log("fix:%f",FIXRATE);
- CENTERPOINT=Point(VX+VW/2,VY+VH/2);
- selectedCharaNum=0;
- collectCount=0;
- makeInterface();
- goalLayer=GoalLayer::create();
- goalLayer->setPosition(Point(VX,VY-40));
- this->addChild(goalLayer,42);
- goalLayer->setVisible(false);
- clockLayer=ClockLayer::create();
- clockLayer->setPosition(Point(VX + 100,VY +17));
- this->addChild(clockLayer,41);
- log("clocklayer = %f , %f", clockLayer->getPosition().x , clockLayer->getPosition().y);
- scrollLayer=ScrollLayer::create();
- scrollLayer->setDelegete(this);
- scrollLayer->makeInterface();
- scrollLayer->setContentSize(Size(1250*FIXRATE,768*FIXRATE));
- scrollLayer->setAnchorPoint(Point::ZERO);
- scrollLayer->setPosition(Point(0,0));
- scrollView = ScrollView::create(Size(VW,VH));
- scrollView->setViewSize(Size(VW,VH));
- scrollView->setContentSize(Size(VW,VH));
- scrollView->setPosition(Point(VX,VY));
- scrollView->setTag(501);
- scrollView->setDirection(ScrollView::Direction::BOTH);
- scrollView->setContainer(scrollLayer);
- scrollView->setContentOffset(Point(-300,-200),false);
- scrollView->setBounceable(false);
- this->addChild(scrollView,11);
- NativeLauncher::showAd(true);
- NativeLauncher::showCenterAd(false);
- auto listener = EventListenerTouchOneByOne::create();
- listener->onTouchBegan = CC_CALLBACK_2(Main::touchBegan, this);
- listener->onTouchEnded = CC_CALLBACK_2(Main::touchEnded, this);
- listener->onTouchMoved = CC_CALLBACK_2(Main::touchMoved, this);
- Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(
- listener, this);
- SimpleAudioEngine::getInstance()->playBackgroundMusic("bgm/bgm1.mp3",false);
- log("fin:%d",SaveData::loadInt("fin"));
- if(SaveData::loadInt("fin")==1){
- auto delayAction = DelayTime::create(0.8f);
- auto callSelectorAction = CallFunc::create(this,
- callfunc_selector(Main::goal));
- this->runAction(Sequence::create(delayAction, callSelectorAction, nullptr));
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////////
- // TOUCHES RELATED EVENT
- void Main::isLockLayer(bool isLockTmp){
- isLock=isLockTmp;
- }
- bool Main::touchBegan(Touch* touch, Event* event) {
- log("touchBegan Main");
- if(isLock){
- scrollView->setTouchEnabled(false);
- }
- return true;
- }
- void Main::touchMoved(Touch *touch, Event *event) {
- log("touchMoved Main");
- }
- void Main::touchEnded(Touch *touch, Event *event) {
- log("touchEnded Main");
- scrollView->setTouchEnabled(true);
- }
- void Main::reset(Ref* pSender){
- SaveData::saveInt("fin", 0);
- SaveData::saveInt("curentScoreTime", 0);
- playSound("action/flip.mp3");
- SimpleAudioEngine::getInstance()->playBackgroundMusic("bgm/bgm1.mp3",false);
- scrollLayer->reset();
- lastNumText->setString("47");
- goalLayer->setVisible(false);
- goalLayer->clearAnimation();
- clearObject(200);
- clearObject(2000);
- clockLayer->clockNeedle->runAction(RotateTo::create(0.2f,0.0));
- clockLayer->restartNeedle();
- }
- void Main::back(Ref* pSender){
- // SaveData::saveInt("back",1);
- SimpleAudioEngine::getInstance()->stopBackgroundMusic(true);
- auto pScene = Start::createScene();
- auto transition = TransitionFade::create(0.5f, pScene);
- Director::getInstance()->replaceScene(transition);
- }
- void Main::makeInterface(){
- auto titleImg=Sprite::create("title.png");
- titleImg->setPosition(Point(VX+titleImg->getContentSize().width/2,VY+VH - (titleImg->getContentSize().height /2)));
- this->addChild(titleImg,41);
- auto lastNumBox=Sprite::create("after-number.png");
- lastNumBox->setPosition(Point(CENTERPOINT.x-15,VY+VH-2-lastNumBox->getContentSize().height/2));
- this->addChild(lastNumBox,41);
- lastNumText=Label::createWithSystemFont("47","Arial Black",22*FIXRATE,Size::ZERO,TextHAlignment::CENTER,TextVAlignment::CENTER);
- lastNumText->setPosition(Point(CENTERPOINT.x-15,VY+VH-4-lastNumBox->getContentSize().height/2));
- lastNumText->setColor(Color3B::WHITE);
- this->addChild(lastNumText,41);
- auto titleLabel=Label::createWithSystemFont("パズル","Doroid Sans",22*FIXRATE,Size::ZERO,TextHAlignment::CENTER,TextVAlignment::CENTER);
- titleLabel->setPosition(Point(CENTERPOINT.x-55,VY+VH-lastNumBox->getContentSize().height/2));
- titleLabel->setColor(Color3B::ORANGE);
- this->addChild(titleLabel,41);
- auto resetBtn=MenuItemImage::create("icon-reset.png","icon-reset.png",CC_CALLBACK_1(Main::reset,this));
- resetBtn->setPosition(Point((VW-VX) - (resetBtn->getContentSize().width/2),VY+VH - (resetBtn->getContentSize().width/2)));
- auto btnMenu=Menu::create(resetBtn,nullptr);
- btnMenu->setPosition(Point::ZERO);
- this->addChild(btnMenu,41,1);
- auto backBtn=MenuItemImage::create("icon-home.png","icon-home.png",CC_CALLBACK_1(Main::back,this));
- backBtn->setPosition(Point(VX+10+backBtn->getContentSize().width/2,VY+10+backBtn->getContentSize().height/2));
- btnMenu->addChild(backBtn,41);
- }
- void Main::touchBackGround(Ref* pSender) {
- log("touch back");
- }
- void Main::clearObject(int num) {
- auto oldNum = this->getChildByTag(num);
- if (oldNum != nullptr) {
- oldNum->removeFromParentAndCleanup(true);
- }
- }
- void Main::showParticle(float dt){
- ParticleSystemQuad *particle;
- particle = ParticleSystemQuad::create("particle.plist");
- particle->resetSystem();
- particle->setPosition(this->getContentSize() / 2);
- particle->setTag(2000);
- this->addChild(particle, 40);
- }
- ////////////////////////////////////////////////////////////////////
- //サウンド
- void Main::prepareSound(){
- SimpleAudioEngine::getInstance()->preloadEffect("action/ending.mp3");
- SimpleAudioEngine::getInstance()->preloadEffect("action/flip.mp3");
- }
- void Main::playSound(const char *name) {
- SimpleAudioEngine::getInstance()->playEffect(name,false);
- }
- ///////////////////////////////////
- //DELEGATE
- void Main::updateScore(int count){
- log("count:%d",count);
- auto text=String::createWithFormat("%d",47-count);
- lastNumText->setString(text->getCString());
- }
- void Main::goal(){
- log("goal");
- SaveData::saveInt("fin",1);
- SimpleAudioEngine::getInstance()->stopBackgroundMusic(true);
- clockLayer->stopNeedle();
- int scoretime=clockLayer->scoreTime();
- if(SaveData::loadInt("scoreTime")==0 || SaveData::loadInt("scoreTime")>scoretime){
- SaveData::saveInt("scoreTime",scoretime);
- clockLayer->setHighScore(scoretime);
- }
- auto mask = LayerColor::create(Color4B(40, 40, 40, 180),
- WW, WH);
- this->addChild(mask, 41,300);
- bgBtn=MenuItemImage::create("",
- "", CC_CALLBACK_1(Main::touchBackGround,this));
- bgBtn->setContentSize(Size(VW,VH));
- bgBtn->setPosition(Point(VX+VW/2,VY+VH/2));
- menu=Menu::create(bgBtn,nullptr);
- menu->setPosition(Point::ZERO);
- this->addChild(menu,41,200);
- playSound("action/ending.mp3");
- goalLayer->makeScore(scoretime);
- goalLayer->setVisible(true);
- goalLayer->animation();
- this->scheduleOnce(schedule_selector(Main::showParticle), 1.0f);
- auto fileName=String::create("btn_close2.png");
- if(SaveData::loadInt("notJapanese")==1){
- fileName=String::create("btn_close2_en.png");
- }
- NativeLauncher::showCenterAd(true);
- goalCloseBtn=MenuItemImage::create(fileName->getCString(),fileName->getCString(), CC_CALLBACK_1(Main::removeGoal,this));
- goalCloseBtn->setPosition(CENTERPOINT.x, VY+50);
- // goalCloseBtn->setPosition(CENTERPOINT.x, VY+30);
- goalCloseBtn->setTag(301);
- auto goalCloseMenu=Menu::create(goalCloseBtn,nullptr);
- goalCloseMenu->setPosition(Point::ZERO);
- this->addChild(goalCloseMenu,42,301);
- }
- void Main::removeGoal(Ref* pSender) {
- clearObject(200);
- clearObject(300);
- clearObject(301);
- goalLayer->setVisible(false);
- goalLayer->clearAnimation();
- clearObject(2000);
- NativeLauncher::showAd(true);
- NativeLauncher::showCenterAd(false);
- // NativeLauncher::showInterAd(true);
- }
Add Comment
Please, Sign In to add comment