diff options
author | Wolfgang Beck <wolfgang.beck@nokia.com> | 2011-09-23 15:05:58 +1000 |
---|---|---|
committer | Lincoln Ramsay <lincoln.ramsay@nokia.com> | 2011-10-10 09:25:31 +1000 |
commit | 4a30e784182a41d54d8b908ba47d948ed4172236 (patch) | |
tree | 2ff42941e52d0f0273fa918b0be91ffb970492da /examples/sensors/maze/Mouse.qml | |
parent | 8ad3f314812136d37cbdb0d4eef65206d9171fac (diff) |
MTMW-288 add Maze (TiltSensor Example)
Change-Id: I023e4baeb82facfb7d2f97c3b6076d7f1e816e16
Reviewed-on: http://codereview.qt-project.org/5434
Reviewed-by: Wolfgang Beck <wolfgang.beck@nokia.com>
Diffstat (limited to 'examples/sensors/maze/Mouse.qml')
-rw-r--r-- | examples/sensors/maze/Mouse.qml | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/examples/sensors/maze/Mouse.qml b/examples/sensors/maze/Mouse.qml new file mode 100644 index 00000000..32489b50 --- /dev/null +++ b/examples/sensors/maze/Mouse.qml @@ -0,0 +1,76 @@ +//Import the declarative plugins +import QtQuick 2.0 + +//Import the javascript functions for this game +import "lib.js" as Lib + +//Implementation of the Mouse control. +Item { + id: mouse + x: 0 + y: 0 + width: Lib.cellDimension + height: Lib.cellDimension + state: 'right' + + AnimatedImage { + id: img + anchors.fill: parent + visible: true + } + + //for different moves we have different gif animations + states: [ + State { + name: "up" + PropertyChanges { target: img; source: "images/mouse_up.gif" } + }, + State { + name: "down" + PropertyChanges { target: img; source: "images/mouse_down.gif" } + }, + State { + name: "left" + PropertyChanges { target: img; source: "images/mouse_left.gif" } + }, + State { + name: "right" + PropertyChanges { target: img; source: "images/mouse_right.gif" } + }, + + State { + name: "rightup" + PropertyChanges { target: img; source: "images/mouse_rightup.gif" } + }, + State { + name: "rightdown" + PropertyChanges { target: img; source: "images/mouse_rightdown.gif" } + }, + State { + name: "leftup" + PropertyChanges { target: img; source: "images/mouse_leftup.gif" } + }, + State { + name: "leftdown" + PropertyChanges { target: img; source: "images/mouse_leftdown.gif" } + } + + ] + + //Function for moving the mouse + function move(newx, newy) + { + var newstatus = ""; + if (mouse.x < newx) + newstatus += "right"; + else if (mouse.x > newx) + newstatus += "left"; + if (mouse.y < newy) + newstatus += "down"; + else if (mouse.y > newy) + newstatus += "up"; + mouse.state = newstatus; + mouse.x = newx; + mouse.y = newy; + } +} |