Browse Source

adicionando nivel

capellaresumo 7 years ago
parent
commit
fd5a6ecc9c

+ 1 - 1
Classes/AppDelegate.cpp

@@ -53,7 +53,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
     auto glview = director->getOpenGLView();
     if(!glview) {
 #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
-    //director->setContentScaleFactor(2);
+    director->setContentScaleFactor(2);
     glview = GLViewImpl::createWithRect("RedCore", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
 #else
         glview = GLViewImpl::create("RedCore");

+ 9 - 4
Classes/BlocksLayer.cpp

@@ -21,7 +21,8 @@ bool BlocksLayer::init() {
     
     this->setPosition(center);
     
-    for (int i = 5; i >= 0; i--) {
+    // aumentar aqui
+    for (int i = -1; i >= 0; i--) {
         auto circle = createCircle(CORE_RADIUS*0.75, i, 10, 0.2);
         this->addChild(circle, 9);
     }
@@ -31,12 +32,15 @@ bool BlocksLayer::init() {
     physicsBody->setVelocity(Vec2(0,0));
     physicsBody->setLinearDamping(0);
     physicsBody->setDynamic(false);
+    physicsBody->setGroup(-1);
+    physicsBody->setContactTestBitmask(0xFFFFFFFF);
     //physicsBody->setPositionOffset(center);
     
     auto core = DrawNode::create();
     //core->drawCircle(center, CORE_RADIUS, M_PI, 30, false, Color4F(COLOR_blue));
     core->drawDot(Vec2(), CORE_RADIUS, COLOR_red);
     core->addComponent(physicsBody);
+    core->setTag(CORE_TAG);
     this->addChild(core, 40);
     
     
@@ -88,9 +92,9 @@ Node* BlocksLayer::createSegment (double r_internal, double r_externa, double be
     int ns_in_phy; // numeros de segmentos internos da fisica
     int ns_ex_phy; // numeros de segmentos externos do da fisica
     
-    ns_ex_draw = (end - begin)*r_externa/10.0;
-    ns_ex_phy = (end - begin)*r_externa/50.0;
-    ns_in_phy = (end - begin)*r_internal/50.0;
+    ns_ex_draw = (end - begin)*sqrt(r_externa)/1.5;
+    ns_ex_phy = (end - begin)*sqrt(r_externa)/4.0;
+    ns_in_phy = (end - begin)*sqrt(r_internal)/4.0;
     
     // Previne segmentos muito errados!
     if (ns_ex_draw < 2) ns_ex_draw = 2;
@@ -135,6 +139,7 @@ Node* BlocksLayer::createSegment (double r_internal, double r_externa, double be
     physicsBody->setGravityEnable(false);
     physicsBody->setDynamic(false);
     physicsBody->setContactTestBitmask(0xFFFFFFFF);
+    physicsBody->setGroup(-1);
     
     draw->addComponent(physicsBody);
     if (!especial)

+ 41 - 18
Classes/GameScene.cpp

@@ -30,10 +30,9 @@ Scene* GameScene::createScene() {
     material.friction = 0.0f;
     
     // the edge of the screen
-    visibleSize.height += BALL_SIZE;
     auto body = PhysicsBody::createEdgeBox(visibleSize, material);
     auto edgeNode = Node::create();
-    edgeNode->setPosition(Point(visibleSize.width/2,visibleSize.height/2-BALL_SIZE));
+    edgeNode->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
     body->setDynamic(false);
     edgeNode->setPhysicsBody(body);
     scene->addChild(edgeNode);
@@ -58,7 +57,7 @@ bool GameScene::init() {
     
     
     auto ball = Ball::create();
-    ball->setPosition(visibleSize.width / 2, BALL_SIZE*2);
+    ball->setPosition(visibleSize.width / 2, RAQUETE_ALTURA+BALL_SIZE);
     ball->throwBall();
     this->addChild(ball, 21);
     
@@ -66,12 +65,13 @@ bool GameScene::init() {
     blocks->setPosition(visibleSize.width/2, visibleSize.height);
     this->addChild(blocks, 20);
     
-    raquete = DrawNode::create();
+    auto raquete = DrawNode::create();
     float py = RAQUETE_HEIGHT/2.0;
     float pxl = - RAQUETE_WIDTH/2;
     float pxr =  RAQUETE_WIDTH/2;
     raquete->drawSegment(Vec2(pxl, py), Vec2(pxr, py), py, Color4F(COLOR_grey));
     raquete->setPositionX(visibleSize.width/2);
+    raquete->setPositionY(RAQUETE_ALTURA);
     
     auto bsize = Size(RAQUETE_WIDTH+RAQUETE_HEIGHT, RAQUETE_HEIGHT);
     auto physicsBody = PhysicsBody::createBox(bsize, PhysicsMaterial(0.1f, 1.0f, 0.0f));
@@ -108,7 +108,7 @@ bool GameScene::init() {
     // the edge of bottom
     auto body = PhysicsBody::createEdgeBox(Size(visibleSize.width, 0));
     auto edgeNode = Node::create();
-    edgeNode->setPosition(Point(visibleSize.width/2, -BALL_SIZE));
+    edgeNode->setPosition(Point(visibleSize.width/2, 0));
     body->setDynamic(false);
     edgeNode->setTag(BOTTOM_TAG);
     body->setContactTestBitmask(0xFFFFFFFF);
@@ -130,25 +130,48 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
     if (nodeA && nodeB && nodeA->getTag() != nodeB->getTag()) {
         CCLOG("%d %d", nodeB->getTag(), nodeA->getTag());
         
-        if (nodeA->getTag() == BLOCK_TAG && nodeB->getTag() != INDESTRUCTIBLE_BLOCK_TAG) {
+        if (nodeA->getTag() == BLOCK_TAG) {
             nodeA->removeFromParentAndCleanup(true);
-        } else if (nodeB->getTag() == BLOCK_TAG && nodeA->getTag() != INDESTRUCTIBLE_BLOCK_TAG) {
+        } else if (nodeB->getTag() == BLOCK_TAG) {
             nodeB->removeFromParentAndCleanup(true);
         } else if (nodeA->getTag() == BOTTOM_TAG && nodeB->getTag() == BALL_TAG) {
-            ParticleSun* m_emitter = ParticleSun::create();
-            m_emitter->setPosition(nodeB->getPosition());
-            m_emitter->setDuration(1);
-            this->getScene()->addChild(m_emitter);
-            nodeB->removeFromParentAndCleanup(true);
+            ball_collision(nodeB);
         } else if (nodeB->getTag() == BOTTOM_TAG && nodeA->getTag() == BALL_TAG) {
-            ParticleSun* m_emitter = ParticleSun::create();
-            m_emitter->setPosition(nodeA->getPosition());
-            m_emitter->setDuration(1);
-            this->getScene()->addChild(m_emitter);
-            nodeA->removeFromParentAndCleanup(true);
+            ball_collision(nodeA);
+        }  else if (nodeB->getTag() == CORE_TAG && nodeA->getTag() == BALL_TAG) {
+            ball_core(nodeB, nodeA);
+        }  else if (nodeB->getTag() == BALL_TAG && nodeA->getTag() == CORE_TAG) {
+            ball_core(nodeA, nodeB);
         }
     }
-    
     //bodies can collide
     return true;
 }
+
+void GameScene::ball_collision (Node *ball) {
+    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) {
+    auto scaleBy = ScaleBy::create(1.0f, 20.0f);
+    core->getPhysicsBody()->setEnabled(false);
+    core->runAction(scaleBy);
+    
+    auto callbackRotate = CallFunc::create([=](){
+        auto visibleSize = Director::getInstance()->getVisibleSize();
+        auto menu_item_start = MenuItemFont::create("Next Level");
+        menu_item_start->setPosition(Point(visibleSize.width / 2, (visibleSize.height / 2)));
+        auto *menu = Menu::create(menu_item_start, NULL);
+        menu->setPosition(Point(0, 0));
+        this->addChild(menu, 30);
+    });
+    
+    // create a sequence with the actions and callbacks
+    auto seq = Sequence::create(scaleBy, callbackRotate, nullptr);
+    core->runAction(seq);
+    ball->removeFromParentAndCleanup(true);
+}

+ 2 - 1
Classes/GameScene.h

@@ -22,7 +22,8 @@ class GameScene : public cocos2d::Layer {
     // implement the "static create()" method manually
     CREATE_FUNC(GameScene);
 private:
-    cocos2d::DrawNode *raquete;
+    void ball_collision (cocos2d::Node *ball);
+    void ball_core (cocos2d::Node *core, cocos2d::Node *ball);
 };
 
 

+ 2 - 1
Classes/params.h

@@ -11,7 +11,7 @@
 
 // BALL
 #define BALL_SIZE 15
-#define THROW_ANG 20 // in degrees
+#define THROW_ANG 0 // in degrees
 #define INITIAL_SPEED 500
 
 // CORE
@@ -20,6 +20,7 @@
 // RAQUETE
 #define RAQUETE_WIDTH 120
 #define RAQUETE_HEIGHT 10
+#define RAQUETE_ALTURA 90
 
 // CORES
 #define COLOR_back Color4B(39, 40, 34, 255)

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


+ 3 - 3
proj.ios_mac/RedCore2.xcodeproj/xcuserdata/capella.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -26,11 +26,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../Classes/BlocksLayer.cpp"
-            timestampString = "518065746.882652"
+            timestampString = "518157078.037242"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "133"
-            endingLineNumber = "133"
+            startingLineNumber = "137"
+            endingLineNumber = "137"
             landmarkName = "BlocksLayer::createSegment (double r_internal, double r_externa, double begin, double end, bool especial)"
             landmarkType = "7">
          </BreakpointContent>