-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
352 lines (280 loc) · 10.5 KB
/
main.qml
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*|File: main.qml
|Author: Son Hai Nguyen
|License: LGPL
|*/
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtMultimedia 5.3
import QtQuick.Window 2.0
import Duck 1.0
import Trees 1.0
import Ball 1.0
import Barrels 1.0
import Clouds 1.0
import Game 1.0
import FileStream 1.0
import "logic/duckLogic.js" as DuckLogic
import "logic/barrelLogic.js" as BarrelLogic
import "logic/cloudLogic.js" as CloudLogic
import "logic/backgroundLogic.js" as BackgroundLogic
import "logic/generalLogic.js" as GL
import "logic/gestures.js" as Gestures
import "res/shapes.js" as Shapes
import "components_static"
ApplicationWindow {
id: root
/*--smazat--*/ //možná
width: 1//854
height: 1//480
visible: true
/*----------*/
/*---Údaje o kliku myší---*/
property real touchX
property real touchY
property bool mousePressed: false
/*-----------------------*/
onVisibilityChanged: {
if(visibility==3) //možná ještě 0
game.paused = true
console.log(visibility + "------------------------------------------------------------------------")
}
onWidthChanged: {
DuckLogic.updateOutlines()
if(root.width>0 && graphics.firstTrees.width==0 && game.sizeOfPixel)
BackgroundLogic.initFirstTrees()
}
Game {
id: game
/*---------------------------------*/
/*--------------Font---------------*/
/*---------------------------------*/
FontLoader {
id: pixelFont
source: "res/fonts/Fleftex_M.ttf"
}
/*---------------------------------*/
/*--------------Zvuky--------------*/
/*---------------------------------*/
Sounds { id: sounds }
/*---------------------------------*/
/*--------Container grafiky--------*/
/*---------------------------------*/
Graphics {
id: graphics
objectName: "graphics"
}
/*---------------------------------*/
/*---------Game Over dialog--------*/
/*---------------------------------*/
ScoreDialog {
id: scoreDialog
objectName: "scoreDialog"
}
/*---------------------------------*/
/*--------Soubor high score--------*/
/*---------------------------------*/
FileStream {
id: scoreFile
objectName: "scoreFile"
source: "score.txt"
}
/*---------------------------------*/
/*------------Tutorial-------------*/
/*---------------------------------*/
Tutorial { id: tutorial }
/*----Nastavení vazby----*/
sizeOfPixel: (root.height * GL.fraction(120, 480))/Shapes.getDuckNumberOfPixels("column")
/*-----------------------*/
highScore: scoreFile.read()
onScoreChanged: {
graphics.scoreText.text = game.score
}
onSizeOfPixelChanged: {
DuckLogic.updateOutlines()
BarrelLogic.updateOutlines()
}
/*---------------------------------*/
/*------------Kachnička------------*/
/*---------------------------------*/
Duck {
id: duck
objectName: "duck"
/*---Vlasnosti kachničky---*/
heightOfJump: root.height * GL.fraction(160, 480)
size: game.sizeOfPixel * 14
/*-------------------------*/
/*--Pozicování kachničky--*/
defaultX: root.width * GL.fraction(150, 850)
defaultY: root.height-size - 2*game.sizeOfPixel
/*------------------------*/
/*---Grafika kachničky---*/
image: graphics.duckImage
property var outlines: DuckLogic.initOutlines()
/*-----------------------*/
Connections {
target: game
onPausedChanged: {
if(game.paused) {
if(jumpAnimation.running)
jumpAnimation.pause()
}
else
jumpAnimation.resume()
}
}
/*--Animace skákání a posunování okrajů kachničky--*/
onJump: SequentialAnimation {
id: jumpAnimation
objectName: "jumpAnimation"
ScriptAction { script: (function() { if(!duck.canJump) { jumpAnimation.stop() } })() }
ScriptAction { script: sounds.outWaterSound.play() }
NumberAnimation { target: duck.image; property: "y"; to: duck.image.y-duck.heightOfJump; duration: 500; easing.type: Easing.OutQuad }
NumberAnimation { target: duck.image; property: "y"; to: duck.image.y; duration: 500; easing.type: Easing.InQuad }
ScriptAction { script: sounds.inWaterSound.play() }
}
/*-------------------------------------------------*/
}
/*---------------------------------*/
/*------Házený kus kovu(míč)-------*/
/*---------------------------------*/
Ball {
id: ball
objectName: "ball"
image: graphics.ballImage
/*----------------Animace hodu míče----------------*/
onUpdatePosition: SequentialAnimation {
id: throwAnimation
objectName: "throwAnimation"
loops: Animation.Infinite
NumberAnimation { duration: 1 }
ScriptAction { script: ball.updateBallPosition() }
}
/*-------------------------------------------------*/
}
/*---------------------------------*/
/*--------Barrely(překážky)--------*/
/*---------------------------------*/
Barrels {
id: barrels
/*--Objekty a informace--*/
property var isAvailable: new Array
property var objects: new Array
/*-----------------------*/
Component.onCompleted: {
BarrelLogic.initBarrels()
}
SequentialAnimation {
id: barrelGenerator
objectName: "generator"
running: true
NumberAnimation { id: barrelGeneratorDelay }
ScriptAction { script: BarrelLogic.sendBarrel() }
onRunningChanged: barrelGenerator.start()
}
}
/*---------------------------------*/
/*--------------Mraky--------------*/
/*---------------------------------*/
Clouds {
id: clouds
/*---Objekty a informace----*/
property var objects: new Array
property var isAvailable: new Array
/*--------------------------*/
Component.onCompleted: {
CloudLogic.initClouds()
}
SequentialAnimation {
id: cloudGenerator
objectName: "generator"
running: true
NumberAnimation { id: cloudGeneratorDelay }
ScriptAction { script: CloudLogic.sendCloud() }
onRunningChanged: cloudGenerator.start()
}
}
/*---------------------------------*/
/*---------Stromy(pozadí)----------*/
/*---------------------------------*/
Trees { // není v graphics, protože obsahuje jen data
id: trees
/*---Objekty a informace----*/
property var objects: new Array
property var isAvailable: new Array
/*--------------------------*/
Component.onCompleted: {
BackgroundLogic.initTrees()
}
SequentialAnimation {
id: treeGenerator
objectName: "generator"
running: true
NumberAnimation { id: treeGeneratorDelay }
ScriptAction { script: BackgroundLogic.sendTree() }
onRunningChanged: treeGenerator.start()
}
}
Component.onCompleted: { //propojení vše se signály game
game.onPausedChanged.connect(duck.handleGamePause)
game.onPausedChanged.connect(ball.handleGamePause)
game.onPausedChanged.connect(barrels.handleGamePause)
game.onPausedChanged.connect(clouds.handleGamePause)
game.onPausedChanged.connect(trees.handleGamePause)
game.onPausedChanged.connect(sounds.soundtrack.handleGamePause)
game.restart.connect(scoreDialog.hide)
game.restart.connect(duck.restart)
game.restart.connect(ball.disable)
}
}
/*---------------------------------*/
/*----------Pause button-----------*/
/*---------------------------------*/
Image {
id: pauseButton
source: "res/images/pauseButton.svg"
x: root.width-(width+2*game.sizeOfPixel)
y: 2*game.sizeOfPixel
z: 1
width: 6*game.sizeOfPixel
height: 7*game.sizeOfPixel
/*----Renderovací velikost----*/
sourceSize.width: 6*game.sizeOfPixel
sourceSize.height: 7*game.sizeOfPixel
/*----------------------------*/
MouseArea {
anchors.fill: parent
enabled: false
onClicked: if(!game.over) { game.paused = (game.paused) ?false :true }
}
}
/*---------------------------------*/
/*--------------Eventy-------------*/
/*---------------------------------*/
MouseArea {
id: rootMouseArea
objectName: "rootMouseArea"
anchors.fill: parent
onPressed: {
root.mousePressed = true;
root.touchX = mouse.x;
root.touchY = mouse.y ;
}
onReleased: {
root.mousePressed = false;
if(Gestures.checkClick(root.touchX, root.touchY, mouse.x, mouse.y, GL.pixels(Screen.logicalPixelDensity, 2.5))) //pokud byl proveden klik hodí kachnička míčem
ball.calculateInfo(mouse.x, mouse.y);
if(Gestures.checkClick(root.touchX, root.touchY, mouse.x, mouse.y, GL.pixels(Screen.logicalPixelDensity, 2.5)) && tutorial.visible) { //první klik ve hře
tutorial.opacity = 0.0
pauseButton.children[0].enabled = true
game.paused = false
}
}
onPositionChanged: {
switch(Gestures.checkSlide(root.touchY, mouse.y, GL.pixels(Screen.logicalPixelDensity, 12))) {
case "slide up":
duck.jump()
break;
}
}
}
}