Warning, file /education/gcompris/src/activities/clickgame/clickgame.js was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* GCompris - clickgame.js 0002 * 0003 * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port) 0008 * Timothée Giet <animtim@gmail.com> (animation refactoring) 0009 * 0010 * SPDX-License-Identifier: GPL-3.0-or-later 0011 */ 0012 .pragma library 0013 .import QtQuick 2.12 as Quick 0014 .import GCompris 1.0 as GCompris 0015 .import "qrc:/gcompris/src/core/core.js" as Core 0016 0017 var fishes = [ 0018 { 0019 "imgName": "blueking2.webp", 0020 "nbFrame": 2, 0021 "width": 118, 0022 "height": 76 0023 }, 0024 { 0025 "imgName": "butfish.webp", 0026 "nbFrame": 2, 0027 "width": 98, 0028 "height": 82 0029 }, 0030 { 0031 "imgName": "cichlid1.webp", 0032 "nbFrame": 2, 0033 "width": 63, 0034 "height": 37 0035 }, 0036 { 0037 "imgName": "cichlid4.webp", 0038 "nbFrame": 2, 0039 "width": 73, 0040 "height": 44 0041 }, 0042 { 0043 "imgName": "collaris.webp", 0044 "nbFrame": 2, 0045 "width": 62, 0046 "height": 50 0047 }, 0048 { 0049 "imgName": "discus2.webp", 0050 "nbFrame": 2, 0051 "width": 100, 0052 "height": 100 0053 }, 0054 { 0055 "imgName": "discus3.webp", 0056 "nbFrame": 2, 0057 "width": 63, 0058 "height": 57 0059 }, 0060 { 0061 "imgName": "f00.webp", 0062 "nbFrame": 2, 0063 "width": 64, 0064 "height": 59 0065 }, 0066 { 0067 "imgName": "f01.webp", 0068 "nbFrame": 2, 0069 "width": 63, 0070 "height": 50 0071 }, 0072 { 0073 "imgName": "f02.webp", 0074 "nbFrame": 2, 0075 "width": 71, 0076 "height": 44 0077 }, 0078 { 0079 "imgName": "f03.webp", 0080 "nbFrame": 2, 0081 "width": 83, 0082 "height": 52 0083 }, 0084 { 0085 "imgName": "f04.webp", 0086 "nbFrame": 2, 0087 "width": 93, 0088 "height": 62 0089 }, 0090 { 0091 "imgName": "f05.webp", 0092 "nbFrame": 2, 0093 "width": 90, 0094 "height": 49 0095 }, 0096 { 0097 "imgName": "f06.webp", 0098 "nbFrame": 2, 0099 "width": 93, 0100 "height": 44 0101 }, 0102 { 0103 "imgName": "f07.webp", 0104 "nbFrame": 2, 0105 "width": 82, 0106 "height": 75 0107 }, 0108 { 0109 "imgName": "f08.webp", 0110 "nbFrame": 2, 0111 "width": 91, 0112 "height": 70 0113 }, 0114 { 0115 "imgName": "f09.webp", 0116 "nbFrame": 2, 0117 "width": 108, 0118 "height": 86 0119 }, 0120 { 0121 "imgName": "f10.webp", 0122 "nbFrame": 2, 0123 "width": 97, 0124 "height": 60 0125 }, 0126 { 0127 "imgName": "f11.webp", 0128 "nbFrame": 2, 0129 "width": 116, 0130 "height": 42 0131 }, 0132 { 0133 "imgName": "f12.webp", 0134 "nbFrame": 2, 0135 "width": 100, 0136 "height": 35 0137 }, 0138 { 0139 "imgName": "f13.webp", 0140 "nbFrame": 2, 0141 "width": 116, 0142 "height": 73 0143 }, 0144 { 0145 "imgName": "manta.webp", 0146 "nbFrame": 2, 0147 "width": 266, 0148 "height": 91 0149 }, 0150 { 0151 "imgName": "newf1.webp", 0152 "nbFrame": 2, 0153 "width": 118, 0154 "height": 81 0155 }, 0156 { 0157 "imgName": "QueenAngel.webp", 0158 "nbFrame": 2, 0159 "width": 78, 0160 "height": 54 0161 }, 0162 { 0163 "imgName": "shark1.webp", 0164 "nbFrame": 2, 0165 "width": 187, 0166 "height": 53 0167 }, 0168 { 0169 "imgName": "six_barred.webp", 0170 "nbFrame": 2, 0171 "width": 76, 0172 "height": 63 0173 }, 0174 { 0175 "imgName": "teeth.webp", 0176 "nbFrame": 8, 0177 "width": 64, 0178 "height": 64 0179 }, 0180 ] 0181 0182 var levelProperty = [ 0183 { 0184 "nbFish": 5, 0185 "minDuration": 2000 0186 }, 0187 { 0188 "nbFish": 7, 0189 "minDuration": 1500 0190 }, 0191 { 0192 "nbFish": 10, 0193 "minDuration": 1000 0194 }, 0195 { 0196 "nbFish": 12, 0197 "minDuration": 800 0198 }, 0199 { 0200 "nbFish": 15, 0201 "minDuration": 600 0202 }, 0203 { 0204 "nbFish": 18, 0205 "minDuration": 400 0206 } 0207 ] 0208 var currentImageId = 0 0209 var items 0210 var activity 0211 var background 0212 var bar 0213 var bonus 0214 0215 var isActivityStopped = false 0216 0217 // The array of created fishes object 0218 var createdFishes 0219 var component = Qt.createComponent("qrc:/gcompris/src/activities/clickgame/Fish.qml"); 0220 0221 function start(activity_, background_, bar_, bonus_, items_) { 0222 activity = activity_ 0223 background = background_ 0224 bar = bar_ 0225 bonus = bonus_ 0226 items = items_ 0227 items.currentLevel = Core.getInitialLevel(levelProperty.length); 0228 isActivityStopped = false 0229 initLevel() 0230 items.killedFishes = 0 0231 } 0232 0233 function stop() { 0234 isActivityStopped = true 0235 destroyFishes(); 0236 } 0237 0238 function initLevel() { 0239 if(isActivityStopped) 0240 return; 0241 0242 destroyFishes(); 0243 background.source = "qrc:/gcompris/src/activities/clickgame/resource/sea" + 0244 (items.currentLevel + 1) + ".webp" 0245 var nbFish = levelProperty[items.currentLevel].nbFish 0246 createdFishes = new Array(nbFish) 0247 for(var i = 0; i < nbFish; ++i) { 0248 createdFishes[i] = createFish(levelProperty[items.currentLevel].minDuration) 0249 } 0250 items.score.numberOfSubLevels = nbFish 0251 } 0252 0253 function nextLevel() { 0254 items.currentLevel = Core.getNextLevel(items.currentLevel, levelProperty.length); 0255 initLevel(); 0256 } 0257 0258 function previousLevel() { 0259 items.currentLevel = Core.getPreviousLevel(items.currentLevel, levelProperty.length); 0260 initLevel(); 0261 } 0262 0263 function createFish(minDuration) { 0264 var fishSource = fishes[Math.floor(Math.random() * fishes.length)] 0265 var minY = items.score.y + items.score.height 0266 var maxY = bar.y - fishSource.height - bar.height 0267 var maxX = background.width - fishSource.width 0268 var fish = component.createObject( 0269 background, 0270 { 0271 "activity": activity, 0272 "background": background, 0273 "bar": bar, 0274 "y": (Math.random() * (maxY - minY + 1)) + minY, 0275 "x": (Math.random() * (maxX + 1)), 0276 "width": fishSource.width * 1.1 * GCompris.ApplicationInfo.ratio, 0277 "height": fishSource.height * 1.1 * GCompris.ApplicationInfo.ratio, 0278 "source": "qrc:/gcompris/src/activities/clickgame/resource/" + 0279 fishSource.imgName, 0280 "frameCount": fishSource.nbFrame, 0281 "xSpeed": (background.width + fishSource.width * 1.1 * GCompris.ApplicationInfo.ratio) / (minDuration + Math.floor(Math.random() * 500)), 0282 "ySpeed": (background.height + fishSource.height * 1.1 * GCompris.ApplicationInfo.ratio) / (minDuration * 2 + Math.floor(Math.random() * 500)) 0283 }); 0284 if (fish === null) { 0285 // Error Handling 0286 console.log("Error creating object"); 0287 } 0288 else 0289 fish.restart() 0290 return fish; 0291 } 0292 0293 function destroyFishes() { 0294 if (createdFishes) { 0295 for(var i = 0; i < createdFishes.length; ++i) { 0296 createdFishes[i].destroy() 0297 } 0298 createdFishes.length = 0 0299 } 0300 items.killedFishes = 0 0301 } 0302 0303 function fishKilled() { 0304 if(++items.killedFishes === createdFishes.length) { 0305 bonus.good("flower") 0306 } 0307 items.score.playWinAnimation(); 0308 } 0309