summaryrefslogtreecommitdiffstats
path: root/examples/sensors/maze/Mouse.qml
blob: 32489b50ff3b549586ff93e84a889108f9b9faac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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;
    }
}