summaryrefslogtreecommitdiffstats
path: root/examples/declarative/tutorials/samegame/samegame2/samegame.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/tutorials/samegame/samegame2/samegame.js')
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/samegame.js32
1 files changed, 16 insertions, 16 deletions
diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js
index 0ec3a8b..d7cbd8d 100644
--- a/examples/declarative/tutorials/samegame/samegame2/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js
@@ -1,16 +1,16 @@
//![0]
//Note that X/Y referred to here are in game coordinates
-var maxX = 10;//Nums are for tileSize 40
-var maxY = 15;
+var maxColumn = 10;//Nums are for tileSize 40
+var maxRow = 15;
var tileSize = 40;
-var maxIndex = maxX*maxY;
+var maxIndex = maxColumn*maxRow;
var board = new Array(maxIndex);
var tileSrc = "Block.qml";
var component;
//Index function used instead of a 2D array
-function index(xIdx,yIdx) {
- return xIdx + (yIdx * maxX);
+function index(column,row) {
+ return column + (row * maxColumn);
}
function initBoard()
@@ -22,21 +22,21 @@ function initBoard()
}
//Calculate board size
- maxX = Math.floor(background.width/tileSize);
- maxY = Math.floor(background.height/tileSize);
- maxIndex = maxY*maxX;
+ maxColumn = Math.floor(background.width/tileSize);
+ maxRow = Math.floor(background.height/tileSize);
+ maxIndex = maxRow*maxColumn;
//Initialize Board
board = new Array(maxIndex);
- for(var xIdx=0; xIdx<maxX; xIdx++){
- for(var yIdx=0; yIdx<maxY; yIdx++){
- board[index(xIdx,yIdx)] = null;
- createBlock(xIdx,yIdx);
+ for(var column=0; column<maxColumn; column++){
+ for(var row=0; row<maxRow; row++){
+ board[index(column,row)] = null;
+ createBlock(column,row);
}
}
}
-function createBlock(xIdx,yIdx){
+function createBlock(column,row){
if(component==null)
component = createComponent(tileSrc);
@@ -52,11 +52,11 @@ function createBlock(xIdx,yIdx){
return false;
}
dynamicObject.parent = background;
- dynamicObject.x = xIdx*tileSize;
- dynamicObject.y = yIdx*tileSize;
+ dynamicObject.x = column*tileSize;
+ dynamicObject.y = row*tileSize;
dynamicObject.width = tileSize;
dynamicObject.height = tileSize;
- board[index(xIdx,yIdx)] = dynamicObject;
+ board[index(column,row)] = dynamicObject;
}else{//isError or isLoading
print("error loading block component");
print(component.errorsString());