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