#include "level1.h" #include "level2.h" #include "menu.h" #include "SimpleAudioEngine.h" using namespace CocosDenshion; USING_NS_CC; Scene* level1::createScene() { auto scene = Scene::createWithPhysics(); scene->getPhysicsWorld()->setGravity(Vec2(0,-2000)); auto layer = level1::create(); layer->setPhysicsWorld(scene->getPhysicsWorld()); scene->addChild(layer); return scene; } bool level1::init() { if (!Scene::init()) { return false; } auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); //menu tombolPause1 = MenuItemImage::create("gfx/paused.png", "gfx/paused clicked.png", CC_CALLBACK_1(level1::OutputTombolPause, this)); tombolPause1->setPosition(Vec2(visibleSize.width / 2 - 550 + origin.x, visibleSize.height + origin.y - 100)); tombolPause1->setScale(0.35f); menuPause = Menu::create(tombolPause1, NULL); menuPause->setPosition(Vec2::ZERO); menuPause->setLocalZOrder(11); menuPause->setVisible(false); this->addChild(menuPause); judulPaused = Sprite::create("gfx/pausedJudul.png"); judulPaused->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y + 250)); judulPaused->setScale(0.35f); judulPaused->setLocalZOrder(11); judulPaused->setVisible(false); this->addChild(judulPaused); continue1 = MenuItemImage::create("gfx/continue.png", "gfx/continue clicked.png", CC_CALLBACK_1(level1::OutputContinue, this)); continue1->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y)); continue1->setScale(0.35f); menu1 = MenuItemImage::create("gfx/menu.png", "gfx/menu clicked.png", CC_CALLBACK_1(level1::OutputMenu, this)); menu1->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y - 100)); menu1->setScale(0.35f); menuPause2 = Menu::create(continue1, menu1, NULL); menuPause2->setPosition(Vec2::ZERO); menuPause2->setLocalZOrder(11); menuPause2->setVisible(false); this->addChild(menuPause2); penutup0 = Sprite::create("gfx/hitam.jpg"); penutup0->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y)); penutup0->setOpacity(100.0f); penutup0->setVisible(false); penutup0->setLocalZOrder(10); this->addChild(penutup0); //bool melaju = true; melaju2 = true; cekSentuhan2 = true; cekLompat = true; cekLompat2 = true; //int truee = 1; //opening this->scheduleOnce(schedule_selector(level1::helloVoid),2.0f); this->scheduleOnce(schedule_selector(level1::welcomeVoid), 6.0f); this->scheduleOnce(schedule_selector(level1::game), 9.0f); this->scheduleOnce(schedule_selector(level1::cameraKembali), 9.4f); this->scheduleOnce(schedule_selector(level1::sambutanHangatt), 13.0f); this->scheduleOnce(schedule_selector(level1::sambutanHangattt), 16.5f); this->scheduleOnce(schedule_selector(level1::cameraKembali2), 16.4f); //penutup paralax11 = Sprite::create("gfx/paralax1.png"); paralax11->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax11->setLocalZOrder(-10); paralax11->setOpacity(0.0f); paralax11->setScale(0.5f); this->addChild(paralax11); paralax22 = Sprite::create("gfx/paralax2.png"); paralax22->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax22->setLocalZOrder(-11); paralax22->setOpacity(0.0f); paralax22->setScale(0.5f); this->addChild(paralax22); paralax33 = Sprite::create("gfx/paralax3.png"); paralax33->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax33->setLocalZOrder(-12); paralax33->setOpacity(0.0f); paralax33->setScale(0.5f); this->addChild(paralax33); paralax44 = Sprite::create("gfx/paralax4.png"); paralax44->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax44->setLocalZOrder(-13); paralax44->setOpacity(0.0f); paralax44->setScale(0.5f); this->addChild(paralax44); paralax55 = Sprite::create("gfx/paralax5.png"); paralax55->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax55->setLocalZOrder(-14); paralax55->setOpacity(0.0f); paralax55->setScale(0.5f); this->addChild(paralax55); paralax1 = Sprite::create("gfx/paralax1.png"); paralax1->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax1->setLocalZOrder(-5); paralax1->setOpacity(0.0f); paralax1->setScale(0.5f); this->addChild(paralax1); paralax2 = Sprite::create("gfx/paralax2.png"); paralax2->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax2->setLocalZOrder(-6); paralax2->setOpacity(0.0f); paralax2->setScale(0.5f); this->addChild(paralax2); paralax3 = Sprite::create("gfx/paralax3.png"); paralax3->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax3->setLocalZOrder(-7); paralax3->setOpacity(0.0f); paralax3->setScale(0.5f); this->addChild(paralax3); paralax4 = Sprite::create("gfx/paralax4.png"); paralax4->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax4->setLocalZOrder(-8); paralax4->setOpacity(0.0f); paralax4->setScale(0.5f); this->addChild(paralax4); paralax5 = Sprite::create("gfx/paralax5.png"); paralax5->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 200)); paralax5->setLocalZOrder(-14); paralax5->setOpacity(0.0f); paralax5->setScale(0.5f); this->addChild(paralax5); // auto penutup = Sprite::create("gfx/hitam.jpg"); penutup->setPosition(Vec2(-visibleSize.width, -visibleSize.height - 1425)); penutup->setLocalZOrder(11); this->addChild(penutup); auto penutup2 = Sprite::create("gfx/hitam.jpg"); penutup2->setPosition(Vec2(-visibleSize.width - 2145, -visibleSize.height - 500)); penutup2->setLocalZOrder(1); this->addChild(penutup2); auto penutup3 = Sprite::create("gfx/hitam.jpg"); penutup3->setPosition(Vec2(-visibleSize.width + 2145, -visibleSize.height - 500)); penutup3->setLocalZOrder(1); this->addChild(penutup3); //game batas = Sprite::create("gfx/hitam.jpg"); batas->setPosition(Vec2(-visibleSize.width, -visibleSize.height - 1335)); auto batasmaterial = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto batasbody1 = PhysicsBody::createBox(batas->getContentSize(), batasmaterial); batasbody1->setCollisionBitmask(3); batasbody1->setContactTestBitmask(true); batasbody1->setDynamic(false); batas->setPhysicsBody(batasbody1); this->addChild(batas); batas2 = Sprite::create("gfx/hitam.jpg"); batas2->setPosition(Vec2(-visibleSize.width - 1905, -visibleSize.height - 900)); auto batasmaterial2 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto batasbody2 = PhysicsBody::createBox(batas2->getContentSize(), batasmaterial2); batasbody2->setDynamic(false); batasbody2->setCollisionBitmask(4); batasbody2->setContactTestBitmask(true); batas2->setPhysicsBody(batasbody2); this->addChild(batas2); batas4 = Sprite::create("gfx/hitam.jpg"); batas4->setPosition(Vec2(-visibleSize.width + 1905, -visibleSize.height - 900)); auto batasmaterial4 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto batasbody4 = PhysicsBody::createBox(batas4->getContentSize(), batasmaterial4); batasbody4->setDynamic(false); batasbody2->setCollisionBitmask(4); batasbody2->setContactTestBitmask(true); batas4->setPhysicsBody(batasbody4); this->addChild(batas4); block1 = Sprite::create("gfx/base3.png"); block1->setPosition(Vec2(-visibleSize.width, -visibleSize.height - 50)); block1->setOpacity(0.0f); block1->setScale(0.5f); block1->setScaleX(1.8f); this->addChild(block1); block2 = Sprite::create("gfx/base4.png"); block2->setPosition(Vec2(-visibleSize.width - 700, -visibleSize.height - 100)); block2->setLocalZOrder(2); block2->setOpacity(0.0f); auto groundMaterial2 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body2 = PhysicsBody::createBox(block2->getContentSize(), groundMaterial2); body2->setDynamic(false); body2->setCollisionBitmask(4); body2->setContactTestBitmask(true); block2->setPhysicsBody(body2); this->addChild(block2); block3 = Sprite::create("gfx/base3.png"); block3->setPosition(Vec2(-visibleSize.width - 640, -visibleSize.height + 380)); block3->setLocalZOrder(2); block3->setOpacity(0.0f); auto groundMaterial3 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body3 = PhysicsBody::createBox(block3->getContentSize(), groundMaterial3); body3->setDynamic(false); block3->setPhysicsBody(body3); this->addChild(block3); block4 = Sprite::create("gfx/base3.png"); block4->setPosition(Vec2(-visibleSize.width - 520, -visibleSize.height + 600)); block4->setOpacity(0.0f); block4->setLocalZOrder(2); auto groundMaterial4 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body4 = PhysicsBody::createBox(block4->getContentSize(), groundMaterial4); body4->setDynamic(false); block4->setPhysicsBody(body4); this->addChild(block4); block5 = Sprite::create("gfx/base3.png"); block5->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 840)); block5->setOpacity(0.0f); block5->setLocalZOrder(2); auto groundMaterial5 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body5 = PhysicsBody::createBox(block5->getContentSize(), groundMaterial5); body5->setDynamic(false); block5->setPhysicsBody(body5); this->addChild(block5); block6 = Sprite::create("gfx/base4.png"); block6->setPosition(Vec2(-visibleSize.width + 700, -visibleSize.height - 100)); block6->setOpacity(0.0f); auto groundMaterial6 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body6 = PhysicsBody::createBox(block6->getContentSize(), groundMaterial6); body6->setDynamic(false); body6->setCollisionBitmask(4); body6->setContactTestBitmask(true); block6->setPhysicsBody(body6); block6->setLocalZOrder(2); this->addChild(block6); block7 = Sprite::create("gfx/base3.png"); block7->setPosition(Vec2(-visibleSize.width + 640, -visibleSize.height + 380)); block7->setOpacity(0.0f); block7->setLocalZOrder(2); auto groundMaterial7 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body7 = PhysicsBody::createBox(block7->getContentSize(), groundMaterial7); body7->setDynamic(false); block7->setPhysicsBody(body7); this->addChild(block7); block8 = Sprite::create("gfx/base3.png"); block8->setPosition(Vec2(-visibleSize.width + 520, -visibleSize.height + 600)); block8->setOpacity(0.0f); block8->setLocalZOrder(2); auto groundMaterial8 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body8 = PhysicsBody::createBox(block8->getContentSize(), groundMaterial8); body8->setDynamic(false); block8->setPhysicsBody(body8); this->addChild(block8); block9 = Sprite::create("gfx/base3.png"); block9->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 840)); block9->setOpacity(0.0f); block9->setLocalZOrder(2); auto groundMaterial9 = PhysicsMaterial(0.0f, 0.0f, 0.0f); auto body9 = PhysicsBody::createBox(block9->getContentSize(), groundMaterial9); body9->setDynamic(false); block9->setPhysicsBody(body9); this->addChild(block9); kucing = Sprite::create("gfx/gameplay/animKanan/kanan1.png"); kucing->setOpacity(0.0f); kucing->setScale(1.5f); auto playerMaterial = PhysicsMaterial(10.0f, 0.0f, 0.0f); auto playerBody = PhysicsBody::createBox(kucing->getContentSize() / 2, playerMaterial); playerBody->setCollisionBitmask(1); playerBody->setContactTestBitmask(true); auto fl = Follow::create(kucing, Rect::ZERO); fl->setTag(80); this->runAction(fl); playerBody->addMass(1); playerBody->setRotationEnable(false); kucing->setPhysicsBody(playerBody); kucing->setLocalZOrder(1); kucing->setPosition(Vec2(-visibleSize.width - 450, -visibleSize.height + 50)); this->addChild(kucing); Vector frames = Vector(); frames.pushBack(Sprite::create("gfx/gameplay/animKanan/kanan1.png")->getSpriteFrame()); frames.pushBack(Sprite::create("gfx/gameplay/animKanan/kanan2.png")->getSpriteFrame()); frames.pushBack(Sprite::create("gfx/gameplay/animKanan/kanan2.png")->getSpriteFrame()); cocos2d::Animation* anim = cocos2d::Animation::createWithSpriteFrames(frames, 0.1f); anim->setLoops(-1); cocos2d::Animate* anim_action = cocos2d::Animate::create(anim); anim_action->setTag(99); kucing->runAction(anim_action); //gate gate1 = Sprite::create("gfx/gate.png"); gate1->setPosition(Vec2(-visibleSize.width - 450, -visibleSize.height + 90)); gate1->setOpacity(0.0f); gate1->setLocalZOrder(-1); gate1->setScale(0.5f); this->addChild(gate1); gate2 = Sprite::create("gfx/gate.png"); gate2->setPosition(Vec2(-visibleSize.width + 450, -visibleSize.height + 90)); gate2->setOpacity(0.0f); gate2->setScale(0.5f); gate2->setLocalZOrder(-1); this->addChild(gate2); //com pipe = Sprite::create("gfx/gameplay/pipe.png"); pipe->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 60)); pipe->setOpacity(0.0f); pipe->setScale(0.3f); pipe->setLocalZOrder(-2); this->addChild(pipe); com = Sprite::create("gfx/gameplay/computer01.png"); com->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 130)); com->setOpacity(0.0f); this->addChild(com); sambutanHangat = Sprite::create("gfx/gameplay/sambutanHangat.png"); sambutanHangat->setOpacity(0.0f); sambutanHangat->setScale(1.5f); sambutanHangat->setPosition(Vec2(-visibleSize.width, -visibleSize.height + 180)); this->addChild(sambutanHangat); //kontak auto contactListener = EventListenerPhysicsContact::create(); contactListener->onContactBegin = CC_CALLBACK_1(level1::kontak, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this); //jejak UserDefault *JEJAK11 = UserDefault::getInstance(); JejakLevel11 = JEJAK11->getIntegerForKey("JEJAK111", 0); UserDefault *LEV22 = UserDefault::getInstance(); perpindahanLevel222 = LEV22->getIntegerForKey("LEV22", 1); return true; } void level1::OutputContinue(Ref*sender) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/click.mp3"); // cekSentuhan2 = true; penutup0->setVisible(false); menuPause->setVisible(true); menuPause2->setVisible(false); judulPaused->setVisible(false); } void level1::OutputMenu(Ref*sender) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/click.mp3"); // auto scene = menu::createScene(); Director::getInstance()->replaceScene(TransitionFade::create(1.0f, scene)); } void level1::OutputTombolPause(Ref*sender) { cekSentuhan2 = false; judulPaused->setVisible(true); penutup0->setVisible(true); menuPause->setVisible(false); menuPause2->setVisible(true); } void level1::cameraKembali(float dt) { auto fl = Follow::create(kucing, Rect::ZERO); fl->setTag(80); this->runAction(fl); } void level1::cameraKembali2(float dt) { auto fl = Follow::create(kucing, Rect::ZERO); fl->setTag(80); this->runAction(fl); } bool level1::kontak(cocos2d::PhysicsContact &contact) { PhysicsBody *a = contact.getShapeA()->getBody(); PhysicsBody *b = contact.getShapeB()->getBody(); if ((1 == a->getCollisionBitmask() && 2 == b->getCollisionBitmask()) || (2 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())) { //menghentikan suara langkah SimpleAudioEngine::getInstance()->stopEffect(ID_audio_step_right); SimpleAudioEngine::getInstance()->stopEffect(ID_audio_step_left); // auto mendekat = ScaleBy::create(0.5f, 1.2f); this->runAction(mendekat); if (JejakLevel11 < 1) { perpindahanLevel222++; UserDefault::getInstance()->setIntegerForKey("LEV22", perpindahanLevel222); JejakLevel11++; int aduh = JejakLevel11; UserDefault::getInstance()->setIntegerForKey("JEJAK111", aduh); } auto scene = level2::createScene(); Director::getInstance()->replaceScene(TransitionFade::create(0.5f,scene)); } if ((1 == a->getCollisionBitmask() && 3 == b->getCollisionBitmask()) || (3 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())) { truee = 1; cekLompat = true; cekLompat2 = true; this->unschedule(schedule_selector(level1::gravityKembali2)); } if ((1 == a->getCollisionBitmask() && 4 == b->getCollisionBitmask()) || (4 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask())) { } return true; } void level1::sambutanHangattt(float dt) { this->stopActionByTag(80); auto shake1 = MoveBy::create(0.1f, Vec2(-20, 0)); auto shake2 = MoveBy::create(0.1f, Vec2(0, 20)); auto shake3 = MoveBy::create(0.1f, Vec2(0, -20)); auto shake4 = MoveBy::create(0.1f, Vec2(20, 0)); auto sq = Sequence::create(shake1, shake2, shake3, shake4, NULL); auto repeat = Repeat::create(sq, 2); this->runAction(repeat); auto gateMaterial = PhysicsMaterial(10.0f, 0.0f, 0.0f); auto gateBody = PhysicsBody::createBox(gate2->getContentSize() / 2.0f, gateMaterial); gateBody->setCollisionBitmask(2); gateBody->setContactTestBitmask(true); gateBody->setDynamic(false); gate2->setPhysicsBody(gateBody); } void level1::sambutanHangatt(float dt) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/click.mp3"); // auto muncul = FadeIn::create(1.0f); auto muncul2 = FadeIn::create(1.0f); auto sq = Sequence::create(muncul, DelayTime::create(2.0f), RemoveSelf::create(), NULL); sambutanHangat->runAction(sq); auto dl = DelayTime::create(3.0f); auto sq2 = Sequence::create( dl,muncul2, NULL); gate2->runAction(sq2); } void level1::helloVoid(float dt) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/click.mp3"); // hello = Label::createWithTTF("HELLO WORLD", "fonts/slkscr.ttf", 60); hello->setPosition(visibleSize.width + origin.x + 683, visibleSize.height + origin.y + 384); hello->setLocalZOrder(10); hello->setOpacity(0.0f); auto muncul = FadeIn::create(1.0f); auto hilang = FadeOut::create(1.0f); auto sq = Sequence::create(muncul,DelayTime::create(1.0f), hilang, NULL); hello->runAction(sq); this->addChild(hello); } void level1::welcomeVoid(float dt) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/click.mp3"); // welcome = Label::createWithTTF("WELCOME TO REEDkw", "fonts/slkscr.ttf", 60); welcome->setPosition(visibleSize.width + origin.x + 683, visibleSize.height + origin.y + 384); welcome->setLocalZOrder(10); welcome->setOpacity(0.0f); welcome->enableGlow(Color4B::YELLOW); auto muncul = FadeIn::create(1.0f); auto hilang = FadeOut::create(1.0f); auto sq = Sequence::create(muncul, DelayTime::create(1.0f), hilang, NULL); welcome->runAction(sq); this->addChild(welcome); } void level1::game(float dt) { //audio auto audio1 = SimpleAudioEngine::getInstance(); audio1->playBackgroundMusic("sfx/thunder.mp3", true); // //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/fire.mp3"); // menuPause->setVisible(true); this->stopActionByTag(80); auto shake1 = MoveBy::create(0.1f, Vec2(-20, 0)); auto shake2 = MoveBy::create(0.1f, Vec2(0, 20)); auto shake3 = MoveBy::create(0.1f, Vec2(0, -20)); auto shake4 = MoveBy::create(0.1f, Vec2(20, 0)); auto sq = Sequence::create(shake1, shake2, shake3, shake4, NULL); auto repeat = Repeat::create(sq, 2); this->runAction(repeat); auto muncul = FadeIn::create(1.0f); auto muncul2 = FadeIn::create(1.0f); auto muncul3 = FadeIn::create(1.0f); auto muncul4 = FadeIn::create(1.0f); auto muncul5 = FadeIn::create(1.0f); auto muncul6 = FadeIn::create(1.0f); auto muncul7 = FadeIn::create(1.0f); auto muncul8 = FadeIn::create(1.0f); auto muncul9 = FadeIn::create(1.0f); auto muncul10 = FadeIn::create(1.0f); auto muncul11 = FadeIn::create(1.0f); auto muncul12 = FadeIn::create(1.0f); auto muncul13 = FadeIn::create(1.0f); auto muncul14 = FadeIn::create(1.0f); auto muncul15 = FadeIn::create(1.0f); auto muncul16 = FadeIn::create(1.0f); auto muncul17 = FadeIn::create(1.0f); auto muncul18 = FadeIn::create(1.0f); auto muncul19 = FadeIn::create(1.0f); auto muncul20 = FadeIn::create(1.0f); auto muncul21 = FadeIn::create(1.0f); auto muncul22 = FadeIn::create(1.0f); auto muncul23 = FadeIn::create(1.0f); block1->runAction(muncul); kucing->runAction(muncul2); block2->runAction(muncul3); block3->runAction(muncul4); block4->runAction(muncul5); block5->runAction(muncul6); block6->runAction(muncul7); block7->runAction(muncul8); block8->runAction(muncul9); block9->runAction(muncul10); gate1->runAction(muncul11); pipe->runAction(muncul12); com->runAction(muncul13); paralax1->runAction(muncul14); paralax2->runAction(muncul15); paralax3->runAction(muncul16); paralax4->runAction(muncul17); paralax5->runAction(muncul18); paralax11->runAction(muncul19); paralax22->runAction(muncul20); paralax33->runAction(muncul21); paralax44->runAction(muncul22); paralax55->runAction(muncul23); //input auto keylistener = EventListenerKeyboard::create(); keylistener->onKeyPressed = CC_CALLBACK_2(level1::panahatas, this); keylistener->onKeyReleased = CC_CALLBACK_2(level1::panahataslepas, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(keylistener, this); //userdefault UserDefault *LEV22 = UserDefault::getInstance(); perpindahanLevel222 = LEV22->getIntegerForKey("LEV22", 1); } void level1::panahatas(EventKeyboard::KeyCode keyCode, Event* event) { if (cekSentuhan2 == true) { if (keyCode == EventKeyboard::KeyCode::KEY_UP_ARROW ) { //menghentikan suara langkah SimpleAudioEngine::getInstance()->stopEffect(ID_audio_step_right); SimpleAudioEngine::getInstance()->stopEffect(ID_audio_step_left); // if (truee <= 2 && cekLompat == true) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/jump.mp3"); // cekLompat = false; truee++; auto moveUp = MoveBy::create(0.18f, Vec2(0, 160)); auto hampirmelayang = MoveBy::create(0.05f, Vec2(0, 20)); auto melayang = MoveBy::create(0.05f, Vec2(0, 10)); auto repeat = Sequence::create(moveUp, hampirmelayang, melayang, NULL); kucing->runAction(repeat); this->scheduleOnce(schedule_selector(level1::gravityKembali2), 0.2f); } else if (truee <= 2 && cekLompat == false) { if (cekLompat2 == true ) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/jump.mp3"); // truee++; auto moveUp = MoveBy::create(0.18f, Vec2(0, 150)); auto hampirmelayang = MoveBy::create(0.05f, Vec2(0, 20)); auto melayang = MoveBy::create(0.05f, Vec2(0, 10)); auto repeat = Sequence::create(moveUp, hampirmelayang, melayang, NULL); kucing->runAction(repeat); cekLompat2 = true; this->unschedule(schedule_selector(level1::gravityKembali2)); } if(cekLompat2 == false ) { //audio auto audio3 = SimpleAudioEngine::getInstance(); audio3->playEffect("sfx/jump.mp3"); // auto world = _director->getRunningScene()->getPhysicsWorld(); world->setGravity(Vec2(0,2800)); this->scheduleOnce(schedule_selector(level1::gravityKembali), 0.2f); truee++; auto moveUp = MoveBy::create(0.18f, Vec2(0, 150)); auto hampirmelayang = MoveBy::create(0.05f, Vec2(0, 20)); auto melayang = MoveBy::create(0.05f, Vec2(0, 10)); auto repeat = Sequence::create(moveUp, hampirmelayang, melayang, NULL); kucing->runAction(repeat); cekLompat2 = true; } } } if (keyCode == EventKeyboard::KeyCode::KEY_RIGHT_ARROW) { //audio jalan auto audio_step_right = SimpleAudioEngine::getInstance(); audio_step_right->playEffect("sfx/click.mp3", true); audio_step_right->setEffectsVolume(0.50f); ID_audio_step_right; ID_audio_step_right = audio_step_right->playEffect("sfx/click.mp3", true); // kucing->stopActionByTag(99); kucing->stopActionByTag(98); kucing->stopActionByTag(97); auto kanan = MoveBy::create(0.2f, Vec2(70, 0)); auto kanann = RepeatForever::create(kanan); kucing->runAction(kanann); Vector frames = Vector(); frames.pushBack(Sprite::create("gfx/gameplay/animKanan/kanan1.png")->getSpriteFrame()); frames.pushBack(Sprite::create("gfx/gameplay/animKanan/kanan2.png")->getSpriteFrame()); frames.pushBack(Sprite::create("gfx/gameplay/animKanan/kanan2.png")->getSpriteFrame()); cocos2d::Animation* anim = cocos2d::Animation::createWithSpriteFrames(frames, 0.1f); anim->setLoops(-1); cocos2d::Animate* anim_action2 = cocos2d::Animate::create(anim); anim_action2->setTag(98); kucing->runAction(anim_action2); //paralax auto paralaxKanan = MoveBy::create(1.0f, Vec2(20, 0)); auto paralaxKanan2 = MoveBy::create(0.8f, Vec2(30, 0)); auto paralaxKanan3 = MoveBy::create(0.6f, Vec2(40, 0)); auto paralaxKanan4 = MoveBy::create(0.4f, Vec2(50, 0)); auto sq = RepeatForever::create(paralaxKanan); auto sq2 = RepeatForever::create(paralaxKanan2); auto sq3 = RepeatForever::create(paralaxKanan3); auto sq4 = RepeatForever::create(paralaxKanan4); sq->setTag(70); sq2->setTag(71); sq3->setTag(72); sq4->setTag(73); paralax1->runAction(sq); paralax2->runAction(sq2); paralax3->runAction(sq3); paralax4->runAction(sq4); melaju = false; } if (keyCode == EventKeyboard::KeyCode::KEY_LEFT_ARROW) { //audio auto audio_step_left = SimpleAudioEngine::getInstance(); audio_step_left->playEffect("sfx/click.mp3", true); audio_step_left->setEffectsVolume(0.50f); ID_audio_step_left; ID_audio_step_left = audio_step_left->playEffect("sfx/click.mp3", true); // kucing->stopActionByTag(99); kucing->stopActionByTag(98); kucing->stopActionByTag(97); auto kiri = MoveBy::create(0.2f, Vec2(-70, 0)); auto kirii = RepeatForever::create(kiri); kucing->runAction(kirii); Vector frames = Vector(); frames.pushBack(Sprite::create("gfx/gameplay/animKiri/kiri1.png")->getSpriteFrame()); frames.pushBack(Sprite::create("gfx/gameplay/animKiri/kiri2.png")->getSpriteFrame()); frames.pushBack(Sprite::create("gfx/gameplay/animKiri/kiri3.png")->getSpriteFrame()); cocos2d::Animation* anim = cocos2d::Animation::createWithSpriteFrames(frames, 0.1f); anim->setLoops(-1); cocos2d::Animate* anim_action3 = cocos2d::Animate::create(anim); anim_action3->setTag(97); kucing->runAction(anim_action3); //paralax auto paralaxKanan = MoveBy::create(1.0f, Vec2(-20, 0)); auto paralaxKanan2 = MoveBy::create(0.8f, Vec2(-30, 0)); auto paralaxKanan3 = MoveBy::create(0.6f, Vec2(-40, 0)); auto paralaxKanan4 = MoveBy::create(0.4f, Vec2(-50, 0)); auto sq = RepeatForever::create(paralaxKanan); auto sq2 = RepeatForever::create(paralaxKanan2); auto sq3 = RepeatForever::create(paralaxKanan3); auto sq4 = RepeatForever::create(paralaxKanan4); sq->setTag(74); sq2->setTag(75); sq3->setTag(76); sq4->setTag(77); paralax1->runAction(sq); paralax2->runAction(sq2); paralax3->runAction(sq3); paralax4->runAction(sq4); melaju2 = false; } } } void level1::panahataslepas(EventKeyboard::KeyCode keyCode, Event* event) { if (cekSentuhan2 == true) { if (keyCode == EventKeyboard::KeyCode::KEY_RIGHT_ARROW && melaju == false) { //audio SimpleAudioEngine::getInstance()->stopEffect(ID_audio_step_right); // auto kananStop = MoveBy::create(0.2f, Vec2(-70, 0)); auto kanann = RepeatForever::create(kananStop); kucing->runAction(kanann); auto paralaxKanan = MoveBy::create(1.0f, Vec2(-20, 0)); auto paralaxKanan2 = MoveBy::create(0.8f, Vec2(-30, 0)); auto paralaxKanan3 = MoveBy::create(0.6f, Vec2(-40, 0)); auto paralaxKanan4 = MoveBy::create(0.4f, Vec2(-50, 0)); auto sq = RepeatForever::create(paralaxKanan); auto sq2 = RepeatForever::create(paralaxKanan2); auto sq3 = RepeatForever::create(paralaxKanan3); auto sq4 = RepeatForever::create(paralaxKanan4); sq->setTag(60); sq2->setTag(61); sq3->setTag(62); sq4->setTag(63); paralax1->runAction(sq); paralax2->runAction(sq2); paralax3->runAction(sq3); paralax4->runAction(sq4); melaju = true; } if (keyCode == EventKeyboard::KeyCode::KEY_LEFT_ARROW && melaju2 == false) { //audio SimpleAudioEngine::getInstance()->stopEffect(ID_audio_step_left); // auto kiriStop = MoveBy::create(0.2f, Vec2(70, 0)); auto kirii = RepeatForever::create(kiriStop); kucing->runAction(kirii); auto paralaxKanan = MoveBy::create(1.0f, Vec2(20, 0)); auto paralaxKanan2 = MoveBy::create(0.8f, Vec2(30, 0)); auto paralaxKanan3 = MoveBy::create(0.6f, Vec2(40, 0)); auto paralaxKanan4 = MoveBy::create(0.4f, Vec2(50, 0)); auto sq = RepeatForever::create(paralaxKanan); auto sq2 = RepeatForever::create(paralaxKanan2); auto sq3 = RepeatForever::create(paralaxKanan3); auto sq4 = RepeatForever::create(paralaxKanan4); sq->setTag(64); sq2->setTag(65); sq3->setTag(66); sq4->setTag(67); paralax1->runAction(sq); paralax2->runAction(sq2); paralax3->runAction(sq3); paralax4->runAction(sq4); melaju2 = true; } } } void level1::gravityKembali(float dt) { auto world2 = _director->getRunningScene()->getPhysicsWorld(); world2->setGravity(Vec2(0, -2000)); } void level1::gravityKembali2(float dt) { cekLompat2 = false; this->scheduleOnce(schedule_selector(level1::gravityKembali3), 0.2f); } void level1::gravityKembali3(float dt) { cekLompat2 = true; }