5 var maxIndex = maxColumn * maxRow;
6 var board = new Array(maxIndex);
9 //Index function used instead of a 2D array
10 function index(column, row) {
11 return column + (row * maxColumn);
14 function startNewGame() {
15 //Delete blocks from previous game
16 for (var i = 0; i < maxIndex; i++) {
21 //Calculate board size
22 maxColumn = Math.floor(background.width / blockSize);
23 maxRow = Math.floor(background.height / blockSize);
24 maxIndex = maxRow * maxColumn;
27 board = new Array(maxIndex);
28 for (var column = 0; column < maxColumn; column++) {
29 for (var row = 0; row < maxRow; row++) {
30 board[index(column, row)] = null;
31 createBlock(column, row);
36 function createBlock(column, row) {
37 if (component == null)
38 component = Qt.createComponent("Block.qml");
40 // Note that if Block.qml was not a local file, component.status would be
41 // Loading and we should wait for the component's statusChanged() signal to
42 // know when the file is downloaded and ready before calling createObject().
43 if (component.status == Component.Ready) {
44 var dynamicObject = component.createObject(background);
45 if (dynamicObject == null) {
46 console.log("error creating block");
47 console.log(component.errorString());
50 dynamicObject.x = column * blockSize;
51 dynamicObject.y = row * blockSize;
52 dynamicObject.width = blockSize;
53 dynamicObject.height = blockSize;
54 board[index(column, row)] = dynamicObject;
56 console.log("error loading block component");
57 console.log(component.errorString());