Changeset View
Changeset View
Standalone View
Standalone View
src/activities/planegame/planegame.js
Show All 35 Lines | |||||
36 | var upPressed | 36 | var upPressed | ||
37 | var downPressed | 37 | var downPressed | ||
38 | var leftPressed | 38 | var leftPressed | ||
39 | var rightPressed | 39 | var rightPressed | ||
40 | 40 | | |||
41 | var items | 41 | var items | ||
42 | var dataset | 42 | var dataset | ||
43 | 43 | | |||
44 | var cloudComponent = Qt.createComponent(url + "Cloud.qml"); | 44 | var cloudComponent = Qt.createComponent(url + "Cloud.qml"); | ||
jjazeix: these are specific to numbers-odd-even activity, the instructions should be on its folder (you… | |||||
45 | var clouds = new Array; | 45 | var clouds = new Array; | ||
46 | var cloudsErased = new Array; | 46 | var cloudsErased = new Array; | ||
47 | 47 | | |||
48 | function start(items_, dataset_) { | 48 | function start(items_, dataset_) { | ||
49 | Core.checkForVoices(items_.background); | 49 | Core.checkForVoices(items_.background); | ||
50 | 50 | | |||
51 | items = items_ | 51 | items = items_ | ||
52 | dataset = dataset_ | 52 | dataset = dataset_ | ||
53 | numberOfLevel = dataset.length | 53 | numberOfLevel = dataset.length | ||
54 | currentLevel = 0 | 54 | currentLevel = 0 | ||
55 | initLevel() | 55 | initLevel() | ||
jjazeix: indentation | |||||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | function stop() { | 58 | function stop() { | ||
59 | cloudDestroy(clouds) | 59 | cloudDestroy(clouds) | ||
60 | cloudDestroy(cloudsErased) | 60 | cloudDestroy(cloudsErased) | ||
61 | items.movePlaneTimer.stop() | 61 | items.movePlaneTimer.stop() | ||
62 | items.cloudCreation.stop() | 62 | items.cloudCreation.stop() | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | function cloudDestroy(clouds) { | 65 | function cloudDestroy(clouds) { | ||
66 | for(var i = clouds.length - 1; i >= 0 ; --i) { | 66 | for(var i = clouds.length - 1; i >= 0 ; --i) { | ||
67 | var cloud = clouds[i]; | 67 | var cloud = clouds[i]; | ||
68 | // Remove the cloud | 68 | // Remove the cloud | ||
69 | cloud.destroy() | 69 | cloud.destroy() | ||
70 | // Remove the element from the list | 70 | // Remove the element from the list | ||
71 | clouds.splice(i, 1) | 71 | clouds.splice(i, 1) | ||
72 | } | 72 | } | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | function initLevel() { | 75 | function initLevel() { | ||
76 | | ||||
76 | items.bar.level = currentLevel + 1; | 77 | items.bar.level = currentLevel + 1; | ||
77 | currentSubLevel = 0 | 78 | currentSubLevel = 0 | ||
78 | numberOfSubLevels = dataset[currentLevel].data.length | 79 | numberOfSubLevels = dataset[currentLevel].data.length | ||
79 | | ||||
80 | items.movePlaneTimer.stop(); | 80 | items.movePlaneTimer.stop(); | ||
81 | items.cloudCreation.stop() | 81 | items.cloudCreation.stop() | ||
82 | 82 | | |||
83 | items.score.visible = dataset[currentLevel].showNext | 83 | | ||
84 | items.score.message = dataset[currentLevel].data[currentSubLevel] | 84 | items.score.message = dataset[currentLevel].data[currentSubLevel] | ||
85 | 85 | | |||
86 | upPressed = false | 86 | upPressed = false | ||
87 | downPressed = false | 87 | downPressed = false | ||
88 | leftPressed = false | 88 | leftPressed = false | ||
89 | rightPressed = false | 89 | rightPressed = false | ||
90 | 90 | | |||
91 | cloudDestroy(clouds) | 91 | cloudDestroy(clouds) | ||
92 | cloudDestroy(cloudsErased) | 92 | cloudDestroy(cloudsErased) | ||
93 | 93 | | |||
94 | // Tend towards 0.5 ratio | 94 | // Tend towards 0.5 ratio | ||
95 | items.plane.state = "init" | 95 | items.plane.state = "init" | ||
96 | items.movePlaneTimer.interval = 1000 | 96 | items.movePlaneTimer.interval = 1000 | ||
97 | items.movePlaneTimer.start(); | 97 | items.movePlaneTimer.start(); | ||
98 | if(items.tutorialImage.visible === false) { | ||||
99 | items.score.visible = dataset[currentLevel].showNext | ||||
98 | items.cloudCreation.start() | 100 | items.cloudCreation.start() | ||
99 | // Inject the first cloud now | 101 | //Inject the first cloud now | ||
100 | createCloud() | 102 | createCloud() | ||
103 | | ||||
104 | | ||||
105 | } | ||||
101 | } | 106 | } | ||
102 | 107 | | |||
103 | function nextLevel() { | 108 | function nextLevel() { | ||
104 | if(numberOfLevel <= ++currentLevel) { | 109 | if(numberOfLevel <= ++currentLevel) { | ||
105 | currentLevel = 0 | 110 | currentLevel = 0 | ||
106 | } | 111 | } | ||
107 | | ||||
108 | initLevel(); | 112 | initLevel(); | ||
jjazeix: indentation | |||||
109 | } | 113 | } | ||
110 | 114 | | |||
111 | function previousLevel() { | 115 | function previousLevel() { | ||
112 | if(--currentLevel < 0) { | 116 | if(--currentLevel < 0) { | ||
113 | currentLevel = numberOfLevel - 1 | 117 | currentLevel = numberOfLevel - 1 | ||
114 | } | 118 | } | ||
115 | initLevel(); | 119 | initLevel(); | ||
jjazeix: indentation | |||||
116 | } | 120 | } | ||
117 | 121 | | |||
118 | function repositionObjectsOnWidthChanged(factor) { | 122 | function repositionObjectsOnWidthChanged(factor) { | ||
119 | if(items && items.plane) { | 123 | if(items && items.plane) { | ||
120 | items.movePlaneTimer.interval = 1000 | 124 | items.movePlaneTimer.interval = 1000 | ||
121 | items.plane.state = "init" | 125 | items.plane.state = "init" | ||
122 | } | 126 | } | ||
123 | for(var i = clouds.length - 1; i >= 0 ; --i) { | 127 | for(var i = clouds.length - 1; i >= 0 ; --i) { | ||
▲ Show 20 Lines • Show All 210 Lines • Show Last 20 Lines |
these are specific to numbers-odd-even activity, the instructions should be on its folder (you can put them in the qml)