Browse Source

1496372421

capellaresumo 7 years ago
parent
commit
6b1be86743

+ 156 - 0
.gitignore

@@ -0,0 +1,156 @@
+# Ignore thumbnails created by windows
+Thumbs.db
+
+# Ignore files build by Visual Studio
+*.obj
+*.exe
+*.pdb
+*.aps
+*.vcproj.*.user
+*.vcxproj.user
+*.csproj.user
+*.vspscc
+*_i.c
+*.i
+*.icf
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.cache
+*.ilk
+*.log
+[Bb]in
+[Dd]ebug/
+[Dd]ebug.win32/
+*.sbr
+*.sdf
+obj/
+[Rr]elease/
+[Rr]elease.win32/
+_ReSharper*/
+[Tt]est[Rr]esult*
+ipch/
+*.opensdf
+*.opendb
+SubmissionInfo
+Generated Files
+AppPackages
+BundleArtifacts
+.vs/
+*.VC.db
+
+# Ignore files build by ndk and eclipse
+/libs/
+bin/
+obj/
+gen/
+assets/
+local.properties
+
+# Ignore python compiled files
+*.pyc
+
+# Ignore files build by airplay and marmalade
+build_*_xcode/
+build_*_vc10/
+
+# Ignore files build by xcode
+*.mode*v*
+*.pbxuser
+*.xcbkptlist
+*.xcworkspacedata
+*.xcuserstate
+*.xccheckout
+xcschememanagement.plist
+.DS_Store
+._.*
+xcuserdata/
+DerivedData/
+
+# Ignore files built by AppCode
+.idea/
+
+# Ignore files built by bada
+.Simulator-Debug/
+.Target-Debug/
+.Target-Release/
+
+# Ignore files built by blackberry
+Simulator/
+Device-Debug/
+Device-Release/
+
+# Ignore vim swaps
+*.swp
+*.swo
+
+# Ignore files created by create_project.py
+projects/
+
+# Ignore config files in javascript bindings generator
+tools/tojs/user.cfg
+# ... userconf.ini generated if running from tools/tojs
+tools/tojs/userconf.ini
+tools/tolua/userconf.ini
+# ... userconf.ini generated if running from tools/jenkins_scripts/mac/android/
+tools/jenkins_scripts/mac/android/userconf.ini
+
+# CTags
+tags
+
+# ignore files, created with make-all-linux-project script
+/lib
+/build/linux-build
+
+# Cmake files
+CMakeCache.txt
+CMakeFiles
+Makefile
+cmake_install.cmake
+CMakeLists.txt.user
+
+# Ignore files generated by console
+build/build/
+cocos/scripting/lua-bindings/proj.ios_mac/build/
+tests/*/runtime/
+tests/*/publish/
+tests/*/project/proj.android-studio/app/build.xml
+tests/*/project/proj.android-studio/app/proguard-project.txt
+tests/*/proj.android-studio/app/build.xml
+tests/*/proj.android-studio/app/proguard-project.txt
+
+# Android
+project.properties
+*.iml
+
+# Ignore prebuilt libraries folder
+/external/*
+!/external/config.json
+/templates/lua-template-runtime/runtime
+/v*-deps-*.zip
+/v*-lua-runtime-*.zip
+/v*-console-*.zip
+/tools/fbx-conv/
+tests/cpp-tests/Resources/audio
+/tests/lua-empty-test/src/cocos/
+/tests/lua-game-controller-test/src/cocos/
+/tests/lua-tests/src/cocos/
+/tests/js-tests/res/
+/tools/framework-compile/bin/proj_modifier/plutil-win32/
+!/tools/framework-compile/bin/
+
+# generated by framework-compile
+/templates/*-template-binary/
+/prebuilt/
+/*/prebuilt-mk/Android.mk
+/*/*/prebuilt-mk/Android.mk
+/*/*/*/prebuilt-mk/Android.mk
+/*/*/*/*/prebuilt-mk/Android.mk
+*.xcscmblueprint
+tests/cpp-empty-test/proj.tizen/res/
+tests/cpp-tests/proj.tizen/res/
+tests/lua-empty-test/project/proj.tizen/res/
+tests/lua-tests/project/proj.tizen/res/

+ 1 - 1
Classes/AppDelegate.cpp

@@ -89,7 +89,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
     register_all_packages();
 
     // create a scene. it's an autorelease object
-    auto scene = HelloWorld::createScene();
+    auto scene = GameScene::createScene();
 
     // run
     director->runWithScene(scene);

+ 49 - 3
Classes/Ball.cpp

@@ -18,17 +18,63 @@ bool Ball::init() {
     ball_draw->drawDot(Vec2(0, 0), BALL_SIZE, Color4F(COLOR_grey));
     this->addChild(ball_draw);
     
+//    ParticleSun* m_emitter = ParticleSun::create();
+//    m_emitter->setPosition(Vec2(0, 0));
+//    this->addChild(m_emitter);
+    //
+    
     auto material = PHYSICSBODY_MATERIAL_DEFAULT;
-    material.density = 1.0f;
-    material.restitution = 1.0f;
+    material.density = 0.0f;
+    material.restitution = 1.001f;
     material.friction = 0.0f; //set friction here
     
     auto physicsBody = PhysicsBody::createCircle(BALL_SIZE, material);
     physicsBody->setGravityEnable(false);
     physicsBody->setVelocity(Vec2(0,0));
-    physicsBody->setLinearDamping(0);
+    physicsBody->setLinearDamping(0.0);
+    //physicsBody->setRotationEnable(false);
+    physicsBody->setMass(1000.0f);
+    
+    physicsBody->setContactTestBitmask(0xFFFFFFFF);
+    
     this->addComponent(physicsBody);
+    this->setTag(BALL_TAG);
+    
+    auto contactListener = EventListenerPhysicsContact::create();
+    contactListener->onContactBegin = CC_CALLBACK_1(Ball::onContactBegin, this);
+    _eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
+
+    
+    return true;
+}
+
+bool Ball::onContactBegin(PhysicsContact& contact) {
+    auto nodeA = contact.getShapeA()->getBody()->getNode();
+    auto nodeB = contact.getShapeB()->getBody()->getNode();
+    
+    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) {
+            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);
+        } 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);
+        }
+    }
+    
+    //bodies can collide
     return true;
 }
 

+ 3 - 0
Classes/Ball.h

@@ -18,6 +18,9 @@ class Ball : public cocos2d::Node {
     
     void throwBall();
     
+    bool onContactBegin(cocos2d::PhysicsContact& contact);
+
+    
     // implement the "static create()" method manually
     CREATE_FUNC(Ball);
     

+ 70 - 37
Classes/BlocksLayer.cpp

@@ -21,17 +21,12 @@ bool BlocksLayer::init() {
     
     this->setPosition(center);
     
-    for (int i = 0; i >= 0; i--) {
-        auto circle = createCircle(CORE_RADIUS, i, 10, 0.1);
+    for (int i = 5; i >= 0; i--) {
+        auto circle = createCircle(CORE_RADIUS*0.75, i, 10, 0.1);
         this->addChild(circle, 9);
     }
     
-    auto material = PHYSICSBODY_MATERIAL_DEFAULT;
-    material.density = 1.0f;
-    material.restitution = 1.0f;
-    material.friction = 0.0f; //set friction here
-    
-    auto physicsBody = PhysicsBody::createCircle(CORE_RADIUS, material);
+    auto physicsBody = PhysicsBody::createCircle(CORE_RADIUS, PhysicsMaterial(0.1f, 1.0f, 0.0f));
     physicsBody->setGravityEnable(false);
     physicsBody->setVelocity(Vec2(0,0));
     physicsBody->setLinearDamping(0);
@@ -42,20 +37,20 @@ bool BlocksLayer::init() {
     //core->drawCircle(center, CORE_RADIUS, M_PI, 30, false, Color4F(COLOR_blue));
     core->drawDot(Vec2(), CORE_RADIUS, COLOR_red);
     core->addComponent(physicsBody);
-    this->addChild(core);
+    this->addChild(core, 40);
     
     
     return true;
 }
 
-Node* BlocksLayer::createCircle (float size, int number, int number_of_segments, float p) {
+Node* BlocksLayer::createCircle (double size, int number, int number_of_segments, double p) {
     auto node = Node::create();
-    float interna = number * size + CORE_RADIUS;
-    float externa = (1 + number) * size + CORE_RADIUS;
+    double interna = number * size + CORE_RADIUS;
+    double externa = (1 + number) * size + CORE_RADIUS;
+    
+    double* points = new double[number_of_segments+2];
+    //bool* indestructible = new bool[number_of_segments+1];
     
-    float* points = new float[number_of_segments+2];
-    bool* indestrictible = new bool[number_of_segments+1];
-
     for (int i = 0; i < number_of_segments; i++) {
         points[i] = 2.0*M_PI/number_of_segments * i;
         points[i] += rand_minus1_1()*0.9*M_PI/number_of_segments;
@@ -64,44 +59,82 @@ Node* BlocksLayer::createCircle (float size, int number, int number_of_segments,
     points[number_of_segments] = points[0] + 2*M_PI;
     
     for (int i = 0; i < number_of_segments; i++) {
-        CCLOG(">> %d (%f %f)", i, points[i], points[i+1]);
-        auto seg = createSegment(interna+3, externa, points[i]+0.02, points[i+1]-0.015, 1, false);
+        auto seg = createSegment(interna, externa, points[i], points[i+1], false);
         node->addChild(seg);
     }
+    auto back = DrawNode::create();
+    back->drawDot(Vec2(), interna+2, Color4F(COLOR_back));
+    node->addChild(back, 1);
+    
+    auto rotate = RotateBy::create(1, rand_minus1_1()*30.0);
+    
+    node->runAction(RepeatForever::create(rotate));
     
     delete [] points;
     return node;
-
+    
 }
 
-Node* BlocksLayer::createSegment (float r_internal, float r_externa, float begin, float end, int resolution, bool especial) {
+Node* BlocksLayer::createSegment (double r_internal, double r_externa, double begin, double end, bool especial) {
     int i;
+    double sinV, cosV, step;
     auto draw = DrawNode::create();
-    auto material = PHYSICSBODY_MATERIAL_DEFAULT;
-    material.density = 1.0f;
-    material.restitution = 1.0f;
-    material.friction = 0.0f; //set friction here
     
-
-    int n_points = roundf((end-begin)*r_externa*resolution);
+    // borda
+    begin += 1/r_externa;
+    end -= 1/r_externa;
+    
+    int ns_ex_draw; // numeros de segmentos externos do desenho
+    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;
+    
+    // Previne segmentos muito errados!
+    if (ns_ex_draw < 2) ns_ex_draw = 2;
+    if (ns_ex_phy < 2) ns_ex_phy = 2;
+    if (ns_in_phy < 2) ns_in_phy = 2;
+    
+    std::vector<Vec2> p_ex_draw(ns_ex_draw+2); // pontos do arco para desenho
+    p_ex_draw[ns_ex_draw+1] = Vec2();
     
-    std::vector<Vec2> points(2*n_points+2);
+    std::vector<Vec2> p_physics(ns_in_phy+ns_ex_phy+2); // pontos da fisica
     
-    float step = (end-begin)/n_points;
     
-    for (i = 0; i <= n_points; i++) {
-        float sin = sinf(begin+step*i);
-        float cos = cosf(begin+step*i);
-        
-        points[i] = Vec2 (sin * r_externa, cos * r_externa);
-        points[2*n_points-i+1] = Vec2 (sin * r_internal, cos * r_internal);
+    step = (end - begin)/(double)ns_ex_draw;
+    for (i = 0; i <= ns_ex_draw; i++) {
+        sinV = sin(begin + step * (double) i) * r_externa;
+        cosV = cos(begin + step * (double) i) * r_externa;
+        p_ex_draw[i] = Vec2 (sinV, cosV);
+    }
+    
+    step = (end - begin)/(double)ns_ex_phy;
+    for (i = 0; i <= ns_ex_phy; i++) {
+        sinV = sin(begin + step * (double) i) * r_externa;
+        cosV = cos(begin + step * (double) i) * r_externa;
+        p_physics[i] = Vec2 (sinV, cosV);
+    }
+    
+    step = (end - begin)/(double)ns_in_phy;
+    for (i = 0; i <= ns_in_phy; i++) {
+        sinV = sin(begin + step * (double) i) * r_internal;
+        cosV = cos(begin + step * (double) i) * r_internal;
+        p_physics[ns_ex_phy - i + 1 + ns_in_phy] = Vec2 (sinV, cosV);
     }
     
-    //draw->drawPoly(points.data(), 2*n_points+2, false, Color4F(COLOR_blue));
-
     Color4B color = Color4B(102*(rand_0_1()/5+0.5), 217*(rand_0_1()/5+0.5), 239*(rand_0_1()/5+0.5), 255);
-    draw->drawSolidPoly(points.data(), 2*n_points+2, Color4F(color));
-
+    draw->drawSolidPoly(p_ex_draw.data(), ns_ex_draw + 2, Color4F(color));
+    
+    auto physicsBody = PhysicsBody::createEdgePolygon(p_physics.data(), ns_in_phy+ns_ex_phy+2, PhysicsMaterial(0.1f, 1.0f, 0.0f));
+    physicsBody->setGravityEnable(false);
+    physicsBody->setDynamic(false);
+    physicsBody->setContactTestBitmask(0xFFFFFFFF);
+    
+    draw->addComponent(physicsBody);
+    draw->setTag(BLOCK_TAG);
+    
     return draw;
 }
 

+ 2 - 2
Classes/BlocksLayer.h

@@ -20,9 +20,9 @@ class BlocksLayer : public cocos2d::Node {
     CREATE_FUNC(BlocksLayer);
     
     private:
-    Node* createCircle (float size, int number, int number_of_segments, float p);
+    Node* createCircle (double size, int number, int number_of_segments, double p);
     
-    Node* createSegment (float r_internal, float r_externa, float begin, float end, int resolution, bool especial);
+    Node* createSegment (double r_internal, double r_externa, double begin, double end, bool especial);
 };
 
 

+ 53 - 9
Classes/GameScene.cpp

@@ -30,9 +30,10 @@ 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));
+    edgeNode->setPosition(Point(visibleSize.width/2,visibleSize.height/2-BALL_SIZE));
     body->setDynamic(false);
     edgeNode->setPhysicsBody(body);
     scene->addChild(edgeNode);
@@ -52,24 +53,67 @@ bool GameScene::init() {
     Vec2 origin = Director::getInstance()->getVisibleOrigin();
     
     // Adiona o fundo
-    auto bg = cocos2d::LayerColor::create(COLOR_back);
+    auto bg = LayerColor::create(COLOR_back);
     this->addChild(bg);
     
     
     auto ball = Ball::create();
     ball->setPosition(visibleSize.width / 2, BALL_SIZE*2);
     ball->throwBall();
-    this->addChild(ball);
+    this->addChild(ball, 21);
     
     auto blocks = BlocksLayer::create();
-    this->addChild(blocks, 110);
-
+    blocks->setPosition(visibleSize.width/2, visibleSize.height);
+    this->addChild(blocks, 20);
+    
+    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);
+    
+    auto bsize = Size(RAQUETE_WIDTH+RAQUETE_HEIGHT, RAQUETE_HEIGHT);
+    auto physicsBody = PhysicsBody::createBox(bsize, PhysicsMaterial(0.1f, 1.0f, 0.0f));
+    physicsBody->setPositionOffset(Vec2(0, RAQUETE_HEIGHT/2));
+    physicsBody->setGravityEnable(false);
+    physicsBody->setDynamic(false);
+    physicsBody->setContactTestBitmask(0xFFFFFFFF);
+    raquete->addComponent(physicsBody);
+    
+    this->addChild(raquete);
+    
+    auto listener1 = EventListenerTouchOneByOne::create();
+    
+    // trigger when you push down
+    listener1->onTouchBegan = [=](Touch* touch, Event* event){
+        raquete->setPositionX(touch->getLocation().x);
+        float px = touch->getLocation().x;
+        if (px >= RAQUETE_WIDTH/2 && px < visibleSize.width - RAQUETE_WIDTH/2)
+            raquete->setPositionX(touch->getLocation().x);
+        return true; // if you are consuming it
+    };
+    
+    // trigger when moving touch
+    listener1->onTouchMoved = [=](Touch* touch, Event* event){
+        float px = touch->getLocation().x;
+        if (px >= RAQUETE_WIDTH/2 && px <= visibleSize.width - RAQUETE_WIDTH/2)
+            raquete->setPositionX(touch->getLocation().x);
+    };
+    
 
+    // Add listener
+    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
 
-//    ParticleSmoke* m_emitter = ParticleSmoke::create();
-//    m_emitter->setPosition(visibleSize.width/2,visibleSize.height/2);
-//    this->addChild(m_emitter);
-//    
+    // the edge of bottom
+    auto body = PhysicsBody::createEdgeBox(Size(visibleSize.width, 0));
+    auto edgeNode = Node::create();
+    edgeNode->setPosition(Point(visibleSize.width/2, -BALL_SIZE));
+    body->setDynamic(false);
+    edgeNode->setTag(BOTTOM_TAG);
+    body->setContactTestBitmask(0xFFFFFFFF);
+    edgeNode->setPhysicsBody(body);
+    this->addChild(edgeNode);
     
     return true;
 }

+ 2 - 0
Classes/GameScene.h

@@ -19,6 +19,8 @@ class GameScene : public cocos2d::Layer {
         
     // implement the "static create()" method manually
     CREATE_FUNC(GameScene);
+private:
+    cocos2d::DrawNode *raquete;
 };
 
 

+ 10 - 0
Classes/params.h

@@ -17,6 +17,10 @@
 // CORE
 #define CORE_RADIUS 50
 
+// RAQUETE
+#define RAQUETE_WIDTH 120
+#define RAQUETE_HEIGHT 10
+
 // CORES
 #define COLOR_back Color4B(39, 40, 34, 255)
 #define COLOR_pink Color4B(249,38,114, 255)
@@ -26,4 +30,10 @@
 #define COLOR_grey Color4B(120,120,120, 255)
 #define COLOR_red Color4F(0.988, 0.147, 0.030, 1)
 
+// TAGs
+#define BALL_TAG 15
+#define BLOCK_TAG 10
+#define CORE_TAG 11
+#define BOTTOM_TAG 12
+
 #endif /* params_h */

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


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

@@ -26,12 +26,12 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../Classes/BlocksLayer.cpp"
-            timestampString = "518030032.292412"
+            timestampString = "518059649.204962"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "68"
-            endingLineNumber = "68"
-            landmarkName = "BlocksLayer::createCircle (float size, int number, int number_of_segments, float p)"
+            startingLineNumber = "129"
+            endingLineNumber = "129"
+            landmarkName = "BlocksLayer::createSegment (double r_internal, double r_externa, double begin, double end, bool especial)"
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>