SlideShare a Scribd company logo
FLAPPY BIRD GAME
By: Hamza Gulistan
Reg no: FA14-Bcs-027
Introduction
• It is a simple game in which one bird is moving between
different obstacles.
• If the bird touches any obstacle then the game will be end
and the total score will show on the screen.
• Every time the bird crosses any obstacle the score
increases by 1.
Creating a Flappy Bird game in Visual
Studio Using C#
• Create Windows Form Application
• 4 Picture boxes,
• 1 Timer Object
• 4 Labels
Naming
Name Text Property
PictureBox1 flappyBird
PictureBox2 pipeTop
PictureBox3 pipeBottom
PictureBox4 ground
label1
label2
label3
label4
scoreText
endText1
endText2
gameDesigner
timer1 gameTimer
Coding
the core variables for the game
bool jumping = false;
Int pipeSpeed = 5;
int gravity = 5;
Int Inscore = 0;
Set the label properties
• endText1.Text = "Game Over!";
• endText2.Text = "Your final score is: " + Inscore;
• gameDesigner.Text = "Game Designed By your name
here";
• endText1.Visible = false;
• endText2.Visible = false;
• gameDesigner.Visible = false;
Functions
• We need 3 functions that will be triggered by various
events
• 1) Timer function
• 2) keydown function
• 3) key up function
• 4) game end function
Adding timer properties:
name = gameTimer
Enabled = True
Interval = 15
gameTimer_Tick function
pipeBottom.Left -= pipeSpeed;
pipeTop.Left -= pipeSpeed;
flappyBird.Top += gravity;
scoreText.Text = " " + Inscore; //for scores
This will scroll the pipes to the left and drop the bird using
the gravity variable.
The bounds property
• Ending game
• Bounds check for height and width of each of the picture
box. Intersects with will check the height and width of
another picture against the first one and check to see if
they are colliding.
Enter the following code in the timer
function
if (flappyBird.Bounds.IntersectsWith(ground.Bounds))
{
endGame();
}
elseif (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds))
{
endGame();
}
elseif (flappyBird.Bounds.IntersectsWith(pipeTop.Bounds))
{
endGame();
}
gameTimer.Stop();
Regenerating pipes
Enter the following code in the game timer function
if (pipeBottom.Left< -80)
{
pipeBottom.Left = 1000;
Inscore += 1; //score add
}
elseif (pipeTop.Left< -95)
{
pipeTop.Left = 1100;
Inscore += 1; //score add
}
The code above checks whether the pipes have left the screen
and gone beyond -80px to the left.
score on screen
scoreText.Text = “ " + Inscore;
Code of key down function & keyUp
• this will reverse the gravity and make the character jump.
if (e.KeyCode == Keys.Space)
{
jumping = true;
gravity = -7;
}
• Enter the following code in the key up function, this will enable
gravity again to the character
if (e.KeyCode == Keys.Space)
{
jumping = false;
gravity = 5;
}
endGame()
• create a function to be used when we want to the end the
game.
private void endGame()
{
gameTimer.Stop();
endText1.Visible = true;
endText2.Visible = true;
gameDesigner.Visible = true;
}
Full Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Flappy_Bird
{
public partial class Game : Form
{
bool jumping = false;
int pipeSpeed = 5;
int gravity = 5;
int Inscore = 3;
public Game()
{
InitializeComponent();
endText1.Text = "Game Over!";
endText2.Text = "Your final score is: " + Inscore;
gameDesigner.Text = "Game Designed Hamza Gulistan";
endText1.Visible = false;
endText2.Visible = false;
gameDesigner.Visible = false;
}
}
private void gameTimer_Tick(object sender, EventArgs e)
{
pipeBottom.Left -= pipeSpeed;
pipeTop.Left -= pipeSpeed;
flappyBird.Top += gravity;
scoreText.Text = " " + Inscore;
if (pipeBottom.Left < -50) //ending game
{
pipeBottom.Left = 800;
Inscore = Inscore + 1;
}
else if (pipeTop.Left < -75)
{
pipeTop.Left = 910;
Inscore += 1;
}
if (flappyBird.Bounds.IntersectsWith(ground.Bounds)) //regenreting pipes
{
endGame();
}
else if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds))
{
endGame();
}
else if (flappyBird.Bounds.IntersectsWith(pipeTop.Bounds))
{
endGame();
}
}
private void endGame()
{
gameTimer.Stop();
endText1.Visible = true;
endText2.Visible = true;
gameDesigner.Visible = true;
}
private void endText2_Click(object sender, EventArgs e)
{
endText2.Text = "Your final score is: " +Inscore;
}
private void GameKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
jumping = true;
gravity = -7;
}
}
private void GameKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
jumping = false;
gravity = 5;
}
}
}
}

