From ebcec1a247c4cb67537131c0d801780f4987a810 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 20 Jul 2009 16:25:53 +1000 Subject: Update Gnome theme to only spin on mouse over, like same-gnome Note that currently we can only get mouse move signals if a button is pressed. --- demos/declarative/samegame/SameGame.qml | 1 + demos/declarative/samegame/content/BoomBlock.qml | 1 + demos/declarative/samegame/content/FastBlock.qml | 1 + demos/declarative/samegame/content/SpinBlock.qml | 2 + .../samegame/content/pics/gnome/blueStone.gif | Bin 19122 -> 19122 bytes .../samegame/content/pics/gnome/greenStone.gif | Bin 20545 -> 20545 bytes .../samegame/content/pics/gnome/redStone.gif | Bin 18455 -> 18455 bytes demos/declarative/samegame/content/samegame.js | 75 ++++++++++++++------- 8 files changed, 56 insertions(+), 24 deletions(-) diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index fd3ca88..5e998e8 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -22,6 +22,7 @@ Rect { MouseRegion { id: gameMR; anchors.fill: parent; onClicked: handleClick(mouseX, mouseY); + onPositionChanged: handleHover(mouseX, mouseY); } } HorizontalLayout { diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 542e7bc..9148e60 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -1,6 +1,7 @@ Item { id:block property bool dying: false property bool spawned: false + property bool selected: false property int type: 0 property int targetX: 0 property int targetY: 0 diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml index 6e02ced..5149911 100644 --- a/demos/declarative/samegame/content/FastBlock.qml +++ b/demos/declarative/samegame/content/FastBlock.qml @@ -2,6 +2,7 @@ Rect { id:block //Note: These properties are the interface used to control the blocks property bool dying: false property bool spawned: false + property bool selected: false property int type: 0 property int targetY: 0 property int targetX: 0 diff --git a/demos/declarative/samegame/content/SpinBlock.qml b/demos/declarative/samegame/content/SpinBlock.qml index 6737196..42276d0 100644 --- a/demos/declarative/samegame/content/SpinBlock.qml +++ b/demos/declarative/samegame/content/SpinBlock.qml @@ -2,6 +2,7 @@ Item { id:block //Note: These properties are the interface used to control the blocks property bool dying: false property bool spawned: false + property bool selected: false property int type: 0 property int targetY: 0 property int targetX: 0 @@ -14,6 +15,7 @@ Item { id:block } else { "pics/gnome/greenStone.gif"; } + playing: selected } opacity: 0 y: targetY diff --git a/demos/declarative/samegame/content/pics/gnome/blueStone.gif b/demos/declarative/samegame/content/pics/gnome/blueStone.gif index 4e6bd35..333efbe 100644 Binary files a/demos/declarative/samegame/content/pics/gnome/blueStone.gif and b/demos/declarative/samegame/content/pics/gnome/blueStone.gif differ diff --git a/demos/declarative/samegame/content/pics/gnome/greenStone.gif b/demos/declarative/samegame/content/pics/gnome/greenStone.gif index c572e80..1bc5bf4 100644 Binary files a/demos/declarative/samegame/content/pics/gnome/greenStone.gif and b/demos/declarative/samegame/content/pics/gnome/greenStone.gif differ diff --git a/demos/declarative/samegame/content/pics/gnome/redStone.gif b/demos/declarative/samegame/content/pics/gnome/redStone.gif index c6c10c5..b80f901 100644 Binary files a/demos/declarative/samegame/content/pics/gnome/redStone.gif and b/demos/declarative/samegame/content/pics/gnome/redStone.gif differ diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 1f76b9f..1814031 100644 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -46,55 +46,82 @@ function initBoard() //TODO: a flag that handleMouse uses to ignore clicks when we're loading } -var removed; +var fillFound; var floodBoard; + +var lastHoveredIdx = -1 +function handleHover(x,y, btn) +{ + xIdx = Math.floor(x/tileSize); + yIdx = Math.floor(y/tileSize); + if(index(xIdx, yIdx) == lastHoveredIdx) + return; + lastHoveredIdx = index(xIdx, yIdx); + //if(btn != 0) + // return; + floodFill(xIdx, yIdx, -1, "hover"); + for(i=0; i= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) return; - removed = 0; - floodBoard = new Array(maxIndex); - floodKill(xIdx,yIdx, -1); - if(removed <= 0) + floodFill(xIdx,yIdx, -1, "kill"); + if(fillFound <= 0) return; - gameCanvas.score += (removed - 1) * (removed - 1); + gameCanvas.score += (fillFound - 1) * (fillFound - 1); shuffleDown(); victoryCheck(); } -function floodKill(xIdx,yIdx,type) +//cmd = "kill" is the removal case, cmd = "hover" is the mouse overed case +function floodFill(xIdx,yIdx,type, cmd) { - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) - return; - if(floodBoard[index(xIdx, yIdx)] == 1) - return; if(board[index(xIdx, yIdx)] == null) return; var first = false; if(type == -1){ - type = board[index(xIdx,yIdx)].type; first = true; - }else{ - if(type != board[index(xIdx,yIdx)].type) - return; + type = board[index(xIdx,yIdx)].type; + + //Flood fill initialization + fillFound = 0; + floodBoard = new Array(maxIndex); } + if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + return; + if(floodBoard[index(xIdx, yIdx)] == 1) + return; + if(!first && type != board[index(xIdx,yIdx)].type) + return; floodBoard[index(xIdx, yIdx)] = 1; - floodKill(xIdx+1,yIdx,type); - floodKill(xIdx-1,yIdx,type); - floodKill(xIdx,yIdx+1,type); - floodKill(xIdx,yIdx-1,type); - if(first==true && removed == 0){ + floodFill(xIdx+1,yIdx,type,cmd); + floodFill(xIdx-1,yIdx,type,cmd); + floodFill(xIdx,yIdx+1,type,cmd); + floodFill(xIdx,yIdx-1,type,cmd); + if(first==true && fillFound == 0){ //TODO: Provide a way to inform the delegate return;//Can't remove single tiles } - board[index(xIdx,yIdx)].dying = true; - board[index(xIdx,yIdx)] = null;//They'll have to destroy themselves(can we do that?) - removed += 1; + if(cmd == "kill"){ + board[index(xIdx,yIdx)].dying = true; + board[index(xIdx,yIdx)] = null;//They'll have to destroy themselves(can we do that?) + }else if(cmd == "hover"){ + board[index(xIdx,yIdx)].selected = true; + }else{ + print ("Flood Error"); + } + fillFound += 1; } function shuffleDown() -- cgit v0.12