void BubbleGrid::dropBubbles() { // Find any bubbles not connected and set them to fall for (int i = 0; i < GRID_WIDTH; i++) { for (int j = 0; j < GRID_HEIGHT; j++) { if(m_pBubbles[i][j]->getChecked() == false) { if(m_pBubbles[i][j]->getType() != EMPTY) { // Store the falling bubble in the vector for updating Bubble *fallingBubble = m_pBubbles[i][j]; fallingBubble->setFalling(true); m_pFallingBubbles.push_back(fallingBubble); // create a new bubble in its place Bubble *bubble = Bubble::create(); bubble->setPosition(getPosition(i, j)); this->addChild(bubble); m_pBubbles[i][j] = bubble; } } } } }
void GameBoard::updateBubblePostion(float dt){ Bubble * bubble; CCPoint * point; for (int i=0; i<bubblesData->count(); i++) { bubble = (Bubble*) bubblesData->objectAtIndex(bubblesData->count() - 1 - i); point = getBubblePostion(bubble); if (!bubble->active) { bubble->x = point->x; bubble->y = point->y; bubble->setPosition(CCPointMake(bubble->x, bubble->y)); }else{ bubble->update(dt); } } }
void BubbleGrid::buildGrid() { // Create the array with the rows m_pBubbles = new Bubble**[GRID_WIDTH]; // Fill each row with the cols for(int i = 0; i < GRID_WIDTH; i++) m_pBubbles[i] = new Bubble*[GRID_HEIGHT]; CCSize size = CCDirector::sharedDirector()->getWinSize(); float startingPosX = BUBBLE_RADIUS; float startingPosY = size.height - BUBBLE_RADIUS; // fill the 2D array wiht bubbles for (int i = 0; i < GRID_WIDTH; i++) { for (int j = 0; j < GRID_HEIGHT; j++) { Bubble *bubble = Bubble::create(); bubble->setPosition(getPosition(i, j)); if(j < GRID_HEIGHT_START) { bubble->setType((BUBBLE_TYPE)((int)((CCRANDOM_0_1() * 4) + 1))); if(j % 2 != 0) { if(i == GRID_WIDTH - 1) // odd rows have 1 less bubble bubble->setType(EMPTY); } } else { bubble->setType(EMPTY); } this->addChild(bubble); m_pBubbles[i][j] = bubble; } } }
void BubbleSystem::emitParticle() { Bubble *bubble = new Bubble(); bubble->setPosition(this->getParent()->getPosition()); bubble->setVelocity(this->getVelocity()); this->getParent()->getParent()->add(bubble); }