-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.qml
More file actions
1677 lines (1523 loc) · 66 KB
/
main.qml
File metadata and controls
1677 lines (1523 loc) · 66 KB
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2026 - Timo Könnecke <github.com/moWerk>
*
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.15
import QtSensors 5.11
import Nemo.Ngf 1.0
import QtQuick.Shapes 1.15
import org.asteroid.controls 1.0
import org.asteroid.blaster 1.0
import Nemo.KeepAlive 1.1
Item {
id: root
anchors.fill: parent
visible: true
// ── Balance block ─────────────────────────────────────────────────────────
QtObject {
id: balance
// Spawning
readonly property int initialSpawnCount: 8
readonly property int spawnCountBase: 6 // asteroids per wave = spawnCountBase + level
readonly property int spawnIntervalStart: 2000 // ms between spawns at level 1, decreases each level
readonly property int spawnIntervalFloor: 300 // minimum ms between spawns, never goes below this
readonly property int spawnIntervalStep: 100 // ms reduction per level on the spawn interval
readonly property int midAsteroidCap: 20
readonly property int smallAsteroidCap: 100
// Asteroid movement
readonly property real largeSpeed: 0.27
readonly property real midSpeed: 0.36
readonly property real smallSpeed: 0.54
readonly property real rotationSpeedBase: 10
readonly property real rotationSpeedVariance: 1
// UFO
readonly property real ufoSpeed: 1
readonly property int ufoSpawnDelay: 4000
readonly property int ufoCooldownDuration: 12000
// Player
readonly property real tiltSmoothing: 0.5
readonly property real tiltRotationSpeed: 60
readonly property int startingShields: 3
// Shooting
readonly property int fireInterval: 160
readonly property int rapidFireInterval: 60
readonly property real shotSpeed: 8
readonly property real shotSpawnOffset: 5
readonly property real wideShotAngle: 20
readonly property real wideShotSpeedMult: 0.65
readonly property real tripleShotSpread: 3
readonly property real laserFireMult: 1.2
// Scoring
readonly property int pointsLarge: 20
readonly property int pointsMid: 50
readonly property int pointsSmall: 100
readonly property real perimeterBonusMult: 2.0
readonly property real perimeterRadius: 27.5
// Power-ups
readonly property int powerupDuration: 10000
readonly property real pierceFourwayFireMult: 1.333
// Physics
readonly property real playerProximityRange: 20
readonly property real collisionPushFactor: 0.5
}
// ── Mutable game state ────────────────────────────────────────────────────
property bool calibrating: true
property int calibrationTimer: 3
property bool debugMode: false
property bool gameOver: false
property int level: 1
property bool paused: false
property int score: 0
property int shield: balance.startingShields
property real dimsFactor: Dims.l(100) / 100
property var activeShots: []
property var activeAsteroids: []
property real lastFrameTime: 0
property real baselineX: 0
property real smoothedX: 0
property real playerRotation: 0
property int initialAsteroidsToSpawn: balance.initialSpawnCount
property int asteroidsSpawned: 0
property real centerX: root.width / 2
property real centerY: root.height / 2
// UFO state
property bool ufoActive: false
property var ufoObject: null
property bool playerDying: false
readonly property real ufoSize: dimsFactor * 8
// Power-up state
property string activePowerup: ""
property color glowColor: "#00000000"
property string powerupLabel: ""
property string unlockLabel: ""
property string pendingUnlockType: ""
NonGraphicalFeedback {
id: feedback
event: "press"
}
onGameOverChanged: {
if (gameOver) {
GameStorage.highScore = score
GameStorage.highLevel = level
}
}
onCalibratingChanged: {
if (!calibrating) ufoSpawnTimer.restart()
}
onLevelChanged: {
if (!calibrating && level > 1) {
levelFlashAnim.restart()
levelColorAnim.restart()
}
}
// ── Timers ────────────────────────────────────────────────────────────────
Timer {
id: gameTimer
interval: 16
running: !gameOver && !calibrating && !paused && !playerDying
repeat: true
property real lastFps: 60
property var fpsHistory: []
property real lastFpsUpdate: 0
property real lastGraphUpdate: 0
onTriggered: {
var currentTime = Date.now()
var deltaTime = lastFrameTime > 0 ? (currentTime - lastFrameTime) / 1000 : 0.016
if (deltaTime > 0.033) deltaTime = 0.033
lastFrameTime = currentTime
updateGame(deltaTime)
var rawX = accelerometer.reading.x
smoothedX = smoothedX + balance.tiltSmoothing * (rawX - smoothedX)
var deltaX = (smoothedX - baselineX) * -2
playerRotation += deltaX * balance.tiltRotationSpeed * deltaTime
playerRotation = (playerRotation + 360) % 360
var currentFps = deltaTime > 0 ? 1 / deltaTime : 60
lastFps = currentFps
if (debugMode && currentTime - lastFpsUpdate >= 500) {
lastFpsUpdate = currentTime
fpsDisplay.text = "FPS: " + Math.round(currentFps)
}
if (debugMode && currentTime - lastGraphUpdate >= 500) {
lastGraphUpdate = currentTime
var tempHistory = fpsHistory.slice()
tempHistory.push(currentFps)
if (tempHistory.length > 10) tempHistory.shift()
fpsHistory = tempHistory
}
}
}
Timer {
id: calibrationCountdownTimer
interval: 1000
running: calibrating
repeat: true
onTriggered: {
calibrationTimer--
if (calibrationTimer <= 0) {
baselineX = accelerometer.reading.x
smoothedX = baselineX
calibrating = false
feedback.play()
}
}
}
Timer {
id: autoFireTimer
interval: activePowerup === "rapid" ? balance.rapidFireInterval : activePowerup === "pierce" ? Math.round(balance.fireInterval * balance.pierceFourwayFireMult) : activePowerup === "laser" ? Math.round(balance.fireInterval * balance.laserFireMult) : balance.fireInterval
running: !gameOver && !calibrating && !paused && !playerDying
repeat: true
onTriggered: {
var rad = playerRotation * Math.PI / 180
var shotX = playerContainer.x + playerHitbox.x + playerHitbox.width / 2 - dimsFactor * 0.5
var shotY = playerContainer.y + playerHitbox.y + playerHitbox.height / 2 - dimsFactor * 2.5
var ox = shotX + Math.sin(rad) * (dimsFactor * balance.shotSpawnOffset)
var oy = shotY - Math.cos(rad) * (dimsFactor * balance.shotSpawnOffset)
var isPierce = activePowerup === "pierce"
var angles = isPierce ? [rad, rad + Math.PI * 0.5, rad + Math.PI, rad + Math.PI * 1.5]
: [rad]
for (var ai = 0; ai < angles.length; ai++) {
var a = angles[ai]
var sox = shotX + Math.sin(a) * (dimsFactor * balance.shotSpawnOffset)
var soy = shotY - Math.cos(a) * (dimsFactor * balance.shotSpawnOffset)
var shot = autoFireShotComponent.createObject(shotLayer, {
"x": sox, "y": soy,
"directionX": Math.sin(a),
"directionY": -Math.cos(a),
"rotation": playerRotation + ai * 90,
"shotColor": isPierce ? "#DDCC00" : activePowerup === "rapid" ? "#AA44FF" : activePowerup === "triple" ? "#33FF66" : activePowerup === "frenzy" ? "#FFAA00" : activePowerup === "wide" ? "#FF44AA" : activePowerup === "laser" ? "#00FFAA" : activePowerup === "chain" ? "#2299FF" : "#00FFFF",
"piercing": isPierce
})
activeShots.push(shot)
}
if (activePowerup === "wide") {
var aL = rad - balance.wideShotAngle * Math.PI / 180
var aR = rad + balance.wideShotAngle * Math.PI / 180
var sL = autoFireShotComponent.createObject(shotLayer, {
"x": ox, "y": oy,
"directionX": Math.sin(aL), "directionY": -Math.cos(aL),
"rotation": playerRotation - balance.wideShotAngle,
"shotColor": "#FF44AA",
"speed": balance.shotSpeed * balance.wideShotSpeedMult
})
var sR = autoFireShotComponent.createObject(shotLayer, {
"x": ox, "y": oy,
"directionX": Math.sin(aR), "directionY": -Math.cos(aR),
"rotation": playerRotation + balance.wideShotAngle,
"shotColor": "#FF44AA",
"speed": balance.shotSpeed * balance.wideShotSpeedMult
})
activeShots.push(sL)
activeShots.push(sR)
}
if (activePowerup === "triple") {
var perpX = Math.cos(rad)
var perpY = Math.sin(rad)
var spread = dimsFactor * balance.tripleShotSpread
var sTL = autoFireShotComponent.createObject(shotLayer, {
"x": ox - perpX * spread, "y": oy - perpY * spread,
"directionX": Math.sin(rad), "directionY": -Math.cos(rad),
"rotation": playerRotation,
"shotColor": "#33FF66"
})
var sTR = autoFireShotComponent.createObject(shotLayer, {
"x": ox + perpX * spread, "y": oy + perpY * spread,
"directionX": Math.sin(rad), "directionY": -Math.cos(rad),
"rotation": playerRotation,
"shotColor": "#33FF66"
})
activeShots.push(sTL)
activeShots.push(sTR)
}
if (activePowerup === "laser") {
var removed = activeShots.pop()
if (removed) removed.destroy()
var beam = autoFireShotComponent.createObject(shotLayer, {
"x": sox - dimsFactor * 1,
"y": soy - dimsFactor * 50,
"directionX": Math.sin(rad),
"directionY": -Math.cos(rad),
"rotation": playerRotation,
"transformOrigin": Item.Bottom,
"shotColor": "#00FFAA",
"width": dimsFactor * 2,
"height": dimsFactor * 50,
"speed": balance.shotSpeed * 5,
"piercing": true
})
activeShots.push(beam)
}
if (activePowerup === "chain") {
var cs = activeShots[activeShots.length - 1]
if (cs) {
cs.chaining = true
cs.generation = 0
cs.shotColor = "#2299FF"
cs.width = dimsFactor * 2
cs.speed = balance.shotSpeed * 0.85
}
}
}
}
Timer {
id: asteroidSpawnTimer
interval: Math.max(balance.spawnIntervalFloor,
balance.spawnIntervalStart - (level - 1) * balance.spawnIntervalStep)
running: !gameOver && !calibrating && !paused && asteroidsSpawned < initialAsteroidsToSpawn
repeat: true
triggeredOnStart: true
onTriggered: {
spawnLargeAsteroid()
asteroidsSpawned++
if (asteroidsSpawned >= initialAsteroidsToSpawn) stop()
}
}
Timer {
id: ufoSpawnTimer
interval: balance.ufoSpawnDelay
repeat: false
onTriggered: {
if (!ufoActive && !gameOver) spawnUfo()
}
}
Timer {
id: powerupTimer
interval: balance.powerupDuration
repeat: false
onTriggered: {
activePowerup = ""
glowColor = "#00000000"
powerupBarContainer.opacity = 0
if (ufoObject) {
ufoObject.cooldown = true
ufoCooldownTimer.restart()
}
}
}
Timer {
id: ufoCooldownTimer
interval: balance.ufoCooldownDuration
repeat: false
onTriggered: {
if (ufoObject) {
ufoObject.colorIndex = ufoObject.nextColorIndex()
ufoObject.cooldown = false
ufoObject.dimmed = false
}
}
}
Timer {
id: unlockGiftTimer
interval: 2000
repeat: false
onTriggered: {
if (activePowerup === "" && pendingUnlockType !== "") {
var giftColors = {
"wide": "#FF44AA", "rapid": "#AA44FF", "triple": "#33FF66",
"pierce": "#DDCC00", "laser": "#00FFAA", "chain": "#2299FF", "nuke": "#FFFFFF"
}
activatePowerup(pendingUnlockType, giftColors[pendingUnlockType])
if (ufoObject) ufoObject.dimmed = true
}
pendingUnlockType = ""
}
}
Timer {
id: deathSequenceTimer
interval: 1000
repeat: false
onTriggered: {
gameOver = true
asteroidSpawnTimer.stop()
ufoSpawnTimer.stop()
powerupTimer.stop()
ufoCooldownTimer.stop()
activePowerup = ""
glowColor = "#00000000"
destroyUfo()
for (var i = 0; i < activeAsteroids.length; i++) {
if (activeAsteroids[i]) activeAsteroids[i].destroy()
}
for (var j = 0; j < activeShots.length; j++) {
if (activeShots[j]) activeShots[j].destroy()
}
activeAsteroids = []
activeShots = []
}
}
// ── Components ────────────────────────────────────────────────────────────
Component {
id: ufoComponent
Ufo {
dimsFactor: root.dimsFactor
paused: root.paused
gameOver: root.gameOver
calibrating: root.calibrating
level: root.level
}
}
Component {
id: explosionParticleComponent
ExplosionShader { }
}
Component {
id: autoFireShotComponent
Rectangle {
width: dimsFactor * 1
height: dimsFactor * 4
color: shotColor
visible: true
property string shotColor: "#00FFFF"
property real speed: balance.shotSpeed
property real directionX: 0
property real directionY: -1
property bool piercing: false
property bool chaining: false
property int generation: 0
rotation: playerRotation
}
}
Component {
id: scoreParticleComponent
ScoreParticle { }
}
Component {
id: deathShaderComponent
DeathShader { }
}
Component {
id: asteroidComponent
Shape {
id: asteroid
property real size: dimsFactor * 20
property real speed: {
if (asteroidSize === "large") return balance.largeSpeed
if (asteroidSize === "mid") return balance.midSpeed
if (asteroidSize === "small") return balance.smallSpeed
return 2
}
property real mass: size * size
property real directionX: 0
property real directionY: 0
property string asteroidSize: "large"
readonly property bool isUfo: false
property real rotationSpeed: (Math.random() < 0.5 ? -1 : 1)
* (balance.rotationSpeedBase
+ Math.random() * balance.rotationSpeedVariance * 2
- balance.rotationSpeedVariance)
width: size
height: size
property var asteroidPoints: {
var basePoints = Math.floor(5 + Math.random() * 3)
var pointsArray = []
var cx = size / 2
var cy = size / 2
for (var i = 0; i < basePoints; i++) {
var baseAngle = (i / basePoints) * 2 * Math.PI
var angle = baseAngle + Math.random() * 0.2 - 0.1
var isSpike = Math.random() < 0.7
var minR = isSpike ? size * 0.35 : size * 0.25
var maxR = isSpike ? size * 0.48 : size * 0.32
var r = minR + Math.random() * (maxR - minR)
pointsArray.push({ x: cx + r * Math.cos(angle), y: cy + r * Math.sin(angle) })
if (Math.random() < 0.3 && i < basePoints - 1) {
var midAngle = baseAngle + (1 / basePoints) * Math.PI + (Math.random() * 0.2 - 0.1)
var midR = size * (0.2 + Math.random() * 0.15)
pointsArray.push({ x: cx + midR * Math.cos(midAngle),
y: cy + midR * Math.sin(midAngle) })
}
}
return pointsArray
}
rotation: 0
NumberAnimation on rotation {
running: !paused && !gameOver && !calibrating
loops: Animation.Infinite
from: 0
to: 360 * (rotationSpeed < 0 ? -1 : 1)
duration: Math.abs(360 / rotationSpeed) * 800
}
ShapePath {
strokeWidth: dimsFactor * 1
strokeColor: paused ? "#444444" : "white"
fillColor: paused ? "transparent" : "#222222"
capStyle: ShapePath.RoundCap
joinStyle: ShapePath.RoundJoin
startX: asteroid.asteroidPoints[0].x
startY: asteroid.asteroidPoints[0].y
PathPolyline {
path: {
var pts = []
for (var i = 0; i < asteroid.asteroidPoints.length; i++)
pts.push(Qt.point(asteroid.asteroidPoints[i].x, asteroid.asteroidPoints[i].y))
pts.push(Qt.point(asteroid.asteroidPoints[0].x, asteroid.asteroidPoints[0].y))
return pts
}
}
}
function split() {
if (asteroidSize === "large"
&& activeAsteroids.filter(function(a) { return !a.isUfo && a.asteroidSize === "mid" }).length < balance.midAsteroidCap) {
spawnSplitAsteroids("mid", dimsFactor * 12, 2, x, y, directionX, directionY)
} else if (asteroidSize === "mid"
&& activeAsteroids.filter(function(a) { return !a.isUfo && a.asteroidSize === "small" }).length < balance.smallAsteroidCap) {
spawnSplitAsteroids("small", dimsFactor * 6, 2, x, y, directionX, directionY)
}
destroyAsteroid(this)
}
}
}
// ── Scene ─────────────────────────────────────────────────────────────────
// Paint order via declaration order only — no z: values anywhere.
// Layer Items (shotLayer, asteroidLayer, vfxLayer) are named insertion
// points for dynamically created objects. Their declaration position
// in gameContent determines when they paint relative to static items.
//
// Bottom → top within gameContent:
// scorePerimeter — bonus zone circle
// shotLayer — shots
// playerContainer — glow (first child) then ship (second child)
// asteroidLayer — asteroids + UFO
// vfxLayer — explosions + score particles
// HUD — level, bar, unlock, popup, score, shield
// calibrationContainer
// dimmingLayer
// pauseText + debug
//
// gameOverContainer is a sibling to gameContent declared after it,
// so it always paints on top without any z: needed.
Item {
id: gameArea
anchors.fill: parent
// Solid black background — first child of gameArea, paints behind everything.
Rectangle {
id: backgroundRect
anchors.fill: parent
color: "black"
SequentialAnimation {
id: levelFlashAnim
ColorAnimation { target: backgroundRect; property: "color"; to: "#00CCCC"; duration: 200 }
ColorAnimation { target: backgroundRect; property: "color"; to: "black"; duration: 800 }
}
}
Item {
id: gameContent
anchors.fill: parent
Rectangle {
id: scorePerimeter
width: dimsFactor * 55
height: dimsFactor * 55
radius: dimsFactor * 27.5
color: "#010A13"
border.color: "#0860C4"
border.width: 1
anchors.centerIn: parent
visible: !calibrating
Behavior on border.color { ColorAnimation { duration: 1000; easing.type: Easing.OutQuad } }
Behavior on color { ColorAnimation { duration: 1000; easing.type: Easing.OutQuad } }
}
Timer {
id: perimeterFlashTimer
interval: 100
repeat: false
onTriggered: {
scorePerimeter.border.color = "#0860C4"
scorePerimeter.color = "#010A13"
}
}
Item {
id: shotLayer
anchors.fill: parent
}
Item {
id: playerContainer
x: root.width / 2 - player.width / 2 + dimsFactor * 5
y: root.height / 2 - player.height / 2 + dimsFactor * 5
visible: !calibrating
Rectangle {
id: playerGlow
width: dimsFactor * 22
height: dimsFactor * 22
radius: dimsFactor * 11
anchors.centerIn: parent
color: glowColor
opacity: 0.0
visible: activePowerup !== ""
SequentialAnimation on opacity {
running: activePowerup !== ""
loops: Animation.Infinite
NumberAnimation { to: 0.55; duration: 500; easing.type: Easing.InOutQuad }
NumberAnimation { to: 0.0; duration: 500; easing.type: Easing.InOutQuad }
}
}
Image {
id: player
width: dimsFactor * 10
height: dimsFactor * 10
source: "file:///usr/share/asteroid-launcher/watchfaces-img/asteroid-logo.svg"
anchors.centerIn: parent
rotation: playerRotation
}
Shape {
id: playerHitbox
width: dimsFactor * 10
height: dimsFactor * 10
anchors.centerIn: parent
visible: false
rotation: playerRotation
ShapePath {
strokeWidth: -1
fillColor: "transparent"
startX: dimsFactor * 5; startY: 0
PathLine { x: dimsFactor * 10; y: dimsFactor * 5 }
PathLine { x: dimsFactor * 5; y: dimsFactor * 10 }
PathLine { x: 0; y: dimsFactor * 5 }
PathLine { x: dimsFactor * 5; y: 0 }
}
}
Shape {
id: shieldHitbox
width: dimsFactor * 14
height: dimsFactor * 14
anchors.centerIn: parent
visible: shield > 0
opacity: shield >= 4 ? 1.0
: shield === 3 ? 0.8
: shield === 2 ? 0.6
: shield === 1 ? 0.4 : 0.0
rotation: playerRotation
ShapePath {
strokeWidth: 2
strokeColor: "#DD1155"
fillColor: "transparent"
startX: dimsFactor * 7; startY: 0
PathLine { x: dimsFactor * 14; y: dimsFactor * 7 }
PathLine { x: dimsFactor * 7; y: dimsFactor * 14 }
PathLine { x: 0; y: dimsFactor * 7 }
PathLine { x: dimsFactor * 7; y: 0 }
}
}
}
Item {
id: asteroidLayer
anchors.fill: parent
}
Item {
id: vfxLayer
anchors.fill: parent
}
// ── HUD
Text {
id: levelNumber
text: level
color: "#00FFFF"
font { pixelSize: dimsFactor * 12; family: "Teko"; styleName: "SemiBold" }
anchors { top: root.top; horizontalCenter: parent.horizontalCenter }
visible: !calibrating
SequentialAnimation {
id: levelColorAnim
ColorAnimation { target: levelNumber; property: "color"; to: "#FFAA00"; duration: 200 }
ColorAnimation { target: levelNumber; property: "color"; to: "#00FFFF"; duration: 800 }
}
}
Item {
id: powerupBarContainer
width: dimsFactor * 40
height: dimsFactor * 3
anchors {
top: levelNumber.bottom
topMargin: -dimsFactor * 1.4
horizontalCenter: parent.horizontalCenter
}
visible: !calibrating && !gameOver && activePowerup !== "" && activePowerup !== "shield"
opacity: 0
SequentialAnimation {
id: barOpacityAnim
NumberAnimation { target: powerupBarContainer; property: "opacity"; to: 1.0; duration: 200; easing.type: Easing.InQuad }
PauseAnimation { duration: balance.powerupDuration - 1200 }
NumberAnimation { target: powerupBarContainer; property: "opacity"; to: 0.0; duration: 1000; easing.type: Easing.InQuad }
}
Rectangle {
anchors.fill: parent
radius: height / 2
color: Qt.rgba(1, 1, 1, 0.15)
}
Rectangle {
id: powerupBarFill
width: powerupBarContainer.width
height: parent.height
radius: height / 2
color: glowColor
Behavior on color { ColorAnimation { duration: 150 } }
}
NumberAnimation {
id: powerupBarAnim
target: powerupBarFill
property: "width"
from: powerupBarContainer.width
to: 0
duration: balance.powerupDuration
easing.type: Easing.Linear
}
}
Text {
id: powerupUnlock
text: unlockLabel
color: "white"
font { pixelSize: dimsFactor * 11; family: "Teko"; styleName: "Bold"; letterSpacing: dimsFactor * 0.3 }
anchors {
top: powerupBarContainer.bottom
topMargin: dimsFactor * 4
horizontalCenter: parent.horizontalCenter
}
opacity: 0
visible: !calibrating && !gameOver
SequentialAnimation {
id: unlockAnim
NumberAnimation { target: powerupUnlock; property: "opacity"; to: 0.85; duration: 400 }
PauseAnimation { duration: 1600 }
NumberAnimation { target: powerupUnlock; property: "opacity"; to: 0.0; duration: 1600; easing.type: Easing.InQuad }
}
}
Text {
id: powerupPopup
text: powerupLabel
color: glowColor
font { pixelSize: dimsFactor * 14; family: "Teko"; styleName: "Bold"; letterSpacing: dimsFactor * 0.3 }
anchors {
bottom: scoreText.top
bottomMargin: -dimsFactor * 5
horizontalCenter: parent.horizontalCenter
}
opacity: 0
visible: !calibrating && !gameOver
SequentialAnimation {
id: popupAnim
NumberAnimation { target: powerupPopup; property: "opacity"; to: 0.8; duration: 100 }
NumberAnimation { target: powerupPopup; property: "opacity"; to: 0.4; duration: 50 }
NumberAnimation { target: powerupPopup; property: "opacity"; to: 0.9; duration: 50 }
NumberAnimation { target: powerupPopup; property: "opacity"; to: 1.0; duration: 50 }
NumberAnimation { target: powerupPopup; property: "opacity"; to: 0.9; duration: 50 }
PauseAnimation { duration: 2200 }
NumberAnimation { target: powerupPopup; property: "opacity"; to: 0.0; duration: 400; easing.type: Easing.InQuad }
}
}
Text {
id: scoreText
text: score
color: "#FFAA00"
font { pixelSize: dimsFactor * 13; family: "Teko"; styleName: activePowerup === "frenzy" ? "Medium" : "Light" }
anchors {
bottom: shieldText.top
bottomMargin: -dimsFactor * 8.4
horizontalCenter: parent.horizontalCenter
}
visible: !gameOver && !calibrating
Behavior on color { ColorAnimation { duration: 300 } }
}
Text {
id: shieldText
text: shield
color: "#DD1155"
opacity: shield > 0 ? 1 : 0
font { pixelSize: dimsFactor * 12; family: "Teko"; styleName: "SemiBold" }
anchors {
bottom: parent.bottom
bottomMargin: -dimsFactor * 5
horizontalCenter: parent.horizontalCenter
}
visible: !calibrating && !gameOver
SequentialAnimation on opacity {
running: shield <= 0
loops: Animation.Infinite
NumberAnimation { to: 0; duration: 300; easing.type: Easing.InOutQuad }
NumberAnimation { to: 1; duration: 300; easing.type: Easing.InOutQuad }
onRunningChanged: { if (!running) shieldText.opacity = 1 }
}
}
// ── Calibration ───────────────────────────────────────────────────
Item {
id: calibrationContainer
anchors.fill: parent
visible: calibrating
Text {
text: "v2.0\nAsteroid Blaster"
color: "#dddddd"
lineHeightMode: Text.ProportionalHeight
lineHeight: 0.6
font { family: "Teko"; pixelSize: dimsFactor * 16; styleName: "Medium" }
anchors {
bottom: calibrationText.top
bottomMargin: dimsFactor * 10
horizontalCenter: parent.horizontalCenter
}
horizontalAlignment: Text.AlignHCenter
}
Column {
id: calibrationText
anchors { top: parent.verticalCenter; horizontalCenter: parent.horizontalCenter }
spacing: dimsFactor * 1
Text {
text: "Calibrating"
color: "white"
font.pixelSize: dimsFactor * 9
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: "Hold your watch comfy"
color: "white"
font.pixelSize: dimsFactor * 6
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: calibrationTimer + "s"
color: "white"
font.pixelSize: dimsFactor * 9
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
}
}
MouseArea {
anchors.fill: parent
enabled: calibrating
onClicked: {
baselineX = accelerometer.reading.x
smoothedX = baselineX
calibrating = false
feedback.play()
}
}
}
// ── Dimming overlay ───────────────────────────────────────────────
Rectangle {
id: dimmingLayer
anchors.fill: parent
color: "#000000"
opacity: (paused && !gameOver && !calibrating) || gameOver ? 0.8 : 0.0
Behavior on opacity { NumberAnimation { duration: 500; easing.type: Easing.InOutQuad } }
}
// ── Pause + debug ─────────────────────────────────────────────────
Text {
id: pauseText
text: "Paused"
color: "white"
font { pixelSize: dimsFactor * 22; family: "Teko" }
anchors.centerIn: parent
opacity: 0
visible: !gameOver && !calibrating
Behavior on opacity { NumberAnimation { duration: 250; easing.type: Easing.InOutQuad } }
MouseArea {
anchors.fill: parent
enabled: !gameOver && !calibrating
onClicked: {
paused = !paused
pauseText.opacity = paused ? 1.0 : 0.0
}
}
}
Text {
id: fpsDisplay
text: "FPS: 60"
color: "white"
opacity: 0.5
font.pixelSize: dimsFactor * 10
anchors { horizontalCenter: parent.horizontalCenter; bottom: fpsGraph.top }
visible: debugMode && !gameOver && !calibrating
}
Rectangle {
id: fpsGraph
width: dimsFactor * 30; height: dimsFactor * 10
color: "#00000000"
opacity: 0.5
anchors {
horizontalCenter: parent.horizontalCenter
top: debugToggle.top
topMargin: dimsFactor * 3
}
visible: debugMode && !gameOver && !calibrating
Row {
anchors.fill: parent
spacing: 0
Repeater {
model: 10
Rectangle {
width: fpsGraph.width / 10
height: {
var fps = index < gameTimer.fpsHistory.length ? gameTimer.fpsHistory[index] : 0
return Math.min(dimsFactor * 10, Math.max(0, (fps / 60) * dimsFactor * 10))
}
color: {
var fps = index < gameTimer.fpsHistory.length ? gameTimer.fpsHistory[index] : 0
return fps > 60 ? "green" : fps >= 50 ? "orange" : "red"
}
}
}
}
}
Text {
id: debugToggle
text: "Debug"
color: "white"
opacity: debugMode ? 1 : 0.5
font { pixelSize: dimsFactor * 10; bold: debugMode }
anchors {
bottom: pauseText.top
horizontalCenter: parent.horizontalCenter
bottomMargin: dimsFactor * 4
}
Behavior on opacity { NumberAnimation { duration: 250; easing.type: Easing.InOutQuad } }
visible: paused && !gameOver && !calibrating
MouseArea {
anchors.fill: parent
onClicked: { debugMode = !debugMode }
}
}
}
// ── Game over — sibling to gameContent, always paints on top ──────────
Item {
id: gameOverContainer
anchors.fill: parent
visible: gameOver
Text {
text: "Game Over"
color: "#DDFFFFFF"
font { pixelSize: dimsFactor * 19; family: "Teko"; styleName: "Medium" }
anchors {
bottom: scoreOverText.top
bottomMargin: -dimsFactor * 8
horizontalCenter: parent.horizontalCenter
}
}
Text {
id: scoreOverText
text: "Score: " + score + "\nLevel: " + level