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 "samegame.js" as Logic
47 property bool gameOver: true
49 property int highScore: 0
51 property string mode: ""
52 property ParticleSystem ps: particleSystem
54 property alias backgroundVisible: bg.visible
55 property string background: "gfx/background.png"
56 property string blockFile: "Block.qml"
57 onBlockFileChanged: Logic.changeBlock(blockFile);
58 property alias particlePack: auxLoader.source
60 property int score2: 0
61 property int curTurn: 1
62 property bool autoTurnChange: false
64 property bool swapping: false
65 //onSwapPlayers: if (autoTurnChange) Logic.turnChange();//Now implemented below
68 property bool puzzleWon: false
69 signal puzzleLost //Since root is tracking the puzzle progress
70 function showPuzzleEnd (won) {
72 smokeParticle.color = Qt.rgba(0,1,0,0);
75 smokeParticle.color = Qt.rgba(1,0,0,0);
80 function showPuzzleGoal (str) {
81 puzzleTextBubble.opacity = 1;
82 puzzleTextLabel.text = str;
89 fillMode: Image.PreserveAspectCrop
93 anchors.fill: parent; onClicked: {
94 if (puzzleTextBubble.opacity == 1) {
95 puzzleTextBubble.opacity = 0;
96 Logic.finishLoadingMap();
97 } else if (!swapping) {
98 Logic.handleClick(mouse.x,mouse.y);
104 id: highScoreTextBubble
105 opacity: mode == "arcade" && gameOver && gameCanvas.score == gameCanvas.highScore ? 1 : 0
106 Behavior on opacity { NumberAnimation {} }
107 anchors.centerIn: parent
109 source: "gfx/bubble-highscore.png"
111 anchors.centerIn: parent
112 source: "gfx/text-highscore-new.png"
119 anchors.centerIn: parent
121 Behavior on opacity { NumberAnimation {} }
123 source: "gfx/bubble-puzzle.png"
126 onModeChanged: if (mode != "puzzle" && puzzleTextBubble.opacity > 0) puzzleTextBubble.opacity = 0;
130 width: parent.width - 24
131 anchors.centerIn: parent
132 horizontalAlignment: Text.AlignHCenter
136 wrapMode: Text.WordWrap
140 p1WonImg.opacity = 0;
141 p2WonImg.opacity = 0;
143 SmokeText { id: puzzleWin; source: "gfx/icon-ok.png"; system: particleSystem }
144 SmokeText { id: puzzleFail; source: "gfx/icon-fail.png"; system: particleSystem }
147 smokeParticle.color = "yellow"
154 clickDelay.running = true;
156 SequentialAnimation {
158 ScriptAction { script: gameCanvas.swapping = true; }
159 PauseAnimation { duration: 750 }
160 ScriptAction { script: gameCanvas.swapping = false; }
164 id: p1Text; source: "gfx/text-p1-go.png";
165 system: particleSystem; playerNum: 1
166 opacity: p1WonImg.opacity + p2WonImg.opacity > 0 ? 0 : 1
170 id: p2Text; source: "gfx/text-p2-go.png";
171 system: particleSystem; playerNum: 2
172 opacity: p1WonImg.opacity + p2WonImg.opacity > 0 ? 0 : 1
176 if (gameCanvas.mode == "multiplayer") {
177 if (gameCanvas.score >= gameCanvas.score2) {
178 p1WonImg.opacity = 1;
180 p2WonImg.opacity = 1;
186 source: "gfx/text-p1-won.png"
187 anchors.centerIn: parent
189 Behavior on opacity { NumberAnimation {} }
194 source: "gfx/text-p2-won.png"
195 anchors.centerIn: parent
197 Behavior on opacity { NumberAnimation {} }
208 source: "gfx/particle-smoke.png"
216 source: "PrimaryPack.qml"
218 if (item && "particleSystem" in item)
219 item.particleSystem = particleSystem
220 if (item && "gameArea" in item)
221 item.gameArea = gameCanvas