diff --git a/src/activities/numbers-odd-even/NumbersOddEven.qml b/src/activities/numbers-odd-even/NumbersOddEven.qml index fade95cea..bb53e9c9d 100644 --- a/src/activities/numbers-odd-even/NumbersOddEven.qml +++ b/src/activities/numbers-odd-even/NumbersOddEven.qml @@ -1,42 +1,82 @@ /* gcompris - NumberOddEven.qml Copyright (C) 2014 Bruno Coudoin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . */ import QtQuick 2.6 import "../planegame" Planegame { + showTutorial: true + dataset: [ { data: "0 2 4 6 8 10 12 14 16 18 20".split(" "), showNext: true }, { data: "1 3 5 7 9 11 13 15 17 19 21".split(" "), showNext: true }, { data: "0 2 4 6 8 10 12 14 16 18 20".split(" "), showNext: false }, { data: "1 3 5 7 9 11 13 15 17 19 21".split(" "), showNext: false } ] + + tutorialInstructions: [ + { + "instruction": qsTr("This activity teaches about even and odd numbers."), + "instructionQml": "" + }, + { + "instruction": qsTr("Even numbers are numbers which leave remainder 0 when divided by 2."), + "instructionQml": "" + }, + + { + "instruction": qsTr("What is meant by remainder of a number?"), + "instructionQml" : "qrc:/gcompris/src/activities/numbers-odd-even/resource/Tutorial1.qml" + }, + + { + "instruction": qsTr("Even numbers are numbers which leave remainder 0 when divided by 2."), + "instructionQml" : "qrc:/gcompris/src/activities/numbers-odd-even/resource/Tutorial2.qml" + }, + { + "instruction": qsTr("Odd numbers are numbers which do not leave remainder 0 when divided by 2."), + "instructionQml": "qrc:/gcompris/src/activities/numbers-odd-even/resource/Tutorial3.qml" + }, + { + "instruction": qsTr("Exercise to test your understanding."), + "instructionQml": "qrc:/gcompris/src/activities/numbers-odd-even/resource/Tutorial4.qml" + }, + { + "instruction": qsTr("Exercise to test your understanding."), + "instructionQml": "qrc:/gcompris/src/activities/numbers-odd-even/resource/Tutorial5.qml" + }, + { + "instruction": qsTr("Exercise to test your understanding."), + "instructionQml": "qrc:/gcompris/src/activities/numbers-odd-even/resource/Tutorial6.qml" + } + + ] } diff --git a/src/activities/numbers-odd-even/resource/Tutorial1.qml b/src/activities/numbers-odd-even/resource/Tutorial1.qml new file mode 100644 index 000000000..952f7102b --- /dev/null +++ b/src/activities/numbers-odd-even/resource/Tutorial1.qml @@ -0,0 +1,45 @@ +/* GCompris - Tutorial1.qml + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../../core" + +Rectangle { + id: tutorialRectangle + anchors.fill: parent + color: "#80FFFFFF" + + GCText { + id: remainder + text: qsTr("The remainder is the amount \"left over\" after dividing the given number with the other number.\n If 6 is divided by 2 the result is 3 and the remainder is 0.\n If 7 is divided by 2 the result is 3 and the remainder is 1.") + fontSizeMode: Text.Fit + fontSize: mediumSize + anchors.left: tutorialRectangle.left + anchors.leftMargin: parent.height * 0.01 + color: "black" + horizontalAlignment: Text.AlignLeft + width: parent.width + height: parent.height + wrapMode: Text.WordWrap + z: 2 + } +} diff --git a/src/activities/numbers-odd-even/resource/Tutorial2.qml b/src/activities/numbers-odd-even/resource/Tutorial2.qml new file mode 100644 index 000000000..efedf5de1 --- /dev/null +++ b/src/activities/numbers-odd-even/resource/Tutorial2.qml @@ -0,0 +1,45 @@ +/* GCompris - Tutorial2.qml + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../../core" + +Rectangle { + id: tutorialRectangle + anchors.fill: parent + color: "#80FFFFFF" + + GCText { + id: even + text: qsTr("For example: 12, 38, 52, 68, 102, 118, 168, 188, 502, 532, 700, 798, 842, 892, 1000. All of these numbers are even numbers as they leave remainder 0 when divided by 2.") + fontSizeMode: Text.Fit + fontSize: mediumSize + anchors.left: tutorialRectangle.left + anchors.leftMargin: parent.height * 0.01 + color: "black" + horizontalAlignment: Text.AlignLeft + width: parent.width + height: parent.height + wrapMode: Text.WordWrap + z: 2 + } +} diff --git a/src/activities/numbers-odd-even/resource/Tutorial3.qml b/src/activities/numbers-odd-even/resource/Tutorial3.qml new file mode 100644 index 000000000..c67d2ee79 --- /dev/null +++ b/src/activities/numbers-odd-even/resource/Tutorial3.qml @@ -0,0 +1,45 @@ +/* GCompris - Tutorial3.qml + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../../core" + +Rectangle { + id: tutorialRectangle + anchors.fill: parent + color: "#80FFFFFF" + + GCText { + id: odd + text: qsTr("For example: 15, 19, 51, 65, 103, 119, 169, 185, 505, 533, 701, 799, 845, 897, 1001. All of these numbers are odd numbers as they do not leave remainder 0 when divided by 2.") + fontSizeMode: Text.Fit + fontSize: mediumSize + anchors.left: tutorialRectangle.left + anchors.leftMargin: parent.height * 0.01 + color: "black" + horizontalAlignment: Text.AlignLeft + width: parent.width + height: parent.height + wrapMode: Text.WordWrap + z: 2 + } +} diff --git a/src/activities/numbers-odd-even/resource/Tutorial4.qml b/src/activities/numbers-odd-even/resource/Tutorial4.qml new file mode 100644 index 000000000..d83f91ef7 --- /dev/null +++ b/src/activities/numbers-odd-even/resource/Tutorial4.qml @@ -0,0 +1,31 @@ +/* GCompris - Tutorial4.qml + + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../../core" + +TutorialBase { + + firstNumber: "2" + secondNumber: "5" +} diff --git a/src/activities/numbers-odd-even/resource/Tutorial5.qml b/src/activities/numbers-odd-even/resource/Tutorial5.qml new file mode 100644 index 000000000..464736629 --- /dev/null +++ b/src/activities/numbers-odd-even/resource/Tutorial5.qml @@ -0,0 +1,32 @@ +/* GCompris - Tutorial5.qml + + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../../core" + +TutorialBase { + + isEvenExpected: false + firstNumber: "59" + secondNumber: "52" +} diff --git a/src/activities/numbers-odd-even/resource/Tutorial6.qml b/src/activities/numbers-odd-even/resource/Tutorial6.qml new file mode 100644 index 000000000..b5a2379d9 --- /dev/null +++ b/src/activities/numbers-odd-even/resource/Tutorial6.qml @@ -0,0 +1,30 @@ +/* GCompris - Tutorial6.qml + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../../core" + +TutorialBase { + + firstNumber: "111" + secondNumber: "108" +} diff --git a/src/activities/numbers-odd-even/resource/TutorialBase.qml b/src/activities/numbers-odd-even/resource/TutorialBase.qml new file mode 100644 index 000000000..97a972fd6 --- /dev/null +++ b/src/activities/numbers-odd-even/resource/TutorialBase.qml @@ -0,0 +1,147 @@ +/* GCompris - TutorialBase.qml + * + * Copyright (C) 2019 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import "../../../core" + +Rectangle { + id: tutorialRectangle + anchors.fill: parent + color: "#80FFFFFF" + property alias firstNumber: firstNumber.textLabel + property alias secondNumber: secondNumber.textLabel + property alias message: message.text + property bool isEvenExpected: true + + GCText { + id: question + anchors { + left: parent.left + verticalCenter: parent.verticalCenter + leftMargin: parent.height * 0.1 + centerIn: parent.Center + top: parent.top + topMargin: parent.height * 0.05 + } + text: isEvenExpected ? qsTr("Choose the even number:") : qsTr("Choose the odd number:") + fontSize: mediumSize + color: "black" + horizontalAlignment: Text.AlignLeft + width: 1.8 * parent.width + height: 1.8 * parent.height + wrapMode: Text.WordWrap + z: 2 + } + + AnswerButton { + id: firstNumber + textLabel: "" + anchors { + top: parent.top + topMargin: parent.height * 0.3 + left: parent.left + leftMargin: parent.width * 0.2 + } + width: parent.width * 0.2 + height: parent.height * 0.4 + isCorrectAnswer: (isEvenExpected && Number(textLabel) % 2 === 0) || + (!isEvenExpected && Number(textLabel) % 2 !== 0) + onPressed: { + if(isCorrectAnswer) { + message.text = qsTr("Great") + } + else { + if(isEvenExpected) { + message.text = qsTr("There is an error: when divided by 2, %1 leaves remainder as 1. Therefore this is an odd number.").arg(textLabel) + } + else { + message.text = qsTr("There is an error: when divided by 2, %1 leaves remainder as 0. Therefore this is an even number.").arg(textLabel) + } + } + message.visible = true + messageRectangle.visible = true + } + } + + AnswerButton { + id: secondNumber + textLabel: "" + anchors { + top: parent.top + topMargin: parent.height * 0.3 + left: parent.left + leftMargin: parent.width * 0.65 + } + width: parent.width * 0.2 + height: parent.height * 0.4 + isCorrectAnswer: (isEvenExpected && Number(textLabel) % 2 === 0) || + (!isEvenExpected && Number(textLabel) % 2 !== 0) + onPressed: { + if(isCorrectAnswer) { + message.text = qsTr("Great") + } + else { + if(isEvenExpected) { + message.text = qsTr("There is an error: when divided by 2, %1 leaves remainder as 1. Therefore this is an odd number.").arg(textLabel) + } + else { + message.text = qsTr("There is an error: when divided by 2, %1 leaves remainder as 0. Therefore this is an even number.").arg(textLabel) + } + } + message.visible = true + messageRectangle.visible = true + } + } + + Rectangle { + id: messageRectangle + anchors { + horizontalCenter: parent.horizontalCenter + top: parent.top + topMargin: parent.height * 0.75 + } + opacity: 0.8 + radius: 10 + border.width: 6 + color: "white" + border.color: "#87A6DD" + width: parent.width * 1.15 + height: parent.height * 0.4 + visible: false + + GCText { + id: message + anchors { + centerIn: parent + margins: parent.border.width+1 + } + text: "" + fontSizeMode: Text.Fit + fontSize: smallSize + color: "black" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + width: parent.width + height: parent.height + wrapMode: Text.WordWrap + z: 2 + } + } +} diff --git a/src/activities/planegame/Planegame.qml b/src/activities/planegame/Planegame.qml index c30d2b425..ea1172e20 100644 --- a/src/activities/planegame/Planegame.qml +++ b/src/activities/planegame/Planegame.qml @@ -1,150 +1,183 @@ /* gcompris - Planegame.qml Copyright (C) 2014 Johnny Jazeix 2003, 2014: Bruno Coudoin: initial version 2014: Johnny Jazeix: Qt port This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . */ import QtQuick 2.6 import GCompris 1.0 import "../../core" import "planegame.js" as Activity ActivityBase { id: activity focus: true onStart: { focus = true; } onStop: { } Keys.onPressed: Activity.processPressedKey(event) Keys.onReleased: Activity.processReleasedKey(event) property var dataset + property var tutorialInstructions + property bool showTutorial: false property int oldWidth: width onWidthChanged: { // Reposition helico and clouds, same for height Activity.repositionObjectsOnWidthChanged(width / oldWidth) oldWidth = width } property int oldHeight: height onHeightChanged: { // Reposition helico and clouds, same for height Activity.repositionObjectsOnHeightChanged(height / oldHeight) oldHeight = height } pageComponent: Image { id: background anchors.fill: parent signal start signal stop source: Activity.url + "../algorithm/resource/desert_scene.svg" sourceSize.width: parent.width Component.onCompleted: { - activity.start.connect(start) - activity.stop.connect(stop) + activity.start.connect(start) + activity.stop.connect(stop) } + QtObject { id: items property alias background: background property alias bar: bar property alias bonus: bonus property alias score: score property alias plane: plane property GCAudio audioVoices: activity.audioVoices property GCSfx audioEffects: activity.audioEffects property alias movePlaneTimer: movePlaneTimer property alias cloudCreation: cloudCreation + property bool showTutorial: activity.showTutorial + } + + onStart: { Activity.start(items, dataset) } + onStop: { Activity.stop() } + + //Tutorial section starts + Loader { + active: showTutorial + anchors.fill: parent + z: 1 + sourceComponent: tutorialComponent + Component { + id: tutorialComponent + Image { + id: tutorialImage + source: "../digital_electricity/resource/texture01.png" + anchors.fill: parent + fillMode: Image.Tile + Tutorial { + id: tutorialSection + tutorialDetails: tutorialInstructions + useImage: false + onSkipPressed: { + showTutorial = false + Activity.initLevel() + } + } + } + } } - onStart: Activity.start(items, dataset) - onStop: Activity.stop(); + // Tutorial section ends MultiPointTouchArea { anchors.fill: parent touchPoints: [ TouchPoint { id: point1 } ] onReleased: { plane.x = point1.x - plane.width / 2 plane.y = point1.y - plane.height / 2 } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar - content: BarEnumContent { value: help | home | level } + content: BarEnumContent { value: items.showTutorial ? (help | home) : (help | home | level) } onHelpClicked: displayDialog(dialogHelp) onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } Score { id: score - visible: false + visible: !showTutorial fontSize: background.width >= background.height ? internalTextComponent.largeSize : internalTextComponent.mediumSize height: internalTextComponent.height + 10 anchors.bottom: bar.top anchors.margins: 10 } property int movePlaneTimerCounter: 0 Timer { id: movePlaneTimer running: false repeat: true onTriggered: { plane.state = "play" interval = 50 if(movePlaneTimerCounter++ % 3 == 0) { /* Do not call this too often or plane commands are too hard */ Activity.handleCollisionsWithCloud(); } Activity.computeVelocity(); Activity.planeMove(); } } Timer { id: cloudCreation running: false repeat: true interval: 10200 - (bar.level * 200) onTriggered: Activity.createCloud() } Plane { id: plane + visible: !showTutorial background: background } } } diff --git a/src/activities/planegame/planegame.js b/src/activities/planegame/planegame.js index 67c280079..ab7dfcb9d 100644 --- a/src/activities/planegame/planegame.js +++ b/src/activities/planegame/planegame.js @@ -1,333 +1,335 @@ /* gcompris - planegame.js Copyright (C) 2003, 2014: Bruno Coudoin: initial version 2014: Johnny Jazeix: Qt port 2014: Bruno Coudoin: Added support for dataset, smooth plane anim This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . */ .pragma library .import QtQuick 2.6 as Quick .import GCompris 1.0 as GCompris //for ApplicationInfo .import "qrc:/gcompris/src/core/core.js" as Core var url = "qrc:/gcompris/src/activities/planegame/" var max_velocity = 500 * GCompris.ApplicationInfo.ratio var currentLevel var numberOfLevel var currentSubLevel var numberOfSubLevels var upPressed var downPressed var leftPressed var rightPressed var items var dataset var cloudComponent = Qt.createComponent(url + "Cloud.qml"); var clouds = new Array; var cloudsErased = new Array; function start(items_, dataset_) { Core.checkForVoices(items_.background); items = items_ dataset = dataset_ numberOfLevel = dataset.length currentLevel = 0 - initLevel() + if(items.showTutorial === false) { + initLevel() + } } function stop() { cloudDestroy(clouds) cloudDestroy(cloudsErased) items.movePlaneTimer.stop() items.cloudCreation.stop() } function cloudDestroy(clouds) { for(var i = clouds.length - 1; i >= 0 ; --i) { var cloud = clouds[i]; // Remove the cloud cloud.destroy() // Remove the element from the list clouds.splice(i, 1) } } function initLevel() { items.bar.level = currentLevel + 1; currentSubLevel = 0 numberOfSubLevels = dataset[currentLevel].data.length items.movePlaneTimer.stop(); items.cloudCreation.stop() - items.score.visible = dataset[currentLevel].showNext items.score.message = dataset[currentLevel].data[currentSubLevel] + items.score.visible = dataset[currentLevel].showNext upPressed = false downPressed = false leftPressed = false rightPressed = false cloudDestroy(clouds) cloudDestroy(cloudsErased) // Tend towards 0.5 ratio items.plane.state = "init" items.movePlaneTimer.interval = 1000 items.movePlaneTimer.start(); items.cloudCreation.start() - // Inject the first cloud now + + //Inject the first cloud now createCloud() } function nextLevel() { if(numberOfLevel <= ++currentLevel) { currentLevel = 0 } - initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } function repositionObjectsOnWidthChanged(factor) { if(items && items.plane) { items.movePlaneTimer.interval = 1000 items.plane.state = "init" } for(var i = clouds.length - 1; i >= 0 ; --i) { var cloud = clouds[i]; } } function repositionObjectsOnHeightChanged(factor) { if(items && items.plane) { items.movePlaneTimer.interval = 1000 items.plane.state = "init" } for(var i = clouds.length - 1; i >= 0 ; --i) { var cloud = clouds[i]; cloud.y *= factor } } var cloudCounter = 1 function createCloud() { var cloud = cloudComponent.createObject( items.background, { "background": items.background, "x": items.background.width, "heightRatio": 1.0 - 0.5 * currentLevel / 10 }); /* Random cloud number but at least one in 3 */ if(cloudCounter++ % 3 == 0 || getRandomInt(0, 1) === 0) { /* Put the target */ cloud.text = dataset[currentLevel].data[currentSubLevel]; cloudCounter = 1 } else { var min = Math.max(1, currentSubLevel - 1); var index = Math.min(min + getRandomInt(0, currentSubLevel - min + 3), numberOfSubLevels - 1) cloud.text = dataset[currentLevel].data[index] } clouds.push(cloud); } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function processPressedKey(event) { switch(event.key) { case Qt.Key_Right: rightPressed = true; event.accepted = true; break; case Qt.Key_Left: leftPressed = true; event.accepted = true; break; case Qt.Key_Up: upPressed = true; event.accepted = true; break; case Qt.Key_Down: downPressed = true; event.accepted = true; } } function processReleasedKey(event) { switch(event.key) { case Qt.Key_Right: rightPressed = false; event.accepted = true; break; case Qt.Key_Left: leftPressed = false; event.accepted = true; break; case Qt.Key_Up: upPressed = false; event.accepted = true; break; case Qt.Key_Down: downPressed = false; event.accepted = true; } } var speedX = 0 var speedY = 0 var speedFactor = 20 function computeVelocity() { if(rightPressed && speedX < 300) speedX += speedFactor if(leftPressed && speedX > -300) speedX -= speedFactor if(!rightPressed && speedX > 0) speedX = 0 else if(!leftPressed && speedX < 0) speedX = 0 else if(leftPressed || rightPressed) items.plane.x += speedX if(upPressed && speedY > -300) speedY -= speedFactor if(downPressed && speedY < 300) speedY += speedFactor if(!upPressed && speedY < 0) speedY = 0 else if(!downPressed && speedY > 0) speedY = 0 else if(upPressed || downPressed) items.plane.y += speedY items.plane.rotation = speedX * 10 / max_velocity } /* We move x/y of the plane to let its smooth animation track it */ function planeMove() { if(items.plane.x + items.plane.width > items.background.width) { items.plane.x = items.background.width - items.plane.width; } if(items.plane.x < 0) { items.plane.x = 0; } if(items.plane.y < 0) { items.plane.y = 0; } if(items.plane.y + items.plane.height > items.background.height - items.bar.height) { items.plane.y = items.background.height - (items.plane.height + items.bar.height); } } function isIn(x1, y1, px1, py1, px2, py2) { return (x1>px1 && x1py1 && y1= 0 ; --i) { var cloud = clouds[i]; var x1 = cloud.x var x2 = cloud.x + cloud.width var y1 = cloud.y var y2 = cloud.y + cloud.height if(x2 < 0) { // Remove the cloud cloud.destroy() clouds.splice(i, 1) } else if(isIn(x1, y1, planeX1, planeY1, planeX2, planeY2) || isIn(x2, y1, planeX1, planeY1, planeX2, planeY2) || isIn(x1, y2, planeX1, planeY1, planeX2, planeY2) || isIn(x2, y2, planeX1, planeY1, planeX2, planeY2)) { gotOne = true // Collision, look for id if(cloud.text === dataset[currentLevel].data[currentSubLevel]) { playLetterSound(cloud.text) // Move the cloud to the erased list cloud.done() cloudsErased.push(cloud) clouds.splice(i, 1) currentSubLevel++ if(currentSubLevel === numberOfSubLevels) { /* Try the next level */ items.bonus.good("flower") } else { items.score.message = dataset[currentLevel].data[currentSubLevel] } } else { /* Touched the wrong cloud */ if(!cloud.touched) items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/crash.wav") cloud.touch() } break; } } // Reset the touched state on the clouds if(!gotOne) { for(var i = clouds.length - 1; i >= 0 ; --i) { clouds[i].touched = false } } } } function playLetterSound(number) { if(number > 9) items.audioVoices.play(GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/" + number + ".$CA")) else items.audioVoices.play( GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/" + Core.getSoundFilenamForChar(number))) }