blob: c696d970cd3bef7bdb12c324d07e02879c26fd85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Particles
import "content/samegame.js" as Logic
import "content"
Rectangle {
id: root
width: Settings.screenWidth; height: Settings.screenHeight
property int acc: 0
function loadPuzzle() {
if (gameCanvas.mode != "")
Logic.cleanUp();
Logic.startNewGame(gameCanvas,"puzzle","levels/level"+acc+".qml")
}
function nextPuzzle() {
acc = (acc + 1) % 10;
loadPuzzle();
}
Timer {
id: gameOverTimer
interval: 1500
running : gameCanvas.gameOver && gameCanvas.mode == "puzzle" //mode will be reset by cleanUp();
repeat : false
onTriggered: {
Logic.cleanUp();
nextPuzzle();
}
}
Image {
source: "content/gfx/background.png"
anchors.fill: parent
}
GameArea {
id: gameCanvas
z: 1
y: Settings.headerHeight
width: parent.width
height: parent.height - Settings.headerHeight - Settings.footerHeight
backgroundVisible: root.state == "in-game"
onModeChanged: if (gameCanvas.mode != "puzzle") puzzleWon = false; //UI has stricter constraints on this variable than the game does
Age {
groups: ["redspots", "greenspots", "bluespots", "yellowspots"]
enabled: root.state == ""
system: gameCanvas.ps
}
onPuzzleLost: root.acc--;//So that nextPuzzle() reloads the current one
}
Item {
id: menu
z: 2
width: parent.width;
anchors.top: parent.top
anchors.bottom: bottomBar.top
LogoAnimation {
x: 64
y: Settings.headerHeight
particleSystem: gameCanvas.ps
running: root.state == ""
}
Row {
x: 112
y: 20
Image { source: "content/gfx/logo-a.png" }
Image { source: "content/gfx/logo-m.png" }
Image { source: "content/gfx/logo-e.png" }
}
Column {
y: 100 + 40
spacing: Settings.menuButtonSpacing
width: parent.width
height: parent.height - (140 + Settings.footerHeight)
Button {
width: root.width
rotatedButton: true
imgSrc: Qt.resolvedUrl("content/gfx/but-game-1.png")
onClicked: {
if (root.state == "in-game")
return //Prevent double clicking
root.state = "in-game"
gameCanvas.blockFile = "Block.qml"
gameCanvas.background = "gfx/background.png"
arcadeTimer.start();
}
//Emitted particles don't fade out, because ImageParticle is on the GameArea
system: gameCanvas.ps
group: "green"
Timer {
id: arcadeTimer
interval: Settings.menuDelay
running : false
repeat : false
onTriggered: Logic.startNewGame(gameCanvas)
}
}
Button {
width: root.width
rotatedButton: true
imgSrc: Qt.resolvedUrl("content/gfx/but-game-2.png")
onClicked: {
if (root.state == "in-game")
return
root.state = "in-game"
gameCanvas.blockFile = "Block.qml"
gameCanvas.background = "gfx/background.png"
twopTimer.start();
}
system: gameCanvas.ps
group: "green"
Timer {
id: twopTimer
interval: Settings.menuDelay
running : false
repeat : false
onTriggered: Logic.startNewGame(gameCanvas, "multiplayer")
}
}
Button {
width: root.width
rotatedButton: true
imgSrc: Qt.resolvedUrl("content/gfx/but-game-3.png")
onClicked: {
if (root.state == "in-game")
return
root.state = "in-game"
gameCanvas.blockFile = "SimpleBlock.qml"
gameCanvas.background = "gfx/background.png"
endlessTimer.start();
}
system: gameCanvas.ps
group: "blue"
Timer {
id: endlessTimer
interval: Settings.menuDelay
running : false
repeat : false
onTriggered: Logic.startNewGame(gameCanvas, "endless")
}
}
Button {
width: root.width
rotatedButton: true
imgSrc: Qt.resolvedUrl("content/gfx/but-game-4.png")
group: "yellow"
onClicked: {
if (root.state == "in-game")
return
root.state = "in-game"
gameCanvas.blockFile = "PuzzleBlock.qml"
gameCanvas.background = "gfx/background.png"
puzzleTimer.start();
}
Timer {
id: puzzleTimer
interval: Settings.menuDelay
running : false
repeat : false
onTriggered: root.loadPuzzle();
}
system: gameCanvas.ps
}
}
}
Image {
id: scoreBar
source: "content/gfx/bar.png"
width: parent.width
z: 6
y: -Settings.headerHeight
height: Settings.headerHeight
Behavior on opacity { NumberAnimation {} }
SamegameText {
id: arcadeScore
anchors { right: parent.right; topMargin: 3; rightMargin: 11; top: parent.top}
text: '<font color="#f7d303">P1:</font> ' + gameCanvas.score
font.pixelSize: Settings.fontPixelSize
textFormat: Text.StyledText
color: "white"
opacity: gameCanvas.mode == "arcade" ? 1 : 0
Behavior on opacity { NumberAnimation {} }
}
SamegameText {
id: arcadeHighScore
anchors { left: parent.left; topMargin: 3; leftMargin: 11; top: parent.top}
text: '<font color="#f7d303">Highscore:</font> ' + gameCanvas.highScore
opacity: gameCanvas.mode == "arcade" ? 1 : 0
}
SamegameText {
id: p1Score
anchors { right: parent.right; topMargin: 3; rightMargin: 11; top: parent.top}
text: '<font color="#f7d303">P1:</font> ' + gameCanvas.score
opacity: gameCanvas.mode == "multiplayer" ? 1 : 0
}
SamegameText {
id: p2Score
anchors { left: parent.left; topMargin: 3; leftMargin: 11; top: parent.top}
text: '<font color="#f7d303">P2:</font> ' + gameCanvas.score2
opacity: gameCanvas.mode == "multiplayer" ? 1 : 0
rotation: 180
}
SamegameText {
id: puzzleMoves
anchors { left: parent.left; topMargin: 3; leftMargin: 11; top: parent.top}
text: '<font color="#f7d303">Moves:</font> ' + gameCanvas.moves
opacity: gameCanvas.mode == "puzzle" ? 1 : 0
}
SamegameText {
Image {
source: "content/gfx/icon-time.png"
x: -20
}
id: puzzleTime
anchors { topMargin: 3; top: parent.top; horizontalCenter: parent.horizontalCenter; horizontalCenterOffset: 20}
text: "00:00"
opacity: gameCanvas.mode == "puzzle" ? 1 : 0
Timer {
interval: 1000
repeat: true
running: gameCanvas.mode == "puzzle" && !gameCanvas.gameOver
onTriggered: {
var elapsed = Math.floor((new Date() - Logic.gameDuration)/ 1000.0);
var mins = Math.floor(elapsed/60.0);
var secs = (elapsed % 60);
puzzleTime.text = (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs;
}
}
}
SamegameText {
id: puzzleScore
anchors { right: parent.right; topMargin: 3; rightMargin: 11; top: parent.top}
text: '<font color="#f7d303">Score:</font> ' + gameCanvas.score
opacity: gameCanvas.mode == "puzzle" ? 1 : 0
}
}
Image {
id: bottomBar
width: parent.width
height: Settings.footerHeight
source: "content/gfx/bar.png"
y: parent.height - Settings.footerHeight;
z: 2
Button {
id: quitButton
height: Settings.toolButtonHeight
imgSrc: Qt.resolvedUrl("content/gfx/but-quit.png")
onClicked: {Qt.quit(); }
anchors { left: parent.left; verticalCenter: parent.verticalCenter; leftMargin: 11 }
}
Button {
id: menuButton
height: Settings.toolButtonHeight
imgSrc: Qt.resolvedUrl("content/gfx/but-menu.png")
visible: (root.state == "in-game");
onClicked: {root.state = ""; Logic.cleanUp(); gameCanvas.mode = ""}
anchors { left: quitButton.right; verticalCenter: parent.verticalCenter; leftMargin: 0 }
}
Button {
id: againButton
height: Settings.toolButtonHeight
imgSrc: Qt.resolvedUrl("content/gfx/but-game-new.png")
visible: (root.state == "in-game");
opacity: gameCanvas.gameOver && (gameCanvas.mode == "arcade" || gameCanvas.mode == "multiplayer")
Behavior on opacity{ NumberAnimation {} }
onClicked: {if (gameCanvas.gameOver) { Logic.startNewGame(gameCanvas, gameCanvas.mode);}}
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 11 }
}
Button {
id: nextButton
height: Settings.toolButtonHeight
imgSrc: Qt.resolvedUrl("content/gfx/but-puzzle-next.png")
visible: (root.state == "in-game") && gameCanvas.mode == "puzzle" && gameCanvas.puzzleWon
opacity: gameCanvas.puzzleWon ? 1 : 0
Behavior on opacity{ NumberAnimation {} }
onClicked: {if (gameCanvas.puzzleWon) root.nextPuzzle();}
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 11 }
}
}
Connections {
target: root
function onStateChanged() {
stateChangeAnim.running = true
}
}
SequentialAnimation {
id: stateChangeAnim
ParallelAnimation {
NumberAnimation { target: bottomBar; property: "y"; to: root.height; duration: Settings.menuDelay/2; easing.type: Easing.OutQuad }
NumberAnimation { target: scoreBar; property: "y"; to: -Settings.headerHeight; duration: Settings.menuDelay/2; easing.type: Easing.OutQuad }
}
ParallelAnimation {
NumberAnimation { target: bottomBar; property: "y"; to: root.height - Settings.footerHeight; duration: Settings.menuDelay/2; easing.type: Easing.OutBounce}
NumberAnimation { target: scoreBar; property: "y"; to: root.state == "" ? -Settings.headerHeight : 0; duration: Settings.menuDelay/2; easing.type: Easing.OutBounce}
}
}
states: [
State {
name: "in-game"
PropertyChanges {
menu {
opacity: 0
visible: false
}
}
}
]
transitions: [
Transition {
NumberAnimation {properties: "x,y,opacity"}
}
]
//"Debug mode"
focus: true
Keys.onAsteriskPressed: Logic.nuke();
Keys.onSpacePressed: gameCanvas.puzzleWon = true;
}
|