Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / examples / declarative / particles / plasmapatrol / plasmapatrol.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 QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 import QtQuick 2.0
42 import QtQuick.Particles 2.0
43 import "content"
44
45 Rectangle {
46     id: root
47     property bool readySetGo: false
48     //Debugging
49     property int hits: 0
50     property int misses: 0
51     property real ratio: hits/(misses?misses:1)
52     //Move to JS file?
53     property Ship redVar1: Ship {shipType: 1; gunType: 1}
54     property Ship redVar2: Ship {shipType: 1; gunType: 2}
55     property Ship redVar3: Ship {shipType: 1; gunType: 3}
56     property Ship greenVar1: Ship {shipType: 3; gunType: 1}
57     property Ship greenVar2: Ship {shipType: 2; gunType: 2}
58     property Ship greenVar3: Ship {shipType: 1; gunType: 3}
59     property string winner: "0"
60     property int players: 0
61     function aiSet(ship) {
62         ship.gunType = Math.floor(Math.random() * 3) + 1
63         ship.shipType = Math.floor(Math.random() * 3) + 1
64     }
65
66     width: 360
67     height: 600
68     color: "black"
69     SequentialLoader {
70         anchors.fill: parent
71         //General Children
72         Image {
73             anchors.centerIn: parent
74             source: "../images/finalfrontier.png"
75         }
76         ParticleSystem {
77             id: particles
78         }
79         PlasmaPatrolParticles { sys: particles; z: 100 }//Renders all particles on the one plane
80         //Component parts
81         id: pageControl
82         Component.onCompleted: advance();
83         pages:[
84         Component {Item {
85             id: menu
86             width: root.width
87             height: root.height
88             Column {
89                 anchors.verticalCenter: parent.verticalCenter
90                 width: parent.width
91                 spacing: 8
92                 Item {
93                     id: title
94                     width: root.width
95                     height: 240
96                     Emitter {
97                         anchors.fill: parent
98                         system: particles
99                         enabled: true
100                         group: "default"
101                         emitRate: 1200
102                         lifeSpan: 1200
103                         shape: MaskShape {source:"content/pics/TitleText.png"}
104                         size: 16
105                         endSize: 0
106                         sizeVariation: 8
107                         speed: AngleDirection {angleVariation:360; magnitudeVariation: 6}
108                     }
109                 }
110                 Button {
111                     text: "1P"
112                     onClicked: {root.players = 1; pageControl.advance();}
113                     anchors.horizontalCenter: parent.horizontalCenter
114                 }
115                 Button {
116                     text: "2P"
117                     onClicked: {root.players = 2; pageControl.advance();}
118                     anchors.horizontalCenter: parent.horizontalCenter
119                 }
120                 Button {
121                     text: "Demo"
122                     anchors.horizontalCenter: parent.horizontalCenter
123                     onClicked: {root.players = 0; 
124                         aiSet(redVar1);
125                         aiSet(redVar2);
126                         aiSet(redVar3);
127                         aiSet(greenVar1);
128                         aiSet(greenVar2);
129                         aiSet(greenVar3);
130                         pageControl.at = 5;//TODO: Not a magic number
131                         pageControl.advance();}
132                 }
133                 Button {
134                     text: "Help"
135                     anchors.horizontalCenter: parent.horizontalCenter
136                     onClicked: {
137                         pageControl.at = 7;//TODO: Not a magic number
138                         pageControl.advance();
139                     }
140                 }
141                 Button {
142                     text: "Quit"
143                     anchors.horizontalCenter: parent.horizontalCenter
144                     onClicked: Qt.quit();
145                 }
146             }
147         }},
148         Component {Item {
149             id: p1Screen
150             z: 101
151             width: root.width
152             height: root.height
153             Rectangle {
154                 anchors.fill: parent
155                 color: "red"
156             }
157             Text {
158                 anchors.centerIn: parent
159                 color: "white"
160                 font.pixelSize: 64
161                 font.bold: true
162                 text: "Player\n    1"
163                 horizontalAlignment: Text.AlignHCenter
164             }
165             MouseArea {
166                 anchors.fill: parent
167                 onClicked: pageControl.advance()
168             }
169         }},
170         Component {Item {
171             id: p1Choices
172             z: 3
173             width: root.width
174             height: root.height
175             Rectangle {
176                 color: "black"
177                 anchors.fill: parent
178             }
179             Column {
180                 spacing: 16
181                 width: root.width
182                 anchors.horizontalCenter: parent.horizontalCenter
183                 ChoiceBox {
184                     target: redVar1
185                     system: particles
186                 }
187                 ChoiceBox {
188                     target: redVar2
189                     system: particles
190                 }
191                 ChoiceBox {
192                     target: redVar3
193                     system: particles
194                 }
195                 Button {
196                     anchors.horizontalCenter: parent.horizontalCenter
197                     text: "Next"
198                     onClicked: {
199                         if (root.players < 2) {
200                             aiSet(greenVar1);
201                             aiSet(greenVar2);
202                             aiSet(greenVar3);
203                             pageControl.at = 5;//TODO: Not a magic number
204                         }
205                         pageControl.advance();
206                     }
207                 }
208             }
209         }},
210         Component {Item {
211             id: p2Screen
212             z: 101
213             width: root.width
214             height: root.height
215             Rectangle {
216                 anchors.fill: parent
217                 color: "green"
218             }
219             Text {
220                 anchors.centerIn: parent
221                 color: "white"
222                 font.pixelSize: 64
223                 font.bold: true
224                 text: "Player\n    2"
225                 horizontalAlignment: Text.AlignHCenter
226             }
227             MouseArea {
228                 anchors.fill: parent
229                 onClicked: pageControl.advance()
230             }
231         }},
232         Component {Item {
233             id: p2Choices
234             z: 1
235             width: root.width
236             height: root.height
237             Rectangle {
238                 color: "black"
239                 anchors.fill: parent
240             }
241             Column {
242                 spacing: 16
243                 width: root.width
244                 anchors.horizontalCenter: parent.horizontalCenter
245                 ChoiceBox {
246                     target: greenVar1
247                     system: particles
248                 }
249                 ChoiceBox {
250                     target: greenVar2
251                     system: particles
252                 }
253                 ChoiceBox {
254                     target: greenVar3
255                     system: particles
256                 }
257                 Button {
258                     anchors.horizontalCenter: parent.horizontalCenter
259                     text: "Next"
260                     onClicked: pageControl.advance()
261                 }
262             }
263         }},
264         Component {Item {
265             id: arena
266             width: root.width
267             height: root.height
268             z: 0
269             Component.onCompleted: root.readySetGo = true
270             Component.onDestruction: root.readySetGo = false
271             property bool victory: redShip3.hp <= 0 || greenShip3.hp <=0
272             onVictoryChanged: {
273                 if (redShip3.hp <= 0) {
274                     if (greenShip3.hp <= 0) {
275                         root.winner = "1&2"
276                     }else {
277                         root.winner = "2"
278                     }
279                 } else {
280                     root.winner = "1"
281                 }
282                 winTimer.start()
283             }
284             Timer {
285                 id: winTimer
286                 interval: 1200
287                 repeat: false
288                 running: false
289                 onTriggered: pageControl.advance();
290             }
291             Ship {
292                 id: redShip1
293                 shipParticle: "redTeam"
294                 system: particles
295                 x: 180-64
296                 y: 128
297                 shipType: redVar1.shipType
298                 gunType: redVar1.gunType
299                 targets: [greenShip1, greenShip2, greenShip3]
300             }
301             Ship {
302                 id: redShip2
303                 shipParticle: "redTeam"
304                 system: particles
305                 x: 0
306                 y: 0
307                 shipType: redVar2.shipType
308                 gunType: redVar2.gunType
309                 targets: [greenShip1, greenShip2, greenShip3]
310             }
311             Ship {
312                 id: redShip3
313                 shipParticle: "redTeam"
314                 system: particles
315                 x: 360-128
316                 y: 0
317                 shipType: redVar3.shipType
318                 gunType: redVar3.gunType
319                 targets: [greenShip1, greenShip2, greenShip3]
320             }
321
322             Ship {
323                 id: greenShip1
324                 shipParticle: "greenTeam"
325                 system: particles
326                 x: 180-64
327                 y: 600 - 128 - 128
328                 shipType: greenVar1.shipType
329                 gunType: greenVar1.gunType
330                 targets: [redShip1, redShip2, redShip3]
331             }
332             Ship {
333                 id: greenShip2
334                 shipParticle: "greenTeam"
335                 system: particles
336                 x: 0
337                 y: 600-128
338                 shipType: greenVar2.shipType
339                 gunType: greenVar2.gunType
340                 targets: [redShip1, redShip2, redShip3]
341             }
342             Ship {
343                 id: greenShip3
344                 shipParticle: "greenTeam"
345                 system: particles
346                 x: 360 - 128
347                 y: 600 - 128
348                 shipType: greenVar3.shipType
349                 gunType: greenVar3.gunType
350                 targets: [redShip1, redShip2, redShip3]
351             }
352         }},
353         Component {Item {
354             id: winScreen
355             z: 101
356             width: root.width
357             height: root.height
358             /*
359             Rectangle {
360                 anchors.fill: parent
361                 color: "black"
362             }
363             */
364             Text {//TODO: Particle Text?
365                 anchors.fill: parent
366                 color: "white"
367                 font.pixelSize: 64
368                 font.bold: true
369                 text: "Player " + root.winner + " wins!"
370                 wrapMode: Text.WordWrap
371                 horizontalAlignment: Text.AlignHCenter
372                 verticalAlignment: Text.AlignVCenter
373             }
374             MouseArea {
375                 anchors.fill: parent
376                 onClicked: {pageControl.at = 0; pageControl.advance();}
377             }
378         }},
379         Component {
380             HelpScreens {
381                 onExitDesired: {pageControl.at = 0; pageControl.advance();}
382             }
383         }
384         ]
385     }
386 }