From 845a663492bf846afef988cf5d1fb325c04fb03b Mon Sep 17 00:00:00 2001 From: Sumer Shinde Date: Wed, 9 Oct 2024 22:39:34 -0400 Subject: [PATCH 1/2] #112: Added rotation, changing sprites when flapped, increased speed of game --- NERODevelopment/CMakeLists.txt | 1 + NERODevelopment/content/CMakeLists.txt | 4 ++ NERODevelopment/content/FlappyBird.qml | 51 +++++++++++++++--- .../content/images/yellowbird-downflap.png | Bin 0 -> 426 bytes .../content/images/yellowbird-midflap.png | Bin 0 -> 425 bytes .../content/images/yellowbird-upflap.png | Bin 0 -> 427 bytes 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 NERODevelopment/content/images/yellowbird-downflap.png create mode 100644 NERODevelopment/content/images/yellowbird-midflap.png create mode 100644 NERODevelopment/content/images/yellowbird-upflap.png diff --git a/NERODevelopment/CMakeLists.txt b/NERODevelopment/CMakeLists.txt index f5bc53f..231754a 100644 --- a/NERODevelopment/CMakeLists.txt +++ b/NERODevelopment/CMakeLists.txt @@ -80,6 +80,7 @@ qt_add_resources(NEROApp "configuration" qtquickcontrols2.conf ) + qt_add_protobuf(NEROApp PROTO_FILES src/proto/serverdata/serverdata.proto diff --git a/NERODevelopment/content/CMakeLists.txt b/NERODevelopment/content/CMakeLists.txt index e9ca36d..c18a9d9 100644 --- a/NERODevelopment/content/CMakeLists.txt +++ b/NERODevelopment/content/CMakeLists.txt @@ -65,4 +65,8 @@ qt6_add_qml_module(content images/interlocks.jpg images/sidebrb.jpg images/tsms.jpg + images/flappy-bird.png + images/yellowbird-upflap.png + images/yellowbird-midflap.png + images/yellowbird-downflap.png ) diff --git a/NERODevelopment/content/FlappyBird.qml b/NERODevelopment/content/FlappyBird.qml index 5ab1f56..0103fa9 100644 --- a/NERODevelopment/content/FlappyBird.qml +++ b/NERODevelopment/content/FlappyBird.qml @@ -32,6 +32,14 @@ Item { property double speed: 3 property int frameRate: 25 property bool didJump: flappyBirdController.didJump + property string birdFrame1: "qrc:/content/images/yellowbird-downflap.png" + property string birdFrame2: "qrc:/content/images/yellowbird-midflap.png" + property string birdFrame3: "qrc:/content/images/yellowbird-upflap.png" + + property int currentBirdFrame: 0 + + property real birdRotation: 0 + onDidJumpChanged: { if (didJump) { @@ -43,6 +51,11 @@ Item { flappyBird.xWall2 = 650 flappyBird.xWall3 = 800 flappyBird.speed = 3 + + // Reset the bird's rotation and drop speed + flappyBird.birdRotation = 0 + flappyBird.birdDrop = 1 + return } @@ -51,6 +64,7 @@ Item { } } + Timer { function isGameOver() { return yBallValue > parent.height || yBallValue < 0 || (xBallValue + pipeWidth > xWall1 && xBallValue < xWall1 + pipeWidth && (yBallValue < wall1.y + pipeHeight || yBallValue + birdHitBox > wall11.y)) || (xBallValue + pipeWidth > xWall2 && xBallValue < xWall2 + pipeWidth && (yBallValue < wall21.y + pipeHeight || yBallValue + birdHitBox > wall22.y)) || (xBallValue + pipeWidth > xWall3 && xBallValue < xWall3 + pipeWidth && (yBallValue < wall31.y + pipeHeight || yBallValue + birdHitBox > wall32.y)) @@ -61,14 +75,15 @@ Item { repeat: true onTriggered: { if (flappyBird.gameOver) { - flappyBirdController.saveScore(flappyBird.score) - return - } + flappyBirdController.saveScore(flappyBird.score) + return + } time.text = Date().toString() if (isGameOver()) { flappyBird.gameOver = true } + if (xWall1 < 0) { xWall1 = parent.width wall1.y = -100 - Math.round(Math.random() * 100) @@ -89,9 +104,14 @@ Item { flappyBird.score += 1 } + flappyBird.speed += 0.005 + if (!jumpAnimation.running) { yBallValue += flappyBird.birdDrop - flappyBird.birdDrop += 0.2 + flappyBird.birdDrop += 0.3 // Increase the fall speed by incrementing faster + flappyBird.birdRotation = Math.min(90, flappyBird.birdRotation + 5) // Rotate the bird faster as it falls + } else { + flappyBird.birdRotation = -45 } xWall1 -= flappyBird.speed @@ -153,11 +173,12 @@ Item { Keys.onSpacePressed: { flappyBirdController.enterButtonPressed() + birdFlapAnimation.running = true } NumberAnimation on yBallValue { id: jumpAnimation - to: yBallValue - 40 + to: yBallValue - 50 duration: 100 } @@ -169,11 +190,25 @@ Item { id: ball x: xBallValue y: yBallValue - width: 50 - height: 50 - source: flappyBird.birdSrc + width: implicitWidth + height: implicitHeight + source: { + if (currentBirdFrame === 0) return birdFrame1; + else if (currentBirdFrame === 1) return birdFrame2; + else return birdFrame3; + } + rotation: flappyBird.birdRotation } + SequentialAnimation { + id: birdFlapAnimation + running: false + loops: 1 + + PropertyAnimation { target: flappyBird; property: "currentBirdFrame"; from: 2; to: 0; duration: 1000 } + PropertyAnimation { target: flappyBird; property: "currentBirdFrame"; from: 0; to: 1; duration: 500 } + } + Text { id: gameOverText visible: flappyBird.gameOver diff --git a/NERODevelopment/content/images/yellowbird-downflap.png b/NERODevelopment/content/images/yellowbird-downflap.png new file mode 100644 index 0000000000000000000000000000000000000000..e9e1c77b9deb38738f6f4d184243143bca2da46b GIT binary patch literal 426 zcmeAS@N?(olHy`uVBq!ia0vp^N0k@DU)Otn z{rdG|yYcmBXZ~0)JZRAQ|NsAjlBe20X~vQuzhDN3XE)M7oFs2|7ml`jQ>%a+&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=n3;!xN%;9M)g3^gEKe855Q)pZ7Xx_@DDbdch_c|` z+Rz#`qc!rtzdq>=sjVsBUE?z}5|%k^4ByAJ!`ka$T!g!ToEOuzDa{u&IhFo(WoYXz zDx9oRkXI(;$Etnt%hpG8VzmpM7VpkfwA$Ns>~Px5;^<#p`}Q%EMVg;vcHSliv{kjl zHKHUXu_Vlzw{7+P2v7+D!wY8#kY85lg&vOJ8UAvZrIGp!Q0 Uh6&}3^*{{_p00i_>zopr0M`A6wg3PC literal 0 HcmV?d00001 diff --git a/NERODevelopment/content/images/yellowbird-midflap.png b/NERODevelopment/content/images/yellowbird-midflap.png new file mode 100644 index 0000000000000000000000000000000000000000..2ca3c2d034b2332726bb6157591ee3319900c2fc GIT binary patch literal 425 zcmeAS@N?(olHy`uVBq!ia0vp^N0k@DU)Otn z{rdG|yYcmBXZ~0)JZRAQ|NsAjlBe20X~vQuzhDN3XE)M7oFs2|7ml`jQ>%a+&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=n3;!xN%;9M)g3^gOivfb5Q)pJ7ccT2P~cz*2-_hV zaZog3q4tiZ*WX=k-CFeW?_KXB9ZGT)DW}32LR~d)aPO9UxKJfwxlGFf6@%Z?=Pl^{ zvG%BD+$I544c4p8tvx5#F1#mwQfZCt4!*T6202kV(`MNHKjQ6|w8gBn>)PVeKuc9i zTq8@t-i!lHI literal 0 HcmV?d00001 diff --git a/NERODevelopment/content/images/yellowbird-upflap.png b/NERODevelopment/content/images/yellowbird-upflap.png new file mode 100644 index 0000000000000000000000000000000000000000..2f693da65360f492a3b364b2231c4419d9c782af GIT binary patch literal 427 zcmeAS@N?(olHy`uVBq!ia0vp^N0k@DU)Otn z{rdG|yYcmBXZ~0)JZRAQ|NsAjlBe20X~vQuzhDN3XE)M7oFs2|7ml`jQ>%a+&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=n3;!xN%;9M)g3^gY)==*5Q)pZ7b67^DDbdch=}0c z*w7lWf>q~8UGW7c%d}nbAJ~jk1Y89cDsE;t(-Tx6cDq}mWY$sdu9K+~ws_3@r^r9I zCHG+9?$S+MuIzlKO>=(;hl+0XPf?aSSe>cdvL$iD>MaNR?LSVG4zn=ZxrY0iGSFJp z64!{5l*E!$tK_0oAjM#0U}&jpV61Cs7-DE)Wng4wXsK;rW@TXTP|NZ#iiX_$l+3hB W+!`j7H`W6+FnGH9xvX Date: Thu, 10 Oct 2024 20:15:43 -0400 Subject: [PATCH 2/2] #112 nosedive change --- NERODevelopment/content/FlappyBird.qml | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/NERODevelopment/content/FlappyBird.qml b/NERODevelopment/content/FlappyBird.qml index 0103fa9..09af81e 100644 --- a/NERODevelopment/content/FlappyBird.qml +++ b/NERODevelopment/content/FlappyBird.qml @@ -37,6 +37,7 @@ Item { property string birdFrame3: "qrc:/content/images/yellowbird-upflap.png" property int currentBirdFrame: 0 + property bool startFalling: false property real birdRotation: 0 @@ -55,12 +56,25 @@ Item { // Reset the bird's rotation and drop speed flappyBird.birdRotation = 0 flappyBird.birdDrop = 1 - + startFalling = false + birdFallDelay.start() // Start the fall timer to ensure bird starts falling even if no jump is pressed return } jumpAnimation.running = true birdDrop = 1 + startFalling = false + birdFallDelay.restart() + } + } + + Timer { + id: birdFallDelay + interval: 150 + running: false + repeat: false + onTriggered: { + startFalling = true // Bird starts falling faster after delay } } @@ -75,9 +89,9 @@ Item { repeat: true onTriggered: { if (flappyBird.gameOver) { - flappyBirdController.saveScore(flappyBird.score) - return - } + flappyBirdController.saveScore(flappyBird.score) + return + } time.text = Date().toString() if (isGameOver()) { @@ -106,12 +120,15 @@ Item { flappyBird.speed += 0.005 - if (!jumpAnimation.running) { + if (!jumpAnimation.running && startFalling) { yBallValue += flappyBird.birdDrop flappyBird.birdDrop += 0.3 // Increase the fall speed by incrementing faster flappyBird.birdRotation = Math.min(90, flappyBird.birdRotation + 5) // Rotate the bird faster as it falls + } else if (!jumpAnimation.running && !startFalling) { + flappyBird.birdDrop = 1 // Slow initial fall after jump or at the start + flappyBird.birdRotation = Math.min(45, flappyBird.birdRotation + 3) // Slight rotation before full dive } else { - flappyBird.birdRotation = -45 + flappyBird.birdRotation = -45 // Bird flaps up during jump } xWall1 -= flappyBird.speed