3 Commits 4ad1c00626 ... 2e68e41c0c

Autore SHA1 Messaggio Data
  JoaoHL 2e68e41c0c Adicionado power up bolas triplas 7 anni fa
  JoaoHL fa0c45cf38 Adicionado power up bolas triplas 7 anni fa
  JoaoHL ce7f16be29 Adicionado power up bolas triplas 7 anni fa
7 ha cambiato i file con 119 aggiunte e 28 eliminazioni
  1. 1 0
      .gitignore
  2. 5 0
      CMakeLists.txt
  3. 109 26
      Classes/GameScene.cpp
  4. 1 0
      Classes/GameScene.h
  5. 2 1
      Classes/params.h
  6. BIN
      RedCore.apk
  7. 1 1
      build

+ 1 - 0
.gitignore

@@ -20,5 +20,6 @@ tests/*/proj.android-studio/app/proguard-project.txt
 /*/build/
 /proj.android-studio/app/build/
 bin/
+/linux-build/
 .DS_Store
 cocos2d/

+ 5 - 0
CMakeLists.txt

@@ -128,6 +128,8 @@ endif( WIN32 )
 set(GAME_SRC
   Classes/Ball.cpp
   Classes/AppDelegate.cpp
+  Classes/BlocksLayer.cpp
+  Classes/GameScene.cpp
   Classes/HelloWorldScene.cpp
   ${PLATFORM_SPECIFIC_SRC}
 )
@@ -135,7 +137,10 @@ set(GAME_SRC
 set(GAME_HEADERS
   Classes/Ball.h
   Classes/AppDelegate.h
+  Classes/BlocksLayer.h
+  Classes/GameScene.h
   Classes/HelloWorldScene.h
+  Classes/params.h
   ${PLATFORM_SPECIFIC_HEADERS}
 )
 

+ 109 - 26
Classes/GameScene.cpp

@@ -44,10 +44,14 @@ Scene* GameScene::createScene(int level) {
     
     layer->setLevel(level);
     
-    auto delay = DelayTime::create(10.0);
-    CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::saveLevel, layer));
-    auto seq = Sequence::create(delay, runCallback, nullptr);
-    layer->runAction(seq);
+    auto delay_save_level = DelayTime::create(10.0);
+    CallFunc *runCallback_save_level = CallFunc::create(CC_CALLBACK_0(GameScene::saveLevel, layer));
+    auto seq_save_level = Sequence::create(delay_save_level, runCallback_save_level, nullptr);
+    auto delay_triple_balls = DelayTime::create(10.0);
+    CallFunc *runCallback_triple_balls = CallFunc::create(CC_CALLBACK_0(GameScene::tripleBalls, layer));
+    auto seq_triple_balls = Sequence::create(delay_triple_balls, runCallback_triple_balls, nullptr);
+    layer->runAction(seq_save_level);
+    layer->runAction(seq_triple_balls);
     
     return scene;
 }
@@ -82,6 +86,9 @@ bool GameScene::init() {
     ball->setPosition(visibleSize.width / 2, RAQUETE_ALTURA+BALL_SIZE);
     ball->throwBall();
     this->addChild(ball, 21);
+    UserDefault *userdata = UserDefault::getInstance();
+    userdata->setIntegerForKey("ball_count", 1);
+    userdata->flush();
     
     auto raquete = DrawNode::create();
     float py = RAQUETE_HEIGHT/2.0;
@@ -184,36 +191,78 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
             text->setPosition(visibleSize.width/2, visibleSize.height/2);
             this->addChild(text);
             text->runAction(FadeOut::create(3));
+        } else if (nodeB->getTag() == THREE_BALLS_TAG && nodeA->getTag() == RACKET_TAG) {
+
+            Size visibleSize = Director::getInstance()->getVisibleSize();
+            // Salva na "database" o número de bolas na tela
+            UserDefault *userdata = UserDefault::getInstance();
+            int ball_count = userdata->getIntegerForKey("ball_count");
+            userdata->setIntegerForKey("ball_count", ball_count * 3);
+            userdata->flush();
+            nodeB->removeFromParentAndCleanup(true);
+            auto text = Label::createWithTTF("Triple Balls!", "fonts/Marker Felt.ttf", 40);
+            text->setPosition(visibleSize.width/2, visibleSize.height/2 + 2);
+            this->addChild(text);
+            text->runAction(FadeOut::create(3));
+            // cria as bolas e as adiciona no cenário
+            for (int i = ball_count; i < (ball_count * 3); i++) {
+                auto ball = Ball::create();
+                ball->setPosition(nodeB->getPositionX(), RAQUETE_ALTURA+BALL_SIZE);
+                ball->throwBall();
+                this->addChild(ball, 21);
+            }
         } else if (nodeB->getTag() == SAVE_TAG && nodeA->getTag() == BOTTOM_TAG) {
             nodeB->removeFromParentAndCleanup(true);
+        } else if (nodeB->getTag() == THREE_BALLS_TAG && nodeA->getTag() == BOTTOM_TAG) {
+            nodeB->removeFromParentAndCleanup(true);
         }
+
     }
     return true;
 }
 
 void GameScene::ball_collision (Node *ball) {
-    this->over = true;
-    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);
-    
     UserDefault *userdata = UserDefault::getInstance();
