Code Flappy Bird in Java

Поділитися
Вставка
  • Опубліковано 29 січ 2024
  • How to code flappy bird game in java. In this tutorial, you will learn how to code flappy bird using java awt/swing graphics.
    Throughout the tutorial, you will learn how to create the game loop, create a jframe and jpanel, draw images on the jpanel, add click handlers to make the flappy bird jump, randomly generate pipes and move them across the screen, detect collisions between the flappy bird and each pipe, and add a running score.
    Setup Java with Visual Studio Code:
    • How to set up Java in ...
    Code: github.com/ImKennyYip/flappy-...
    Website: www.kennyyipcoding.com/
    Java Game Programming Projects Playlist:
    • Java Game Programming ...
    JavaScript Game Programming Projects Playlist:
    • JavaScript Game Progra...
    Subscribe for more coding tutorials 😄!

КОМЕНТАРІ • 66

  • @Legendary_MoMo
    @Legendary_MoMo 5 місяців тому +4

    I have to say, your java videos have been very helpful for me, thank you very much mate

  • @YashKumar-dd6kg
    @YashKumar-dd6kg Місяць тому +2

    great tutorial man, your videos are the only ones i can follow without getting a thousand errors. I subbed

  • @user-jp9ec7ez3w
    @user-jp9ec7ez3w 4 місяці тому +2

    Thank you sir. Your Java videos are really Wonderful. They motivate me to learn java more deeply. I am a third year cs engineering student enjoying your videos. Completed the tutorial and it's working. You are a great teacher ❤️❤️😊

  • @alllatesttoday1387
    @alllatesttoday1387 3 місяці тому +20

    Bro I'm going to submit this as my final year java project. Wish me luck🤞🏾💪🏾

    • @tasneemahsan6849
      @tasneemahsan6849 2 місяці тому

      I’m working on this form my Java class’ final project as well

    • @3bood_kr
      @3bood_kr 2 місяці тому

      Final year of what

    • @_Prit_Patel_
      @_Prit_Patel_ Місяць тому

      ​@@3bood_kr His degree, probability BE BTech!!!

    • @hananch786
      @hananch786 Місяць тому

      😂 brother I'm also submitting this project

    • @thecoolnewsguy
      @thecoolnewsguy 14 днів тому +1

      I don't believe in luck

  • @kiro1923
    @kiro1923 2 місяці тому +1

    this past month my college faculty announced a strike, and i stopped studying java for these few weeks. But your videos made me code all week long and practice everyday! Your way to teach is very easy to understand, keep the great work! I think in a few I'll watch your web dev games and practice with them too!

    • @KennyYipCoding
      @KennyYipCoding  2 місяці тому

      ahh sorry to hear that! Fortunately youtube exists :) ! Glad you enjoy the tutorials! Will be uploading more as the year goes on.

  • @damirospanbek4339
    @damirospanbek4339 4 місяці тому +1

    so clean thank you for such a content

  • @yu-tehuang7437
    @yu-tehuang7437 Місяць тому

    THank you for doing this tutorial it's pretty awesome

  • @williamkakooza4603
    @williamkakooza4603 3 місяці тому

    Thank you Professor Ken😊

  • @abeltesfa143
    @abeltesfa143 9 днів тому

    thank you projects really help

  • @eyzake
    @eyzake 2 місяці тому

    so far so good ... i used vim to write the code (was using vim for the first time ... i can say this much i am a fast learner... learnt some java swing , and how projects are made and ofcourse how to run terminal in vim and also i learnt i can compile multiple files using javac app.java flppybird.java anf then bla bla bla) man i still have to complete this video (rn i am where you explained, oh just as a quick recap the screen resolution is this and we got the bg image loaded) ama go grab something to eat i am tired
    edit just realised: it has only been 12 minutes (i wanna cry)

  • @trsk
    @trsk День тому

    thank you sir....

  • @ishakumari457
    @ishakumari457 26 днів тому

    Thank you!!

  • @ChastenRamirez
    @ChastenRamirez 3 дні тому

    damn sir how did you memorize all the codes . you are so pro!

  • @robtai6225
    @robtai6225 Місяць тому

    thank you sooso much!

  • @TheBearCoder
    @TheBearCoder 2 дні тому

    Hey man, i really appreciate your videos, i'm learning alot from them! However i think your collision method assumes that the bird is a rectangle, am i right ? Can you please explain the logic of how you would implement the collision method to make it more precise 🙏

    • @KennyYipCoding
      @KennyYipCoding  2 дні тому +1

      So the concept of collision detection of 2D games is based on the ideal of hit boxes, which is basically a rectangle surrounding the player. It would be too difficult to get the precision down to each individual pixel. The image itself is a rectangle and the empty space is part of the image. What you can do is create another X y width height for a new hit box bird instead of using the actual bird image dimensions. This hit box would essentially be a smaller rectangle.

    • @KennyYipCoding
      @KennyYipCoding  2 дні тому +1

      Another more complex solution is to divide each part of the bird with different rectangles. One for the wing, one for the head, one for the beak. And then you would loop through each hit box and do a collision check. This would be used for if you had let’s say a street fighter game, for each arm and leg, there would be a separate rectangle for collision detection since the characters are much bigger, there would be too much empty spaces in the images to just check one rectangle for the entire image.

    • @TheBearCoder
      @TheBearCoder День тому

      @@KennyYipCoding Thanks for the response ❤ I'm going to surround the bird image (the black corners) with Rectangles and also add Rectangles on the pipes. Then i'm going to check if the bird corners collide with the pipes. But i'm not going to check weather the bird corners collide with the pipes all the time but rather only when the bird is close to the pipes (which is when the collision method that you implemented on this video is true). What do you think about that idea?

  • @obiku1971
    @obiku1971 Місяць тому

    Thanks for this tutorial.
    Following a course on Java on uDemy and watching yours, but also other youtubers tutorials, I was wondering why during the course to instuctor is hammering on encapsulation?
    Because in 4 of these youtube tutorials concerning creating games in Java, most the varialbles are declared package private. Is encapsulatimg variables to private over exaggerated of these instructors?
    Your feedback is much appreciated and helps me to get a better understanding.

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому +1

      Generally it is good habit to make a data member private if it doesn’t need to be accessed outside the class, and const if the value will not change. But this is something you can do when finalizing code changes and cleaning up. For the game tutorials, I generally ignore this because I want to focus on the concepts and thought process of game programming and avoid any syntax nitpick !

    • @obiku1971
      @obiku1971 Місяць тому

      @@KennyYipCoding Great feedback :) It makes completing my assignments a lot easier when I first make the assignment work and then refactor it and encapsulate what's needed.

  • @omsable9540
    @omsable9540 3 місяці тому

    @KennyYipCoding what is the main method in flappy bird class

  • @leonelmessi3010
    @leonelmessi3010 15 днів тому

    pipes ArrayList is added with pipes.add(topPipe); So does it mean the it is added infinitely to the pipes ArrayList? If so, then pipes.size() is infinite?
    Sorry I don't have good knowledge about these memory management since I am new at programming

  • @N_Ananonymous.
    @N_Ananonymous. 19 днів тому

    hi, i would like to ask if is it possible to modify the game that it would show a choices of "restart or quit" at the end of the game and shows the score of the player. Then the game speeds up after a long time. if yes, how can i do it?

  • @taitekrogfus1382
    @taitekrogfus1382 3 місяці тому

    Am i able to still code this on eclipse IDE?

  • @yogesh__janghel
    @yogesh__janghel 4 місяці тому

    helpful

  • @nikhilgaming1567
    @nikhilgaming1567 6 годин тому

    How to add sounds to background

  • @robtai6225
    @robtai6225 11 днів тому

    can you give a tutorial on platformer?

  • @ajayrajpoot6315
    @ajayrajpoot6315 Місяць тому

    the video is only 1 hour long but it took me 3 hours to watch and build this game.

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому

      that is part of learning hahaha. the video is only 1 hour long but it took me much longer to learn how to build a game in java, create a flappy bird game, record the tutorial, and edit it :)

  • @abhisheksah2010
    @abhisheksah2010 Місяць тому

    how can I get a demo of it?

  • @isabellefrancisco7179
    @isabellefrancisco7179 Місяць тому

    Does the code only run in visual studio? It doesn't seem to work in NetBeans

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому

      I’ve never used net beans so not sure what the project setup is like. Try creating a project in net beans and writing the code from there.

  • @ssmaragdine6018
    @ssmaragdine6018 Місяць тому

    May I ask How can I export to IOS app? Thanks

  • @rahulshrestha1568
    @rahulshrestha1568 3 місяці тому

    How do i keep my high score saved and have a start a new game button

    • @KennyYipCoding
      @KennyYipCoding  3 місяці тому

      depends, if you want to keep track of the high score only when you open the program, you can create another variable to keep track of that.
      However if you want to keep track of high score permanently, so that it remembers every time you run a new instance of the program, you'd need to write and read that information, such as with a txt file

  • @user-ug8xk8yn1e
    @user-ug8xk8yn1e Місяць тому

  • @schroedingers838
    @schroedingers838 Місяць тому

    Hello! Today (11 May 2024) the game seems to be very hard and sometimes impossible to win: pipes are placed very near horizontally and sometimes empty space between two pipes does not connect contiguously to the empty space of the horizontally following two pipes. Could it depend on the random components that today make it be so hard? In particular, yesterday all was normal and playable, both in my pc and in your website, and today the same issue there is both in my local run and in the one in your website.

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому

      Do you mean the java version or the js version ?

    • @schroedingers838
      @schroedingers838 Місяць тому

      @@KennyYipCoding The js version, and later a couple of hours that I wrote the message, it happened that the played returned "normal", with the pipes at the right distance... I did not understand if the issue depended from the randomness or from something in my browser.

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому +1

      Hmm interesting, it could be the random function. Math.random() is pseudo random so it uses the system time with a deterministic algorithm

    • @schroedingers838
      @schroedingers838 Місяць тому

      @@KennyYipCoding It was funny because I used your template to do an happy birthday variation of the game in which I replaced the bird with the picture of the cat of a friend of mine and then I added a condition that after a number of pipes equals to her new age the game was win with an Happy Birthday message. And it was such hard that to make it possibile for her to win I had to modify parameters because at the hour I sent it to her, the game was almost impossible to win😬

  • @user-rh4rh8uq5o
    @user-rh4rh8uq5o 4 місяці тому

    how can I make the flappy bird wing move up & down like a bird

    • @KennyYipCoding
      @KennyYipCoding  4 місяці тому

      You would need an animated gif for that

  • @xlr8.tech.customs
    @xlr8.tech.customs 3 місяці тому

    i keep getting the error "Cannot read properties of null (reading 'length')" im only at where you spawn the first window,my code is perfect not one mistake and i dont have any plugins but the ones you told us to get in the java on vsc, what could be causing this? is there something wrong with vsc??

    • @KennyYipCoding
      @KennyYipCoding  3 місяці тому

      Unfortunately your code is not perfect and there is a mistake somewhere! You are trying to call length on a variable that is null. The debug console should tell you which line you’re getting the error on. Also helps to backtrack and see if you missed a step somewhere

    • @xlr8.tech.customs
      @xlr8.tech.customs 3 місяці тому

      @@KennyYipCoding well like i said at that point i was only like 10 lines deep so it wasnt that hard to reread everything, chatgpt, tabnine, and my 2 debuggers all said there was no issues aswel, i ennded up putting it in a different editor app and it worked fine its just specifically vsc

    • @KennyYipCoding
      @KennyYipCoding  3 місяці тому

      Ah interesting, not sure why you’re getting the issue in vscode. If you copy and paste the completed code into your java project, do you still get the same issue?

    • @xlr8.tech.customs
      @xlr8.tech.customs 3 місяці тому

      @@KennyYipCoding on vsc i dont get anything not even an error, on normal vs it works, im not sure whats going on but i just uninstalled it

  • @joysardar6109
    @joysardar6109 21 день тому

    Please 🥺🙏 tell me required extensions ??

  • @CodingMation
    @CodingMation 4 місяці тому +1

    Is this code work for android application made by java . I use gradles.

  • @bubule_
    @bubule_ 4 місяці тому

    12:53 i don't no why the back ground is not there only one white rectabgle, i have made all the step

    • @KennyYipCoding
      @KennyYipCoding  4 місяці тому

      You should backtrack to see which line you made an error on. You probably didn’t add the JPanel to the Jframe in the main file or something. I have the completed code in the GitHub link for you to compare to

    • @bubule_
      @bubule_ 4 місяці тому

      @@KennyYipCoding thanks i gonna see

  • @JotaroKujo-xx5uu
    @JotaroKujo-xx5uu Місяць тому

    what program is this ?

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому

      vs code

    • @JotaroKujo-xx5uu
      @JotaroKujo-xx5uu Місяць тому

      ​@@KennyYipCodingis it free ?

    • @KennyYipCoding
      @KennyYipCoding  Місяць тому

      Yes, as mentioned in the video, if you check the description, there’s a link to the video for how to setup java in vscode

  • @boredbrainedbeing
    @boredbrainedbeing 3 місяці тому

    Idk why, but when i hit a pipe, my game doesn't freeze. it says game over, no new pipes come from the right, but the pipes existing on the screen keep moving to the left, and my score goes up too 🫠🫠 I copied it all, step by step but am not able to find the mistake

    • @zainbhairb
      @zainbhairb 18 днів тому

      Your answer gives chat gpt