void NumboLevel::fillBlocks() {
    for(int i = 0; i < NUM_ROWS; ++i) {
        for(int j = 0; j < NUM_COLS; ++j) {
            int blockVal = RandomHelper::random_int(1, BLOCK_MAX_VALUE);
            spawnBlock(j, i, blockVal);
        }
    }
}
Example #2
0
Result game(int seed) {
    Result result = {LOSE, 0};
    srand(seed);
    Block blocks[size*size];
    int blocksLeft = 0;
    resetGame(blocks, &blocksLeft, &result);
    int index = 0;
    int spawn = FALSE;
    int quit = FALSE;
    while (!quit) {
        if (KEY_DOWN_NOW(BUTTON_UP)) {
            if (moveBlocks(blocks, UP, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_UP));
        }
        if (KEY_DOWN_NOW(BUTTON_DOWN)) {
            if (moveBlocks(blocks, DOWN, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_DOWN));
        }
        if (KEY_DOWN_NOW(BUTTON_LEFT)) {
            if (moveBlocks(blocks, LEFT, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_LEFT));
        }
        if (KEY_DOWN_NOW(BUTTON_RIGHT)) {
            if (moveBlocks(blocks, RIGHT, &result.score, &blocksLeft, &result.outcome) && blocksLeft) {
                spawn = TRUE;
            }
            while (KEY_DOWN_NOW(BUTTON_RIGHT));
        }
        if (spawn) {
            index = spawnBlock(blocks, blocksLeft--);
            result.score += 1<<blocks[index].num;
            waitForVblank();
            drawBlock(blocks, index);
            updateScoreDisplay(result.score);
            quit = !hasMoves(blocks);
            spawn = FALSE;
        }
        if (KEY_DOWN_NOW(BUTTON_B)) {
            quit = TRUE;
            while (KEY_DOWN_NOW(BUTTON_B));
        }
        if (KEY_DOWN_NOW(BUTTON_SELECT)) {
            resetGame(blocks, &blocksLeft, &result);
            while (KEY_DOWN_NOW(BUTTON_SELECT));
        }
    }
    //put a while loop here to check if game ends properly
    return result;
}
Example #3
0
void resetGame(Block *blocks, int *blocksLeft, Result *result) {
    result->outcome = LOSE;
    result->score = 0;
    initializeBlocks(blocks);
    *blocksLeft = size*size;
    int index[2];
    index[0] = spawnBlock(blocks, *blocksLeft);
    (*blocksLeft)--;
    index[1] = spawnBlock(blocks, *blocksLeft);
    (*blocksLeft)--;
    result->score += 1<<blocks[index[0]].num;
    result->score += 1<<blocks[index[1]].num;
    waitForVblank();
    fillScreen(BLACK);
    waitForVblank();
    drawBoard();
    drawGameText();
    updateScoreDisplay(result->score);
    drawBlock(blocks, index[0]);
    drawBlock(blocks, index[1]);
}
Example #4
0
void LevelScene::placeItemByMouse(int x, int y)
{
    if(!placingMode) return;
    for(int i=0;i<cameras.size(); i++)
    {
        PGE_Rect camRect;
        camRect.setRect(0, cameras[i].h()*i, cameras[i].w(), cameras[i].h());
        if(camRect.collidePoint(x, y))
        {
            x+=cameras[i].posX();
            y+=cameras[i].posY();
            break;
        }
    }

    qDebug()<<"Placed:" << placingMode_item_type<<" in pos:" << x << y;

    switch(placingMode_item_type)
    {
        case 0:
            placingMode_block.x=x;
            placingMode_block.y=y;
            spawnBlock(placingMode_block);
            break;
        case 1:
            placingMode_bgo.x=x;
            placingMode_bgo.y=y;
            spawnBGO(placingMode_bgo);
            break;
        case 2:
            placingMode_npc.x=x;
            placingMode_npc.y=y;
            spawnNPC(placingMode_npc, GENERATOR_APPEAR, SPAWN_UP);
            break;
    }
}