More Related Content

What's hot

Car racing game for android
Car racing game for androidCar racing game for android
Car racing game for android
ravijot singh
 
Android Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationAndroid Application And Unity3D Game Documentation
Android Application And Unity3D Game Documentation
Sneh Raval
 
Unity
UnityUnity
Unity 3D, A game engine
Unity 3D, A game engineUnity 3D, A game engine
Unity 3D, A game engine
Md. Irteza rahman Masud
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
Utkarsh Aggarwal
 
Zombi - Shoot for Survive
Zombi - Shoot for SurviveZombi - Shoot for Survive
Zombi - Shoot for Survive
Divy Singh Rathore
 
Flappy Bird Game
Flappy Bird GameFlappy Bird Game
Flappy Bird Game
Sheersh Bhatnagar
 
project on snake game in c language
project on snake game in c languageproject on snake game in c language
project on snake game in c language
Ashutosh Kumar
 
Game Design fundamentals
Game Design fundamentalsGame Design fundamentals
Game Design fundamentals
Mirco Pasqualini
 
Final Year Game Project Presentation
Final Year Game Project Presentation Final Year Game Project Presentation
Final Year Game Project Presentation
Nusrat Jahan Shanta
 
Flutter workshop
Flutter workshopFlutter workshop
Flutter workshop
Vishnu Suresh
 
snake game
snake gamesnake game
snake game
Shailesh kumar
 
PRESENTATION ON Game Engine
PRESENTATION ON Game EnginePRESENTATION ON Game Engine
PRESENTATION ON Game EngineDiksha Bhargava
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
Ahmed Abu Eldahab
 
Proposal of 3d GAME Final Year Project
Proposal of  3d GAME Final Year ProjectProposal of  3d GAME Final Year Project
Proposal of 3d GAME Final Year Project
fahim shahzad
 
Artificial intelligence In Modern-Games.
Artificial intelligence In Modern-Games. Artificial intelligence In Modern-Games.
Artificial intelligence In Modern-Games. Nitish Kavishetti
 
Design phase of game development of unity 2d game
Design phase of game development of unity 2d game Design phase of game development of unity 2d game
Design phase of game development of unity 2d game
Muhammad Maaz Irfan
 
Android summer training report
Android summer training reportAndroid summer training report
Android summer training report
Shashendra Singh
 
report on snake game
report on snake game report on snake game
report on snake game
azhar niaz
 
Car Game - Final Year Project
Car Game - Final Year ProjectCar Game - Final Year Project
Car Game - Final Year ProjectVivek Naskar
 

What's hot (20)

Car racing game for android
Car racing game for androidCar racing game for android
Car racing game for android
 
Android Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationAndroid Application And Unity3D Game Documentation
Android Application And Unity3D Game Documentation
 
Unity
UnityUnity
Unity
 
Unity 3D, A game engine
Unity 3D, A game engineUnity 3D, A game engine
Unity 3D, A game engine
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
Zombi - Shoot for Survive
Zombi - Shoot for SurviveZombi - Shoot for Survive
Zombi - Shoot for Survive
 
Flappy Bird Game
Flappy Bird GameFlappy Bird Game
Flappy Bird Game
 
project on snake game in c language
project on snake game in c languageproject on snake game in c language
project on snake game in c language
 
Game Design fundamentals
Game Design fundamentalsGame Design fundamentals
Game Design fundamentals
 
Final Year Game Project Presentation
Final Year Game Project Presentation Final Year Game Project Presentation
Final Year Game Project Presentation
 
Flutter workshop
Flutter workshopFlutter workshop
Flutter workshop
 
snake game
snake gamesnake game
snake game
 
PRESENTATION ON Game Engine
PRESENTATION ON Game EnginePRESENTATION ON Game Engine
PRESENTATION ON Game Engine
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
 
Proposal of 3d GAME Final Year Project
Proposal of  3d GAME Final Year ProjectProposal of  3d GAME Final Year Project
Proposal of 3d GAME Final Year Project
 
Artificial intelligence In Modern-Games.
Artificial intelligence In Modern-Games. Artificial intelligence In Modern-Games.
Artificial intelligence In Modern-Games.
 
Design phase of game development of unity 2d game
Design phase of game development of unity 2d game Design phase of game development of unity 2d game
Design phase of game development of unity 2d game
 
Android summer training report
Android summer training reportAndroid summer training report
Android summer training report
 
report on snake game
report on snake game report on snake game
report on snake game
 
