C# Tutorial - Make a flappy bird game in windows form
HTML-код
- Опубликовано: 28 сен 2024
- Images and source code here - www.mooict.com...
Get the New Flappy Bird V2 Game Tutorial on Udemy and Support MOO ICT -
www.udemy.com/...
This is one of the first tutorials I've written for MOOICT, now its on the fully explained tutorials. This video will take you through how to make the flappy bird game in visual studio with Windows form and C# programming. All of the components, images, data types, events and functions are written and explained in the video. Hope you like the video and see you on the next one.
Happy Programming
Moo Out.
Download this project github.com/mooict/C-Flappy-Bird-Game-Windows-Form
Is GUI involved in this code?
Great vid!
Btw, may I ask what switches are you using in your keyboard?
I've got a mix of BOX Navy and BOX Jade in my 'board but yours sound like you're getting more tactile feedback.
I was going to switch mine out for BOX Royals but they're five pin and the GMMK only supports three pin switches.
You can scalpel off the extra two pins but it's not a perfect solution by any means.
After the game is over I want to assign a key so that the game restarts whenever that key is pressed. But I don't know how to do that. Pls help!!
@@aneeshkumar2613 You can put the game function in a "while" statement (basically a loop) and end the game with a blank console.readline(); so that the user has to press enter at the end of every game which would restart the loop.
Look! We have almost the same amount of subscribers!
At the beginning I thought he said " we are going to create a f***ing good game" im like. Da*n like the confidence lol
no swearing bro, but i like the joke its funny lol
:)))))
If you want to develop a Speech Recognition, view these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
hahaha
@@mustafaaljanabi4818 No swearing?
Fuck that shit balls!
Swearing is cunt fucking awesome!!
imagine this guy did it in 20 minutes while my prof trys to explain it in 3 months....
Lol yep. I taught myself starting at 9. Born in 85. I took one semester of college was like nope. Id rather buy the books and read em. Senior lead full stack now. And growing…. 😉
Wow that's amazing any advice I'm in my second year of college software engineering student
Great tutorial. And it leaves plenty to play around with and add to. Like instead of having an end game for flying too high, I just changed it to if the box gets above a height, it just resets to that same height.
Some other things for others to try are to change the pipe positions (a random range for the pipes to be set. Or if you're like me and have the pipes like the original game, set one's height then the other a set distance gap), make the bird rotate while rising or falling, changing the button press to have a gradual change in gravity instead of an instant shift and a constant press no longer works, and setting up a game start screen along with a button on gameover to return to that or play again immediately.
Hi, these are great suggestions for this game. Thank you 😊
Hey, I am an old business app programmer, but have been curious about game programming since I was a kid. Back in the 80's, attempted to create space invaders on a TRS-80 Color Computer. It was such a disaster, I never tried game programming again. You, sir have shown me the way. This is an AWESOME first project. Not sure I'd ever think to bind the timer event to move stuff on the screen. Thanks for posting this.
Thanks Brad you are very kind. I'm glad this tutorial helped 😃
You should use a game engiene it is much easier than just c##
Just A Newbie Person with not know anything about code. Thank You So Much to you Mr. MOO. It is easy to understand the code, logic, KEEP GOING MR. MOO !!!!!!!!!!!
Mr Moo lol 🤣
The name of my game will be "Crappy Bird"
LMFAO
If you want to develop a Speech Recognition, view these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Crappy turd
I was trying to make my own game and i dont know how to do it and now i know it and you help me so much. Thank you
Bro the typing and clicking of your mouse and keyboard is so satisfying to hear for some reason
lol thanks
Thank you very much! This is my first C# project and its working great!
Awesome!
Not very hard to code and easy to understand :)
I did it from scratch and add features for my project.
Great tutorial. Thanks for giving me a base. I am going to make a advanced game from this, with proper start and end game screen, etc.
Hey do you think I could see your code if you ever got it done?
If you want to develop a Speech Recognition, view these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
You are the real programmer, I appreciate your hardworking and as well as your logic this game is impossible without this, keep going sir.
Thank you Arham, that's very kind.
Wow I learned so much. Thank you for explanation
Hello, it was great.❤😍
It is better to add a reset button so that there is no need to close and open the program again👍👌
this help me a lot from online class. thank you so much. i learn a lot from this video!
Excellent tutorial!!
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Windows Forms App was really hard to work with for me. I used the .NET Core version and it kept freezing and I couldn't import the images the same way.
It worked without problems in .NET Framework. Thank you for the tutorial.
This project uses .net framework not the .net core.
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Thanks for this valuable tutorial .
Please make a video for deployment this kind of games on browser or play store .
You can also reply the steps in the comments
To make this kind of games for web or phones use Unity. It has built in support for webgl- play it on the browser or app can be built to submit to android or iOS.
Hope this helps
Hey Moo ICT i have already made a different comment of how good this tutorial is, but i did run in to a problem and this is not ur fault.
I got the error: MSB4018, The "ResolvePackageAssets" task failed unexpectedly.
If you can help me im the happiest person on earth :D
Hi, I haven't encountered this particular error before. I looked through Google it seems it was a bug in visual studio however you can try the following try deleting all of the files from debug folder and rebuild the solution again and update visual studio.
I will give it a try thank you and keep up the good work!
It seems that i at the beginning clicked on windows form app (.net) instead of windows form app (.net framework)
still thank you tho :D
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Thank you sir for teaching basic of making game in windows form
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
hello, please make a tutorial on the "play again" button
love you man, God bless you
this is amazing. great work. I'm starting now and i have a question... How do you get the images or how do you make the images that you use in your games?
You can download the images for this project from the link in the description.
sir i have an important question how you insert key up key down function i really can't understand
Thx for this awesome video mate, really easy to follow and everything worked great for me! Wondering if you could help out with adding a "restart button"
Hi you can make a restart button and make sure its disabled and hidden when the game starts, when the game is over you can run the click event from that button to reset the bird, pipes, score and time back to the their default positions and disable/make the button invisible from inside the event too. You can make the button visible again when the game over function runs. Have a go
a shortcut if the restart button/method is too hard is to change to a second form and then comeback. Maybe you can use the second one like a menu
@@mooict When i press the restart button and then when i start playing and press Space it keeps restarting the game like i am pressing restart button over and over again but i dont .Any help?
@@tr0x219 when you press the restart button disable the button by buttonName.Enabled = false; this way the forms focus won't be on the button when the game restarts. Then when the game ends enable the button again so it can be clicked on.
@@mooict It worked man, thank you!
In the code part of the game it says that the private void endgame has 0 references how do I fix this
Excellent video, but can you zoom the TEXT, it is difficult to read
How to make a restart button when you lost?
Thank you very much, i was trying to make flappy bird for my final school project and ran into some problems, but thanks to your guide i managed to finish it
Thanks a lot again :D
hey, can you share the code with me I'm having some problems with the code?
pipeBottom.Left -= pipeSpeed;
for this, it says "the name pipeBottom does not exist in the current context."
and "the name pipeSpeed does not exist in the current context."
@@mariamtariq1601 I think that because object that you use as bottom pipe not named "pipeBottom", check how it is named and use it in code:
For example: NameOfPipeObject.left -= speed;
I hope it will help you
Those image stretches hurt my soul
What is your visual studio version?
thank for tutorial, you are awesome, keep pushing bro!!!!
Thanks, will do!
Why do you not mention calling of timer1.Start() in your implementation (either in Form1_Load or the Constructor) ?
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Thank You Very Much Sir, buh How to resize the elements of the form with the form itself? like If you wanna play it in Fullscreen mode, You can maximize it.
when i start the project it starts the endgame function instantly and i don't know why
how do i get the properties tab pls help i am new
Right click on the form and select properties it's usually on the bottom right hand corner of the screen
Did, though how would I restart the game once is game over?
i just made this code today and my flappy wont move up and down. what should i do?
Check inside the timer if you have the line flappy bird.top += gravity; this line will animate the bird picture box
Great tutorial! Thanks!!
Keysisup and keyisdown can't use , how to fix it , can you help me
Hey man how do i fix the images having the square border when obove the other images? Thanks.
Unfortunately windows form picture. Boxes do not support transparency but you can try the WPF C# version of it where the images don't have that problem. Here is the tutorial ruclips.net/video/rdxylTJJv5c/видео.html
Thanks!
The "KeyDown and KeyUp" property is missing.
I'm using Visual Studio Express 2015. Can You help me, please!
Thank you so much sir
Great tutorial. Good job!
Bro I have an Error What is the error plzzz help
Error CS0103 The name 'scoreText' does not exist in the current context
Change labels NAME in the properties window to scoreText. This error means it cannot find the score text named label in the code.
Hola! How would I make a restart button?
why is it so laggy when I place an image in a form background instead of solid color
If you use a background image on the form then you will need to enable the double buffer option from the properties for the form. That will improve the frame rate for it.
*variabul* lol...BTW Thanks for the tutorial
hello sir i am a 16 year old who loves coding and a who has just started to learn coding i needed an inspiration to start and i got it after watching this tutorial . I have a request for you can you please code a multiplayer fps shooting game so that i can get an idea on how to create multiplayer games and improvise it
Hey Varun. That's great you are starting up in programming. Making a multiplayer FPS game will be a big project. I have made some local multiplayer style games on unity before but not the massive multiplayer ones. I'm glad you are finding my simple tutorials useful. I'll try to make more in depth ones in the future.
Great tutorial! Thank you
Your welcome glad you liked it
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Thank You! Keep it up
Keyboard name please. Love the sound
It's my laptop key sound.
U R GOD, U SAVED ME
QUESTION
Are the variables Gravity, Pipspeed and score automatically recognised by the game or wouldnt you have to specify what the variables relate to within the game?
How would the game recognize them?
If you look more carefully, he's using them like here:
PipeBottom.Left -= PipeSpeed
Which means that every tick the position is adjusted by the value of PipeSpeed.
@@TheShadowArtCom ....oh yeah
So I kinda understand why you can do Control.Left and Control.Top but not Control.Right and Control.Bottom cuz the latter 2 are read only and it has to do with how windows scale and all. But is there a way to work around this if I wanted to say make this game play from right to left instead?
If you want the pipes to move right rather then left you can use += sign in the time when linking to the pipe speed. TopPipe.Left += pipeSpeed; will move the top pipe picture box towards the right of the screen. Then just move the bird picture box to the right it won't need any code since it only moves up and down. Only thing you will need to change is flip the bird picture so it's facing left instead of right.
Im getting like 6 errors like what am i doing wrong???? Someone help me please. This is the code that im doing but still wont work at all for me:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Flappy_Bird_Windows_Form
{
public partial class Form1 : Form
{
// coded for MOO ICT Flappy Bird Tutorial
// Variables start here
int pipeSpeed = 8; // default pipe speed defined with an integer
int gravity = 15; // default gravity speed defined with an integer
int score = 0; // default score integer set to 0
// variable ends
public Form1()
{
InitializeComponent();
}
private void gamekeyisdown(object sender, KeyEventArgs e)
{
// this is the game key is down event thats linked to the main form
if (e.KeyCode == Keys.Space)
{
// if the space key is pressed then the gravity will be set to -15
gravity = -15;
}
}
private void gamekeyisup(object sender, KeyEventArgs e)
{
// this is the game key is up event thats linked to the main form
if (e.KeyCode == Keys.Space)
{
// if the space key is released then gravity is set back to 15
gravity = 15;
}
}
private void endGame()
{
// this is the game end function, this function will when the bird touches the ground or the pipes
gameTimer.Stop(); // stop the main timer
scoreText.Text += " Game over!!!"; // show the game over text on the score text, += is used to add the new string of text next to the score instead of overriding it
}
private void gameTimerEvent(object sender, EventArgs e)
{
flappyBird.Top += gravity; // link the flappy bird picture box to the gravity, += means it will add the speed of gravity to the picture boxes top location so it will move down
pipeBottom.Left -= pipeSpeed; // link the bottom pipes left position to the pipe speed integer, it will reduce the pipe speed value from the left position of the pipe picture box so it will move left with each tick
pipeTop.Left -= pipeSpeed; // the same is happening with the top pipe, reduce the value of pipe speed integer from the left position of the pipe using the -= sign
scoreText.Text = "Score: " + score; // show the current score on the score text label
// below we are checking if any of the pipes have left the screen
if(pipeBottom.Left < -150)
{
// if the bottom pipes location is -150 then we will reset it back to 800 and add 1 to the score
pipeBottom.Left = 800;
score++;
}
if(pipeTop.Left < -180)
{
// if the top pipe location is -180 then we will reset the pipe back to the 950 and add 1 to the score
pipeTop.Left = 950;
score++;
}
// the if statement below is checking if the pipe hit the ground, pipes or if the player has left the screen from the top
// the two pipe symbols stand for OR inside of an if statement so we can have multiple conditions inside of this if statement because its all going to do the same thing
if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds) ||
flappyBird.Bounds.IntersectsWith(pipeTop.Bounds) ||
flappyBird.Bounds.IntersectsWith(ground.Bounds) || flappyBird.Top < -25
)
{
// if any of the conditions are met from above then we will run the end game function
endGame();
}
// if score is greater then 5 then we will increase the pipe speed to 15
if(score > 5)
{
pipeSpeed = 15;
}
}
}
}
Someone please help me to get this code working. Its coming up with like 6 errors, SIX!.
hi my teacher please can you tell me how to make restart function ? for a button to restart the game it wont work for me i triey app.restart and linked it to a button but it didnt work how to do restart the game with out reload it agian ???
Hi Yazan I'm currently making an add-on video to this tutorial on how to add the restart function. It will be up in the new couple of days.
@@mooict greaat thank you
I can't find key up and key down anywhere =(
Thanks!
Welcome!
Excellent tutorial! Thank you! 💜
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
does this count as making it from scratch
Technically yes
I did the similar thing but when the game ends there appears a play and exit button. When I click on the play button the pipes move but bird doesnt fly when i click the space bar. What should be done?
Exit button closes the application successfully
And another thing I that can you demonstrate how to install the exe file on other system or pc?
You may have to disable and hide the button when it's clicked. In Windows form if there is a button on screen automatically the focus is set on the button. See if that works
i couldnt find key up and key down in events, im using ms visual 2019, pls anyone help.
Thank you very much! also is there any shortcut to restart the game instead of closing the form and running it again?
Try this in GameEnd()
Form1 NewForm = new Form1(); NewForm.Show(); this.Dispose(false);
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
it works but there's one problem. The space Doesn't do anything
what should i do?
Check in the events window if the key down and up are linked to the form.
Please make game of Ludo & Snake Ladder in Visual Studio, would be thankful
That's a great idea
At 17:03 I want to add intersectsWith with the top of the window but I found nothing in the documentation, could you help please
If you want to check if the bird has reached top of the screen then you need to check it with the if(flappyBird.Top < 0) statement. There isn't a intersects with the windows function.
@@mooict Thanks
using this and never lagging
Thank you bro
You're welcome.
bro why when i start my game is over?
thank u great tutorial but i think u missed to add rest game button But Great job thanks
I tried to add in an extra pair of pipes but I suddenly lost control of the bird.
How to run the game? When i press space bar the bird goes up. But when the game is started it automatically touches the pipe and the game is over.
Which keys are used to move the bird up and down?
Just the space bar, when the keys is pressed bird should go up and when released it should go down
@@mooict thanku... Btw it worked... when I set the gravity to 6
Can you pls do a Lucky 7 game like in a casino game?
In the new version of VS is no keyup and no keydown I don't know what to do
Which version of VS is it?
Sry
I found it
(I'm stupid)
Amazing video, thanks
You're welcome, glad you liked it
Great 👏
it only says new file 4 me not new project
Check if you're using the right visual studio. I've used visual studio 2017 for this tutorial. You can download and install the 2019 community edition from the website.
Which keys used to play
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
Thanks.
Your welcome 🙏
@@mooict thanns
This is just amazing man. It works now! It’s bc I did it wrong😂
Ah its the best feeling when it start to work. Keep at it, happy programming 😎
Moo ICT thanks g😃 keep making tutorials and if you want ideas for what to make dm me on intsagram smoked_999
Moo ICT I have something extra you can add. Restart button as R
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
good thanks
Hey bro it works but I have one problem. The space Doesnt do anything :(
Check the key down event, if that's linked properly in the form.
Moo ICT if it’s not do I link it
Yes you need to select the event from the drop down on the key down event that would link it the event and trigger it when the key is pressed down. Do the same for the key is up event.
how can i add restart option to restart the game
Take a look at the PAC man game tutorial. I've added a restart function to that which can be used in this game too.
@@mooict ok
Can I get the code?
Code is in the description link
Thank You!
Good job
Awesome...
I am stuck on "choose image..." it does nothing...
Try restarting visual studio, sometimes that helps
@@mooict thanks. Although it seems I didn't install one needed part still, now works.
ez to follow
thx
You eat a 1 step.... I'm confused 🤐 how to score increase 🙄
Hi bro if this is not working now can you plz help me thankyou.
(flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds) ||
flappyBird.Bounds.IntersectsWith(pipeTop.Bounds) ||
flappyBird.Bounds.IntersectsWith(ground.Bounds) || flappyBird.Top < -25
)
how to do this THING l l
Can someone translate the code in cpp?
Does anybody have the Download link :D
When i press space nothing happens, the bird just goes down.
Check if you have linked the key down event to the form you can do this by clicking on the little lightning bolt icon on the properties window and navigating down to the key down event
@@mooict Yes I did
@@robertmanolache5728 check the code inside the event there is a if statement that controls when player presses the space key, it should reverse the gravity of the bird to pull up
@@mooict yes i have it , if (e.KeyCode ==Keys.Space){gravity = -5 } and another if for up with gravity = 5
Can you check if you click on the form and check the events window for key down and key up? Only thing I can think of may be linking the events to the form correctly so they trigger when the keys are pressed and released
more videos please
View these tutorials: ruclips.net/video/Zk_pAoc4kNI/видео.html
just use GMS2 for games like this , faster , easier, and end result looks so much better
good tutorial but JESUS CHRIST THAT CRUSTY MIC
300