Immense Particles Refactor Part C
[profile/ivi/qtdeclarative.git] / examples / declarative / particles / asteroid / blackhole.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 Rectangle{
45     id: root
46     width: 360
47     height: 540
48     color: "black"
49     property bool spacePressed: false
50     focus: true
51     Image{
52         source: "content/finalfrontier.png"
53         anchors.centerIn:parent
54     }
55     Keys.onPressed: {
56         if (event.key == Qt.Key_Space) {
57             spacePressed = true;
58             event.accepted = true;
59         }
60     }
61     Keys.onReleased: {
62         if (event.key == Qt.Key_Space) {
63             spacePressed = false;
64             event.accepted = true;
65         }
66     }
67
68     Emitter{
69         particle: "stars"
70         system: particles
71         particlesPerSecond: 40
72         particleDuration: 4000
73         emitting: true
74         particleSize: 30
75         particleSizeVariation: 10
76         speed: PointDirection{ x: 220; xVariation: 40 }
77         height: parent.height
78     }
79     Emitter{
80         particle: "roids"
81         system: particles
82         particlesPerSecond: 10
83         particleDuration: 4000
84         emitting: true
85         particleSize: 30
86         particleSizeVariation: 10
87         speed: PointDirection{ x: 220; xVariation: 40 }
88         height: parent.height
89     }
90     ParticleSystem{
91         id: particles
92         anchors.fill: parent
93     }
94     ImageParticle{
95         id: stars
96         particles: ["stars"]
97         system: particles
98         image: "content/star.png"
99         color: "white"
100         colorVariation: 0.1
101         alpha: 0
102     }
103     ImageParticle{
104         id: roids
105         particles: ["roids"]
106         system: particles
107         sprites: Sprite{
108             id: spinState
109             name: "spinning"
110             source: "content/meteor.png"
111             frames: 35
112             duration: 60
113             speedModifiesDuration: -0.1
114         }
115     }
116     ImageParticle{
117         id: shot
118         particles: ["shot"]
119         system: particles
120         image: "content/star.png"
121
122         color: "#0FF06600"
123         colorVariation: 0.3
124     }
125     ImageParticle{
126         id: engine
127         particles: ["engine"]
128         system: particles
129         image: "content/particle4.png"
130
131         color: "orange"
132         SequentialAnimation on color {
133             loops: Animation.Infinite
134             ColorAnimation {
135                 from: "red"
136                 to: "cyan"
137                 duration: 1000
138             }
139             ColorAnimation {
140                 from: "cyan"
141                 to: "red"
142                 duration: 1000
143             }
144         }
145
146         colorVariation: 0.2
147     }
148     PointAttractor{
149         id: gs; x: root.width/2; y: root.height/2; strength: 4000000;
150         system: particles
151         physics: PointAttractor.Acceleration
152         proportionalToDistance: PointAttractor.Quadratic
153     }
154     Kill{
155         system: particles
156         x: gs.x - 8;
157         y: gs.y - 8;
158         width: 16
159         height: 16
160     }
161     Image{
162         source:"content/rocket2.png"
163         id: ship
164         width: 45
165         height: 22
166         MouseArea{
167             id: ma
168             anchors.fill: parent;
169             drag.axis: Drag.XandYAxis
170             drag.target: ship
171         }
172         Emitter{
173             particle: "engine"
174             system: particles
175             particlesPerSecond: 200
176             particleDuration: 1000
177             emitting: true
178             particleSize: 10
179             particleEndSize: 4
180             particleSizeVariation: 4
181             speed: PointDirection{ x: -128; xVariation: 32 }
182             height: parent.height
183             width: 20
184         }
185         Emitter{
186             particle: "shot"
187             system: particles
188             particlesPerSecond: 32
189             particleDuration: 2000
190             emitting: spacePressed
191             particleSize: 40
192             speed: PointDirection{ x: 256; }
193             x: parent.width
194             y: parent.height/2
195         }
196     }
197     Text{
198         color: "white"
199         anchors.bottom: parent.bottom
200         text:"Drag the ship, Spacebar to fire."
201     }
202 }
203