|
@@ -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);
|
|
|
+}
|
|
|
+
|