c3b736bd655edaf82ae3b5ca0213eeaf8e6f18cb
[profile/ivi/qtdeclarative.git] / examples / demos / maroon / maroon.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 import "content"
44 import "content/logic.js" as Logic
45
46 Item {
47     id: root
48     width: 320
49     height: 480
50     property var gameState: Logic.newGameState(canvas);
51     property bool passedSplash: false
52
53     Image {
54         source:"content/gfx/background.png"
55         anchors.bottom: view.bottom
56
57         ParticleSystem {
58             id: particles
59         }
60
61         ImageParticle {
62             id: bubble
63             anchors.fill: parent
64             system: particles
65             source: "content/gfx/catch.png"
66             opacity: 0.25
67             smooth: true
68         }
69         Wander {
70             system: particles
71             anchors.fill: parent
72             xVariance: 25;
73             pace: 25;
74         }
75
76         Emitter {
77             id: fire
78             system: particles
79
80             width: parent.width
81             height: 150
82             anchors.bottom: parent.bottom
83             anchors.bottomMargin: 3
84             startTime: 15000
85
86             emitRate: 2
87             lifeSpan: 15000
88
89             acceleration: PointDirection{ y: -6; xVariation: 2; yVariation: 2 }
90
91             size: 24
92             sizeVariation: 16
93         }
94
95     }
96
97     Column {
98         id: view
99         y: -(height - 480)
100         width: 320
101
102         GameOverScreen { gameCanvas: canvas }
103
104         Item {
105             id: canvasArea
106             width: 320
107             height: 480
108
109             Row {
110                 height: childrenRect.height
111                 Image {
112                     id: wave
113                     y: 30
114                     source:"content/gfx/wave.png"
115                 }
116                 Image {
117                     y: 30
118                     source:"content/gfx/wave.png"
119                 }
120                 NumberAnimation on x { from: 0; to: -(wave.width); duration: 16000; loops: Animation.Infinite }
121                 SequentialAnimation on y {
122                     loops: Animation.Infinite
123                     NumberAnimation { from: y - 2; to: y + 2; duration: 1600; easing.type: Easing.InOutQuad }
124                     NumberAnimation { from: y + 2; to: y - 2; duration: 1600; easing.type: Easing.InOutQuad }
125                 }
126             }
127
128             Row {
129                 opacity: 0.5
130                 Image {
131                     id: wave2
132                     y: 25
133                     source: "content/gfx/wave.png"
134                 }
135                 Image {
136                     y: 25
137                     source: "content/gfx/wave.png"
138                 }
139                 NumberAnimation on x { from: -(wave2.width); to: 0; duration: 32000; loops: Animation.Infinite }
140                 SequentialAnimation on y {
141                     loops: Animation.Infinite
142                     NumberAnimation { from: y + 2; to: y - 2; duration: 1600; easing.type: Easing.InOutQuad }
143                     NumberAnimation { from: y - 2; to: y + 2; duration: 1600; easing.type: Easing.InOutQuad }
144                 }
145             }
146
147             Image {
148                 source: "content/gfx/sunlight.png"
149                 opacity: 0.02
150                 y: 0
151                 anchors.horizontalCenter: parent.horizontalCenter
152                 transformOrigin: Item.Top
153                 SequentialAnimation on rotation {
154                     loops: Animation.Infinite
155                     NumberAnimation { from: -10; to: 10; duration: 8000; easing.type: Easing.InOutSine }
156                     NumberAnimation { from: 10; to: -10; duration: 8000; easing.type: Easing.InOutSine }
157                 }
158             }
159
160             Image {
161                 source: "content/gfx/sunlight.png"
162                 opacity: 0.04
163                 y: 20
164                 anchors.horizontalCenter: parent.horizontalCenter
165                 transformOrigin: Item.Top
166                 SequentialAnimation on rotation {
167                     loops: Animation.Infinite
168                     NumberAnimation { from: 10; to: -10; duration: 8000; easing.type: Easing.InOutSine }
169                     NumberAnimation { from: -10; to: 10; duration: 8000; easing.type: Easing.InOutSine }
170                 }
171             }
172
173             Image {
174                 source: "content/gfx/grid.png"
175                 opacity: 0.5
176             }
177
178             GameCanvas {
179                 id: canvas
180                 anchors.bottom: parent.bottom
181                 anchors.bottomMargin: 20
182                 x: 32
183                 focus: true
184             }
185
186             InfoBar { anchors.bottom: canvas.top; anchors.bottomMargin: 6; width: parent.width }
187
188             //3..2..1..go
189             Timer {
190                 id: countdownTimer
191                 interval: 1000
192                 running: root.countdown < 5
193                 repeat: true
194                 onTriggered: root.countdown++
195             }
196             Repeater {
197                 model: ["content/gfx/text-blank.png", "content/gfx/text-3.png", "content/gfx/text-2.png", "content/gfx/text-1.png", "content/gfx/text-go.png"]
198                 delegate: Image {
199                     visible: root.countdown <= index
200                     opacity: root.countdown == index ? 0.5 : 0.1
201                     scale: root.countdown >= index ? 1.0 : 0.0
202                     source: modelData
203                     Behavior on opacity { NumberAnimation {} }
204                     Behavior on scale { NumberAnimation {} }
205                 }
206             }
207         }
208
209         NewGameScreen {
210             onStartButtonClicked: root.passedSplash = true
211         }
212     }
213
214     property int countdown: 10
215     Timer {
216         id: gameStarter
217         interval: 4000
218         running: false
219         repeat: false
220         onTriggered: Logic.startGame(canvas);
221     }
222
223     states: [
224         State {
225             name: "gameOn"; when: gameState.gameOver == false && passedSplash
226             PropertyChanges { target: view; y: -(height - 960) }
227             StateChangeScript { script: root.countdown = 0; }
228             PropertyChanges { target: gameStarter; running: true }
229         },
230         State {
231             name: "gameOver"; when: gameState.gameOver == true
232             PropertyChanges { target: view; y: 0 }
233         }
234     ]
235
236     transitions: Transition {
237         NumberAnimation { properties: "x,y"; duration: 1200; easing.type: Easing.OutQuad }
238     }
239 }