1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the examples of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
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
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.
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."
39 ****************************************************************************/
42 import QtQuick.Particles 2.0
43 import "content/samegame.js" as Logic
48 width: 320; height: 480
50 property int menuDelay: 500
52 function loadPuzzle() {
53 if (gameCanvas.mode != "")
55 Logic.startNewGame(gameCanvas,"puzzle","levels/level"+acc+".qml")
57 function nextPuzzle() {
64 running : gameCanvas.gameOver && gameCanvas.mode == "puzzle" //mode will be reset by cleanUp();
73 source: "content/gfx/background.png"
83 height: parent.height - 64
84 backgroundVisible: root.state == "in-game"
85 onModeChanged: if (gameCanvas.mode != "puzzle") puzzleWon = false; //UI has stricter constraints on this variable than the game does
87 groups: ["redspots", "greenspots", "bluespots", "yellowspots"]
88 enabled: root.state == ""
92 onPuzzleLost: acc--;//So that nextPuzzle() reloads the current one
100 anchors.top: parent.top
101 anchors.bottom: bottomBar.top
106 particleSystem: gameCanvas.ps
107 running: root.state == ""
112 Image { source: "content/gfx/logo-a.png" }
113 Image { source: "content/gfx/logo-m.png" }
114 Image { source: "content/gfx/logo-e.png" }
125 imgSrc: "content/gfx/but-game-1.png"
127 if (root.state == "in-game")
128 return //Prevent double clicking
129 root.state = "in-game"
130 gameCanvas.blockFile = "Block.qml"
131 gameCanvas.background = "gfx/background.png"
134 //Emitted particles don't fade out, because ImageParticle is on the GameArea
135 system: gameCanvas.ps
142 onTriggered: Logic.startNewGame(gameCanvas)
150 imgSrc: "content/gfx/but-game-2.png"
152 if (root.state == "in-game")
154 root.state = "in-game"
155 gameCanvas.blockFile = "Block.qml"
156 gameCanvas.background = "gfx/background.png"
159 system: gameCanvas.ps
166 onTriggered: Logic.startNewGame(gameCanvas, "multiplayer")
174 imgSrc: "content/gfx/but-game-3.png"
176 if (root.state == "in-game")
178 root.state = "in-game"
179 gameCanvas.blockFile = "SimpleBlock.qml"
180 gameCanvas.background = "gfx/background.png"
181 endlessTimer.start();
183 system: gameCanvas.ps
190 onTriggered: Logic.startNewGame(gameCanvas, "endless")
198 imgSrc: "content/gfx/but-game-4.png"
201 if (root.state == "in-game")
203 root.state = "in-game"
204 gameCanvas.blockFile = "PuzzleBlock.qml"
205 gameCanvas.background = "gfx/background.png"
213 onTriggered: loadPuzzle();
215 system: gameCanvas.ps
222 source: "content/gfx/bar.png"
227 Behavior on opacity { NumberAnimation {} }
230 anchors { right: parent.right; topMargin: 3; rightMargin: 11; top: parent.top}
231 text: '<font color="#f7d303">P1:</font> ' + gameCanvas.score
233 textFormat: Text.StyledText
235 opacity: gameCanvas.mode == "arcade" ? 1 : 0
236 Behavior on opacity { NumberAnimation {} }
240 anchors { left: parent.left; topMargin: 3; leftMargin: 11; top: parent.top}
241 text: '<font color="#f7d303">Highscore:</font> ' + gameCanvas.highScore
244 textFormat: Text.StyledText
245 opacity: gameCanvas.mode == "arcade" ? 1 : 0
246 Behavior on opacity { NumberAnimation {} }
250 anchors { right: parent.right; topMargin: 3; rightMargin: 11; top: parent.top}
251 text: '<font color="#f7d303">P1:</font> ' + gameCanvas.score
252 textFormat: Text.StyledText
255 opacity: gameCanvas.mode == "multiplayer" ? 1 : 0
256 Behavior on opacity { NumberAnimation {} }
260 anchors { left: parent.left; topMargin: 3; leftMargin: 11; top: parent.top}
261 text: '<font color="#f7d303">P2:</font> ' + gameCanvas.score2
262 textFormat: Text.StyledText
265 opacity: gameCanvas.mode == "multiplayer" ? 1 : 0
266 Behavior on opacity { NumberAnimation {} }
271 anchors { left: parent.left; topMargin: 3; leftMargin: 11; top: parent.top}
272 text: '<font color="#f7d303">Moves:</font> ' + gameCanvas.moves
273 textFormat: Text.StyledText
276 opacity: gameCanvas.mode == "puzzle" ? 1 : 0
277 Behavior on opacity { NumberAnimation {} }
281 source: "content/gfx/icon-time.png"
285 anchors { topMargin: 3; top: parent.top; horizontalCenter: parent.horizontalCenter; horizontalCenterOffset: 20}
289 opacity: gameCanvas.mode == "puzzle" ? 1 : 0
290 Behavior on opacity { NumberAnimation {} }
294 running: gameCanvas.mode == "puzzle" && !gameCanvas.gameOver
296 var elapsed = Math.floor((new Date() - Logic.gameDuration)/ 1000.0);
297 var mins = Math.floor(elapsed/60.0);
298 var secs = (elapsed % 60);
299 puzzleTime.text = (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs;
305 anchors { right: parent.right; topMargin: 3; rightMargin: 11; top: parent.top}
306 text: '<font color="#f7d303">Score:</font> ' + gameCanvas.score
307 textFormat: Text.StyledText
310 opacity: gameCanvas.mode == "puzzle" ? 1 : 0
311 Behavior on opacity { NumberAnimation {} }
319 source: "content/gfx/bar.png"
320 y: parent.height - 44
322 function selectButtons() {
323 menuButton.visible = (root.state == "in-game");
324 nextButton.visible = (root.state == "in-game");
325 againButton.visible = (root.state == "in-game");
329 imgSrc: "content/gfx/but-quit.png"
330 onClicked: {Qt.quit(); }
331 anchors { left: parent.left; verticalCenter: parent.verticalCenter; leftMargin: 11 }
335 imgSrc: "content/gfx/but-menu.png"
337 onClicked: {root.state = ""; Logic.cleanUp(); gameCanvas.mode = ""}
338 anchors { left: quitButton.right; verticalCenter: parent.verticalCenter; leftMargin: 0 }
342 imgSrc: "content/gfx/but-game-new.png"
344 opacity: gameCanvas.gameOver && (gameCanvas.mode == "arcade" || gameCanvas.mode == "multiplayer") ? 1 : 0
345 Behavior on opacity{ NumberAnimation {} }
346 onClicked: {if (gameCanvas.gameOver) Logic.startNewGame(gameCanvas, gameCanvas.mode);}
347 anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 11 }
351 imgSrc: "content/gfx/but-puzzle-next.png"
353 opacity: gameCanvas.puzzleWon ? 1 : 0
354 Behavior on opacity{ NumberAnimation {} }
355 onClicked: {if (gameCanvas.puzzleWon) nextPuzzle();}
356 anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 11 }
362 onStateChanged: stateChangeAnim.running = true
364 SequentialAnimation {
367 NumberAnimation { target: bottomBar; property: "y"; to: root.height; duration: menuDelay/2; easing.type: Easing.OutQuad }
368 NumberAnimation { target: scoreBar; property: "y"; to: -24; duration: menuDelay/2; easing.type: Easing.OutQuad }
370 ScriptAction { script: bottomBar.selectButtons(); }
372 NumberAnimation { target: bottomBar; property: "y"; to: root.height - 44; duration: menuDelay/2; easing.type: Easing.OutBounce}
373 NumberAnimation { target: scoreBar; property: "y"; to: root.state == "" ? -24 : 0; duration: menuDelay/2; easing.type: Easing.OutBounce}
390 NumberAnimation {properties: "x,y,opacity"}
396 Keys.onAsteriskPressed: Logic.nuke();
397 Keys.onSpacePressed: gameCanvas.puzzleWon = true;