06cacea116ecfcd2545bf619f3aa511ecae435a0
[profile/ivi/qtdeclarative.git] / examples / declarative / particles / affectors / spritegoal.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the examples of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **   * Redistributions of source code must retain the above copyright
16 **     notice, this list of conditions and the following disclaimer.
17 **   * Redistributions in binary form must reproduce the above copyright
18 **     notice, this list of conditions and the following disclaimer in
19 **     the documentation and/or other materials provided with the
20 **     distribution.
21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 **     the names of its contributors may be used to endorse or promote
23 **     products derived from this software without specific prior written
24 **     permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
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                 frames: 35
109                 frameDuration: 40
110                 randomStart: true
111                 to: {"explode":0, "spinning":1}
112             },Sprite {
113                 name: "explode"
114                 source: "../images/_explo.png"
115                 frames: 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                 frames: 1
122                 frameDuration: 1000
123             }
124         ]
125     }
126     SpriteGoal {
127         groups: ["meteor"]
128         system: sys
129         goalState: "explode"
130         jump: true
131         anchors.centerIn: holder//A bug in affectors currently isn't compensating for relative x,y. when that's fixed this can just anchors.fill: rocketShip
132         width: 60
133         height: 60
134     }
135     Image {
136         id: rocketShip
137         source: "../images/rocket.png"
138         smooth: true
139         anchors.centerIn: holder
140         rotation: (circle.percent+0.25) * 360
141         z: 2
142     }
143     Item {
144         id: holder
145         x: circle.x - Math.sin(circle.percent * 6.28316530714)*200
146         y: circle.y + Math.cos(circle.percent * 6.28316530714)*200
147         z: 1
148     }
149
150     Item {
151         id: circle
152         x: root.width / 1.2 
153         y: root.height / 1.7
154         property real percent: 0
155
156         SequentialAnimation on percent {
157             id: circleAnim1
158             loops: Animation.Infinite
159             running: true
160             NumberAnimation {
161             duration: 4000
162             from: 1
163             to: 0
164             }
165
166         }
167     }
168
169     ImageParticle {
170         z:0 
171         system: sys
172         groups: ["exhaust"]
173         source: "../images/particle4.png"
174
175         color: "orange"
176         SequentialAnimation on color {
177             loops: Animation.Infinite
178             ColorAnimation {
179                 from: "red"
180                 to: "cyan"
181                 duration: 1000
182             }
183             ColorAnimation {
184                 from: "cyan"
185                 to: "red"
186                 duration: 1000
187             }
188         }
189
190         colorVariation: 0.2
191     }
192
193     Emitter {
194         id: trailsNormal2
195         system: sys
196         group: "exhaust"
197
198         emitRate: 300
199         lifeSpan: 500
200
201         y: holder.y
202         x: holder.x 
203
204         speed: PointDirection { xVariation: 40; yVariation: 40; }
205         speedFromMovement: 16
206
207         acceleration: PointDirection { xVariation: 10; yVariation: 10; }
208
209         size: 4
210         sizeVariation: 4
211     }
212 }