Car Game - Final Year Project
Car Game - Final Year ProjectCar Game - Final Year Project
Car Game - Final Year Project
 

Viewers also liked

UniteKorea2014 - Making flappy bird workshop
UniteKorea2014 - Making flappy bird workshopUniteKorea2014 - Making flappy bird workshop
UniteKorea2014 - Making flappy bird workshop
GukHwan Ji
 
παιχνίδι στο Powerpoint
παιχνίδι στο Powerpointπαιχνίδι στο Powerpoint
παιχνίδι στο Powerpointangelikipatsea
 
Flappy Bird Social Media Monitoring in Vietnam -- Case Study
Flappy Bird Social Media Monitoring in Vietnam -- Case StudyFlappy Bird Social Media Monitoring in Vietnam -- Case Study
Flappy Bird Social Media Monitoring in Vietnam -- Case Study
Boomerang
 
μέτρα και βρες
μέτρα και βρεςμέτρα και βρες
μέτρα και βρες
patrik4
 
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!
Despina Kamilali
 
Cross-platform Game Dev w/ CocosSharp
Cross-platform Game Dev w/ CocosSharpCross-platform Game Dev w/ CocosSharp
Cross-platform Game Dev w/ CocosSharp
Alexey Strakh
 
Cross platform physics games - NDC 2014
Cross platform physics games - NDC 2014Cross platform physics games - NDC 2014
Cross platform physics games - NDC 2014
Runegri
 
Madrid .NET Meetup: Microsoft open sources .NET!
Madrid .NET Meetup: Microsoft open sources .NET!Madrid .NET Meetup: Microsoft open sources .NET!
Madrid .NET Meetup: Microsoft open sources .NET!
Alfonso Garcia-Caro
 
Games with Win 8 Style by Neneng
Games with Win 8 Style by NenengGames with Win 8 Style by Neneng
Games with Win 8 Style by NenengAgate Studio
 
Flappy - Paris 2015
Flappy -  Paris 2015Flappy -  Paris 2015
Flappy - Paris 2015
Phillip Trelford
 
EastBay.NET - Introduction to MonoTouch
EastBay.NET - Introduction to MonoTouchEastBay.NET - Introduction to MonoTouch
EastBay.NET - Introduction to MonoTouch
mobiweave
 
Multyplatform and mono part 2 - Matteo Nicolotti
Multyplatform and mono part 2 - Matteo Nicolotti Multyplatform and mono part 2 - Matteo Nicolotti
Multyplatform and mono part 2 - Matteo Nicolotti
Codemotion
 
Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...
Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...
Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...
SanaChoudary
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid Does
Kevin McMahon
 
Introduction to CocosSharp
Introduction to CocosSharpIntroduction to CocosSharp
Introduction to CocosSharp
James Montemagno
 
Gaming in Csharp
Gaming in CsharpGaming in Csharp
Gaming in Csharp
Vidyasagar Machupalli
 
Generative Art Hands On with F#
Generative Art Hands On with F#Generative Art Hands On with F#
Generative Art Hands On with F#
Phillip Trelford
 

Viewers also liked (20)

UniteKorea2014 - Making flappy bird workshop
UniteKorea2014 - Making flappy bird workshopUniteKorea2014 - Making flappy bird workshop
UniteKorea2014 - Making flappy bird workshop
 
παιχνίδι στο Powerpoint
παιχνίδι στο Powerpointπαιχνίδι στο Powerpoint
παιχνίδι στο Powerpoint
 
The success of flappy bird
The success of flappy birdThe success of flappy bird
The success of flappy bird
 
Flappy Bird Social Media Monitoring in Vietnam -- Case Study
Flappy Bird Social Media Monitoring in Vietnam -- Case StudyFlappy Bird Social Media Monitoring in Vietnam -- Case Study
Flappy Bird Social Media Monitoring in Vietnam -- Case Study
 
μέτρα και βρες
μέτρα και βρεςμέτρα και βρες
μέτρα και βρες
 
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το Powerpoint!
 
CocosSharp_XHackNight_07feb
CocosSharp_XHackNight_07febCocosSharp_XHackNight_07feb
CocosSharp_XHackNight_07feb
 
Cross-platform Game Dev w/ CocosSharp
Cross-platform Game Dev w/ CocosSharpCross-platform Game Dev w/ CocosSharp
Cross-platform Game Dev w/ CocosSharp
 
Xna and mono game
Xna and mono gameXna and mono game
Xna and mono game
 
Cross platform physics games - NDC 2014
Cross platform physics games - NDC 2014Cross platform physics games - NDC 2014
Cross platform physics games - NDC 2014
 
