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