The Easiest Flappy Bird Tutorial Ever? - Beginner Javascript Game

  Рет қаралды 134,916

KnifeCircus

KnifeCircus

4 жыл бұрын

Learn how to code Flappy Bird with the basics of web development. (HTML, CSS & Javascript)
LINK TO CODE: github.com/Beat0154/FlappyBird
LINK TO GAME: beat0154.github.io/FlappyBird/
My website: shawnbeaton.knifecircus.com
Follow me below and reach out if you need any help!
Twitter: ShawnJBeaton
Instagram: ShawnJBeaton
In this video I be showed you how to code flappy bird with just html, css and javascript. It’s pretty fun to play, and not too hard to code and you can change some of the values to make your game unique if you want!
To start, make a new folder, name it flappy bird and then open it in with brackets. Brackets is a text editor that makes it very easy to render a preview of what your website will look like.
Create three files: index.html, style.css, script.js. In the index.html file we’ll begin by creating a basic HTML layout, a head and a body and we’ll change the title to Flappy Bird. Next connect the css file and the script file.
Create a game div which contains all the elements of flappy bird. Inside of that, create 3 more divs, the first with id=”block”, the next one with “hole” and the final div with “character”.
Hop over to your CSS file and begin by removing the basic paddings and margins that are automatically added by the browser. Next start giving the game div some styles. A width and a height and a border so that we can see the outline of it. Also add margin: auto; so that it’s always centered.
Next start styling the block div. We’ll add a width and a height and a background-color. Add left: 400px, because thats the width of the game, and that left property won’t work unless the div has position: relative.
Now create a keyframe animation that will start with the block on the right, and finish with it on the left. Add it to the block div with the animation property, and set it to be infinite. You’ll notice the block goes outside the game div, so just add overflow: hidden to the game div to make it look a lot better!
Next start adding properties to the hole div. Give it mostly the same properties as the block div, except the height will only be 150px and the background color will be white. Because the block and hole div are both position relative that means they come ontop of eachother, so add the property top: -500px to the hole to bring it down 500px, which is the height of the block!
Next we’ll change the position of the hole after every animation.
Start by creating some variables for the block and hole so that we can use the right elements. Next create an event listener that runs a function after every hole “animationiteration”. Inside that function we’ll create a variable random. Math.random returns a random decimal between 0 and 1, multiply it by 300 so that it returns a number between 0 and 300. Also add 150 after, so that it returns a number between 150 and 450, and then also set that to be negative so that its between -150 and -450. Set the top position of the hole to that random number. Now every time the animation runs the hole will have a different position.
Now onto the character. Start by adding some css properties; width, height, background-color: red, position: absolute, top: 100px, and border-radius to make it a ball.
Next create a function that will act as gravity. Make an interval function that runs every 10 milliseconds. Create a new variable characterTop and its going to be equal to the current top position of the character div. We can get that by using “window.getComputedStyles()” and then the element we want the styles from, then “getPropertyValue()” and we want the top property. So now our variable characterTop will be equal to the css value of the top property of the character div. Next set a new top position for the character, and it’ll be the same amount as before except we’re going to add 3px to it.
Next create another function named jump which will make the ball go up, basically the opposite of our gravity function. We’ll have to go back to our HTML and add an onclick to run our jump function, and we’ll put it on the html tag so that it works if the user clicks literally anything.
Next go back to your javascript and create a new variable “jumping” and set it to zero.
Inside the jump function set our new variable to 1 and then when our function ends, set it back to 0. That means that if the jumping variable equals 1 then we are currently jumping, if it equals 0 then we’re not jumping.
Now add an if statement so that the gravity function only changes the top if we’re not currently jumping, or else we would be moving the ball up and down at the same time and that just gets messy.
transcript etc...
Now our flappy bird game is fully functioning. But don’t stop there! Keep adjusting the code and properties and make the game more interesting! Maybe super wide blocks? Or slower or faster movements! Anything is possible!

