SlideShare une entreprise Scribd logo
1  sur  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;
}
}
}
}

Contenu connexe

Tendances

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
 
Final project report Snake Game in Python
Final project report Snake Game in PythonFinal project report Snake Game in Python
Final project report Snake Game in PythonMuhammad Aziz
 
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
 
The Principles of Game Design
The Principles of Game DesignThe Principles of Game Design
The Principles of Game DesignInstantTechInfo
 
Game project Final presentation
Game project Final presentationGame project Final presentation
Game project Final presentationgemmalunney
 
Ludo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationLudo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationZakaria Hossain
 
06. Game Architecture
06. Game Architecture06. Game Architecture
06. Game ArchitectureAmin Babadi
 
Final Year Game Project Report - Riko: The Aventurer
 Final Year Game Project Report - Riko: The Aventurer  Final Year Game Project Report - Riko: The Aventurer
Final Year Game Project Report - Riko: The Aventurer Nusrat Jahan Shanta
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI ProgrammingRTS Tech
 
Game design document template for serious games
Game design document template for serious gamesGame design document template for serious games
Game design document template for serious gamesAntoine Taly
 
Project presentation FPS
Project presentation FPSProject presentation FPS
Project presentation FPSShubham Rajput
 
Final year project presentation
Final year project presentationFinal year project presentation
Final year project presentationSulemanAliMalik
 

Tendances (20)

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
 
Final project report Snake Game in Python
Final project report Snake Game in PythonFinal project report Snake Game in Python
Final project report Snake Game in Python
 
CG mini project
CG mini projectCG mini project
CG mini project
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
User Interface
User InterfaceUser Interface
User Interface
 
The Principles of Game Design
The Principles of Game DesignThe Principles of Game Design
The Principles of Game Design
 
Game project Final presentation
Game project Final presentationGame project Final presentation
Game project Final presentation
 
First-person Shooters
First-person ShootersFirst-person Shooters
First-person Shooters
 
Ludo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationLudo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentation
 
06. Game Architecture
06. Game Architecture06. Game Architecture
06. Game Architecture
 
Final Year Game Project Report - Riko: The Aventurer
 Final Year Game Project Report - Riko: The Aventurer  Final Year Game Project Report - Riko: The Aventurer
Final Year Game Project Report - Riko: The Aventurer
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
 
Tic toc game presentation
Tic toc game presentationTic toc game presentation
Tic toc game presentation
 
Tic Tac Toe ppt
Tic Tac Toe pptTic Tac Toe ppt
Tic Tac Toe ppt
 
Game design document template for serious games
Game design document template for serious gamesGame design document template for serious games
Game design document template for serious games
 
Project presentation FPS
Project presentation FPSProject presentation FPS
Project presentation FPS
 
Game Worlds
Game WorldsGame Worlds
Game Worlds
 
Final year project presentation
Final year project presentationFinal year project presentation
Final year project presentation
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395VishruthKhare
 
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
 

Similaire à 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
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395
 
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
 

Dernier

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Dernier (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

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