Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#112 Animation of Flappy Bird #118

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NERODevelopment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ qt_add_resources(NEROApp "configuration"
qtquickcontrols2.conf
)


qt_add_protobuf(NEROApp
PROTO_FILES
src/proto/serverdata/serverdata.proto
Expand Down
4 changes: 4 additions & 0 deletions NERODevelopment/content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
64 changes: 58 additions & 6 deletions NERODevelopment/content/FlappyBird.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ 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 bool startFalling: false

property real birdRotation: 0


onDidJumpChanged: {
if (didJump) {
Expand All @@ -43,14 +52,33 @@ Item {
flappyBird.xWall2 = 650
flappyBird.xWall3 = 800
flappyBird.speed = 3

// 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
}
}


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))
Expand All @@ -69,6 +97,7 @@ Item {
if (isGameOver()) {
flappyBird.gameOver = true
}

if (xWall1 < 0) {
xWall1 = parent.width
wall1.y = -100 - Math.round(Math.random() * 100)
Expand All @@ -89,9 +118,17 @@ Item {
flappyBird.score += 1
}

if (!jumpAnimation.running) {
flappyBird.speed += 0.005

if (!jumpAnimation.running && startFalling) {
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 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 // Bird flaps up during jump
}

xWall1 -= flappyBird.speed
Expand Down Expand Up @@ -153,11 +190,12 @@ Item {

Keys.onSpacePressed: {
flappyBirdController.enterButtonPressed()
birdFlapAnimation.running = true
}

NumberAnimation on yBallValue {
id: jumpAnimation
to: yBallValue - 40
to: yBallValue - 50
duration: 100
}

Expand All @@ -169,11 +207,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
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NERODevelopment/content/images/yellowbird-upflap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading