Here is one possibility:
import QtQuick 1.1
Rectangle {
id: root
width: 360
height: 360
Rectangle {
property bool hit: false
id: duck
width: 50
height: width
radius: width/2
color: "red"
y: 60
NumberAnimation on x {
duration: 3000
from: 0
to: root.width
loops: NumberAnimation.Infinite
running: !duck.hit
}
NumberAnimation on y {
duration: 500
to: root.height
running: duck.hit
}
}
Rectangle {
id: crosshair
width: 40
height: width
border.color: "black"
border.width: 1
color: "transparent"
}
MouseArea {
id: aim
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
crosshair.x = mouse.x-crosshair.width/2
crosshair.y = mouse.y-crosshair.height/2
}
onClicked: {
if(mouse.x >= duck.x && mouse.x <= duck.x+duck.width && mouse.y >= duck.y && mouse.y <= duck.y+duck.height) {
duck.hit = true
}
}
}
}
import QtQuick 1.1
Rectangle {
id: root
width: 360
height: 360
Rectangle {
property bool hit: false
id: duck
width: 50
height: width
radius: width/2
color: "red"
y: 60
NumberAnimation on x {
duration: 3000
from: 0
to: root.width
loops: NumberAnimation.Infinite
running: !duck.hit
}
NumberAnimation on y {
duration: 500
to: root.height
running: duck.hit
}
}
Rectangle {
id: crosshair
width: 40
height: width
border.color: "black"
border.width: 1
color: "transparent"
}
MouseArea {
id: aim
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
crosshair.x = mouse.x-crosshair.width/2
crosshair.y = mouse.y-crosshair.height/2
}
onClicked: {
if(mouse.x >= duck.x && mouse.x <= duck.x+duck.width && mouse.y >= duck.y && mouse.y <= duck.y+duck.height) {
duck.hit = true
}
}
}
}
To copy to clipboard, switch view to plain text mode
Here is another:
import QtQuick 1.1
Rectangle {
id: root
width: 360
height: 360
Rectangle {
property bool hit: false
id: duck
width: 50
height: width
radius: width/2
color: "red"
y: 60
NumberAnimation on x {
duration: 3000
from: 0
to: root.width
loops: NumberAnimation.Infinite
running: !duck.hit
}
NumberAnimation on y {
duration: 500
to: root.height
running: duck.hit
}
MouseArea {
anchors.fill: parent
onClicked: duck.hit = true
}
}
Rectangle {
id: crosshair
width: 40
height: width
border.color: "black"
border.width: 1
color: "transparent"
}
MouseArea {
id: aim
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
onPositionChanged: {
crosshair.x = mouse.x-crosshair.width/2
crosshair.y = mouse.y-crosshair.height/2
}
}
}
import QtQuick 1.1
Rectangle {
id: root
width: 360
height: 360
Rectangle {
property bool hit: false
id: duck
width: 50
height: width
radius: width/2
color: "red"
y: 60
NumberAnimation on x {
duration: 3000
from: 0
to: root.width
loops: NumberAnimation.Infinite
running: !duck.hit
}
NumberAnimation on y {
duration: 500
to: root.height
running: duck.hit
}
MouseArea {
anchors.fill: parent
onClicked: duck.hit = true
}
}
Rectangle {
id: crosshair
width: 40
height: width
border.color: "black"
border.width: 1
color: "transparent"
}
MouseArea {
id: aim
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
onPositionChanged: {
crosshair.x = mouse.x-crosshair.width/2
crosshair.y = mouse.y-crosshair.height/2
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks