File indexing completed on 2024-04-28 15:08:00

0001 /* GCompris - submarine.js
0002  *
0003  * SPDX-FileCopyrightText: 2017 Rudra Nil Basu <rudra.nil.basu.1996@gmail.com>
0004  *
0005  * Authors:
0006  *   Pascal Georges <pascal.georges1@free.fr> (GTK+ version)
0007  *   Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 .pragma library
0012 .import GCompris 1.0 as GCompris
0013 .import QtQuick 2.12 as Quick
0014 .import "qrc:/gcompris/src/core/core.js" as Core
0015 
0016 var numberOfLevel = 10
0017 var items
0018 
0019 var tutorials = [
0020             [
0021                 qsTr("Move the submarine to the other side of the screen."),
0022                 qsTr("The leftmost item in the control panel is the engine of the submarine, indicating the current speed of the submarine."),
0023                 qsTr("Increase or decrease the velocity of the submarine using the engine."),
0024                 qsTr("Press the + button to increase the velocity, or the - button to decrease the velocity."),
0025             ],
0026             [
0027                 qsTr("The item next to the engine is the ballast tank."),
0028                 qsTr("The ballast tanks are used to float or dive under water."),
0029                 qsTr("If the ballast tanks are empty, the submarine will float. If the ballast tanks are full of water, the submarine will dive underwater."),
0030                 qsTr("Turning the upper valve on or off will alternatively allow or stop the water from filling in the ballast tank, thus allowing it to dive underwater."),
0031                 qsTr("Turning the lower valve on or off will alternatively allow or stop the water from flushing out the ballast tank, thus allowing it to float on the surface of the water."),
0032             ],
0033             [
0034                 qsTr("The rightmost item in the control panel controls the diving planes of the submarine"),
0035                 qsTr("The diving planes in a submarine are used to control the depth of the submarine accurately once it is underwater."),
0036                 qsTr("Once the submarine is moving underwater, increasing or decreasing the angle of the planes will increase and decrease the depth of the submarine."),
0037                 qsTr("The + button will increase the depth of the submarine, while the - button will decrease the depth of the submarine."),
0038                 qsTr("Grab the crown to open the gate."),
0039                 qsTr("Check out the help menu for the keyboard controls."),
0040             ]
0041 ]
0042 
0043 function start(items_) {
0044     items = items_
0045     items.currentLevel = Core.getInitialLevel(numberOfLevel)
0046     initLevel()
0047 }
0048 
0049 function stop() {
0050 }
0051 
0052 function initLevel() {
0053 
0054     /* Tutorial Levels, display tutorials */
0055     if (items.currentLevel < tutorials.length) {
0056         items.tutorial.visible = true
0057         items.tutorial.index = 0
0058         items.tutorial.intro = tutorials[items.currentLevel]
0059     } else {
0060         items.tutorial.visible = false
0061     }
0062 
0063     setUpLevelElements()
0064 }
0065 
0066 function setUpLevelElements() {
0067     /* Set up initial position and state of the submarine */
0068     items.submarine.resetSubmarine()
0069 
0070     if(items.ship.visible) {
0071         items.ship.reset()
0072     }
0073 
0074     items.crown.reset()
0075     items.whale.reset()
0076     items.controls.resetVannes()
0077 
0078     items.processingAnswer = false
0079 
0080     resetUpperGate()
0081 }
0082 
0083 function resetUpperGate() {
0084     if (items && items.crown && !items.crown.visible && items.upperGate && items.upperGate.visible) {
0085         items.upperGate.isGateOpen = true
0086     }
0087 }
0088 
0089 function closeGate() {
0090     if (items.upperGate.visible) {
0091         items.upperGate.isGateOpen = false
0092     }
0093 }
0094 
0095 function finishLevel(win) {
0096     if (items.processingAnswer)
0097         return
0098     items.processingAnswer = true
0099     if (win) {
0100         items.bonus.good("flower")
0101     } else {
0102         items.submarine.destroySubmarine()
0103         items.bonus.bad("flower")
0104     }
0105 }
0106 
0107 function nextLevel() {
0108     items.processingAnswer = true
0109     closeGate()
0110 
0111     items.currentLevel = Core.getNextLevel(items.currentLevel, numberOfLevel);
0112     initLevel();
0113 }
0114 
0115 function previousLevel() {
0116     items.processingAnswer = true
0117     closeGate()
0118 
0119     items.currentLevel = Core.getPreviousLevel(items.currentLevel, numberOfLevel);
0120     initLevel();
0121 }