Пікірлер: 246
@pierreder1368
@pierreder1368 3 жыл бұрын
"Every single hole has a different position", lol. He was gonna laugh at that, lol.
@robertefremov9380
@robertefremov9380 Жыл бұрын
Simple and easy, doesn't over-explain, like a tutorial should be! Well done!
@dpdoescode
@dpdoescode 4 жыл бұрын
saw the post yesterday on reddit for this, great video and you explain your thought processes really well! love it, thank you! 🤙
@thisIsPathan
@thisIsPathan 3 жыл бұрын
Man, your videos are really helping me learning some coding during the quarantine. Thank you.
@ImY0urHuckl3berry
@ImY0urHuckl3berry 3 жыл бұрын
Nice man, really digging the clean code and simplicity. Thanks for the knowledge
@beastlydom2861
@beastlydom2861 3 жыл бұрын
I love making games in code especially with your tutorials I’ve been making a website where I keep all my games I’ve coded
@lucahemmi299
@lucahemmi299 11 ай бұрын
this video is hilarious ive watched it about 20 times now in the span of a while and everytime I watch it it gets better
@andrei9115
@andrei9115 2 жыл бұрын
Man, you're a genious. I think you are among a few programmers that actually know how to explain the code in "real human language"...you should have had much more followers for all your work that you do! As a sidenote, I'd like a bit more interaction and interactivity between the js code and the actual rendered html especially when you had to show how modifying the position of the elements is reflected on the page...but anyways, you do alot of work to make everyone understand! I liked so much how you imagined the "gape" with that relative div thing, very logical and straightforward as well!! Also, your english is so easy to understand and I am a romanian :) Well done, bro!!
@TheSaltyCook
@TheSaltyCook 2 жыл бұрын
your videos are super helpful, thank you for making the information so approachable
@simpleprogramming4671
@simpleprogramming4671 3 жыл бұрын
what a beautiful explanation loved it, you made my day !
@sterlingday6362
@sterlingday6362 4 жыл бұрын
Dude your projects are really helping me start making my own games! I love your content! I figured out your last code, can't wait to give this one a go.
@KnifeCircus
@KnifeCircus 4 жыл бұрын
That's so amazing to hear! Thanks so much for the support!
@komalkarwa5624
@komalkarwa5624 3 жыл бұрын
@@KnifeCircus Me too,but i have a question, which coding app or browser do you use?
@18hridyandeshpande94
@18hridyandeshpande94 3 жыл бұрын
@@komalkarwa5624 He uses brackets as his code editor
@amitsoni7685
@amitsoni7685 3 жыл бұрын
@@KnifeCircus Debugging your code by looking you video many times I can't understand when I copy code for github it does not works and . Do you have any suggestions please I want to work on this project because it is cool. You also don't used any input that would be taken from flappy bird that made me think like what you wrote in js.
@nikeedev
@nikeedev 3 жыл бұрын
@@komalkarwa5624 he said in beginning
@user-sk7cc6fk3t
@user-sk7cc6fk3t 3 жыл бұрын
It's a good demo for my first game and help me practice what I learned.
@UnhistoricActs
@UnhistoricActs 4 жыл бұрын
Really cool to see these games take shape - keep them coming Shawn! 💯
@noobde3462
@noobde3462 3 жыл бұрын
yeah
@tanercoder1915
@tanercoder1915 3 жыл бұрын
this will make a nice weekend project!
@splashbeats_
@splashbeats_ 3 жыл бұрын
Thanks for helping me learn JavaScript!
@user-rf8sj1yy4c
@user-rf8sj1yy4c 2 жыл бұрын
really really thanks a lot!!! today is the first day to love javascript!!!!!!!!!! I got motivation to prepare my portfolio for webpublisher.. thank you!
@simoncordova5655
@simoncordova5655 3 жыл бұрын
Hey buddy keep it up - I've been coding for almosot 5 years and I'm a decade older but but enjoying some of your videos - keep it up buds! PS I see that Raptors mat yes sir!
@jaredspencer3304
@jaredspencer3304 4 жыл бұрын
Super cool. Thanks for the tutorial!
@shobhitpreetamsahoo4267
@shobhitpreetamsahoo4267 4 жыл бұрын
Whoa bro!! Thank you for making such videos... It's really helpful for JS beginners.
@boneBasterd
@boneBasterd 4 жыл бұрын
Really awesome idea and also nice dialogue, intresting and thorough, subbed!
@KnifeCircus
@KnifeCircus 4 жыл бұрын
Thanks so much! It really means a lot!
@umarjonbakirov6850
@umarjonbakirov6850 3 жыл бұрын
@@KnifeCircus can you creat pin ball in javascript
@mithunchan02
@mithunchan02 3 жыл бұрын
Nice brother!! You are doing great!!Keep coming with more 😎
@greencodeliz6049
@greencodeliz6049 3 жыл бұрын
Thank you!🥰 your videos are really helpful
@aa-kv2zk
@aa-kv2zk 4 жыл бұрын
loved it man!
@Waveclaw18
@Waveclaw18 3 жыл бұрын
Once again, an epic video by KnifeCircus!
@noobde3462
@noobde3462 3 жыл бұрын
yes
@moiraleon8744
@moiraleon8744 2 жыл бұрын
Amazing Tutorial!!! I love these and thank you so much! Just for anyone coding along if you run into errors with the jump function it might have been the same as mine. At 9:26 line 24 (at this time 23)is if((characterTop>6)&&(counter6)&&(jumpCount
@switchtoanotherone
@switchtoanotherone Жыл бұрын
Thanks a lot!!! I just started to learn JavaScript since today. And I wrote some code as him but it didn’t work. But I could solved it thanks to you!!
@mayankchandratre191
@mayankchandratre191 Жыл бұрын
its a great tutorial thank u for uploading it...I TRIED IT AND IT WORKS SOO FINE!
@samehzaky
@samehzaky 2 жыл бұрын
very simple and effective tutorial, keep up awesome games
@vaibhavpatil1916
@vaibhavpatil1916 Жыл бұрын
Thank you for sharing ur knowledge
@memecroissant5869
@memecroissant5869 2 жыл бұрын
thanks this is gonna be my first game thanks dood
@anythingguns4890
@anythingguns4890 3 жыл бұрын
how can I make it so it jumps or moves when the spacebar is pressed?
@paulhan3314
@paulhan3314 2 жыл бұрын
i love this. thanks for sharing
@hazeedits1106
@hazeedits1106 2 жыл бұрын
After the jump is added for some reason when I click the ball just stops moving.
@djblobby
@djblobby 3 жыл бұрын
awesome dude, keep it up!
@TheCuriousCorner007
@TheCuriousCorner007 2 жыл бұрын
Can we run the jump function by clicking 'space' key??
@aaravtomar786
@aaravtomar786 2 жыл бұрын
who can even dislike this ??
@BitCloud047
@BitCloud047 3 жыл бұрын
this is awesome!! But how do you add a sprite to overlap the dot?
@burakaltintas5918
@burakaltintas5918 2 жыл бұрын
Hi I appreciate what you do I have got a question for you, which I would like to know if we can change the ball and how can we actually change it? Thank you
@jordankolev6107
@jordankolev6107 3 жыл бұрын
great video, man!
@ShyamnaikGuguloth
@ShyamnaikGuguloth 3 жыл бұрын
Awesome videos .... keep going really loving the videos
@KnifeCircus
@KnifeCircus 3 жыл бұрын
Glad you like them!
@michaelp.channel331
@michaelp.channel331 3 жыл бұрын
I love watching your videos! I learned a lot, I'm hoping you will upload another videos sooner!
@neginma6285
@neginma6285 2 жыл бұрын
THANK YOUUUUUUUUUUUUUUUUU. you saved my LIFE 😂😍
@mikexue5104
@mikexue5104 3 жыл бұрын
my 9 years old son likes this very much. thanks.
@tasin487
@tasin487 3 жыл бұрын
Loved It!
@Almaguer.
@Almaguer. 2 жыл бұрын
Really cool video!
@komalkarwa5624
@komalkarwa5624 3 жыл бұрын
Dude your explanation is awesome, thanks. and can you plzz upload a video on " i.o " games ? plzz
@nair38
@nair38 3 жыл бұрын
This was my first working game :D
@JustSinaaax
@JustSinaaax Жыл бұрын
Question, when you put the ! To make the html what do you press so it creates it? Is it enter? Because when I do it, it doesn’t make the html layout
@simulatclown9986
@simulatclown9986 Жыл бұрын
Its bugged
@soap304
@soap304 Жыл бұрын
why does my bird not jump ? i checked all the code twice. when i click it only stops falling for a second. it does not fly up
@sami9752
@sami9752 3 жыл бұрын
Hey, great video. Just a quick question, what would be the issue if you used a relative position in the "character". Why did you choose to go with absolute?
@KnifeCircus
@KnifeCircus 3 жыл бұрын
because if it were position relative, all the elements before it would push it down the page and then setting the top position would have to be negative numbers, so its just easier to keep as absolute.
@imanmohi2943
@imanmohi2943 4 жыл бұрын
Amazing Shawn 👏
@KnifeCircus
@KnifeCircus 4 жыл бұрын
Thank you :)
@asmol7836
@asmol7836 3 жыл бұрын
Thanks homie
@funwithbhumika5582
@funwithbhumika5582 3 жыл бұрын
it is not working. i dont get space in starting of the script.
@mismatchingshoes5249
@mismatchingshoes5249 Жыл бұрын
I get an error in my Java script saying “parsing error: unexpected token ) hole.addEventListener(‘animationiteration’, () => {
@RealLava
@RealLava 3 жыл бұрын
if there is still a error change "if((characterTop>6)&&(counter6)&&(jumpCount
@noobde3462
@noobde3462 3 жыл бұрын
yes my also
@binhdantat5560
@binhdantat5560 3 жыл бұрын
This works for windows as well, you just need visual studio code
@stunsgd2147
@stunsgd2147 3 жыл бұрын
I did it on VIM
@Mete111
@Mete111 2 жыл бұрын
Does someone know how i can change the speed of falling down ??
@IZZYE661
@IZZYE661 3 жыл бұрын
When the ball hits the block it does not end the game. Only hitting the bottom ends it. I have triple checked the code. Any idea how I can fix this?
@hititpluck
@hititpluck 8 ай бұрын
Im getting an error because of the or symbol ( || ) what am i doing wrong?
@TonyGRD
@TonyGRD 2 жыл бұрын
hello I have a problem whit addEventListener.
@noobguy106
@noobguy106 2 жыл бұрын
For some reason, mine's not working. I followed all and triple checked everything and found an error that says "ERROR: Parsing error: Unexpected token) hole.addEventListener('animationliteration', () => " and I dont know what to do. If maybe someone would help me 👉👈
@alecoostra7074
@alecoostra7074 2 жыл бұрын
Can you also use the Math.random to determine how fast the animation goes? Like one time the tubes go by by 1.5 seconds and the other time it takes 3 seconds?
@NewLondonMarshall
@NewLondonMarshall Жыл бұрын
yup! And math.random for the icon for the bird itself, colour of the tubes etc
@craftwithbrain1179
@craftwithbrain1179 4 жыл бұрын
Really cool man
@crod1232
@crod1232 Жыл бұрын
How do you jump? It won't do anything? The ball just falls
@cerealbawxtv
@cerealbawxtv 3 жыл бұрын
For some reason every time I click, my character just stops moving instead of jumping. If anyone can help in anyway please do. Thanks!
@danoverload999yearsago8
@danoverload999yearsago8 2 жыл бұрын
When I write the first script.js (different hole position) it won't change
@thedrumdude1780
@thedrumdude1780 2 жыл бұрын
what do you click to jump
@ajmaltariq8242
@ajmaltariq8242 3 жыл бұрын
Awesome man
@samtianero558
@samtianero558 3 жыл бұрын
what app did you use on creating that game
@Sankalp20023
@Sankalp20023 2 ай бұрын
Some pillars have holes and others don't have holes. could you tell me how to fix it
@soumya00
@soumya00 3 жыл бұрын
Sir, event listner is not working properly.....what should I do?
@snakgamerz8081
@snakgamerz8081 2 жыл бұрын
what should we press to jump
@rubixcal
@rubixcal 3 жыл бұрын
why's the jumping function not working ? guess. something to do with Mac
@destroyr1242
@destroyr1242 2 жыл бұрын
So quick question because I can’t figure out why the hole isn’t working, I’m at 3:45 in the video, and have everything up to this point word for word but can’t see the hole when I have the background-color set to white
@KnifeCircus
@KnifeCircus 2 жыл бұрын
Try going into inspect element and clicking on the hole element in the html and it should highlight it in blue so you can find it, then adjust it from there. Also changing the background colour temporarily will help.
@ilkinhuseynov9011
@ilkinhuseynov9011 3 жыл бұрын
how did you make your game web searching? like in google
@haroldgordon-smith3462
@haroldgordon-smith3462 3 жыл бұрын
When I click the character just stops and does not bounce back up??
@zhangjeremy4969
@zhangjeremy4969 2 жыл бұрын
Hi guys, it is a nice video. But my red ball will keep falling out of the game border and the scroll bar on the window will be smaller and smaller, what am I going to solve this problem?
@AnandKumar-bj3zf
@AnandKumar-bj3zf 3 жыл бұрын
Can you please tell me how to use an image as your game characters
@shaungeel1363
@shaungeel1363 4 ай бұрын
Where do i get java script html and cc+apps
@sahandumidu2735
@sahandumidu2735 3 жыл бұрын
nice work bro
@marcinooooo
@marcinooooo 2 жыл бұрын
Tutorial on How to make a leaderboard? Great vid btw!
@skeleton-bullfrog
@skeleton-bullfrog 2 жыл бұрын
I know I'm late, but whenever I click the ball just stops. any suggestions?
@chogi9860
@chogi9860 3 жыл бұрын
Hey KnifeCircus, just a question, how can you add a background image to the red square?
@KnifeCircus
@KnifeCircus 3 жыл бұрын
hey! in the css instead of background-color: red; put background-image: url(link ur img here);
@chogi9860
@chogi9860 3 жыл бұрын
wait I can't find the css you are talking about my css only has the canvas css not the square
@sankalpkapoor9031
@sankalpkapoor9031 3 жыл бұрын
Which app are you using which application
@Shawnitis
@Shawnitis 2 күн бұрын
Bro it's a miracle cz my name is also Shawn ❤
@user-ze3ui8ur9h
@user-ze3ui8ur9h 2 жыл бұрын
so i was just thinking, how do i add a high score thing?
@your.free.electrons
@your.free.electrons 3 жыл бұрын
This is awesome🧠 🌚!
@joshua_hc_cr
@joshua_hc_cr 2 жыл бұрын
Just to remind you that the var counter is not even initialized at 9:26, so maybe that is why the "Bird" wasn't performing the function jump(). Thank you very much for the tutorial, it was fun to practice with this game.
@f0ri335
@f0ri335 2 жыл бұрын
i could not understand what the problem is, but thanks to you I found the cause
@Nino-ne3kl
@Nino-ne3kl 3 жыл бұрын
Really cool
@sarveshmishra340
@sarveshmishra340 Жыл бұрын
why we use two html two css and two js file
@SameerAbbasMughal
@SameerAbbasMughal Жыл бұрын
One of the excellent video that I found on the internet❤❤
@aaravtomar786
@aaravtomar786 2 жыл бұрын
thanks,,,,,, subscribed,,,,,,,,,,,please make more videos on,,,,,,doodle jump , memory game , bullseye etc
@malitver
@malitver Жыл бұрын
Thx bro
@desolan9968
@desolan9968 3 жыл бұрын
I try this on android but nothing's happened Can u make a tutorial of basic html games compatible for android
@Murari0004
@Murari0004 Жыл бұрын
After the game over part The animation for block and hole keeps running Can you tell us how to hold it for that interval of time where the alert pops
@irfanmahmood566
@irfanmahmood566 Жыл бұрын
Did you find a solution?
@Murari0004
@Murari0004 Жыл бұрын
​@@irfanmahmood566 i tried
@_xoi.d_
@_xoi.d_ 3 жыл бұрын
do you use a mac book or a I Mac
@obafealabi6570
@obafealabi6570 Жыл бұрын
Thanks allot ❣️
@opivaan8061
@opivaan8061 2 жыл бұрын
how to publish it on google play console?
@Zachary-it8cx
@Zachary-it8cx Жыл бұрын
what button to the jump
@jaymeswilliams1904
@jaymeswilliams1904 Жыл бұрын
Anyone have the dimensions needed to make this full screen in the browser?
@pranomkawa7894
@pranomkawa7894 3 жыл бұрын
dude, I coded everything in the script.js script but the hole in the block doesn't appear.
@KnifeCircus
@KnifeCircus 3 жыл бұрын
did u so a margin-top: -20px? making the background color not white would make it easier to see aswell, and then change it back
Javascript Falling Ball Game Tutorial
11:51
KnifeCircus
Рет қаралды 84 М.
Wordle in JavaScript in 20 minutes
18:02
Double D
Рет қаралды 20 М.
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 108 МЛН
Кәріс өшін алды...| Synyptas 3 | 10 серия
24:51
kak budto
Рет қаралды 1,2 МЛН
Indian sharing by Secret Vlog #shorts
00:13
Secret Vlog
Рет қаралды 62 МЛН
狼来了的故事你们听过吗?#天使 #小丑 #超人不会飞
00:42
超人不会飞
Рет қаралды 66 МЛН
Coding Challenge #31: Flappy Bird
21:44
The Coding Train
Рет қаралды 1,1 МЛН
Can AI code Flappy Bird? Watch ChatGPT try
7:26
candlesan
Рет қаралды 9 МЛН
The Easiest Javascript Game Ever
8:34
KnifeCircus
Рет қаралды 949 М.
If You Want To Be An Advanced Game Developer Build This Project
59:54
Web Dev Simplified
Рет қаралды 147 М.
Build A Calculator With JavaScript Tutorial
38:50
Web Dev Simplified
Рет қаралды 1,5 МЛН
Beginner JavaScript Project - Snake Game Tutorial
1:38:19
freeCodeCamp.org
Рет қаралды 86 М.
JavaScript Game Tutorial with HTML Canvas
27:45
Franks laboratory
Рет қаралды 72 М.
Sprinting with More and More Money
0:29
MrBeast
Рет қаралды 156 МЛН
Be kind
1:01
S1_funny
Рет қаралды 8 МЛН
СДЕЛАЛА рандомную ТАТУ
0:17
Виктор Лодин
Рет қаралды 3,4 МЛН