|
@@ -30,10 +30,9 @@ Scene* GameScene::createScene() {
|
|
|
material.friction = 0.0f;
|
|
|
|
|
|
|
|
|
- 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() {
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
|
|
|
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);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ auto seq = Sequence::create(scaleBy, callbackRotate, nullptr);
|
|
|
+ core->runAction(seq);
|
|
|
+ ball->removeFromParentAndCleanup(true);
|
|
|
+}
|