|
@@ -56,13 +56,11 @@ Scene* GameScene::createScene(int level) {
|
|
|
auto seq_save_level = Sequence::create(delay_save_level, runCallback_save_level, nullptr);
|
|
|
|
|
|
CallFunc *runCallback_triple_balls = CallFunc::create(CC_CALLBACK_0(GameScene::tripleBallsAppearance, layer));
|
|
|
- auto seq_triple_balls = Sequence::create(runCallback_triple_balls, nullptr);
|
|
|
- CallFunc *runCallback_raquete_ball = CallFunc::create(CC_CALLBACK_0(GameScene::raqueteBallAppearance, layer));
|
|
|
- auto seq_raquete_ball = Sequence::create(runCallback_raquete_ball, nullptr);
|
|
|
+ CallFunc *runCallback_paddle_ball = CallFunc::create(CC_CALLBACK_0(GameScene::paddleBallAppearance, layer));
|
|
|
|
|
|
layer->runAction(seq_save_level);
|
|
|
- layer->runAction(seq_triple_balls);
|
|
|
- layer->runAction(seq_raquete_ball);
|
|
|
+ layer->runAction(runCallback_triple_balls);
|
|
|
+ layer->runAction(runCallback_paddle_ball);
|
|
|
|
|
|
layer->addAndThrowBall();
|
|
|
|
|
@@ -77,7 +75,7 @@ bool GameScene::init() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- this->over = false;
|
|
|
+ over = false;
|
|
|
|
|
|
|
|
|
FileUtils::getInstance()->addSearchPath("res");
|
|
@@ -88,22 +86,22 @@ bool GameScene::init() {
|
|
|
audio->preloadEffect("win.wav");
|
|
|
|
|
|
auto visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
- this->width = visibleSize.width;
|
|
|
- this->height = visibleSize.height;
|
|
|
+ width = visibleSize.width;
|
|
|
+ height = visibleSize.height;
|
|
|
Vec2 origin = Director::getInstance()->getVisibleOrigin();
|
|
|
|
|
|
|
|
|
auto bg = LayerColor::create(COLOR_back);
|
|
|
- this->addChild(bg);
|
|
|
+ addChild(bg);
|
|
|
|
|
|
- raquete = DrawNode::create();
|
|
|
- raquete_size = PADDLE_WIDTH;
|
|
|
+ paddle = DrawNode::create();
|
|
|
+ paddle_size = PADDLE_WIDTH;
|
|
|
float py = PADDLE_HEIGHT/2.0;
|
|
|
float pxl = - PADDLE_WIDTH/2;
|
|
|
float pxr = PADDLE_WIDTH/2;
|
|
|
- raquete->drawSegment(Vec2(pxl, py), Vec2(pxr, py), py, Color4F(COLOR_grey));
|
|
|
- raquete->setPositionX(visibleSize.width/2);
|
|
|
- raquete->setPositionY(PADDLE_ALTURA);
|
|
|
+ paddle->drawSegment(Vec2(pxl, py), Vec2(pxr, py), py, Color4F(COLOR_grey));
|
|
|
+ paddle->setPositionX(width/2);
|
|
|
+ paddle->setPositionY(PADDLE_ALTURA);
|
|
|
|
|
|
auto bsize = Size(PADDLE_WIDTH+PADDLE_HEIGHT, PADDLE_HEIGHT);
|
|
|
auto physicsBody = PhysicsBody::createBox(bsize, PhysicsMaterial(0.1f, 1.0f, 0.0f));
|
|
@@ -111,27 +109,28 @@ bool GameScene::init() {
|
|
|
physicsBody->setGravityEnable(false);
|
|
|
physicsBody->setDynamic(false);
|
|
|
physicsBody->setContactTestBitmask(0xFFFFFFFF);
|
|
|
- raquete->setTag(RACKET_TAG);
|
|
|
- raquete->addComponent(physicsBody);
|
|
|
+ paddle->setTag(RACKET_TAG);
|
|
|
+ paddle->addComponent(physicsBody);
|
|
|
+ paddle_size = PADDLE_WIDTH;
|
|
|
|
|
|
- this->addChild(raquete);
|
|
|
+ addChild(paddle);
|
|
|
|
|
|
auto listener1 = EventListenerTouchOneByOne::create();
|
|
|
|
|
|
|
|
|
listener1->onTouchBegan = [=](Touch* touch, Event* event){
|
|
|
- raquete->setPositionX(touch->getLocation().x);
|
|
|
+ paddle->setPositionX(touch->getLocation().x);
|
|
|
float px = touch->getLocation().x;
|
|
|
- if (px >= PADDLE_WIDTH/2 && px < visibleSize.width - PADDLE_WIDTH/2)
|
|
|
- raquete->setPositionX(touch->getLocation().x);
|
|
|
+ if (px >= paddle_size/2 && px < width - paddle_size/2)
|
|
|
+ paddle->setPositionX(touch->getLocation().x);
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
|
|
|
listener1->onTouchMoved = [=](Touch* touch, Event* event){
|
|
|
float px = touch->getLocation().x;
|
|
|
- if (px >= PADDLE_WIDTH/2 && px <= visibleSize.width - PADDLE_WIDTH/2)
|
|
|
- raquete->setPositionX(touch->getLocation().x);
|
|
|
+ if (px >= PADDLE_WIDTH/2 && px <= width - PADDLE_WIDTH/2)
|
|
|
+ paddle->setPositionX(touch->getLocation().x);
|
|
|
};
|
|
|
|
|
|
|
|
@@ -144,15 +143,14 @@ bool GameScene::init() {
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
|
|
|
|
|
|
balls = Node::create();
|
|
|
- this->addChild(balls, 21);
|
|
|
+ addChild(balls, 21);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
void GameScene::addAndThrowBall() {
|
|
|
- auto visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
Ball* ball = Ball::create();
|
|
|
- ball->setPosition(visibleSize.width / 2, PADDLE_ALTURA+BALL_SIZE);
|
|
|
+ ball->setPosition(width / 2, PADDLE_ALTURA+BALL_SIZE);
|
|
|
ball->throwBall();
|
|
|
balls->addChild(ball, 21);
|
|
|
}
|
|
@@ -209,24 +207,21 @@ void GameScene::caseBallCollision (Node *ball) {
|
|
|
ParticleSun* m_emitter = ParticleSun::create();
|
|
|
m_emitter->setPosition(ball->getPosition());
|
|
|
m_emitter->setDuration(1);
|
|
|
- this->addChild(m_emitter);
|
|
|
+ addChild(m_emitter);
|
|
|
ball->removeFromParentAndCleanup(true);
|
|
|
|
|
|
if (balls->getChildrenCount() == 0) {
|
|
|
- this->over = true;
|
|
|
- auto visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
- auto text = Label::createWithTTF("Game Over...", FONT, 40);
|
|
|
- text->setPosition(visibleSize.width/2, visibleSize.height/2);
|
|
|
- this->addChild(text);
|
|
|
+ over = true;
|
|
|
+ auto text = Label::createWithTTF(MSG_OVER, FONT, 40);
|
|
|
+ text->setPosition(width/2, height/2);
|
|
|
+ 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);
|
|
|
+ addChild(menu, 30);
|
|
|
balls->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
}
|
|
@@ -239,12 +234,12 @@ void GameScene::caseBallCore (Node *core, Node *ball) {
|
|
|
audio->playEffect("win.wav");
|
|
|
|
|
|
auto callbackRotate = CallFunc::create([=](){
|
|
|
- auto visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
+ level = level + 1;
|
|
|
auto menu_item_start = MenuItemFont::create("Next Level", CC_CALLBACK_1(GameScene::NextLevel, this));
|
|
|
- menu_item_start->setPosition(Point(visibleSize.width / 2, (visibleSize.height / 2)));
|
|
|
+ menu_item_start->setPosition(Point(width / 2, (height / 2)));
|
|
|
auto *menu = Menu::create(menu_item_start, NULL);
|
|
|
menu->setPosition(Point(0, 0));
|
|
|
- this->addChild(menu, 30);
|
|
|
+ addChild(menu, 30);
|
|
|
});
|
|
|
|
|
|
|
|
@@ -255,31 +250,31 @@ void GameScene::caseBallCore (Node *core, Node *ball) {
|
|
|
|
|
|
void GameScene::caseSaveLevel(Node *powerup_ball) {
|
|
|
UserDefault *userdata = UserDefault::getInstance();
|
|
|
- userdata->setIntegerForKey("level", this->level);
|
|
|
+ userdata->setIntegerForKey("level", level);
|
|
|
userdata->setDoubleForKey("time", (double) time(NULL));
|
|
|
userdata->flush();
|
|
|
+ alert(MSG_LEVEL_SAVED);
|
|
|
powerup_ball->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
|
|
|
void GameScene::NextLevel(Ref *pSender) {
|
|
|
- auto scene = GameScene::createScene(this->level + 1);
|
|
|
+ auto scene = GameScene::createScene(level);
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
}
|
|
|
|
|
|
void GameScene::setLevel(int level) {
|
|
|
- this->level = level;
|
|
|
+ level = level;
|
|
|
char level_text[256];
|
|
|
- sprintf(level_text,"Level %d", this->level);
|
|
|
+ sprintf(level_text,"Level %d", level);
|
|
|
auto text = Label::createWithTTF(level_text, FONT, 30);
|
|
|
text->setAnchorPoint(Vec2());
|
|
|
text->setPosition(10, 10);
|
|
|
- this->addChild(text);
|
|
|
+ addChild(text);
|
|
|
}
|
|
|
|
|
|
|
|
|
void GameScene::saveLevel() {
|
|
|
- if (rand_0_1() < DROP_LEVEL_SAVE && this->over == false){
|
|
|
- Size visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
+ if (rand_0_1() < DROP_LEVEL_SAVE && over == false){
|
|
|
auto ball_draw = DrawNode::create();
|
|
|
ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_green));
|
|
|
|
|
@@ -293,21 +288,20 @@ void GameScene::saveLevel() {
|
|
|
ball_draw->addComponent(physicsBody);
|
|
|
ball_draw->setTag(SAVE_TAG);
|
|
|
|
|
|
- ball_draw->setPosition(visibleSize.width * rand_0_1(), visibleSize.height);
|
|
|
- this->addChild(ball_draw);
|
|
|
+ ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
+ addChild(ball_draw);
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ runAction(seq);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void GameScene::tripleBallsAppearance() {
|
|
|
- if (rand_0_1() < DROP_TRIPLE_BALL && this->over == false){
|
|
|
- Size visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
+ if (rand_0_1() < DROP_TRIPLE_BALL && over == false){
|
|
|
auto ball_draw = DrawNode::create();
|
|
|
ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_pink));
|
|
|
|
|
@@ -322,14 +316,14 @@ void GameScene::tripleBallsAppearance() {
|
|
|
ball_draw->addComponent(physicsBody);
|
|
|
ball_draw->setTag(THREE_BALLS_TAG);
|
|
|
|
|
|
- ball_draw->setPosition(visibleSize.width * rand_0_1(), visibleSize.height);
|
|
|
- this->addChild(ball_draw);
|
|
|
+ ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
+ addChild(ball_draw);
|
|
|
}
|
|
|
|
|
|
auto delay = DelayTime::create(rand_0_1()*10.0);
|
|
|
CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::tripleBallsAppearance, this));
|
|
|
auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
- this->runAction(seq);
|
|
|
+ runAction(seq);
|
|
|
}
|
|
|
|
|
|
void GameScene::caseTripleBalls(Node *powerup_ball) {
|
|
@@ -337,8 +331,8 @@ void GameScene::caseTripleBalls(Node *powerup_ball) {
|
|
|
powerup_ball->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
|
|
|
-void GameScene::raqueteBallAppearance() {
|
|
|
- if (rand_0_1() < DROP_RACKET_BALL && this->over == false){
|
|
|
+void GameScene::paddleBallAppearance() {
|
|
|
+ if (rand_0_1() < DROP_RACKET_BALL && over == false){
|
|
|
Size visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
auto ball_draw = DrawNode::create();
|
|
|
ball_draw->drawDot(Vec2(0, 0), BALL_SIZE/3.0, Color4F(COLOR_blue));
|
|
@@ -353,75 +347,74 @@ void GameScene::raqueteBallAppearance() {
|
|
|
ball_draw->addComponent(physicsBody);
|
|
|
ball_draw->setTag(RACKET_BALL_TAG);
|
|
|
|
|
|
- ball_draw->setPosition(visibleSize.width * rand_0_1(), visibleSize.height);
|
|
|
- this->addChild(ball_draw);
|
|
|
+ ball_draw->setPosition(width * rand_0_1(), height);
|
|
|
+ addChild(ball_draw);
|
|
|
}
|
|
|
|
|
|
auto delay = DelayTime::create(rand_0_1()*10.0);
|
|
|
- CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::raqueteBallAppearance, this));
|
|
|
+ CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(GameScene::paddleBallAppearance, this));
|
|
|
auto seq = Sequence::create(delay, runCallback, nullptr);
|
|
|
- this->runAction(seq);
|
|
|
+ runAction(seq);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
e 50% de chance de diminuir seu tamanho pela metade.
|
|
|
- Para não ficar muito fácil/difícil, impusemos tamanho mínimo/máximo da raquete.
|
|
|
+ Para não ficar muito fácil/difícil, impusemos tamanho mínimo/máximo da paddle.
|
|
|
*/
|
|
|
void GameScene::caseRaqueteBall(Node *powerup_ball) {
|
|
|
if (!over) {
|
|
|
char power_text[256];
|
|
|
|
|
|
if (rand_0_1() < 0.5) {
|
|
|
- if (raquete_size <= PADDLE_WIDTH * 4) {
|
|
|
- sprintf(power_text, "Doubled racket size!");
|
|
|
- raquete_size *= 2;
|
|
|
+ if (paddle_size <= PADDLE_WIDTH * 4) {
|
|
|
+ sprintf(power_text, MSG_DOUBLE_PADDLE);
|
|
|
+ paddle_size *= 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
- if (raquete_size >= PADDLE_WIDTH / 4) {
|
|
|
- sprintf(power_text, "Doubled racket size!");
|
|
|
- raquete_size /= 2;
|
|
|
+ if (paddle_size >= PADDLE_WIDTH / 4) {
|
|
|
+ sprintf(power_text, MSG_HALF_PADDLE);
|
|
|
+ paddle_size /= 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Size visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
auto text = Label::createWithTTF(power_text, FONT, 40);
|
|
|
- text->setPosition(visibleSize.width/2, visibleSize.height/2 + 2);
|
|
|
- this->addChild(text);
|
|
|
+ text->setPosition(width/2, height/2 + 2);
|
|
|
+ addChild(text);
|
|
|
text->runAction(FadeOut::create(3));
|
|
|
|
|
|
-
|
|
|
- auto new_raquete = DrawNode::create();
|
|
|
+
|
|
|
+ auto new_paddle = DrawNode::create();
|
|
|
float py = PADDLE_HEIGHT/2.0;
|
|
|
- float pxl = - raquete_size/2;
|
|
|
- float pxr = raquete_size/2;
|
|
|
- new_raquete->drawSegment(Vec2(pxl, py), Vec2(pxr, py), py, Color4F(COLOR_grey));
|
|
|
- new_raquete->setPositionX(raquete->getPositionX());
|
|
|
- new_raquete->setPositionY(PADDLE_ALTURA);
|
|
|
+ float pxl = - paddle_size/2;
|
|
|
+ float pxr = paddle_size/2;
|
|
|
+ new_paddle->drawSegment(Vec2(pxl, py), Vec2(pxr, py), py, Color4F(COLOR_grey));
|
|
|
+ new_paddle->setPositionX(paddle->getPositionX());
|
|
|
+ new_paddle->setPositionY(PADDLE_ALTURA);
|
|
|
|
|
|
- auto bsize = Size(raquete_size+PADDLE_HEIGHT, PADDLE_HEIGHT);
|
|
|
+ auto bsize = Size(paddle_size+PADDLE_HEIGHT, PADDLE_HEIGHT);
|
|
|
auto physicsBody = PhysicsBody::createBox(bsize, PhysicsMaterial(0.1f, 1.0f, 0.0f));
|
|
|
physicsBody->setPositionOffset(Vec2(0, PADDLE_HEIGHT/2));
|
|
|
physicsBody->setGravityEnable(false);
|
|
|
physicsBody->setDynamic(false);
|
|
|
physicsBody->setContactTestBitmask(0xFFFFFFFF);
|
|
|
- new_raquete->setTag(RACKET_TAG);
|
|
|
- new_raquete->addComponent(physicsBody);
|
|
|
+ new_paddle->setTag(RACKET_TAG);
|
|
|
+ new_paddle->addComponent(physicsBody);
|
|
|
|
|
|
- raquete->removeFromParentAndCleanup(true);
|
|
|
- raquete = new_raquete;
|
|
|
- this->addChild(raquete);
|
|
|
+ paddle->removeFromParentAndCleanup(true);
|
|
|
+ paddle = new_paddle;
|
|
|
+ addChild(paddle);
|
|
|
}
|
|
|
powerup_ball->removeFromParentAndCleanup(true);
|
|
|
}
|
|
|
|
|
|
void GameScene::alert(std::string text) {
|
|
|
- if (!this->over) {
|
|
|
+ if (!over) {
|
|
|
auto display_label = Label::createWithTTF(text, FONT, 40);
|
|
|
- display_label->setPosition(this->width/2, this->height/2);
|
|
|
- this->addChild(display_label);
|
|
|
+ display_label->setPosition(width/2, height/2);
|
|
|
+ addChild(display_label);
|
|
|
display_label->runAction(FadeOut::create(3));
|
|
|
}
|
|
|
}
|
|
|
-
|