Changeset View
Changeset View
Standalone View
Standalone View
src/activities/penalty/Penalty.qml
Context not available. | |||||
45 | activity.stop.connect(stop) | 45 | activity.stop.connect(stop) | ||
---|---|---|---|---|---|
46 | } | 46 | } | ||
47 | 47 | | |||
48 | function changeBallState(saveBallState) { | ||||
49 | instruction.text = "" | ||||
50 | | ||||
51 | if(ball.state === "FAIL") { | ||||
52 | Activity.resetLevel() | ||||
53 | return | ||||
54 | } | ||||
55 | | ||||
56 | /* This is a shoot */ | ||||
57 | var progress = progressTop | ||||
58 | if (saveBallState == "LEFT") { | ||||
59 | progress = progressLeft | ||||
60 | } | ||||
61 | else if(saveBallState == "RIGHT") { | ||||
62 | progress = progressRight | ||||
63 | } | ||||
64 | | ||||
65 | if(progress.ratio > 0) { | ||||
66 | /* Second click, stop animation */ | ||||
67 | progress.anim.running = false; | ||||
68 | | ||||
69 | /* Play sound */ | ||||
70 | activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav") | ||||
71 | | ||||
72 | /* Success or not */ | ||||
73 | if(progress.ratio < 100) { | ||||
74 | /* Success */ | ||||
75 | ball.state = saveBallState | ||||
76 | } else { | ||||
77 | /* failure */ | ||||
78 | ball.state = "FAIL" | ||||
79 | } | ||||
80 | timerBonus.start() | ||||
81 | } else { | ||||
82 | /* First click, start animation*/ | ||||
83 | progress.anim.running = true; | ||||
84 | | ||||
85 | /* Play sound */ | ||||
86 | activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/flip.wav") | ||||
87 | } | ||||
88 | } | ||||
89 | | ||||
48 | // To enable tapping/clicking on left side of goal | 90 | // To enable tapping/clicking on left side of goal | ||
49 | GoalZone { | 91 | Rectangle { | ||
50 | id: rectLeft | 92 | id: rectLeft | ||
51 | state: "LEFT" | 93 | anchors.left: parent.left | ||
52 | progress: progressLeft | 94 | anchors.top: parent.top | ||
53 | anchors.right: player.left | 95 | anchors.right: player.left | ||
96 | anchors.bottom: parent.bottom | ||||
54 | anchors.leftMargin: parent.width * 0.08 | 97 | anchors.leftMargin: parent.width * 0.08 | ||
98 | anchors.topMargin: parent.height * 0.07 | ||||
55 | anchors.bottomMargin: parent.height * 0.45 | 99 | anchors.bottomMargin: parent.height * 0.45 | ||
100 | color: "transparent" | ||||
101 | | ||||
102 | MouseArea { | ||||
103 | anchors.fill: parent | ||||
104 | acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton | ||||
105 | onClicked: { | ||||
106 | if(mouse.button) { | ||||
107 | changeBallState("LEFT") | ||||
108 | } | ||||
109 | } | ||||
110 | } | ||||
56 | } | 111 | } | ||
57 | 112 | | |||
58 | // To enable tapping/clicking on top of goal | 113 | // To enable tapping/clicking on top of goal | ||
59 | GoalZone { | 114 | Rectangle { | ||
60 | id: rectTop | 115 | id: rectTop | ||
61 | state: "CENTER" | 116 | anchors.top: parent.top | ||
62 | progress: progressTop | 117 | anchors.left: rectLeft.right | ||
63 | anchors.left: player.left | 118 | anchors.right: rectRight.left | ||
64 | anchors.right: player.right | | |||
65 | anchors.bottom: player.top | 119 | anchors.bottom: player.top | ||
120 | anchors.topMargin: parent.height * 0.07 | ||||
121 | color: "transparent" | ||||
122 | | ||||
123 | MouseArea { | ||||
124 | anchors.fill: parent | ||||
125 | acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton | ||||
126 | onClicked: { | ||||
127 | if(mouse.button) { | ||||
128 | changeBallState("CENTER") | ||||
129 | } | ||||
130 | } | ||||
131 | } | ||||
66 | } | 132 | } | ||
67 | 133 | | |||
68 | // To enable tapping/clicking on right side of goal | 134 | // To enable tapping/clicking on right side of goal | ||
69 | GoalZone { | 135 | Rectangle { | ||
70 | id: rectRight | 136 | id: rectRight | ||
71 | state: "RIGHT" | | |||
72 | progress: progressRight | | |||
73 | anchors.left: player.right | 137 | anchors.left: player.right | ||
138 | anchors.right: parent.right | ||||
139 | anchors.top: parent.top | ||||
140 | anchors.bottom: parent.bottom | ||||
74 | anchors.rightMargin: parent.width * 0.06 | 141 | anchors.rightMargin: parent.width * 0.06 | ||
142 | anchors.topMargin: parent.height * 0.07 | ||||
75 | anchors.bottomMargin: parent.height * 0.45 | 143 | anchors.bottomMargin: parent.height * 0.45 | ||
144 | color: "transparent" | ||||
145 | | ||||
146 | MouseArea { | ||||
147 | anchors.fill: parent | ||||
148 | acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton | ||||
149 | onClicked: { | ||||
150 | if(mouse.button) { | ||||
151 | changeBallState("RIGHT") | ||||
152 | } | ||||
153 | } | ||||
154 | } | ||||
76 | } | 155 | } | ||
77 | 156 | | |||
78 | // Add here the QML items you need to access in javascript | 157 | // Add here the QML items you need to access in javascript | ||
Context not available. | |||||
88 | property alias bonus: bonus | 167 | property alias bonus: bonus | ||
89 | property int duration : 0 | 168 | property int duration : 0 | ||
90 | property int progressBarOpacity : 40 | 169 | property int progressBarOpacity : 40 | ||
91 | property string saveBallState: "INITIAL" | | |||
92 | property double ballX: ball.parent.width/2 - ball.width/2 | | |||
93 | property double ballY: ball.parent.height*0.77 - ball.height/2 | | |||
94 | } | 170 | } | ||
95 | 171 | | |||
96 | onStart: { Activity.start(items) } | 172 | onStart: { Activity.start(items) } | ||
Context not available. | |||||
141 | 217 | | |||
142 | 218 | | |||
143 | /* The progress bars */ | 219 | /* The progress bars */ | ||
144 | Progress { | 220 | Rectangle { | ||
145 | id: progressLeft | 221 | id: progressLeft | ||
222 | property int ratio: 0 | ||||
223 | property ParallelAnimation anim: animationLeft | ||||
224 | | ||||
225 | opacity: items.progressBarOpacity | ||||
146 | anchors.left: parent.left | 226 | anchors.left: parent.left | ||
147 | anchors.leftMargin: parent.width / parent.implicitWidth * 62 | 227 | anchors.leftMargin: parent.width / parent.implicitWidth * 62 | ||
228 | anchors.top: parent.top | ||||
229 | anchors.topMargin: parent.height / parent.implicitHeight * 100 | ||||
230 | width: ratio / 100 * parent.width / parent.implicitWidth * 200 | ||||
231 | height: parent.height / parent.implicitHeight * 20 | ||||
232 | ParallelAnimation { | ||||
233 | id: animationLeft | ||||
234 | onRunningChanged: { | ||||
235 | if (!animationLeft.running) { | ||||
236 | timerBonus.start() | ||||
237 | } | ||||
238 | } | ||||
239 | PropertyAnimation | ||||
240 | { | ||||
241 | target: progressLeft | ||||
242 | property: "ratio" | ||||
243 | from: 0 | ||||
244 | to: 100 | ||||
245 | duration: items.duration | ||||
246 | } | ||||
247 | PropertyAnimation | ||||
248 | { | ||||
249 | target: progressLeft | ||||
250 | property: "color" | ||||
251 | from: "#00FF00" | ||||
252 | to: "#FF0000" | ||||
253 | duration: items.duration | ||||
254 | } | ||||
255 | } | ||||
148 | } | 256 | } | ||
149 | 257 | | |||
150 | Progress { | 258 | Rectangle { | ||
151 | id: progressRight | 259 | id: progressRight | ||
260 | property int ratio: 0 | ||||
261 | property ParallelAnimation anim: animationRight | ||||
262 | | ||||
263 | opacity: items.progressBarOpacity | ||||
152 | anchors.right: parent.right | 264 | anchors.right: parent.right | ||
153 | anchors.rightMargin: parent.width/parent.implicitWidth * 50 | 265 | anchors.rightMargin: parent.width/parent.implicitWidth * 50 | ||
266 | anchors.top: parent.top | ||||
267 | anchors.topMargin: parent.height/parent.implicitHeight * 100 | ||||
268 | width: ratio / 100 * parent.width / parent.implicitWidth * 200 | ||||
269 | height: parent.height / parent.implicitHeight * 20 | ||||
270 | ParallelAnimation { | ||||
271 | id: animationRight | ||||
272 | onRunningChanged: { | ||||
273 | if (!animationRight.running) { | ||||
274 | timerBonus.start() | ||||
275 | } | ||||
276 | } | ||||
277 | PropertyAnimation | ||||
278 | { | ||||
279 | target: progressRight | ||||
280 | property: "ratio" | ||||
281 | from: 0 | ||||
282 | to: 100 | ||||
283 | duration: items.duration | ||||
284 | } | ||||
285 | PropertyAnimation | ||||
286 | { | ||||
287 | target: progressRight | ||||
288 | property: "color" | ||||
289 | from: "#00FF00" | ||||
290 | to: "#FF0000" | ||||
291 | duration: items.duration | ||||
292 | } | ||||
293 | } | ||||
154 | } | 294 | } | ||
155 | 295 | | |||
156 | Progress { | 296 | Rectangle { | ||
157 | id: progressTop | 297 | id: progressTop | ||
298 | property int ratio: 0 | ||||
299 | property ParallelAnimation anim: animationTop | ||||
300 | | ||||
301 | opacity: items.progressBarOpacity | ||||
302 | anchors.top: parent.top | ||||
158 | anchors.topMargin: parent.width / parent.implicitWidth * 40 | 303 | anchors.topMargin: parent.width / parent.implicitWidth * 40 | ||
159 | anchors.horizontalCenter: parent.horizontalCenter | 304 | anchors.horizontalCenter: parent.horizontalCenter | ||
160 | width: parent.height / parent.implicitHeight * 20 | 305 | width: parent.height / parent.implicitHeight * 20 | ||
161 | height: ratio / 100 * parent.width / parent.implicitWidth * 100 | 306 | height: ratio / 100 * parent.width / parent.implicitWidth * 100 | ||
307 | ParallelAnimation { | ||||
308 | id: animationTop | ||||
309 | onRunningChanged: { | ||||
310 | if (!animationTop.running) { | ||||
311 | timerBonus.start() | ||||
312 | } | ||||
313 | } | ||||
314 | PropertyAnimation { | ||||
315 | target: progressTop | ||||
316 | property: "ratio" | ||||
317 | from: 0 | ||||
318 | to: 100 | ||||
319 | duration: items.duration | ||||
320 | } | ||||
321 | PropertyAnimation { | ||||
322 | target: progressTop | ||||
323 | property: "color" | ||||
324 | from: "#00FF00" | ||||
325 | to: "#FF0000" | ||||
326 | duration: items.duration | ||||
327 | } | ||||
328 | } | ||||
162 | } | 329 | } | ||
163 | | ||||
164 | /* The player */ | 330 | /* The player */ | ||
165 | Image { | 331 | Image { | ||
166 | id: player | 332 | id: player | ||
167 | source: Activity.url + "penalty_player.svg" | 333 | source: Activity.url + "penalty_player.svg" | ||
168 | fillMode: Image.PreserveAspectFit | 334 | fillMode: Image.PreserveAspectFit | ||
169 | anchors.centerIn: parent | 335 | anchors.verticalCenter: parent.verticalCenter | ||
170 | sourceSize.width: 154 * ApplicationInfo.ratio | 336 | sourceSize.width: 154 * ApplicationInfo.ratio | ||
337 | x: parent.width/2 - width/2 | ||||
171 | } | 338 | } | ||
172 | 339 | | |||
173 | /* The 2 click icon */ | 340 | /* The 2 click icon */ | ||
Context not available. | |||||
264 | anchors.fill: parent | 431 | anchors.fill: parent | ||
265 | acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton | 432 | acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton | ||
266 | onClicked: { | 433 | onClicked: { | ||
267 | Activity.resetLevel() | 434 | ball.state = "INITIAL" | ||
435 | progressRight.ratio = 0 | ||||
436 | progressLeft.ratio = 0 | ||||
437 | progressTop.ratio = 0 | ||||
268 | } | 438 | } | ||
269 | } | 439 | } | ||
270 | } | 440 | } | ||
Context not available. |