-    level = userdata->getIntegerForKey("level", 0);
-    auto menu_item_start = MenuItemFont::create("Restart", CC_CALLBACK_1(GameScene::NextLevel, this));
-    menu_item_start->setPosition(text->getPosition());
-    menu_item_start->setPositionY(menu_item_start->getPositionY()-50);
-    auto *menu = Menu::create(menu_item_start, NULL);
-    menu->setPosition(Point(0, 0));
-    this->addChild(menu, 30);
-    
-    auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
-    audio->playEffect("bomb.wav");
-    ParticleSun* m_emitter = ParticleSun::create();
-    m_emitter->setPosition(ball->getPosition());
-    m_emitter->setDuration(1);
-    this->getScene()->addChild(m_emitter);
-    ball->removeFromParentAndCleanup(true);
+    int ball_count = userdata->getIntegerForKey("ball_count");
+
+    if (ball_count <= 1) {
+        this->over = true;
+        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);
+        
+        UserDefault *userdata = UserDefault::getInstance();
+        level = userdata->getIntegerForKey("level", 0);
+        auto menu_item_start = MenuItemFont::create("Restart", CC_CALLBACK_1(GameScene::NextLevel, this));
+        menu_item_start->setPosition(text->getPosition());
+        menu_item_start->setPositionY(menu_item_start->getPositionY()-50);
+        auto *menu = Menu::create(menu_item_start, NULL);
+        menu->setPosition(Point(0, 0));
+        this->addChild(menu, 30);
+        
+        auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
+        audio->playEffect("bomb.wav");
+        ParticleSun* m_emitter = ParticleSun::create();
+        m_emitter->setPosition(ball->getPosition());
+        m_emitter->setDuration(1);
+        this->getScene()->addChild(m_emitter);
+        ball->removeFromParentAndCleanup(true);
+    }
+    else {           
+        // Diminui o contador de bolas do jogo
+        userdata->setIntegerForKey("ball_count", (ball_count-1));
+        userdata->flush();
+
+        // Destrói a bola que tocou o fundo
+        auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
+        audio->playEffect("bomb.wav");
+        ParticleSun* m_emitter = ParticleSun::create();
+        m_emitter->setPosition(ball->getPosition());
+        m_emitter->setDuration(1);
+        this->getScene()->addChild(m_emitter);
+        ball->removeFromParentAndCleanup(true);
+    }
 }
 
 void GameScene::ball_core (Node *core, Node *ball) {
@@ -254,6 +303,7 @@ void GameScene::setLevel(int level) {
     this->addChild(text);
 }
 
+// Power-up: salva o nível atual
 void GameScene::saveLevel() {
     if (rand_0_1() < DROP_LEVEL_SAVE && this->over == false){
         Size visibleSize = Director::getInstance()->getVisibleSize();
@@ -282,6 +332,39 @@ void GameScene::saveLevel() {
     auto delay = DelayTime::create(rand_0_1()*10.0+3.0);
     CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::saveLevel, this));
     auto seq = Sequence::create(delay, runCallback, nullptr);
-    this->runAction(seq);
+    //this->runAction(seq);
     
 }
+
+// Power-up: triplica o número de bolas na tela 
+void GameScene::tripleBalls() {
+    if (rand_0_1() < DROP_TRIPLE_BALL && this->over == false){
+            Size visibleSize = Director::getInstance()->getVisibleSize();
+            auto ball_draw = DrawNode::create();
+            ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_pink));
+        
+            auto material = PHYSICSBODY_MATERIAL_DEFAULT;
+            material.density = 0.0f;
+            material.restitution = 1.0f;
+            material.friction = 0.0f;
+        
+            auto physicsBody = PhysicsBody::createCircle(BALL_SIZE/3.0, material);
+            physicsBody->setGravityEnable(true);
+            physicsBody->setVelocity(Vec2(0,0));
+            physicsBody->setLinearDamping(0.0);
+            physicsBody->setMass(1.0f);
+            physicsBody->setContactTestBitmask(0xFFFFFFFF);
+            physicsBody->setGroup(-1);
+            ball_draw->addComponent(physicsBody);
+            ball_draw->setTag(THREE_BALLS_TAG);
+            
+            ball_draw->setPosition(visibleSize.width * rand_0_1(), visibleSize.height);
+            this->addChild(ball_draw);
+    }
+    
+    auto delay = DelayTime::create(rand_0_1()*50.0+3.0);
+    CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::tripleBalls, this));
+    auto seq = Sequence::create(delay, runCallback, nullptr);
+    this->runAction(seq);
+}
+

+ 1 - 0
Classes/GameScene.h

@@ -24,6 +24,7 @@ class GameScene : public cocos2d::Layer {
         void NextLevel(cocos2d::Ref *pSender);
         int level;
         void saveLevel ();
+        void tripleBalls();
         bool over; // salva se o jogo acabou!
 };
 

+ 2 - 1
Classes/params.h

@@ -42,7 +42,8 @@
 #define THREE_BALLS_TAG 9
 #define SAVE_TAG 8
 
-// Probabilitys
+// Probabilities
 #define DROP_LEVEL_SAVE 1 // deixar em 0.1
+#define DROP_TRIPLE_BALL 1
 
 #endif /* params_h */

BIN
RedCore.apk


+ 1 - 1
build

@@ -9,4 +9,4 @@ fi
 
 ./cocos2d/tools/cocos2d-console/bin/cocos compile -p android --android-studio
 
-cp /Users/gabrielcapella/Desktop/RedCore/bin/debug/android/RedCore-debug.apk ./RedCore.apk
+cp /home/joao/463/bin/debug/android/RedCore-debug.apk ./RedCore.apk