~sil/dropping-letters/add-vcs

« back to all changes in this revision

Viewing changes to dropping-letters.qml

  • Committer: stuart.langridge at canonical
  • Date: 2012-12-07 11:53:15 UTC
  • Revision ID: stuart.langridge@canonical.com-20121207115315-ci501agoo9i180f2
aha, particle systems

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
Rectangle {
7
7
    id: main
 
8
    color: "#333333"
8
9
    width: 48 * 7 + 2 * 7 + 50
9
10
    height: 48 * 10 + 2 * 10 + 50
10
11
    property var selectedItems: []
64
65
        }
65
66
    }
66
67
 
 
68
    Text {
 
69
        id: scoredisplay
 
70
        anchors.centerIn: parent
 
71
        z: 3
 
72
        font.pixelSize: main.height
 
73
        text: "200"
 
74
        color: "red"
 
75
        opacity: 0
 
76
    }
 
77
 
 
78
    ParallelAnimation {
 
79
        id: showscoredisplay
 
80
        NumberAnimation {
 
81
            property: "scale"
 
82
            from: 0.01
 
83
            to: 1.0
 
84
            duration: 400
 
85
            target: scoredisplay
 
86
        }
 
87
        SequentialAnimation {
 
88
            NumberAnimation {
 
89
                property: "opacity"
 
90
                from: 0
 
91
                to: 1.0
 
92
                duration: 20
 
93
                target: scoredisplay
 
94
            }
 
95
            NumberAnimation {
 
96
                property: "opacity"
 
97
                from: 1.0
 
98
                to: 0
 
99
                duration: 380
 
100
                target: scoredisplay
 
101
            }
 
102
        }
 
103
    }
 
104
 
 
105
 
 
106
 
67
107
    Timer {
68
108
        id: droptimer
69
109
        repeat: true
156
196
                        thisscore += main.letterScores[b.containedLetter];
157
197
                        b.state = "dead";
158
198
                    })
159
 
 
160
199
                    main.selectedItems = [];
161
200
                    main.score += thisscore * wordlength;
 
201
                    scoredisplay.text = "" + (thisscore * wordlength);
 
202
                    showscoredisplay.start();
162
203
                } else {
163
204
                    failure.play();
164
205
                    accum.text = "";
195
236
                        property int idx: index
196
237
                        property string containedLetter: letter
197
238
                        id: box
 
239
                        clip: false
198
240
                        scale: -1
199
241
                        width: 48
200
242
                        height: 48
201
 
                        color: selected ? "green" : "red"
 
243
                        color: selected ? (accum.isValid ? "#ddffdd" : "#ffdddd") : "#ffffdd"
202
244
                        radius: 3
203
245
                        y: main.height + box.height
204
246
                        Text {
205
247
                            anchors.centerIn: parent
206
248
                            text: letter
 
249
                            font.pixelSize: box.height * 0.9
 
250
                            color: "#333333"
207
251
                        }
208
252
                        MouseArea {
209
253
                            anchors.fill: parent
217
261
                                }
218
262
                            }
219
263
                        }
220
 
                        Behavior on scale {
 
264
                        Behavior on opacity {
221
265
                            SequentialAnimation {
222
 
                                NumberAnimation { properties:"scale"; duration: 100 }
 
266
                                ScriptAction { script: pulseEmitter.burst(1000); }
 
267
                                NumberAnimation { properties:"opacity"; duration: 500 }
223
268
                                ScriptAction { script: lm.get(box.parent.idx).letters.remove(box.idx); }
224
269
                            }
225
270
                        }
227
272
                            State { name: "alive" },
228
273
                            State {
229
274
                                name: "dead"
230
 
                                PropertyChanges { target: box; scale: 0.01 }
 
275
                                PropertyChanges { target: box; opacity: 0 }
231
276
                            }
232
277
                        ]
 
278
                        ParticleSystem {
 
279
                            id: particles
 
280
                            width: 200
 
281
                            height: 200
 
282
                            anchors.centerIn: parent
 
283
                            clip: false
 
284
                            ImageParticle {
 
285
                                source: "redStar.png"
 
286
                                alpha: 0
 
287
                                colorVariation: 0.6
 
288
                            }
 
289
                            Emitter {
 
290
                                id: pulseEmitter
 
291
                                x: parent.width/2
 
292
                                y: parent.height/2
 
293
                                emitRate: 2000
 
294
                                lifeSpan: 500
 
295
                                enabled: false
 
296
                                velocity: AngleDirection { magnitude: 256; angleVariation: 360; magnitudeVariation: 200; }
 
297
                                size: 32
 
298
                                sizeVariation: 8
 
299
                            }
 
300
                        }
233
301
                    }
234
302
                }
235
303
            }