SlideShare una empresa de Scribd logo
1 de 19
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;
}
}
}
}

Más contenido relacionado

La actualidad más candente

Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d GameIsfand yar Khan
 
SRS REPORT ON A ANDROID GAME
SRS REPORT ON A ANDROID GAMESRS REPORT ON A ANDROID GAME
SRS REPORT ON A ANDROID GAMEmilan tripathi
 
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 Projectfahim shahzad
 
An Introduction To Game development
An Introduction To Game developmentAn Introduction To Game development
An Introduction To Game developmentAhmed
 
Game development
Game developmentGame development
Game developmentRareCoders
 
Snake project report
Snake project reportSnake project report
Snake project reportManju Rajput
 
Car racing game for android
Car racing game for androidCar racing game for android
Car racing game for androidravijot singh
 
Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentationPrionto Abdullah
 
Report on car racing game for android
Report on car racing game for androidReport on car racing game for android
Report on car racing game for androidravijot singh
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report Dileep Maurya
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by StepBayu Sembada
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentSumit Jain
 
Android Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationAndroid Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationSneh Raval
 
Snake game powerpoint presentation by rohit malav
Snake game powerpoint presentation by rohit malavSnake game powerpoint presentation by rohit malav
Snake game powerpoint presentation by rohit malavRohit malav
 
Introduction to game development
Introduction to game developmentIntroduction to game development
Introduction to game developmentGaetano Bonofiglio
 

La actualidad más candente (20)

Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
Zombi - Shoot for Survive
Zombi - Shoot for SurviveZombi - Shoot for Survive
Zombi - Shoot for Survive
 
SRS REPORT ON A ANDROID GAME
SRS REPORT ON A ANDROID GAMESRS REPORT ON A ANDROID GAME
SRS REPORT ON A ANDROID GAME
 
snake game
snake gamesnake game
snake game
 
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
 
An Introduction To Game development
An Introduction To Game developmentAn Introduction To Game development
An Introduction To Game development
 
Game development
Game developmentGame development
Game development
 
Snake project report
Snake project reportSnake project report
Snake project report
 
What is game development
What is game developmentWhat is game development
What is game development
 
Car racing game for android
Car racing game for androidCar racing game for android
Car racing game for android
 
Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentation
 
Street runner final
Street runner finalStreet runner final
Street runner final
 
Report on car racing game for android
Report on car racing game for androidReport on car racing game for android
Report on car racing game for android
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by Step
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Android Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationAndroid Application And Unity3D Game Documentation
Android Application And Unity3D Game Documentation
 
Snake game powerpoint presentation by rohit malav
Snake game powerpoint presentation by rohit malavSnake game powerpoint presentation by rohit malav
Snake game powerpoint presentation by rohit malav
 
Introduction to game development
Introduction to game developmentIntroduction to game development
Introduction to game development
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 

Destacado

UniteKorea2014 - Making flappy bird workshop
UniteKorea2014 - Making flappy bird workshopUniteKorea2014 - Making flappy bird workshop
UniteKorea2014 - Making flappy bird workshopGukHwan 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 StudyBoomerang
 
μέτρα και βρες
μέτρα και βρεςμέτρα και βρες
μέτρα και βρες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/ CocosSharpAlexey Strakh
 
Cross platform physics games - NDC 2014
Cross platform physics games - NDC 2014Cross platform physics games - NDC 2014
Cross platform physics games - NDC 2014Runegri
 
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
 
EastBay.NET - Introduction to MonoTouch
EastBay.NET - Introduction to MonoTouchEastBay.NET - Introduction to MonoTouch
EastBay.NET - Introduction to MonoTouchmobiweave
 
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 DoesKevin McMahon
 
Introduction to CocosSharp
Introduction to CocosSharpIntroduction to CocosSharp
Introduction to CocosSharpJames Montemagno
 

Destacado (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
 
Flappy bird ppt
Flappy bird pptFlappy bird ppt
Flappy bird ppt
 
μέτρα και βρες
μέτρα και βρεςμέτρα και βρες
μέτρα και βρες
 
Δημιουργήστε ένα εκπαιδευτικό παιχνίδι με το 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
 

Similar a 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 UnityKobkrit Viriyayudhakorn
 
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.pdfmanjan6
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programingKrishna 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 macOSBSides Delhi
 
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 UnityKoderunners
 
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 andKellyn 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-ee01083101premrings
 
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.pdfFashionColZone
 
Multiplayer game testing in actions
Multiplayer game testing in actionsMultiplayer game testing in actions
Multiplayer game testing in actionsYevhen Rudiev
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeScott 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 196Mahmoud 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 GamesSouhail 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 2019GoQA
 
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 30Mahmoud Samir Fayed
 

Similar a 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
 

Último

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 

Último (20)

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.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; } } } }