|
@@ -111,6 +111,9 @@ bool GameScene::init() {
|
|
|
balls = Node::create();
|
|
|
addChild(balls, 21);
|
|
|
|
|
|
+ power_ups = Node::create();
|
|
|
+ addChild(power_ups, 20);
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -125,7 +128,7 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
|
|
|
auto nodeA = contact.getShapeA()->getBody()->getNode();
|
|
|
auto nodeB = contact.getShapeB()->getBody()->getNode();
|
|
|
|
|
|
- if (nodeA && nodeB && nodeA->getTag() != nodeB->getTag()) {
|
|
|
+ if (nodeA && nodeB && nodeA->getTag() != nodeB->getTag() && !over) {
|
|
|
|
|
|
if (nodeB->getTag() > nodeA->getTag()) {
|
|
|
auto tmp = nodeB;
|
|
@@ -158,19 +161,19 @@ bool GameScene::onContactBegin(PhysicsContact& contact) {
|
|
|
caseBallCore(nodeB, nodeA);
|
|
|
} else if (nodeB->getTag() == BALL_TAG && nodeA->getTag() == CORE_TAG) {
|
|
|
caseBallCore(nodeA, nodeB);
|
|
|
- } else if (nodeB->getTag() == SAVE_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
+ } else if (nodeB->getTag() == SAVE_TAG && nodeA->getTag() == PADDLE_TAG) {
|
|
|
caseSaveLevel(nodeB);
|
|
|
- } else if (nodeB->getTag() == THREE_BALLS_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
+ } else if (nodeB->getTag() == THREE_BALLS_TAG && nodeA->getTag() == PADDLE_TAG) {
|
|
|
caseTripleBalls(nodeB);
|
|
|
- } else if (nodeB->getTag() == SUPERBALL_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
+ } else if (nodeB->getTag() == SUPERBALL_TAG && nodeA->getTag() == PADDLE_TAG) {
|
|
|
caseSuperBall(nodeB);
|
|
|
- } else if (nodeB->getTag() == RACKET_BALL_TAG && nodeA->getTag() == RACKET_TAG) {
|
|
|
+ } else if (nodeB->getTag() == PADDLE_BALL_TAG && nodeA->getTag() == PADDLE_TAG) {
|
|
|
caseRaqueteBall(nodeB);
|
|
|
} 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);
|
|
|
- } else if (nodeB->getTag() == RACKET_BALL_TAG && nodeA->getTag() == BOTTOM_TAG) {
|
|
|
+ } else if (nodeB->getTag() == PADDLE_BALL_TAG && nodeA->getTag() == BOTTOM_TAG) {
|
|
|
nodeB->removeFromParentAndCleanup(true);
|
|
|
} else if (nodeB->getTag() == SUPERBALL_TAG && nodeA->getTag() == BOTTOM_TAG) {
|
|
|
nodeB->removeFromParentAndCleanup(true);
|
|
@@ -192,6 +195,7 @@ void GameScene::caseBallCollision (Node *ball) {
|
|
|
|
|
|
if (balls->getChildrenCount() == 0) {
|
|
|
over = true;
|
|
|
+ removeBallsAndPowersUP ();
|
|
|
auto text = Label::createWithTTF(MSG_OVER, FONT, 40);
|
|
|
text->setPosition(width/2, height/2);
|
|
|
addChild(text);
|
|
@@ -202,7 +206,6 @@ void GameScene::caseBallCollision (Node *ball) {
|
|
|
auto *menu = Menu::create(menu_item_start, NULL);
|
|
|
menu->setPosition(Point(0, 0));
|
|
|
addChild(menu, 30);
|
|
|
- balls->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -212,10 +215,11 @@ void GameScene::caseBallCore (Node *core, Node *ball) {
|
|
|
core->runAction(scaleBy);
|
|
|
auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
|
|
|
audio->playEffect("win.wav");
|
|
|
-
|
|
|
auto callbackRotate = CallFunc::create([=](){
|
|
|
+ removeBallsAndPowersUP();
|
|
|
level = level + 1;
|
|
|
auto menu_item_start = MenuItemFont::create(MSG_NEXT_LEVEL, CC_CALLBACK_1(GameScene::NextLevel, this));
|
|
|
+ menu_item_start->setFontNameObj(FONT);
|
|
|
menu_item_start->setPosition(Point(width / 2, (height / 2)));
|
|
|
auto *menu = Menu::create(menu_item_start, NULL);
|
|
|
menu->setPosition(Point(0, 0));
|
|
@@ -256,29 +260,13 @@ void GameScene::setLevel(int level) {
|
|
|
void GameScene::saveLevel() {
|
|
|
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));
|
|
|
-
|
|
|
- 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(SAVE_TAG);
|
|
|
-
|
|
|
- ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
- addChild(ball_draw, 20);
|
|
|
- }
|
|
|
-
|
|
|
- auto delay = DelayTime::create(1.0);
|
|
|
+ if (rand_0_1() < DROP_LEVEL_SAVE)
|
|
|
+ createPowerUpBody(COLOR_green, SAVE_TAG);
|
|
|
+
|
|
|
+ auto delay = DelayTime::create(POWER_UP_INTERVAL);
|
|
|
CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::saveLevel, this));
|
|
|
auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
runAction(seq);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -288,25 +276,10 @@ void GameScene::tripleBallsAppearance() {
|
|
|
|
|
|
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));
|
|
|
- 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(width * rand_0_1(), height);
|
|
|
- addChild(ball_draw, 20);
|
|
|
+ createPowerUpBody(COLOR_pink, THREE_BALLS_TAG);
|
|
|
}
|
|
|
|
|
|
- auto delay = DelayTime::create(1.0);
|
|
|
+ auto delay = DelayTime::create(POWER_UP_INTERVAL);
|
|
|
CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::tripleBallsAppearance, this));
|
|
|
auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
runAction(seq);
|
|
@@ -322,25 +295,10 @@ 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));
|
|
|
-
|
|
|
- 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(RACKET_BALL_TAG);
|
|
|
-
|
|
|
- ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
- addChild(ball_draw, 20);
|
|
|
- }
|
|
|
+ if (rand_0_1() < DROP_PADDLE_BALL && over == false)
|
|
|
+ createPowerUpBody(COLOR_blue, PADDLE_BALL_TAG);
|
|
|
|
|
|
- auto delay = DelayTime::create(1.0);
|
|
|
+ auto delay = DelayTime::create(POWER_UP_INTERVAL);
|
|
|
CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::paddleBallAppearance, this));
|
|
|
auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
runAction(seq);
|
|
@@ -376,27 +334,10 @@ void GameScene::alert(std::string text) {
|
|
|
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);
|
|
|
- }
|
|
|
+ if (rand_0_1() < DROP_SUPER_BALL)
|
|
|
+ createPowerUpBody(COLOR_orange, SUPERBALL_TAG);
|
|
|
|
|
|
- auto delay = DelayTime::create(1.0);
|
|
|
+ auto delay = DelayTime::create(POWER_UP_INTERVAL);
|
|
|
CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::superBallAppearance, this));
|
|
|
auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
runAction(seq);
|
|
@@ -410,3 +351,28 @@ void GameScene::caseSuperBall(Node *powerup_ball) {
|
|
|
ball->setSuperball();
|
|
|
powerup_ball->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
+
|
|
|
+void GameScene::removeBallsAndPowersUP () {
|
|
|
+ balls->removeAllChildrenWithCleanup(true);
|
|
|
+ power_ups->removeAllChildrenWithCleanup(true);
|
|
|
+ paddle->removeFromParentAndCleanup(true);
|
|
|
+}
|
|
|
+
|
|
|
+void GameScene::createPowerUpBody(Color4B color, int tag) {
|
|
|
+ auto ball_draw = DrawNode::create();
|
|
|
+ ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(color));
|
|
|
+
|
|
|
+ auto material = PhysicsMaterial(0.0f, 1.0f, 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(SUPERBALL_TAG);
|
|
|
+
|
|
|
+ ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
+ power_ups->addChild(ball_draw, 20);
|
|
|
+}
|