Warning, /education/gcompris/src/activities/ballcatch/Ball.qml is written in an unsupported language. File is not indexed.
0001 /* gcompris - Ball.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 "ballcatch.js" as Activity 0011 import GCompris 1.0 0012 0013 Image { 0014 id: ball 0015 0016 property bool isVertical: background.width <= background.height // To check if in Vertical mode 0017 0018 source: "qrc:/gcompris/src/activities/ballcatch/resource/ball.svg" 0019 sourceSize.height: background.isVertical ? 175 * Application.ratio : 200 * ApplicationInfo.ratio 0020 z: 3 0021 0022 readonly property real initScale: 1.0 0023 0024 // If won, ball goes on tux, if lose, depends on the side clicked first 0025 property int finishX 0026 0027 readonly property int finishY: tux.y + tux.height / 4 0028 readonly property real finishScale: initScale / 2 0029 property int radius: initScale 0030 property bool levelChange: false //needed in case of changing level while animation is running 0031 0032 function stop() { 0033 levelChange = true; 0034 animation.stop(); 0035 } 0036 0037 ParallelAnimation { 0038 id: animation 0039 running: false 0040 0041 NumberAnimation { target: ball; property: "x"; 0042 to: finishX; duration: 1000 0043 easing.type: Easing.InOutQuad } 0044 NumberAnimation { target: ball; property: "y"; 0045 to: finishY; duration: 1000 0046 easing.type: Easing.InOutQuad } 0047 NumberAnimation { target: ball; property: "scale"; 0048 to: finishScale; duration: 1000 0049 easing.type: Easing.InOutQuad } 0050 NumberAnimation { target: ball; property: "rotation"; 0051 to: 360; duration: 1000 0052 easing.type: Easing.InOutQuad } 0053 onStarted: { 0054 items.background.playSound("brick"); 0055 } 0056 0057 onStopped: { 0058 // We are done with the ballon move 0059 if(levelChange) { 0060 return 0061 } else if(Activity.gameWon) { 0062 // This is a win 0063 items.background.playSound("completetask"); 0064 bonus.good("tux"); 0065 } else { 0066 // This is a lose 0067 bonus.bad("tux"); 0068 } 0069 } 0070 } 0071 0072 function startAnimation() { 0073 if(Activity.gameWon) { 0074 finishX = x; 0075 } 0076 else if(Activity.items.leftPressed) { 0077 finishX = tux.x + tux.width * 2; 0078 } 0079 else { 0080 finishX = tux.x - tux.width * 2; 0081 } 0082 /* Only start the timer if the game is at init state. 0083 In init state, radius is initScale */ 0084 if(ball.radius == ball.initScale) 0085 animation.start(); 0086 } 0087 0088 function reinitBall() { 0089 x = background.width / 2 - width / 2; 0090 y = leftHand.y - height / 3; 0091 ball.scale = initScale; 0092 ball.rotation = 0; 0093 levelChange = false; 0094 } 0095 }