bed03e99aaae811108ad9af10dde705e54918d23
[profile/ivi/qtdeclarative.git] / examples / quick / touchinteraction / multipointtouch / content / BearWhackParticleSystem.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 import QtQuick 2.0
41 import QtQuick.Particles 2.0
42
43 ParticleSystem {
44     id: particleSystem
45     function explode(x,y) {
46         fireEmitter.burst(100,x,y);
47     }
48
49     Emitter {
50         id: emitter
51         group: "bears"
52         width: parent.width
53         emitRate: 1
54         NumberAnimation on emitRate {
55             id: goFaster
56             from: 1
57             to: 16
58             running: particleSystem.running
59             loops: 1
60             duration: 60000 * 5
61             easing.type: Easing.Linear
62         }
63         lifeSpan: 4000 + 800*(16-emitRate)
64         maximumEmitted: 128
65         size: 64
66         speed: PointDirection{ y: 40 + 10 * emitter.emitRate }
67     }
68
69     Emitter {
70         id: fireEmitter
71         enabled: false
72         maximumEmitted: 6000
73         group: "flame"
74         emitRate: 1000
75         size: 16
76         endSize: 8
77         speed: CumulativeDirection { AngleDirection {angleVariation: 180; magnitudeVariation: 120;} PointDirection { y: -60 }}
78         lifeSpan: 400
79     }
80     Emitter {
81         id: heartEmitter
82         enabled: false
83         maximumEmitted: 6000
84         group: "hearts"
85         emitRate: 1000
86         size: 16
87         endSize: 8
88         speed: AngleDirection {angleVariation: 180; magnitudeVariation: 180;}
89         lifeSpan: 600
90     }
91     Emitter {
92         id: bloodEmitter
93         enabled: false
94         maximumEmitted: 6000
95         group: "blood"
96         emitRate: 1000
97         size: 16
98         endSize: 8
99         speed: CumulativeDirection { AngleDirection {angleVariation: 180; magnitudeVariation: 80;} PointDirection { y: 40 }}
100         lifeSpan: 600
101     }
102
103     Affector {
104         width: parent.width
105         height: 64
106         once: true
107         y: parent.height - 32
108         groups: "bears"
109         onAffectParticles: {
110             for (var i=0;i<particles.length; i++) {
111                 if (particles[i].animationIndex != 0) {
112                     score++;
113                     bloodEmitter.burst(100, particles[i].x, particles[i].y);
114                 } else {
115                     score--;
116                     heartEmitter.burst(100, particles[i].x, particles[i].y);
117                 }
118                 particles[i].update = 1.0;
119                 particles[i].t -= 1000.0;
120             }
121         }
122     }
123     ImageParticle {
124         groups: ["flame"]
125         source: "blur-circle.png"
126         z: 4
127         colorVariation: 0.1
128         color: "#ffa24d"
129         alpha: 0.4
130     }
131     ImageParticle {
132         groups: ["blood"]
133         color: "red"
134         z: 2
135         source: "blur-circle3.png"
136         alpha: 0.2
137     }
138     ImageParticle {
139         groups: ["hearts"]
140         color: "#ff66AA"
141         z: 3
142         source: "heart-blur.png"
143         alpha: 0.4
144         autoRotation: true
145     }
146     ImageParticle {
147         groups: ["bears"]
148         z: 1
149         spritesInterpolate: false
150         sprites:[
151         Sprite{
152             name: "floating"
153             source: "Bear1.png"
154             frameCount: 9
155             frameWidth: 256
156             frameHeight: 256
157             frameDuration: 80
158             to: {"still":0, "flailing":0}
159         },
160         Sprite{
161             name: "flailing"
162             source: "Bear2.png"
163             frameCount: 8
164             frameWidth: 256
165             frameHeight: 256
166             frameDuration: 80
167             to: {"falling":1}
168         },
169         Sprite{
170             name: "falling"
171             source: "Bear3.png"
172             frameCount: 5
173             frameWidth: 256
174             frameHeight: 256
175             frameDuration: 80
176             to: {"falling":1}
177         }
178         ]
179     }
180 }