diff --git a/src/activities/penalty/Penalty.qml b/src/activities/penalty/Penalty.qml --- a/src/activities/penalty/Penalty.qml +++ b/src/activities/penalty/Penalty.qml @@ -45,6 +45,167 @@ activity.stop.connect(stop) } + //To enable tapping/clicking on left side of goal + Rectangle{ + id: maleft + anchors.fill: parent.left + width: 475 + height: 300 + x: 100 + y: 50 + color: "transparent" + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton + onClicked: { + instruction.text = "" + + if(ball.state === "FAIL") { + Activity.resetLevel() + return + } + + /* This is a shoot */ + var progress = progressTop + if (mouse.button == Qt.LeftButton | mouse.button == Qt.RightButton | mouse.button == Qt.MidButton) { + progress = progressLeft + } + + if(progress.ratio > 0) { + /* Second click, stop animation */ + progress.anim.running = false; + + /* Play sound */ + activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav") + + /* Success or not */ + if(progress.ratio < 100) { + /* Success */ + ball.state = "LEFT" + } else { + /* failure */ + ball.state = "FAIL" + } + timerBonus.start() + } else { + /* First click, start animation*/ + progress.anim.running = true; + + /* Play sound */ + activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/flip.wav") + } + } + } + } + + //To enable tapping/clicking on top of goal + Rectangle{ + id: matop + width: 600 + height: 175 + x: 575 + y: 50 + color: "transparent" + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton + onClicked: { + instruction.text = "" + + if(ball.state === "FAIL") { + Activity.resetLevel() + return + } + + /* This is a shoot */ + var progress = progressTop + if (mouse.button == Qt.LeftButton | mouse.button == Qt.RightButton | mouse.button == Qt.MidButton) { + + } + + if(progress.ratio > 0) { + /* Second click, stop animation */ + progress.anim.running = false; + + /* Play sound */ + activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav") + + /* Success or not */ + if(progress.ratio < 100) { + /* Success */ + ball.state = "CENTER" + } else { + /* failure */ + ball.state = "FAIL" + } + timerBonus.start() + } else { + /* First click, start animation*/ + progress.anim.running = true; + + /* Play sound */ + activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/flip.wav") + } + } + } + } + + //To enable tapping/clicking on right side of goal + Rectangle{ + id: maright + anchors.fill: parent.right + width: 475 + height: 300 + x: 800 + y: 50 + color: "transparent" + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton + onClicked: { + instruction.text = "" + + if(ball.state === "FAIL") { + Activity.resetLevel() + return + } + + /* This is a shoot */ + var progress = progressTop + if (mouse.button == Qt.LeftButton | mouse.button == Qt.RightButton | mouse.button == Qt.MidButton) { + progress = progressRight + } + + if(progress.ratio > 0) { + /* Second click, stop animation */ + progress.anim.running = false; + + /* Play sound */ + activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav") + + /* Success or not */ + if(progress.ratio < 100) { + /* Success */ + ball.state = "RIGHT" + } else { + /* failure */ + ball.state = "FAIL" + } + timerBonus.start() + } else { + /* First click, start animation*/ + progress.anim.running = true; + + /* Play sound */ + activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/flip.wav") + } + } + } + } + // Add here the QML items you need to access in javascript QtObject { id: items @@ -275,7 +436,7 @@ } PropertyChanges { target: instruction - text: qsTr("Double click or double tap on the ball to kick it.") + text: qsTr("Double click or double tap on the side of the goal you want to put the ball in.") } }, State { @@ -320,56 +481,14 @@ } ] - MouseArea { + MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton - onClicked: { - instruction.text = "" - - if(ball.state === "FAIL") { - Activity.resetLevel() - return - } - - /* This is a shoot */ - var progress = progressTop - if (mouse.button == Qt.LeftButton) { - progress = progressLeft - } else if (mouse.button == Qt.RightButton) { - progress = progressRight - } else if (mouse.button == Qt.MidButton) { - progress = progressTop - } - - if(progress.ratio > 0) { - /* Second click, stop animation */ - progress.anim.running = false; - - /* Play sound */ - activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav") - - /* Success or not */ - if(progress.ratio < 100) { - /* Success */ - if(progress === progressLeft) { - ball.state = "LEFT" - } else if(progress === progressRight) { - ball.state = "RIGHT" - } else { - ball.state = "CENTER" - } - } else { - /* failure */ - ball.state = "FAIL" - } - timerBonus.start() - } else { - /* First click, start animation*/ - progress.anim.running = true; - - /* Play sound */ - activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/flip.wav") - } + onClicked:{ + ball.state = "INITIAL" + progressRight.ratio = 0 + progressLeft.ratio = 0 + progressTop.ratio = 0 } } }