Madrid .NET Meetup: Microsoft open sources .NET!
Madrid .NET Meetup: Microsoft open sources .NET!Madrid .NET Meetup: Microsoft open sources .NET!
Madrid .NET Meetup: Microsoft open sources .NET!
 
Games with Win 8 Style by Neneng
Games with Win 8 Style by NenengGames with Win 8 Style by Neneng
Games with Win 8 Style by Neneng
 
Flappy - Paris 2015
Flappy -  Paris 2015Flappy -  Paris 2015
Flappy - Paris 2015
 
EastBay.NET - Introduction to MonoTouch
EastBay.NET - Introduction to MonoTouchEastBay.NET - Introduction to MonoTouch
EastBay.NET - Introduction to MonoTouch
 
Multyplatform and mono part 2 - Matteo Nicolotti
Multyplatform and mono part 2 - Matteo Nicolotti Multyplatform and mono part 2 - Matteo Nicolotti
Multyplatform and mono part 2 - Matteo Nicolotti
 
Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...
Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...
Road to Success (July 1st) - Mobile Game Development Alternatives - Andrew Bu...
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid Does
 
Introduction to CocosSharp
Introduction to CocosSharpIntroduction to CocosSharp
Introduction to CocosSharp
 
Gaming in Csharp
Gaming in CsharpGaming in Csharp
Gaming in Csharp
 
Generative Art Hands On with F#
Generative Art Hands On with F#Generative Art Hands On with F#
Generative Art Hands On with F#
 

Similar to Flappy bird game in c#

Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in Unity
Kobkrit Viriyayudhakorn
 
Flappy bird
Flappy birdFlappy bird
Flappy bird
SantiagoYepesSerna
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
manjan6
 
Presentation 8.pptx
Presentation 8.pptxPresentation 8.pptx
Presentation 8.pptx
adityadivinepc
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programing
Krishna Agarwal
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSides Delhi
 
Types of Gaming Program
Types of Gaming ProgramTypes of Gaming Program
Types of Gaming Program
AbdullahWakeel1
 
Game Development Session - 3 | Introduction to Unity
Game Development Session - 3 | Introduction to  UnityGame Development Session - 3 | Introduction to  Unity
Game Development Session - 3 | Introduction to Unity
Koderunners
 
Programming simple games with a raspberry pi and
Programming simple games with a raspberry pi andProgramming simple games with a raspberry pi and
Programming simple games with a raspberry pi and
Kellyn Pot'Vin-Gorman
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
FashionColZone
 
Multiplayer game testing in actions
Multiplayer game testing in actionsMultiplayer game testing in actions
Multiplayer game testing in actions
Yevhen Rudiev
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-Toe
Scott Wlaschin
 
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196
Mahmoud Samir Fayed
 
Hackathon 2013 - The Art Of Cheating In Games
Hackathon 2013 - The Art Of Cheating In GamesHackathon 2013 - The Art Of Cheating In Games
Hackathon 2013 - The Art Of Cheating In Games
Souhail Hammou
 
ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019
ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019
ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019
QADay
 
Gatcha for developers
Gatcha for developersGatcha for developers
Gatcha for developers
Pieter De Schepper
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
Mahmoud Samir Fayed
 

Similar to Flappy bird game in c# (20)

Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in Unity
 
Flappy bird
Flappy birdFlappy bird
Flappy bird
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
Presentation 8.pptx
Presentation 8.pptxPresentation 8.pptx
Presentation 8.pptx
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programing
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
 
Types of Gaming Program
Types of Gaming ProgramTypes of Gaming Program
Types of Gaming Program
 
Game Development Session - 3 | Introduction to Unity
Game Development Session - 3 | Introduction to  UnityGame Development Session - 3 | Introduction to  Unity
Game Development Session - 3 | Introduction to Unity
 
Programming simple games with a raspberry pi and
Programming simple games with a raspberry pi andProgramming simple games with a raspberry pi and
Programming simple games with a raspberry pi and
 
Pong
PongPong
Pong
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
Multiplayer game testing in actions
Multiplayer game testing in actionsMultiplayer game testing in actions
Multiplayer game testing in actions
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-Toe
 
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196
 
Hackathon 2013 - The Art Of Cheating In Games
Hackathon 2013 - The Art Of Cheating In GamesHackathon 2013 - The Art Of Cheating In Games
Hackathon 2013 - The Art Of Cheating In Games
 
ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019
ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019
ЄВГЕН РУДЄВ «Multiplayer game testing in actions» QADay 2019
 
Gatcha for developers
Gatcha for developersGatcha for developers
Gatcha for developers
 
06b extra methods
06b extra methods06b extra methods
06b extra methods
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 

