Warning, /education/gcompris/src/activities/planegame/Planegame.qml is written in an unsupported language. File is not indexed.
0001 /* gcompris - Planegame.qml
0002
0003 SPDX-FileCopyrightText: 2014 Johnny Jazeix <jazeix@gmail.com>
0004
0005 2003, 2014: Bruno Coudoin: initial version
0006 2014: Johnny Jazeix: Qt port
0007
0008 SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013
0014 import "../../core"
0015 import "planegame.js" as Activity
0016
0017 ActivityBase {
0018 id: activity
0019 focus: true
0020
0021 onStart: { focus = true; }
0022 onStop: { }
0023
0024 Keys.onPressed: Activity.processPressedKey(event)
0025 Keys.onReleased: Activity.processReleasedKey(event)
0026
0027 property var dataset
0028 property var tutorialInstructions: ""
0029 property bool showTutorial: false
0030
0031 property int oldWidth: width
0032 onWidthChanged: {
0033 // Reposition helico and clouds, same for height
0034 Activity.repositionObjectsOnWidthChanged(width / oldWidth)
0035 oldWidth = width
0036 }
0037
0038 property int oldHeight: height
0039 onHeightChanged: {
0040 // Reposition helico and clouds, same for height
0041 Activity.repositionObjectsOnHeightChanged(height / oldHeight)
0042 oldHeight = height
0043 }
0044
0045 pageComponent: Image {
0046 id: background
0047 anchors.fill: parent
0048 signal start
0049 signal stop
0050 signal voiceDone
0051 source: Activity.url + "../algorithm/resource/desert_scene.svg"
0052 sourceSize.width: width
0053 sourceSize.height: height
0054 fillMode: Image.PreserveAspectCrop
0055
0056 Component.onCompleted: {
0057 activity.start.connect(start)
0058 activity.stop.connect(stop)
0059 }
0060
0061 // Needed to get keyboard focus on Tutorial
0062 Keys.forwardTo: tutorialSection
0063
0064 QtObject {
0065 id: items
0066 property Item activityPage: activity
0067 property alias background: background
0068 property alias bar: bar
0069 property int currentLevel: activity.currentLevel
0070 property alias bonus: bonus
0071 property alias score: score
0072 property alias plane: plane
0073 property alias fileChecker: fileChecker
0074 property GCAudio audioVoices: activity.audioVoices
0075 property GCSfx audioEffects: activity.audioEffects
0076 property alias movePlaneTimer: movePlaneTimer
0077 property alias cloudCreation: cloudCreation
0078 property bool showTutorial: activity.showTutorial
0079 property bool goToNextLevel: false
0080 }
0081
0082 onVoiceDone: {
0083 if(items.goToNextLevel) {
0084 items.goToNextLevel = false;
0085 items.bonus.good("flower");
0086 }
0087 }
0088
0089 onStart: {
0090 activity.audioVoices.done.connect(voiceDone)
0091 Activity.start(items, dataset)
0092 }
0093 onStop: { Activity.stop() }
0094
0095 File {
0096 id: fileChecker
0097 }
0098
0099 // Tutorial section starts
0100 Image {
0101 id: tutorialImage
0102 source: "../digital_electricity/resource/texture01.webp"
0103 anchors.fill: parent
0104 fillMode: Image.Tile
0105 z: 1
0106 visible: showTutorial
0107 Tutorial {
0108 id: tutorialSection
0109 tutorialDetails: tutorialInstructions
0110 useImage: false
0111 onSkipPressed: {
0112 showTutorial = false
0113 Activity.initLevel()
0114 }
0115 }
0116 }
0117 // Tutorial section ends
0118
0119 MultiPointTouchArea {
0120 anchors.fill: parent
0121 touchPoints: [ TouchPoint { id: point1 } ]
0122
0123 onReleased: {
0124 plane.x = point1.x - plane.width / 2
0125 plane.y = point1.y - plane.height / 2
0126 }
0127 }
0128
0129 DialogHelp {
0130 id: dialogHelp
0131 onClose: home()
0132 }
0133
0134 Bar {
0135 id: bar
0136 level: items.currentLevel + 1
0137 content: BarEnumContent { value: items.showTutorial ? (help | home) : (help | home | level) }
0138 onHelpClicked: displayDialog(dialogHelp)
0139 onPreviousLevelClicked: Activity.previousLevel()
0140 onNextLevelClicked: Activity.nextLevel()
0141 onHomeClicked: home()
0142 }
0143
0144 Bonus {
0145 id: bonus
0146 Component.onCompleted: win.connect(Activity.nextLevel)
0147 }
0148
0149 Score {
0150 id: score
0151 visible: !showTutorial
0152 fontSize: background.width >= background.height ? internalTextComponent.largeSize : internalTextComponent.mediumSize
0153 height: internalTextComponent.height + 10
0154 anchors.bottom: bar.top
0155 anchors.margins: 10
0156 }
0157
0158 property int movePlaneTimerCounter: 0
0159 Timer {
0160 id: movePlaneTimer
0161 running: false
0162 repeat: true
0163 onTriggered: {
0164 plane.state = "play"
0165 interval = 50
0166 if(movePlaneTimerCounter++ % 3 == 0) {
0167 /* Do not call this too often or plane commands are too hard */
0168 Activity.handleCollisionsWithCloud();
0169 }
0170 Activity.computeVelocity();
0171 Activity.planeMove();
0172 }
0173 }
0174
0175 Timer {
0176 id: cloudCreation
0177 running: false
0178 repeat: true
0179 interval: 10200 - (bar.level * 200)
0180 onTriggered: Activity.createCloud()
0181 }
0182
0183 Plane {
0184 id: plane
0185 visible: !showTutorial
0186 background: background
0187 }
0188
0189 }
0190 }