Warning, /education/gcompris/src/activities/ballcatch/Ballcatch.qml is written in an unsupported language. File is not indexed.

0001 /* gcompris - Ballcatch.qml
0002 
0003  SPDX-FileCopyrightText: 2014 Johnny Jazeix <jazeix@gmail.com>
0004 
0005  Bruno Coudoin: initial Gtk+ version
0006 
0007  SPDX-License-Identifier: GPL-3.0-or-later
0008 */
0009 import QtQuick 2.12
0010 import GCompris 1.0
0011 
0012 import "../../core"
0013 import "../ballcatch"
0014 import "ballcatch.js" as Activity
0015 
0016 ActivityBase {
0017     id: activity
0018 
0019     onStart: {
0020         focus = true;
0021     }
0022     onStop: {}
0023 
0024     Keys.onPressed: {
0025         Activity.processKey(event);
0026     }
0027 
0028     pageComponent: Image {
0029         id: background
0030         signal start
0031         signal stop
0032         focus: true
0033         fillMode: Image.PreserveAspectCrop
0034         source: "qrc:/gcompris/src/activities/ballcatch/resource/beach1.svg"
0035         sourceSize.width: width
0036         sourceSize.height: height
0037 
0038         property bool isVertical: background.width <= background.height     // To check if in Vertical mode
0039 
0040         // Needed to get keyboard focus on IntroMessage
0041         Keys.forwardTo: message
0042 
0043         Component.onCompleted: {
0044             activity.start.connect(start);
0045             activity.stop.connect(stop);
0046         }
0047         QtObject {
0048             id: items
0049             property alias background: background
0050             property int currentLevel: activity.currentLevel
0051             property alias ball: ball
0052             property alias rightHand: rightHand
0053             property alias leftHand: leftHand
0054             property alias deltaPressedTimer: deltaPressedTimer
0055             /* when the corresponding arrow key is pressed, the following boolean pass
0056                to true and is reset at the end of the level */
0057             property bool leftPressed
0058             property bool rightPressed
0059         }
0060 
0061         onStart: Activity.start(items);
0062 
0063         onStop: Activity.stop();
0064 
0065         onWidthChanged: {
0066             leftHand.reinitPosition();
0067             rightHand.reinitPosition();
0068             ball.reinitBall();
0069         }
0070 
0071         onHeightChanged: {
0072             leftHand.reinitPosition();
0073             rightHand.reinitPosition();
0074             ball.reinitBall();
0075         }
0076 
0077         DialogHelp {
0078             id: dialogHelpLeftRight
0079             onClose: home();
0080         }
0081 
0082         Bar {
0083             id: bar
0084             level: items.currentLevel + 1
0085             content: BarEnumContent { value: help | home | level }
0086             onHelpClicked: displayDialog(dialogHelpLeftRight);
0087             onPreviousLevelClicked: if(!bonus.isPlaying) Activity.previousLevel();
0088             onNextLevelClicked: if(!bonus.isPlaying) Activity.nextLevel();
0089             onHomeClicked: home();
0090         }
0091 
0092         Bonus {
0093             id: bonus
0094             winSound: "qrc:/gcompris/src/activities/ballcatch/resource/tuxok.wav"
0095             looseSound: "qrc:/gcompris/src/activities/ballcatch/resource/youcannot.wav"
0096             Component.onCompleted: {
0097                 win.connect(Activity.nextLevel);
0098                 loose.connect(Activity.restartLevel);
0099             }
0100             onStart: tux.opacity = 0;
0101             onStop: tux.opacity = 1;
0102         }
0103 
0104         Image {
0105             id: tux
0106             x: background.width / 2 - width / 2
0107             y: leftHand.y - height / 3 - height / 2
0108             sourceSize.height: 200 * ApplicationInfo.ratio
0109             source: "qrc:/gcompris/src/activities/ballcatch/resource/tux.svg"
0110             Behavior on opacity { PropertyAnimation { easing.type: Easing.InQuad; duration: 250 } }
0111         }
0112 
0113         Image {
0114             id: leftHand
0115             y: background.height - 1.5 * height
0116             z: 5
0117             sourceSize.height: 150 * ApplicationInfo.ratio
0118             source: "qrc:/gcompris/src/activities/ballcatch/resource/hand.svg"
0119 
0120             NumberAnimation {
0121                 id: leftHandAnimation
0122                 target: leftHand; property: "x";
0123                 to: background.width/2 - leftHand.width - 5;
0124                 duration: 1000
0125                 easing.type: Easing.InOutQuad
0126             }
0127 
0128             function animate(newTime) {
0129                 leftHandAnimation.duration = newTime;
0130                 leftHandAnimation.start();
0131             }
0132 
0133             function reinitPosition() {
0134                 leftHandAnimation.stop();
0135                 leftHand.x = background.width / 2 - width * 2;
0136                 leftHand.y = background.height - 1.5 * height;
0137             }
0138 
0139             MultiPointTouchArea {
0140 
0141                 id: mouseAreaLeftShift
0142                 anchors.fill: parent
0143                 onTouchUpdated: {
0144                     // left
0145                     if(!items.leftPressed && !Activity.gameFinished) {
0146                         Activity.leftShiftPressed();
0147                         items.leftPressed = true;
0148                     }
0149                 }
0150             }
0151         }
0152 
0153         Image {
0154             id: rightHand
0155             mirror: true
0156             y: background.height - 1.5 * height
0157             z: 5
0158             sourceSize.height: 150 * ApplicationInfo.ratio
0159             source: "qrc:/gcompris/src/activities/ballcatch/resource/hand.svg"
0160 
0161             function animate(newTime) {
0162                 rightHandAnimation.duration = newTime;
0163                 rightHandAnimation.start();
0164             }
0165 
0166             function reinitPosition() {
0167                 rightHandAnimation.stop();
0168                 rightHand.x = background.width / 2 + width;
0169                 rightHand.y = background.height - 1.5 * height;
0170             }
0171 
0172             NumberAnimation {
0173                 id: rightHandAnimation
0174                 target: rightHand; property: "x";
0175                 to: background.width / 2 + 5;
0176                 duration: 1000;
0177                 easing.type: Easing.InOutQuad
0178             }
0179 
0180             MultiPointTouchArea {
0181                 id: mouseAreaRightShift
0182                 anchors.fill: parent
0183                 onTouchUpdated: {
0184                     // right
0185                     if(!items.rightPressed && !Activity.gameFinished) {
0186                         Activity.rightShiftPressed();
0187                         items.rightPressed = true;
0188                     }
0189                 }
0190             }
0191         }
0192 
0193         Image {
0194             id: leftShift
0195             z: 10
0196             x: background.width / 4 - width
0197             y: background.isVertical ? rightHand.y - height : rightHand.y - height / 2
0198             source: "qrc:/gcompris/src/activities/ballcatch/resource/arrow_key.svg"
0199             scale: background.isVertical ? 0.75 : 1.0
0200             smooth: true
0201             opacity: items.leftPressed ? 1 : 0.5
0202             visible: !ApplicationInfo.isMobile
0203         }
0204 
0205         Image {
0206             id: rightShift
0207             z: 10
0208             mirror: true
0209             x: background.width - background.width / 4
0210             y: background.isVertical ? rightHand.y - height : rightHand.y - height / 2
0211             source: "qrc:/gcompris/src/activities/ballcatch/resource/arrow_key.svg"
0212             scale: background.isVertical ? 0.75 : 1.0
0213             smooth: true
0214             opacity: items.rightPressed ? 1 : 0.5
0215             visible: !ApplicationInfo.isMobile
0216         }
0217 
0218         // Instructions
0219         IntroMessage {
0220             id: message
0221             intro: ApplicationInfo.isMobile ?
0222                        [qsTr("Tap both hands at the same time, " +
0223                             "to make the ball go in a straight line.")] :
0224                        [qsTr("Press left and right arrow keys at the same time, " +
0225                             "to make the ball go in a straight line.")]
0226             anchors {
0227                 top: parent.top
0228                 topMargin: 10
0229             }
0230             z: 10
0231         }
0232 
0233         function playSound(identifier) {
0234             activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/"+ identifier + ".wav");
0235         }
0236 
0237         /* Timer starting when user first presses a first key.
0238            If still running when the user presses the other key, he wins !
0239         */
0240         Timer {
0241             id: deltaPressedTimer
0242             running: false; repeat: false
0243             onTriggered: {
0244                 Activity.endTimer();
0245                 ball.startAnimation();
0246             }
0247         }
0248 
0249         Ball {
0250             id: ball
0251         }
0252 
0253     }
0254 }