Flappy bird game in c#

  • 1. FLAPPY BIRD GAME By: Hamza Gulistan Reg no: FA14-Bcs-027
  • 2. Introduction • It is a simple game in which one bird is moving between different obstacles. • If the bird touches any obstacle then the game will be end and the total score will show on the screen. • Every time the bird crosses any obstacle the score increases by 1.
  • 3. Creating a Flappy Bird game in Visual Studio Using C# • Create Windows Form Application • 4 Picture boxes, • 1 Timer Object • 4 Labels
  • 4. Naming Name Text Property PictureBox1 flappyBird PictureBox2 pipeTop PictureBox3 pipeBottom PictureBox4 ground label1 label2 label3 label4 scoreText endText1 endText2 gameDesigner timer1 gameTimer
  • 5.
  • 6. Coding the core variables for the game bool jumping = false; Int pipeSpeed = 5; int gravity = 5; Int Inscore = 0;
  • 7. Set the label properties • endText1.Text = "Game Over!"; • endText2.Text = "Your final score is: " + Inscore; • gameDesigner.Text = "Game Designed By your name here"; • endText1.Visible = false; • endText2.Visible = false; • gameDesigner.Visible = false;
  • 8. Functions • We need 3 functions that will be triggered by various events • 1) Timer function • 2) keydown function • 3) key up function • 4) game end function
  • 9. Adding timer properties: name = gameTimer Enabled = True Interval = 15
  • 10. gameTimer_Tick function pipeBottom.Left -= pipeSpeed; pipeTop.Left -= pipeSpeed; flappyBird.Top += gravity; scoreText.Text = " " + Inscore; //for scores This will scroll the pipes to the left and drop the bird using the gravity variable.
  • 11. The bounds property • Ending game • Bounds check for height and width of each of the picture box. Intersects with will check the height and width of another picture against the first one and check to see if they are colliding.
  • 12. Enter the following code in the timer function if (flappyBird.Bounds.IntersectsWith(ground.Bounds)) { endGame(); } elseif (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds)) { endGame(); } elseif (flappyBird.Bounds.IntersectsWith(pipeTop.Bounds)) { endGame(); } gameTimer.Stop();
  • 13. Regenerating pipes Enter the following code in the game timer function if (pipeBottom.Left< -80) { pipeBottom.Left = 1000; Inscore += 1; //score add } elseif (pipeTop.Left< -95) { pipeTop.Left = 1100; Inscore += 1; //score add } The code above checks whether the pipes have left the screen and gone beyond -80px to the left.
  • 14. score on screen scoreText.Text = “ " + Inscore;
  • 15. Code of key down function & keyUp • this will reverse the gravity and make the character jump. if (e.KeyCode == Keys.Space) { jumping = true; gravity = -7; } • Enter the following code in the key up function, this will enable gravity again to the character if (e.KeyCode == Keys.Space) { jumping = false; gravity = 5; }
  • 16. endGame() • create a function to be used when we want to the end the game. private void endGame() { gameTimer.Stop(); endText1.Visible = true; endText2.Visible = true; gameDesigner.Visible = true; }
  • 17. Full Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Flappy_Bird { public partial class Game : Form { bool jumping = false; int pipeSpeed = 5; int gravity = 5; int Inscore = 3; public Game() { InitializeComponent(); endText1.Text = "Game Over!"; endText2.Text = "Your final score is: " + Inscore; gameDesigner.Text = "Game Designed Hamza Gulistan"; endText1.Visible = false; endText2.Visible = false; gameDesigner.Visible = false; } }
  • 18. private void gameTimer_Tick(object sender, EventArgs e) { pipeBottom.Left -= pipeSpeed; pipeTop.Left -= pipeSpeed; flappyBird.Top += gravity; scoreText.Text = " " + Inscore; if (pipeBottom.Left < -50) //ending game { pipeBottom.Left = 800; Inscore = Inscore + 1; } else if (pipeTop.Left < -75) { pipeTop.Left = 910; Inscore += 1; } if (flappyBird.Bounds.IntersectsWith(ground.Bounds)) //regenreting pipes { endGame(); } else if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds)) { endGame(); } else if (flappyBird.Bounds.IntersectsWith(pipeTop.Bounds)) { endGame(); } }
  • 19. private void endGame() { gameTimer.Stop(); endText1.Visible = true; endText2.Visible = true; gameDesigner.Visible = true; } private void endText2_Click(object sender, EventArgs e) { endText2.Text = "Your final score is: " +Inscore; } private void GameKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { jumping = true; gravity = -7; } } private void GameKeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { jumping = false; gravity = 5; } } } }