diff --git a/src/activities/parachute/Parachute.qml b/src/activities/parachute/Parachute.qml index 6464c93f4..0bf10190d 100644 --- a/src/activities/parachute/Parachute.qml +++ b/src/activities/parachute/Parachute.qml @@ -1,511 +1,527 @@ /* GCompris - parachute.qml * * Copyright (C) 2015 Rajdeep Kaur * * Authors: * Bruno Coudoin (GTK+ version) * Rajdeep kaur (Qt Quick 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.1 import GCompris 1.0 import QtGraphicalEffects 1.0 import "../../core" import "qrc:/gcompris/src/core/core.js" as Core import "parachute.js" as Activity ActivityBase { id: activity property real velocityX property real velocityY property string dataSetUrl: "qrc:/gcompris/src/activities/parachute/resource/" onStart: focus = true onStop: {} pageComponent: Image { id: background source: activity.dataSetUrl + "back.svg" fillMode: Image.PreserveAspectCrop sourceSize.width: parent.width anchors.fill: parent signal start signal stop Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) } onStart: { } onStop: { Activity.stop() } // Add here the QML items you need to access in javascript QtObject { id: items property Item main : activity.main property alias background: background property alias animationheli: animationheli property alias animationcloud: animationcloud property alias bar: bar property alias bonus: bonus property alias animationboat: animationboat property alias keyunable: keyunable property alias ok: ok property alias loop: loop property alias loopcloud: loopcloud property alias tuxX: tuxX property alias touch: touch property alias tux: tux property alias tuximage: tuximage property alias helimotion: helimotion property alias helicopter : helicopter property real velocityY:velocityY } IntroMessage { id:message onIntroDone: { Activity.start(items) } intro: [ qsTr("The red boat moves in the water from left to right."), qsTr("Penguin Tux falls off from the plane, to land on the boat safely. "), qsTr("The purpose of the game is to determine the exact time when" + "he should fall off from the plane, in order to safely get to the boat. "), qsTr("Tux also carries a parachute, that lets him prevent free fall under gravity, that is dangerous." +"Tux falls off when the player left clicks on the plane."), qsTr("His speed can be controlled by the player by pressing UP and DOWN arrow keys," + "such that Tux is saved from falling in water. "), qsTr("Help Tux save his life!") ] z: 20 anchors { top: parent.top topMargin: 10 right: parent.right rightMargin: 5 left: parent.left leftMargin: 5 } } GCText { id: keyunable anchors.centerIn: parent fontSize: largeSize visible: false text: qsTr("Control fall speed with up and down arrow keys") } Item { id: helimotion width: (bar.level===1?background.width/6:bar.level===2?background.width/4:bar.level===3?background.width/11:bar.level===4?background.width/7:background.width/7) height: (bar.level===1?background.height/6:bar.level===2?background.height/4:bar.level===3?background.height/11:bar.level===4?background.height/7:background.height/7) x: -width Rectangle { id: forhover width: (bar.level===1?background.width/6:bar.level===2?background.width/4:bar.level===3?background.width/11:bar.level===4?background.width/7:background.width/7) height: (bar.level===1?background.height/6:bar.level===2?background.height/4:bar.level===3?background.height/11:bar.level===4?background.height/7:background.height/7) visible: false border.width: 7 radius: 20 border.color: "#A80000" color: "#500000" } Image { id: helicopter source: activity.dataSetUrl + "tuxplane.svg" width: (bar.level === 1?background.width/6:bar.level === 2?background.width/4:bar.level === 3?background.width/11:bar.level === 4?background.width/7:background.width/7) height: (bar.level === 1?background.height/6:bar.level === 2?background.height/4:bar.level === 3?background.height/11:bar.level === 4?background.height/7:background.height/7) MouseArea { id:mousei hoverEnabled: true anchors.fill: parent - onEntered: { - forhover.visible = true - } - onExited: { - forhover.visible = false - } onClicked: { if((Activity.Oneclick === false)&&(Activity.tuxfallingblock ===false)) { helicopter.source = activity.dataSetUrl + Activity.planeWithouttux tuximage.visible=true tux.y = helimotion.y tuxX.stop() /* activity.audioEffects.play(activity.dataSetUrl+"youcannot.wav"); sound file is not supporting in linux please do remove it before the merge */ Activity.tuxImageStatus = 1 Activity.Oneclick = true; velocityX = Activity.velocityX velocityY = (items.bar.level === 1 ? 30 : items.bar.level === 2 ? 40 : items.bar.level === 3 ? 55 : items.bar.level === 4 ? 80 : 12 ) tux.state = "Released" + } } } } SequentialAnimation { id: loop loops: Animation.Infinite PropertyAnimation { id: animationheli target: helimotion properties: "x" from: -helimotion.width to: background.width duration: (bar.level === 1 ? 20000 : bar.level === 2 ? 16000 : bar.level === 3 ? 12000 : bar.level === 4 ? 10000 : 9000) easing.type: Easing.Linear } } + + onXChanged: { + if(Activity.tuxImageStatus === 1 || Activity.tuxImageStatus === 2){ + if(helimotion.x > (background.width - helimotion.width/2)) { + helicopter.visible = false + } + } + } } Item { id: tux width: tuximage.width height: tuximage.height x: -helimotion.width state:"rest" Rectangle { id: tuximagehover width: tuximage.width height: tuximage.height visible: false border.width: 7 radius: 20 border.color: "#A80000" color: "#500000" opacity: 90 } Image { id: tuximage source: activity.dataSetUrl + Activity.minitux visible: false MouseArea { id: tuxmouse anchors.fill: parent hoverEnabled: true onClicked: { if(Activity.tuxImageStatus === 1) { if(tuximagehover.visible === true) { tuximagehover.visible = false } - + tux.state = "Released1" keyunable.visible = true tuximage.source = activity.dataSetUrl + Activity.parachutetux Activity.tuxImageStatus = 2 touch.enabled = true } } onEntered: { if(Activity.tuxImageStatus === 1) { tuximagehover.visible = true } } onExited: { tuximagehover.visible = false } } } onYChanged: { console.log(tux.y) if( (tux.y > background.height/1.5)&& Activity.tuxImageStatus === 1 ) { activity.audioEffects.play(activity.dataSetUrl + "bubble.wav" ) tux.state = "finished" touch.enabled = false Activity.tuxImageStatus = 0 Activity.onLose() } if((tux.y>background.height/1.5 && Activity.tuxImageStatus === 2) && ((tux.x>boatmotion.x) && (tux.xbackground.height/1.5 && Activity.tuxImageStatus === 2) && ((tux.xboatmotion.x+boatmotion.width))){ activity.audioEffects.play(activity.dataSetUrl + "bubble.wav" ) tux.state = "finished" touch.enabled = false Activity.tuxImageStatus = 0 Activity.onLose() } } SequentialAnimation { id: tuxX loops: Animation.Infinite PropertyAnimation { target: tux properties: "x" from: -helimotion.width to: background.width duration: (bar.level === 1 ? 20000 : bar.level === 2 ? 16000 : bar.level === 3 ? 12000 : bar.level === 4 ? 10000 : 9000) } } states: [ State{ name:"rest" PropertyChanges { target: tux y:helimotion.y } }, State { name: "UpPressed" PropertyChanges { target: tux - y:(tux.y + .25) + y:(tux.y + .02) x:(tux.x + 2) } }, State { name: "DownPressed" PropertyChanges { target: tux y:(tux.y + 75) x:(tux.x + 2) } }, State { name: "Released" PropertyChanges { target:tux y:(tux.y + Activity.steps()) x:(tux.x + 2) } }, + State{ + name:"Released1" + PropertyChanges { + target: tux + y:(tux.y + Activity.steps1()) + x:(tux.x +2 ) + } + + }, + State { name: "finished" PropertyChanges { target: tux } } ] Behavior on x { SmoothedAnimation { velocity:Activity.velocityX } } Behavior on y { SmoothedAnimation { velocity:Activity.velocityY[items.barlevel-1] } } } Keys.onReleased: { - if((Activity.tuxImageStatus === 1)||(Activity.tuxImageStatus ===2)) { + if(Activity.tuxImageStatus === 1) { velocityY = Activity.velocityY[bar.level-1] tux.state = "Released" + }else if(Activity.tuxImageStatus === 2) { + velocityY = Activity.velocityY[bar.level-1] + tux.state = "Released1" } } Keys.onUpPressed: { if(Activity.tuxImageStatus === 2) { tux.state = "UpPressed" velocityY = velocityY/2 } } Keys.onDownPressed: { if(Activity.tuxImageStatus === 2) { tux.state = "DownPressed" } } MultiPointTouchArea{ id:touch anchors.fill:parent enabled:false touchPoints: [ TouchPoint { id: point1 } ] onPressed: { if(Activity.tuxImageStatus === 2) { if(point1.y < tux.y ) { tux.state = "UpPressed" velocityY = velocityY/2 } else { tux.state = "DownPressed" } } } onReleased: { if((Activity.tuxImageStatus === 1)||(Activity.tuxImageStatus ===2)) { velocityY = Activity.velocityY[bar.level-1] tux.state = "Released" } } } Item { id: cloudmotion width: cloud.width height: height.height Image { id: cloud source: activity.dataSetUrl + "cloud.svg" y: background.height/7 } SequentialAnimation { id:loopcloud loops: Animation.Infinite PropertyAnimation { id: animationcloud target: cloudmotion properties: "x" - from: Math.random() > 0.2 ? background.width : -cloud.width - to: animationcloud.from === background.width ? -cloud.width : background.width + from:background.width + to:-cloud.width duration: (bar.level === 1 ? 19000 : bar.level === 2 ? 15000 : bar.level === 3 ? 11000 : bar.level === 4 ? 9000 : 9000) easing.type: Easing.Linear } PropertyAnimation { id: animationcloud1 target: cloudmotion properties: "x" from: background.width to: -cloud.width duration: (bar.level === 1 ? 19000 : bar.level === 2 ? 15000 : bar.level === 3 ? 11000 : bar.level === 4 ? 9000 : 9000) easing.type: Easing.Linear } PropertyAnimation { id: animationcloud2 target: cloudmotion properties: "x" from: -cloud.width to: background.width duration: (bar.level === 1 ? 19000 : bar.level === 2 ? 15000 : bar.level === 3 ? 11000 : bar.level === 4 ? 9000 : 9000) easing.type: Easing.Linear } PropertyAnimation { id: animationcloud3 target: cloudmotion properties: "x" from: background.width to: -cloud.width duration: (bar.level === 1 ? 19000 : bar.level === 2 ? 15000 : bar.level === 3 ? 11000 : bar.level === 4 ? 9000 : 9000) easing.type: Easing.Linear } PropertyAnimation { id: animationcloud4 target: cloudmotion properties: "x" from: -cloud.width to: background.width duration: (bar.level === 1 ? 19000 : bar.level === 2 ? 15000 : bar.level === 3 ? 11000 : bar.level === 4 ? 9000 : 9000) easing.type: Easing.Linear } } } Item { id: boatmotion width: background.width/4 height: background.height/4 Image { id: boat source: activity.dataSetUrl + "fishingboat.svg" y: (bar.level === 1 ? background.height/1.4 : bar.level==2 ? background.height/1.4 : bar.level ===3 ? background.height/1.4:bar.level === 4?background.height/1.4:background.height/1.3 ) width: (bar.level === 1 ? background.width/4 : bar.level==2 ? background.width/4.5 : bar.level ===3 ? background.width/5:bar.level === 4?background.width/5.1:background.width/5.1 ) height: background.height/4 } PropertyAnimation { id: animationboat target: boatmotion properties: "x" from: -boat.width to: background.width-2.5*boat.width duration: (bar.level === 1 ? 24000 : bar.level === 2 ? 20500 : bar.level === 3 ? 19000 : bar.level === 4 ? 17000 : 9000) easing.type: Easing.Linear } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() } BarButton { id: ok source: "qrc:/gcompris/src/core/resource/bar_ok.svg"; sourceSize.width: 75 * ApplicationInfo.ratio visible: false anchors.right: background.right onClicked: { Activity.loseflag = true Activity.nextLevel() } } Bonus { id: bonus onWin: ok.visible = true } } } diff --git a/src/activities/parachute/parachute.js b/src/activities/parachute/parachute.js index edc7ec5b7..ec709d198 100644 --- a/src/activities/parachute/parachute.js +++ b/src/activities/parachute/parachute.js @@ -1,173 +1,192 @@ /* GCompris - parachute.js * * Copyright (C) 2015 Rajdeep Kaur * * Authors: * Bruno Coudoin (GTK+ version) * Rajdeep kaur (Qt Quick 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 . */ .pragma library .import QtQuick 2.0 as Quick .import GCompris 1.0 as GCompris .import "qrc:/gcompris/src/core/core.js" as Core var currentLevel = 0 var numberOfLevel = 4 var items var checkPressed = false var pressed var Oneclick var winlose var loseflag = false var minitux = "minitux.svg" var parachutetux = "parachute.svg" var planeWithtux = "tuxplane.svg" var planeWithouttux = "tuxwithoutplane.svg" var tuxImageStatus = 1 var tuxfallingblock = false var velocityY = [30,45,55,80] var velocityX = 18 function start(items_) { items = items_ currentLevel = 0 initLevel() } function stop() { items.loop.stop() items.loopcloud.restart() items.animationboat.stop() } function initLevel() { if(loseflag == false) { items.bar.level = currentLevel + 1 } checkPressed = false winlose = false Oneclick = false pressed = false loseflag =false items.helicopter.source = "qrc:/gcompris/src/activities/parachute/resource/" + planeWithtux + items.helicopter.visible = true tuxImageStatus = 0 items.tux.state = "rest" items.tux.y = 0 tuxfallingblock = false items.ok.visible = false items.loop.restart() items.tuxX.restart() items.loopcloud.restart() items.animationboat.restart() } function onLose() { items.loop.stop() items.loopcloud.stop() items.animationboat.stop() items.tuxX.stop() items.bonus.bad("lion") items.tux.x = -items.helimotion.width items.tux.y = 0 tuxImageStatus = 0 items.tuximage.visible = false items.tuximage.source = "qrc:/gcompris/src/activities/parachute/resource/" + minitux checkPressed = false winlose = false Oneclick = false pressed = false loseflag = true initLevel() } function onWin() { items.loop.stop() items.loopcloud.stop() items.animationboat.stop() items.tuxX.stop() items.tuximage.visible = false checkPressed = false winlose = false Oneclick = false pressed = false items.bonus.good("lion"); items.tux.x = -items.helimotion.width items.tux.y = 0 items.ok.visible = true items.tuximage.source = "qrc:/gcompris/src/activities/parachute/resource/" + minitux } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } onreset(); initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } onreset(); initLevel(); } function onreset() { items.loop.stop() items.loopcloud.stop() items.animationboat.stop() items.tuxX.stop() tuxImageStatus = 0 items.tuximage.visible = false items.tuximage.source = "qrc:/gcompris/src/activities/parachute/resource/" + minitux checkPressed = false winlose = false Oneclick = false pressed = false loseflag = true items.tux.x = -items.helimotion.width items.tux.y = 0 items.loop.restart() items.tuxX.restart() items.loopcloud.restart() items.animationboat.restart() initLevel() } function steps() { switch(items.bar.level) { - case 1: return 0.5; - case 2: return 0.6; - case 3: return 0.7; - case 4: return 0.75; + + case 1: return 0.6; + + case 2: return 0.7; + + case 3: return 0.8; + + case 4: return 0.85; + } } +function steps1() { + + switch(items.bar.level) { + case 1: return 0.35; + + case 2: return 0.45; + + case 3: return 0.55; + + case 4: return 0.60; + + } +}