C# Tutorial - Make a flappy bird game in windows form

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Nice tutorial! What I would say is that Windows forms really isn't designed for this sort of active game stuff, and you'd probably be better off using Monogame or something of the sort to achieve the same effect.

Would also probably drastically improve performance.

👍︎︎ 26 👤︎︎ u/thefirstwave_ 📅︎︎ May 05 2020 🗫︎ replies

Nice, thx!

btw, how to improve FPS?

👍︎︎ 6 👤︎︎ u/terka43 📅︎︎ May 05 2020 🗫︎ replies

Damn, this is impressive ! Well done

👍︎︎ 4 👤︎︎ u/somberryy 📅︎︎ May 05 2020 🗫︎ replies

Have you been using mooict tutorials for this kind of thing? They have tons of game tutorials for little winforms games

👍︎︎ 1 👤︎︎ u/Elephantintheroom1 📅︎︎ May 05 2020 🗫︎ replies
Captions
No welcome to another tutorial from my ICT in this tutorial we are going to create a flappy bird game using windows form application and see our programming to start let's start a new project in videos videos new project select windows form under visual C sharp and let's call this one in this form and just make sure you know you saved it so you can find it later on okay there are some image files that you can get from the website I'll show you where to get them from so now if we make it slightly bigger this fight is fine so to start as usual even to go and change the title so let's pop it bird we also went in the back color to one of the blues sort of like the background of their game now we need four different picture boxes yeah one two three then four so one of them is going to be the ground the one will be the white bottom pipe top on their bed so they stop naming this first and then we can move on to importing the images so in this one it's going to be a third and then this is going to be ground so with all for the named we need a label let's change a few tips with labels so we're gonna make it bigger with give you the different font that did not work only luminous doesn't work very well it's fine you go stick to a wheel for now okay we make it yeah just keep it that way let's name this one's full text it's not that way we know what to change when it comes to things Jonah's close all right um it's trying to import the images so and here I have the tutorial open on new ICT website now the images you into download are right here so if you just download them the written tutorial and the source code already on the website so here I have got the pitch is downloaded so we have the bird the grand pipe and then pipe looking down and then pipe that's looking up okay so if I just come in and right-click on one of the images so they choose image and then make sure that you have the project resource file selected if you choose this one you can only import the image once and it won't necessarily copy it directly into the project folder so since we have lots of them we might as well just bring them in so once the slideshow so now you can select them all and you can import them just select the bird the bird picture is transparent so I made sure like you know there's no white edges on there so if he looks like that that's fine but you can also go and change the size mode to a stretch image so that way now you can she'll make a look anyway they won't let me be here for now must be you okay so this one is looking down once again let's go to stretch image stretch it out stretch okay obviously we have to ground choose image so see this one comes only through here but we can also say you know stretch it could be pulling like this so you can do it have it how are you okay so let's keep it gap for now just to experiment first before we jump into I just made the fluffy were slightly smaller okay so now right now this is the outline of the game so you have got your bad both of the pipes on the ground so the bird should be able to interact with these two and them to moving this way and then ground obviously staying exactly what it is we are going to need one more element that's going to be the timer so let's go here and type in game timer so that's the name of it and then we give this one a 20 millisecond interval if you go to events say game time event press Enter this should take into the C sharp script and put the game time event in there we need two more events we need two more events in there we need a key up and a key down so let's go and check it also say game genius down and then so we're gonna do a couple of variables here okay first one is an INT my speed let's see this one is it int gravity that's five for now we can change you later on zero so that's obviously the default at the moment so we can change that later on as well if you want to right so the game timer one is the one that takes all the way so we also the thing we forgot to enable the timer this enabled is set to false or now when lifter time I started he wouldn't do anything because it just doesn't have anything to do at the moment all right so let's start with the key is done first so got this one so we're gonna check if it comes to a space if the spacebar is pressed we want to change gravity equals same minus 5y and when he is released we're gonna change it back to five okay so just to demonstrate what that is going to do for us is we're going to link the flappy bird so fluffy went up top to say plus equals gravity right so that's going to push the bird down inside the timeline when we press the key space key he will push it back up alright so if you start this now no problem see okay so see it's coming down so when I press the hold on the space key and the moves up so I think also the speed is quite low so doing it too it's caused a Louie know so right now that's working so you can also check to see if it's good 2015 maybe then 15 back to 15 it's up to you how you know okay that's not bad it makes you just find it more challenging I guess ok keydown keyup the timer won't working perfectly noise so at the moment now we need to move the pipes so let's go ahead and move the pipes like 0.01 x equals pipe speed and then mr. dot left pop in here okay so these two are what's going to pull the pipe from this end of the screen to this end so if it's going - - is that this is the hard way it's zero so this is just going to take you all the way through now if you run this it should run no problem so as you can see the pipes are moving nicely but what's the pipes have gone they do not come back so we have to find a way to bring the pipe back to the game okay so this is the if statements come very handy so let's say for example if no wipe left is less than say frozen 1-50 right then lefty is going to be equal to how big this foam is 630 okay so that's about 800 hello okay you can also say about the pipe top is less than minus 50 this one we can check you like say 80 and then don't left is equal to let's say I don't know exactly in the same spot all the time so you know they're just slightly different places are spawning each time so because they're doing in different times it should do just well so there you have it so now if you don the game so see they go back and then they come back again so that's the idea at the moment although looks like I want them to go completely off screen before they do the little jittery bit that looks like they just forcefully being taken off screen 150 then hundred eighty let's try that mmm much more organic always so if you wanna see what he's doing in real time this is the way stress when it goes off screen is basically just pawning back here and then giving the illusion of us moving towards the right of the screen this is the bird comes back just pressing and holding the space key at the moment there you Louise okay so we have got the main okay you've got somewhat of the main bits and bobs ready at the moment now in the initial tutorial you have got a few extra labels that you can put on Bob with it they are optional you don't necessarily have to put them on but you know it's good too because that way you can sort of show some important information about you know final school and then the game designer and so on and so forth but for this tutorial we're gonna skip that but the general gist is going to be exactly the same we're gonna go and make a little function here right now on private would end game so this end game here is going to be what happens when you either hit any of the pipes oh if you hit any of the pipes or if you hit the ground and also what we need to do is we can do the scope plus press on this as well so we'll see if that pipe has gone successfully towards the left then that means you have survived it and the last thing to do here is school text okay so base is just just converting the school integer to string okay so if we start it now we should be able to see the school going up one two sinks yep okay so here comes the big if statement let's go find out how this works so we're gonna say if fluckey Red Dog Pound Drop intersects with ya we'd hike bottom dog bounce right okay we can also say here ask it to do the all sign so this is the two pipe signs right we do the all sign there so if it's hitting that one all we get flappy bird dog balanced or speed C pipe top dog pounds right we also go to so we're checking if we are either intersecting in the section so with that the down left right positions are as they were for both of these objects right so if this one matches this one then that means they are overlapping each other so any in any cases if the overlapping we can end the game right so we also have to check the last one we should apply put the balance though okay and this one is ground so bounds are for the borders right so any so of Hondas this one down slightly so it's a lot easier to understand you can also put them into three different if statements if you want to but because using the all key word there are you in the two pipes right um it's a lot easier for us to sort of condense it down and it becomes much more readable in that sense so this is why instead of having all in one long line so you have to you know JC that way to really you can just make it this way so we know so when somebody else is reading the code they can easily understand what kind of thing you're putting in there okay so if any of these conditions are true we want the endgame function to run right and inside the endgame function we're simply going to say game timer stop so it stops again channel completely and then score text plus equals I'll explain what that is in a minute plus equals game over gives you some sort of visual cue on the screen on so the plus it cause what its gonna do is it's not going to override what's already on there it's basically going to UM it's basically just going to add it to the end so it's going to go find the end of that text and it's just going to say game over next to it okay also I think we have made this one I've made a small mistake there so I could easily done this with it so I can say school and then do a plus split I'm doing good to Street okay so just change that to school and then the scores of my weights a lot more views about what's going on there and what's the last thing I'm gonna do I'm gonna bring that to the front so now it kind of goes on top of the label it look nice when it's no name pulls over the bird okay think pipes look good so if I hit this guy now whoopsie game over alright I'm just gonna send it to the back that way no question okay let's try to hit the bomb pipe now also game over sure if we just move it here so empty space the still nothing they're gonna work that's fine let's try it in the ground now okay cool that's actually a better space much worse basically I think okay so that's that they streamed Nicola [Music] including him well this is possibly good for now as that so we have got the bed moving with the pipe moving and repositioning themselves right over here and then we've got the you know collision working with the ground with this pipe and with this point now of course you can set it so in a way where a say for example are through after a while and the pipes can speed up or you can you know even slow it down or else if you want so say for example if you wanted to try it out for now just to give you a hint on how to do this so I'm just gonna have to run a say for example says that school is greater than five about more than five then I can just increase the swipe speed to eight right now so if I just see message to Professor 15 right so so far it's like this to see the pipes have not sped up a little bit okay so we see I've got massive gap in the middle middle of field I can just you know survive as long as I want now there's also another bit that you might find interesting is that right now I can cheat the game so if I just fly you off I can stay there as long as I want and just get any points right so we need to stop that path as well so we want to have somebody play honestly rather than playing it why cheating in the game so here we can run another if same inside there just say for example if a bird the top right is less than let's say about 25 less than minus 25 right then we just gonna run the endgame function here we can add it there as well because it's doing the exact same thing but for now let's just find out so let's say for them for no one could cheat oops I hit too high the game has ended okay so you can also end it like you know instead of having another if statement if I just do another copy and say this copy and paste died in there so that would do exactly the same thing as this okay so we're also looking for activities you know going to the top okay so now if I go over there game is over so thank you so much for watching and the last bit before we go just to show you about that source code what we have done is we have got three variables five speed gravity and school this is the default function so this is a default constructor for the phone one this is just willing to the transform one here we have added a game timer event keydown and keyup event inside the timer event first thing we're doing is moving the bed down using the gravity variable we're moving the pie both pipes towards the left using the pipe speed variable updating the score text label with the school and the school integer these two if statements are checking if the pipe bomb goes beyond minus hundred and fifty pixels from the left then we will be setting it to 800 then we add one to the school this one checking if it goes 180 below the left of the form then we resetting it to 950 on this side this if statement is basically helping us to catch if the bird is colliding with the pipe pipe top or ground if so we end the game or if somebody has flown too far to the roof of the game then we also end this other way we stopped people from cheating in the game this part here is checking to see if your score is greater than five so if you you know skip the pipe five times we increase the sweet 215 okay game key is done game Keys op is checking for the space key so once this basically is pressed we reverse the gravity from 15 to minus 15 and then when the space key is released we put it back to normal 15 so with the bird continues to move down on the screen the endgame function looks for the game timer in stop C and then obviously the last bit is it just adds that little game over the end of the score so this is why we're using the plus equal sign here okay so just to running one final time so this is the game so I can go between the pipes now is it for it to make your game slightly more challenging you can have the PI slightly longer so the person will have to actually do some skin so for now I can hit any of pipe on the ground to end the game so as you can see since score 15 and it finds where the string ends there that's where the plus equals comes in and it just adds the game overall right here okay all right hopefully you have enjoyed this tutorial the written part is on mu ICT so please do check it out and other than that I'll see you in the next one
Info
Channel: Moo ICT
Views: 122,849
Rating: 4.9165277 out of 5
Keywords: flappy bird, game, how to make a game in c# visual studio, tutorial, windows forms, flappy, bird, how to make a game jump bird in c#, windows form, how to make a game in visual studio 2017, how to make snake and ladder game in android studio, flappy bird programming tutorial, windows forms application, game window form, snake and ladder game code in c++ download, flappy bird (video game), c# tutorial
Id: yUCCv-sFUDQ
Channel Id: undefined
Length: 26min 19sec (1579 seconds)
Published: Mon Mar 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.