1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
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 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
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 "samegame.js" as Logic
47 property bool gameOver: true
49 property int highScore: 0
51 property int blockSize: 32
52 property string mode: ""
53 property ParticleSystem ps: particleSystem
55 property alias backgroundVisible: bg.visible
56 property string background: "gfx/background.png"
57 property string blockFile: "Block.qml"
58 onBlockFileChanged: Logic.changeBlock(blockFile);
59 property alias particlePack: auxLoader.source
61 property int score2: 0
62 property int curTurn: 1
63 property bool autoTurnChange: false
65 property bool swapping: false
66 //onSwapPlayers: if (autoTurnChange) Logic.turnChange();//Now implemented below
69 property bool puzzleWon: false
70 signal puzzleLost //Since root is tracking the puzzle progress
71 function showPuzzleEnd (won) {
73 smokeParticle.color = Qt.rgba(0,1,0,0);
76 smokeParticle.color = Qt.rgba(1,0,0,0);
81 function showPuzzleGoal (str) {
82 puzzleTextBubble.opacity = 1;
83 puzzleTextLabel.text = str;
89 fillMode: Image.PreserveAspectCrop
95 anchors.fill: parent; onClicked: {
96 if (puzzleTextBubble.opacity == 1) {
97 puzzleTextBubble.opacity = 0;
98 Logic.finishLoadingMap();
99 } else if (!swapping) {
100 Logic.handleClick(mouse.x,mouse.y);
106 id: highScoreTextBubble
107 opacity: mode == "arcade" && gameOver && gameCanvas.score == gameCanvas.highScore ? 1 : 0
108 Behavior on opacity { NumberAnimation {} }
109 anchors.centerIn: parent
111 source: "gfx/bubble-highscore.png"
113 anchors.centerIn: parent
114 source: "gfx/text-highscore-new.png"
121 anchors.centerIn: parent
123 Behavior on opacity { NumberAnimation {} }
125 source: "gfx/bubble-puzzle.png"
128 onModeChanged: if (mode != "puzzle" && puzzleTextBubble.opacity > 0) puzzleTextBubble.opacity = 0;
132 width: parent.width - 24
133 anchors.centerIn: parent
134 horizontalAlignment: Text.AlignHCenter
138 wrapMode: Text.WordWrap
142 p1WonImg.opacity = 0;
143 p2WonImg.opacity = 0;
145 SmokeText { id: puzzleWin; source: "gfx/icon-ok.png"; system: particleSystem }
146 SmokeText { id: puzzleFail; source: "gfx/icon-fail.png"; system: particleSystem }
149 smokeParticle.color = "yellow"
156 clickDelay.running = true;
158 SequentialAnimation {
160 ScriptAction { script: gameCanvas.swapping = true; }
161 PauseAnimation { duration: 750 }
162 ScriptAction { script: gameCanvas.swapping = false; }
166 id: p1Text; source: "gfx/text-p1-go.png";
167 system: particleSystem; playerNum: 1
168 opacity: p1WonImg.opacity + p2WonImg.opacity > 0 ? 0 : 1
172 id: p2Text; source: "gfx/text-p2-go.png";
173 system: particleSystem; playerNum: 2
174 opacity: p1WonImg.opacity + p2WonImg.opacity > 0 ? 0 : 1
178 if (gameCanvas.mode == "multiplayer") {
179 if (gameCanvas.score >= gameCanvas.score2) {
180 p1WonImg.opacity = 1;
182 p2WonImg.opacity = 1;
188 source: "gfx/text-p1-won.png"
189 anchors.centerIn: parent
191 Behavior on opacity { NumberAnimation {} }
196 source: "gfx/text-p2-won.png"
197 anchors.centerIn: parent
199 Behavior on opacity { NumberAnimation {} }
210 source: "gfx/particle-smoke.png"
218 source: "PrimaryPack.qml"
220 if (item && "particleSystem" in item)
221 item.particleSystem = particleSystem
222 if (item && "gameArea" in item)
223 item.gameArea = gameCanvas