21aa859dac33e6e030ee677da036c4118d9fce97
[profile/ivi/qtdeclarative.git] / examples / particles / affectors / content / spritegoal.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
41 import QtQuick 2.0
42 import QtQuick.Particles 2.0
43
44 Item {
45     id: root
46     width: 360
47     height: 540
48     MouseArea {
49         id: ma
50         anchors.fill: parent
51     }
52
53     ParticleSystem { id: sys }
54     Image {
55         source: "../../images/finalfrontier.png"
56         transformOrigin: Item.Center
57         anchors.centerIn: parent
58         smooth: true
59         NumberAnimation on rotation {
60             from: 0
61             to: 360
62             duration: 200000
63             loops: Animation.Infinite
64         }
65
66     }
67     ImageParticle {
68         system: sys
69         groups: ["starfield"]
70         source: "../../images/star.png"
71         colorVariation: 0.3
72         color: "white"
73     }
74     Emitter {
75         id: starField
76         system: sys
77         group: "starfield"
78
79         emitRate: 80
80         lifeSpan: 2500
81
82         anchors.centerIn: parent
83
84         //acceleration: AngledDirection {angleVariation: 360; magnitude: 200}//Is this a better effect, more consistent speed?
85         acceleration: PointDirection { xVariation: 200; yVariation: 200; }
86
87         size: 0
88         endSize: 80
89         sizeVariation: 10
90     }
91     Emitter {
92         system: sys
93         group: "meteor"
94         emitRate: 12
95         lifeSpan: 5000
96         acceleration: PointDirection { xVariation: 80; yVariation: 80; }
97         size: 15
98         endSize: 300
99         anchors.centerIn: parent
100      }
101     ImageParticle {
102         system: sys
103         groups: ["meteor"]
104         sprites:[Sprite {
105                 id: spinState
106                 name: "spinning"
107                 source: "../../images/meteor.png"
108                 frameCount: 35
109                 frameDuration: 40
110                 randomStart: true
111                 to: {"explode":0, "spinning":1}
112             },Sprite {
113                 name: "explode"
114                 source: "../../images/_explo.png"
115                 frameCount: 22
116                 frameDuration: 40
117                 to: {"nullFrame":1}
118             },Sprite {//Not sure if this is needed, but seemed easiest
119                 name: "nullFrame"
120                 source: "../../images/nullRock.png"
121                 frameCount: 1
122                 frameDuration: 1000
123             }
124         ]
125     }
126     //! [0]
127     SpriteGoal {
128         groups: ["meteor"]
129         system: sys
130         goalState: "explode"
131         jump: true
132         anchors.fill: rocketShip
133         width: 60
134         height: 60
135     }
136     //! [0]
137     Image {
138         id: rocketShip
139         source: "../../images/rocket.png"
140         smooth: true
141         anchors.centerIn: holder
142         rotation: (circle.percent+0.25) * 360
143         z: 2
144     }
145     Item {
146         id: holder
147         x: circle.x - Math.sin(circle.percent * 6.28316530714)*200
148         y: circle.y + Math.cos(circle.percent * 6.28316530714)*200
149         z: 1
150     }
151
152     Item {
153         id: circle
154         x: root.width / 1.2 
155         y: root.height / 1.7
156         property real percent: 0
157
158         SequentialAnimation on percent {
159             id: circleAnim1
160             loops: Animation.Infinite
161             running: true
162             NumberAnimation {
163             duration: 4000
164             from: 1
165             to: 0
166             }
167
168         }
169     }
170
171     ImageParticle {
172         z:0 
173         system: sys
174         groups: ["exhaust"]
175         source: "../../images/particle4.png"
176
177         color: "orange"
178         SequentialAnimation on color {
179             loops: Animation.Infinite
180             ColorAnimation {
181                 from: "red"
182                 to: "cyan"
183                 duration: 1000
184             }
185             ColorAnimation {
186                 from: "cyan"
187                 to: "red"
188                 duration: 1000
189             }
190         }
191
192         colorVariation: 0.2
193     }
194
195     Emitter {
196         id: trailsNormal2
197         system: sys
198         group: "exhaust"
199
200         emitRate: 300
201         lifeSpan: 500
202
203         y: holder.y
204         x: holder.x 
205
206         speed: PointDirection { xVariation: 40; yVariation: 40; }
207         speedFromMovement: 16
208
209         acceleration: PointDirection { xVariation: 10; yVariation: 10; }
210
211         size: 4
212         sizeVariation: 4
213     }
214 }