Browse Source

Adicionando som

capellaresumo 7 years ago
parent
commit
ee1525d644

+ 2 - 2
Classes/AppDelegate.cpp

@@ -3,7 +3,7 @@
 #include "GameScene.h"
 
 // #define USE_AUDIO_ENGINE 1
-// #define USE_SIMPLE_AUDIO_ENGINE 1
+#define USE_SIMPLE_AUDIO_ENGINE 1
 
 #if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
 #error "Don't use AudioEngine and SimpleAudioEngine at the same time. Please just select one in your game!"
@@ -89,7 +89,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
     register_all_packages();
 
     // create a scene. it's an autorelease object
-    auto scene = GameScene::createScene();
+    auto scene = HelloWorld::createScene();
 
     // run
     director->runWithScene(scene);

+ 1 - 1
Classes/BlocksLayer.cpp

@@ -22,7 +22,7 @@ bool BlocksLayer::init() {
     this->setPosition(center);
     
     // aumentar aqui
-    for (int i = -1; i >= 0; i--) {
+    for (int i = 5; i >= 0; i--) {
         auto circle = createCircle(CORE_RADIUS*0.75, i, 10, 0.2);
         this->addChild(circle, 9);
     }

+ 28 - 7
Classes/GameScene.cpp

@@ -48,6 +48,13 @@ bool GameScene::init() {
         return false;
     }
     
+    // https://www.freesound.org/people/schademans/sounds/13290/
+    FileUtils::getInstance()->addSearchPath("res");
+    auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
+    audio->preloadEffect("pipe.wav");
+    audio->preloadEffect("metal.wav");
+    audio->preloadEffect("bomb.wav");
+    
     auto visibleSize = Director::getInstance()->getVisibleSize();
     Vec2 origin = Director::getInstance()->getVisibleOrigin();
     
@@ -130,12 +137,14 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
     if (nodeA && nodeB && nodeA->getTag() != nodeB->getTag()) {
         CCLOG("%d %d", nodeB->getTag(), nodeA->getTag());
         
-        if (nodeA->getTag() == BLOCK_TAG) {
-            nodeA->removeFromParentAndCleanup(true);
-        } else if (nodeB->getTag() == BLOCK_TAG) {
+        // sempre B < A
+        if (nodeB->getTag() == BLOCK_TAG) {
+            auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
+            audio->playEffect("pipe.wav");
             nodeB->removeFromParentAndCleanup(true);
-        } else if (nodeA->getTag() == BOTTOM_TAG && nodeB->getTag() == BALL_TAG) {
-            ball_collision(nodeB);
+        } if (nodeB->getTag() == INDESTRUCTIBLE_BLOCK_TAG) {
+            auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
+            audio->playEffect("metal.wav");
         } else if (nodeB->getTag() == BOTTOM_TAG && nodeA->getTag() == BALL_TAG) {
             ball_collision(nodeA);
         }  else if (nodeB->getTag() == CORE_TAG && nodeA->getTag() == BALL_TAG) {
@@ -144,11 +153,17 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
             ball_core(nodeA, nodeB);
         }
     }
-    //bodies can collide
     return true;
 }
 
 void GameScene::ball_collision (Node *ball) {
+    auto visibleSize = Director::getInstance()->getVisibleSize();
+    auto text = Label::createWithTTF("Game Over...", "fonts/Marker Felt.ttf", 40);
+    text->setPosition(visibleSize.width/2, visibleSize.height/2);
+    this->addChild(text);
+    
+    auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
+    audio->playEffect("bomb.wav");
     ParticleSun* m_emitter = ParticleSun::create();
     m_emitter->setPosition(ball->getPosition());
     m_emitter->setDuration(1);
@@ -163,7 +178,7 @@ void GameScene::ball_core (Node *core, Node *ball) {
     
     auto callbackRotate = CallFunc::create([=](){
         auto visibleSize = Director::getInstance()->getVisibleSize();
-        auto menu_item_start = MenuItemFont::create("Next Level");
+        auto menu_item_start = MenuItemFont::create("Next Level", CC_CALLBACK_1(GameScene::NextLevel, this));
         menu_item_start->setPosition(Point(visibleSize.width / 2, (visibleSize.height / 2)));
         auto *menu = Menu::create(menu_item_start, NULL);
         menu->setPosition(Point(0, 0));
@@ -175,3 +190,9 @@ void GameScene::ball_core (Node *core, Node *ball) {
     core->runAction(seq);
     ball->removeFromParentAndCleanup(true);
 }
+
+void GameScene::NextLevel(cocos2d::Ref *pSender) {
+    auto scene = GameScene::createScene();
+    Director::getInstance()->replaceScene(scene);
+    //Director::getInstance()->end();
+}

+ 1 - 0
Classes/GameScene.h

@@ -24,6 +24,7 @@ class GameScene : public cocos2d::Layer {
 private:
     void ball_collision (cocos2d::Node *ball);
     void ball_core (cocos2d::Node *core, cocos2d::Node *ball);
+    void NextLevel(Ref *pSender);
 };
 
 

+ 1 - 1
Classes/params.h

@@ -11,7 +11,7 @@
 
 // BALL
 #define BALL_SIZE 15
-#define THROW_ANG 0 // in degrees
+#define THROW_ANG 20 // in degrees
 #define INITIAL_SPEED 500
 
 // CORE

BIN
Resources/res/bomb.wav


BIN
Resources/res/metal.wav


BIN
Resources/res/pipe.wav


BIN
Resources/res/special.wav


BIN
proj.ios_mac/RedCore2.xcodeproj/project.xcworkspace/xcuserdata/capella.xcuserdatad/UserInterfaceState.xcuserstate