diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-07-23 05:47:43 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-07-23 05:47:43 (GMT) |
commit | 5054fafde6b32003c8c00877f2579c611d1524f3 (patch) | |
tree | 9f79976f970095706e82d7d65b068c1e7b728d97 /demos/declarative/samegame | |
parent | dd652f37353a01e0172e20f1e7ef24b001a281db (diff) | |
parent | dc68651b60b552e010735903e45328f8ebf18f69 (diff) | |
download | Qt-5054fafde6b32003c8c00877f2579c611d1524f3.zip Qt-5054fafde6b32003c8c00877f2579c611d1524f3.tar.gz Qt-5054fafde6b32003c8c00877f2579c611d1524f3.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'demos/declarative/samegame')
-rw-r--r-- | demos/declarative/samegame/SameGame.qml | 4 | ||||
-rw-r--r-- | demos/declarative/samegame/content/BoomBlock.qml | 5 | ||||
-rw-r--r-- | demos/declarative/samegame/content/FastBlock.qml | 7 | ||||
-rw-r--r-- | demos/declarative/samegame/content/SpinBlock.qml | 9 | ||||
-rw-r--r-- | demos/declarative/samegame/content/samegame.js | 20 |
5 files changed, 28 insertions, 17 deletions
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index 28b7133..231de03 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -22,10 +22,6 @@ Rect { anchors.fill: parent } - MouseRegion { id: gameMR; anchors.fill: parent; - onClicked: handleClick(mouseX, mouseY); - onPositionChanged: handleHover(mouseX, mouseY); - } } HorizontalLayout { anchors.top: gameCanvas.bottom diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 0f5d4da..9637bd6 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -11,6 +11,11 @@ Item { id:block x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } + MouseRegion { + id: gameMR; anchors.fill: parent + onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + } + Image { id: img source: { if(type == 0){ diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml index 15664a3..f30d8da 100644 --- a/demos/declarative/samegame/content/FastBlock.qml +++ b/demos/declarative/samegame/content/FastBlock.qml @@ -15,8 +15,11 @@ Rect { id:block opacity: 0 y: targetY x: targetX - //y: Behavior { NumberAnimation { properties:"y"; duration: 200 } } - //opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + + MouseRegion { + id: gameMR; anchors.fill: parent + onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + } states: [ diff --git a/demos/declarative/samegame/content/SpinBlock.qml b/demos/declarative/samegame/content/SpinBlock.qml index 1e92d9e..4c8f123 100644 --- a/demos/declarative/samegame/content/SpinBlock.qml +++ b/demos/declarative/samegame/content/SpinBlock.qml @@ -18,6 +18,9 @@ Item { id:block "pics/gnome/greenStone.gif"; } paused: !selected + paused: Behavior { to: true; from: false; + NumberAnimation { properties:"currentFrame"; to:0; duration: 200} + } } opacity: 0 y: targetY @@ -25,6 +28,12 @@ Item { id:block y: Behavior { NumberAnimation { properties:"y"; duration: 200 } } x: Behavior { NumberAnimation { properties:"x"; duration: 200 } } opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + MouseRegion { + id: gameMR; anchors.fill: parent + onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onExited: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); + } states: [ diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index b1b2c50..6bcfd17 100644 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -50,10 +50,8 @@ var fillFound; var floodBoard; var lastHoveredIdx = -2 -function handleHover(x,y, btn) +function handleHover(xIdx,yIdx, btn) { - xIdx = Math.floor(x/tileSize); - yIdx = Math.floor(y/tileSize); if(index(xIdx, yIdx) == lastHoveredIdx) return; lastHoveredIdx = index(xIdx, yIdx); @@ -67,11 +65,9 @@ function handleHover(x,y, btn) //Could use the fillFound value to tell the player how many stones/points } -function handleClick(x,y) +function handleClick(xIdx,yIdx) { //NOTE: Be careful with vars named x,y - they can set to the calling object - xIdx = Math.floor(x/tileSize); - yIdx = Math.floor(y/tileSize); if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) @@ -166,9 +162,8 @@ function victoryCheck() { //awards bonuses deservesBonus = true; - for(xIdx=maxX-1; xIdx>=0; xIdx--) - if(board[index(xIdx, maxY - 1)] != null) - deservesBonus = false; + if(board[index(0, maxY - 1)] != null) + deservesBonus = false; if(deservesBonus) gameCanvas.score += 500; //Checks for game over @@ -180,7 +175,8 @@ function victoryCheck() function noMoreMoves() { - return !floodMoveCheck(0, maxY-1, -1); + moreMoves = floodMoveCheck(0, maxY-1, -1); + return !moreMoves; } function floodMoveCheck(xIdx, yIdx, type) @@ -192,7 +188,9 @@ function floodMoveCheck(xIdx, yIdx, type) myType = board[index(xIdx, yIdx)].type; if(type == myType) return true; - return floodMoveCheck(xIdx + 1, yIdx, myType) || floodMoveCheck(xIdx, yIdx - 1, myType); + var at = myType; + var bt = myType; + return floodMoveCheck(xIdx + 1, yIdx, at) || floodMoveCheck(xIdx, yIdx - 1, bt); } //Need a simpler method of doing this? |