|
@@ -58,10 +58,12 @@ Scene* GameScene::createScene(int level) {
|
|
|
|
|
|
CallFunc *runCallback_triple_balls = CallFunc::create(CC_CALLBACK_0(GameScene::tripleBallsAppearance, layer));
|
|
|
CallFunc *runCallback_paddle_ball = CallFunc::create(CC_CALLBACK_0(GameScene::paddleBallAppearance, layer));
|
|
|
+ CallFunc *runCallback_superball = CallFunc::create(CC_CALLBACK_0(GameScene::superBallAppearance, layer));
|
|
|
|
|
|
layer->runAction(seq_save_level);
|
|
|
layer->runAction(runCallback_triple_balls);
|
|
|
layer->runAction(runCallback_paddle_ball);
|
|
|
+ layer->runAction(runCallback_superball);
|
|
|
|
|
|
layer->addAndThrowBall();
|
|
|
|
|
@@ -77,7 +79,7 @@ bool GameScene::init() {
|
|
|
}
|
|
|
|
|
|
over = false;
|
|
|
- last_touch = 0;
|
|
|
+ last_touch = time(NULL);
|
|
|
|
|
|
// https://www.freesound.org/people/schademans/sounds/13290/
|
|
|
FileUtils::getInstance()->addSearchPath("res");
|
|
@@ -131,12 +133,23 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
|
|
|
nodeA = tmp;
|
|
|
}
|
|
|
|
|
|
+ if (nodeA->getTag() == BALL_TAG) {
|
|
|
+ last_touch = time(NULL);
|
|
|
+ }
|
|
|
+
|
|
|
// sempre B < A
|
|
|
if (nodeB->getTag() == BLOCK_TAG) {
|
|
|
auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
|
|
|
audio->playEffect("pipe.wav");
|
|
|
nodeB->removeFromParentAndCleanup(true);
|
|
|
} else if (nodeB->getTag() == INDESTRUCTIBLE_BLOCK_TAG) {
|
|
|
+ if (nodeA->getTag() == BALL_TAG) {
|
|
|
+ Ball* ball = (Ball*) nodeA;
|
|
|
+ if (ball->superball) {
|
|
|
+ nodeB->removeFromParentAndCleanup(true);
|
|
|
+ ball->resetNormalball();
|
|
|
+ }
|
|
|
+ }
|
|
|
auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
|
|
|
audio->playEffect("metal.wav");
|
|
|
} else if (nodeB->getTag() == BOTTOM_TAG && nodeA->getTag() == BALL_TAG) {
|
|
@@ -149,6 +162,8 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
|
|
|
caseSaveLevel(nodeB);
|
|
|
} else if (nodeB->getTag() == THREE_BALLS_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
caseTripleBalls(nodeB);
|
|
|
+ } else if (nodeB->getTag() == SUPERBALL_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
+ caseSuperBall(nodeB);
|
|
|
} else if (nodeB->getTag() == RACKET_BALL_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
caseRaqueteBall(nodeB);
|
|
|
} else if (nodeB->getTag() == SAVE_TAG && nodeA->getTag() == BOTTOM_TAG) {
|
|
@@ -157,6 +172,8 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
|
|
|
nodeB->removeFromParentAndCleanup(true);
|
|
|
} else if (nodeB->getTag() == RACKET_BALL_TAG && nodeA->getTag() == BOTTOM_TAG) {
|
|
|
nodeB->removeFromParentAndCleanup(true);
|
|
|
+ } else if (nodeB->getTag() == SUPERBALL_TAG && nodeA->getTag() == BOTTOM_TAG) {
|
|
|
+ nodeB->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -178,8 +195,8 @@ void GameScene::caseBallCollision (Node *ball) {
|
|
|
auto text = Label::createWithTTF(MSG_OVER, FONT, 40);
|
|
|
text->setPosition(width/2, height/2);
|
|
|
addChild(text);
|
|
|
-
|
|
|
- auto menu_item_start = MenuItemFont::create("Restart", CC_CALLBACK_1(GameScene::NextLevel, this));
|
|
|
+ auto menu_item_start = MenuItemFont::create(MSG_RESTART, CC_CALLBACK_1(GameScene::NextLevel, this));
|
|
|
+ menu_item_start->setFontNameObj(FONT);
|
|
|
menu_item_start->setPosition(text->getPosition());
|
|
|
menu_item_start->setPositionY(menu_item_start->getPositionY()-50);
|
|
|
auto *menu = Menu::create(menu_item_start, NULL);
|
|
@@ -198,7 +215,7 @@ void GameScene::caseBallCore (Node *core, Node *ball) {
|
|
|
|
|
|
auto callbackRotate = CallFunc::create([=](){
|
|
|
level = level + 1;
|
|
|
- auto menu_item_start = MenuItemFont::create("Next Level", CC_CALLBACK_1(GameScene::NextLevel, this));
|
|
|
+ auto menu_item_start = MenuItemFont::create(MSG_NEXT_LEVEL, CC_CALLBACK_1(GameScene::NextLevel, this));
|
|
|
menu_item_start->setPosition(Point(width / 2, (height / 2)));
|
|
|
auto *menu = Menu::create(menu_item_start, NULL);
|
|
|
menu->setPosition(Point(0, 0));
|
|
@@ -226,7 +243,7 @@ void GameScene::NextLevel(Ref *pSender) {
|
|
|
}
|
|
|
|
|
|
void GameScene::setLevel(int level) {
|
|
|
- level = level;
|
|
|
+ this->level = level;
|
|
|
char level_text[256];
|
|
|
sprintf(level_text,"Level %d", level);
|
|
|
auto text = Label::createWithTTF(level_text, FONT, 30);
|
|
@@ -237,7 +254,9 @@ void GameScene::setLevel(int level) {
|
|
|
|
|
|
// Power-up: salva o nível atual
|
|
|
void GameScene::saveLevel() {
|
|
|
- if (rand_0_1() < DROP_LEVEL_SAVE && over == false){
|
|
|
+ if (over) return;
|
|
|
+
|
|
|
+ if (rand_0_1() < DROP_LEVEL_SAVE){
|
|
|
auto ball_draw = DrawNode::create();
|
|
|
ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_green));
|
|
|
|
|
@@ -252,7 +271,7 @@ void GameScene::saveLevel() {
|
|
|
ball_draw->setTag(SAVE_TAG);
|
|
|
|
|
|
ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
- addChild(ball_draw);
|
|
|
+ addChild(ball_draw, 20);
|
|
|
}
|
|
|
|
|
|
auto delay = DelayTime::create(1.0);
|
|
@@ -264,11 +283,15 @@ void GameScene::saveLevel() {
|
|
|
|
|
|
// Power-up: deixa 3 bolas na tela ao invés de 1
|
|
|
void GameScene::tripleBallsAppearance() {
|
|
|
- if (rand_0_1() < DROP_TRIPLE_BALL && over == false){
|
|
|
+ if (over) return;
|
|
|
+ double delta = (time(NULL)-last_touch);
|
|
|
+
|
|
|
+ if (rand_0_1() < delta*DROP_TRIPLE_BALL){
|
|
|
+ last_touch = time(NULL);
|
|
|
+
|
|
|
auto ball_draw = DrawNode::create();
|
|
|
ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_pink));
|
|
|
|
|
|
-
|
|
|
auto physicsBody = PhysicsBody::createCircle(BALL_SIZE/3.0, PhysicsMaterial(0.0f, 1.0f, 0.0f));
|
|
|
physicsBody->setGravityEnable(true);
|
|
|
physicsBody->setVelocity(Vec2(0,0));
|
|
@@ -280,7 +303,7 @@ void GameScene::tripleBallsAppearance() {
|
|
|
ball_draw->setTag(THREE_BALLS_TAG);
|
|
|
|
|
|
ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
- addChild(ball_draw);
|
|
|
+ addChild(ball_draw, 20);
|
|
|
}
|
|
|
|
|
|
auto delay = DelayTime::create(1.0);
|
|
@@ -297,6 +320,8 @@ void GameScene::caseTripleBalls(Node *powerup_ball) {
|
|
|
}
|
|
|
|
|
|
void GameScene::paddleBallAppearance() {
|
|
|
+ if (over) return;
|
|
|
+
|
|
|
if (rand_0_1() < DROP_RACKET_BALL && over == false){
|
|
|
auto ball_draw = DrawNode::create();
|
|
|
ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_blue));
|
|
@@ -312,7 +337,7 @@ void GameScene::paddleBallAppearance() {
|
|
|
ball_draw->setTag(RACKET_BALL_TAG);
|
|
|
|
|
|
ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
- addChild(ball_draw);
|
|
|
+ addChild(ball_draw, 20);
|
|
|
}
|
|
|
|
|
|
auto delay = DelayTime::create(1.0);
|
|
@@ -346,3 +371,42 @@ void GameScene::alert(std::string text) {
|
|
|
display_label->runAction(FadeOut::create(3));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// Power-up: deixa 3 bolas na tela ao invés de 1
|
|
|
+void GameScene::superBallAppearance() {
|
|
|
+ if (over) return;
|
|
|
+
|
|
|
+ if (rand_0_1() < DROP_SUPER_BALL){
|
|
|
+ last_touch = time(NULL);
|
|
|
+
|
|
|
+ auto ball_draw = DrawNode::create();
|
|
|
+ ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_orange));
|
|
|
+
|
|
|
+ auto physicsBody = PhysicsBody::createCircle(BALL_SIZE/3.0, PhysicsMaterial(0.0f, 1.0f, 0.0f));
|
|
|
+ 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(SUPERBALL_TAG);
|
|
|
+
|
|
|
+ ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
+ addChild(ball_draw, 20);
|
|
|
+ }
|
|
|
+
|
|
|
+ auto delay = DelayTime::create(1.0);
|
|
|
+ CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::superBallAppearance, this));
|
|
|
+ auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
+ runAction(seq);
|
|
|
+}
|
|
|
+
|
|
|
+void GameScene::caseSuperBall(Node *powerup_ball) {
|
|
|
+ if (over) return;
|
|
|
+ alert(MSG_SUPER_BALL);
|
|
|
+ Vector<Node *> balls_vector = balls->getChildren();
|
|
|
+ Ball* ball = (Ball*) balls_vector.at(0);
|
|
|
+ ball->setSuperball();
|
|
|
+ powerup_ball->removeFromParentAndCleanup(true);
|
|
|
+}
|