How to Code Tetris in Java

Coded Tetris for the first time and this is how I did it.
If you want to learn how the game loop works in detail:
• Game Loop and Key Inpu...
The in-game background music is from:
• 【フリーBGM】白い迷宮 - active ...
ポケットサウンド - @pocketse
The sound effects download link:
drive.google.com/drive/folder...
*All sound effects were made using Beepbox
www.beepbox.co
Thanks for watching!
Timestamps
0:00:00 Introduction and Setup
0:01:28 Window and Game Panel
0:04:25 Game Loop
0:08:30 Play Area
0:14:35 Block and Tetromino
0:18:52 Create the First Tetromino
0:25:40 Auto Drop
0:28:32 Movement
0:32:08 Rotation
0:37:05 Create Other 6 Tetrominoes
0:42:45 Pickup a Random Tetromino
0:44:55 Collision
0:54:19 Replace the Current Tetromino with the Next One
0:59:19 Static Blocks Collision
1:01:50 Sliding
1:05:02 Delete line(s)
1:10:15 Add Effect
1:13:00 Game Over
1:15:50 Scores and Level
1:20:40 Music and Sound Effect
1:30:15 FINAL RESULT
#gamedev #javatutorial

Пікірлер: 115

  • @roysterwoo
    @roysterwoo8 ай бұрын

    The goat is back

  • @current_goliath
    @current_goliath8 ай бұрын

    Super excited to see another tutorial! Your explanations are very clear and have helped me a lot. I only have a couple of videos left in the 2D tutorial and I'm looking forward to tackling this one when I'm ready.

  • @JulianAndresRios
    @JulianAndresRios8 ай бұрын

    So great to have new videos from you. Currently following your Java tutorial for creating my 2D game, thank you!

  • @edgaro93
    @edgaro938 ай бұрын

    Love your videos! Thanks so much for uploading a new tutorial.

  • @Phil_is_coding
    @Phil_is_coding7 ай бұрын

    Thank-you so much for the tutorial! It's always so cool to see how people handle these kinds of projects differently and your take was very simple and straight-to-the-point, which I find to be one of the best things about your channel! I can't wait to see what else you have planned in the future and wish the best of luck to you!

  • @SiyumTsega
    @SiyumTsega8 ай бұрын

    Thank you legend, this is just awesome. Your coherent and elegantly paced explanation makes it easy to follow and learn the concepts.

  • @oppaizuki
    @oppaizuki8 ай бұрын

    I have been very excited for this since I saw tweet about the tutorial. It's always exciting to see an upload from you!! I learned so much from your videos 💕

  • @sirdude3859
    @sirdude38598 ай бұрын

    I always look forward to your uploads! They always inspire me to keep coding! Thank you :D

  • @smallC0ckBo1
    @smallC0ckBo17 ай бұрын

    I picked up Java as my first computer language and I can't thank you enough for these tutorials. You are literally the best Java teacher on KZread.

  • @RyiSnow

    @RyiSnow

    7 ай бұрын

    Glad you liked them and good luck with your learning!

  • @user-Red_Haired1984
    @user-Red_Haired19848 ай бұрын

    I've been waiting for your new tutral!! 新しいチュートリアルずっと待ってました!

  • @Sir_Isaac_Newton_

    @Sir_Isaac_Newton_

    4 ай бұрын

    I know some of those, I recognize Shi, Ri, Su'', Tsu, Te, Ma, Ta

  • @fzr666
    @fzr6668 ай бұрын

    love videos like this, would love to see more videos of you making some retro game clones :D

  • @mikemazanetz4183
    @mikemazanetz41832 ай бұрын

    this is really awesome. Just finished following this over 2 days (!) I have found this really good in writing my own projects using your code as a template for how to do things the right way! Many thanks - I look forward to seeing more excellent content.

  • @prophetoverdose
    @prophetoverdose8 ай бұрын

    Gonna give this a go after I make more progress on your Java adventure game. Thanks!

  • @RyiSnow

    @RyiSnow

    8 ай бұрын

    Happy to hear that!

  • @tikabosshs6440
    @tikabosshs64408 ай бұрын

    This looks way more fun than using a Game Engine. And not only that its more fun, but its a great way to learn more cause its so challenging ! Amazing work Ryi .

  • @Bozzyperson
    @Bozzyperson8 ай бұрын

    This is awesome, thanks for the new vid!

  • @Vivetal
    @Vivetal8 ай бұрын

    Thank you so much for this video. You've inspired me to study programming on my own. I don't know if I ever make a career out of it, but I really like it as a hobby :) Keep up the good work, RyiSnow!

  • @Onryo4444
    @Onryo44448 ай бұрын

    I can't thank you enough for these videos, you are an excellent teacher, plus I love your accent!

  • @psharma008
    @psharma0084 ай бұрын

    pls continue making this content... ur way of teaching is awesome.. specially inbetween topic/method explanation. thanks

  • @DydxVT
    @DydxVT6 ай бұрын

    Love your videos ! Keep it up !

  • @laz3664
    @laz36648 ай бұрын

    Thanks for making these!!

  • @user-vx8hj6sw6e
    @user-vx8hj6sw6e5 ай бұрын

    Thank you very much. It's crazy that such legendary games can be so easily replicated in just few hours

  • @josemarioespinoza6652
    @josemarioespinoza66525 ай бұрын

    As always, amazing vid man!

  • @RyiSnow

    @RyiSnow

    5 ай бұрын

    Glad you like it! Gracias for the support🙏

  • @tvrdopakovanye
    @tvrdopakovanye4 ай бұрын

    BRO I JUST LOVE YOU !

  • @vaquitadaplug
    @vaquitadaplug5 ай бұрын

    loved this!

  • @RamdomOfInternet
    @RamdomOfInternet7 ай бұрын

    I thank you for making this code, it is very well explained and complete, greetings from Mexico!!! ❤️🇲🇽

  • @zeroossi5967
    @zeroossi59678 ай бұрын

    I love it thanks !

  • @jeremy88854
    @jeremy888544 ай бұрын

    Just finished following the tutorial series about a few minutes ago. I just want to say thank you RyiSnow for providing these awesome videos and tutorials! You're one of the main reasons why I love the Java programming language 😁 Additional note for those using IntelliJ, you can simply create the "res" Folder as a Directory and then update it into a "Sources Folder" inside the Module Settings or Project Structure menu. And another issue I ran into was with the White-Labyrinth-Active BGM. I don't know why it couldn't be accessed by the AudioInputStream while it was in mp3 format, so I just changed it into wav format and everything worked perfectly.

  • @allanbranson4693

    @allanbranson4693

    4 күн бұрын

    can i please see your code files? on git?

  • @dumdum7099
    @dumdum70998 ай бұрын

    You're so awesome man.

  • @alinadegaltseva5217
    @alinadegaltseva52174 ай бұрын

    I picked up Java as my first computer language and I can't thank you enough for these tutorials. You are literally the best Java teacher on KZread. А еще меня заставили: Ю хев ошибка Ин ер коде

  • @v0idtheory
    @v0idtheory5 ай бұрын

    LOVE your videos! I have a quick question though... what font are you using? lol

  • @uchihaitachi7964
    @uchihaitachi79648 ай бұрын

    so that is a great video thanks a lot.

  • @MattListor
    @MattListor6 ай бұрын

    I love your videos, and have been working on your 2D Game tutorial and want to make a video walking through it. What screen recording software do you use?

  • @jaymakay
    @jaymakay8 ай бұрын

    Awesome video, as always! I am glad you enjoyed coding Tetris. You are incredible, Ryi!

  • @kpm25
    @kpm258 ай бұрын

    Thanks RyiSnow, you are Awesome..:)

  • @darkpaladin.
    @darkpaladin.8 ай бұрын

    Welcome back king❤

  • @matchey1300
    @matchey13005 ай бұрын

    love it

  • @alinadegaltseva5217
    @alinadegaltseva52174 ай бұрын

    PlayManager class 68 line: While the value is 7, Mino Z2 does not fall out, if you change it to 8, then everything works, since now we take into account 0 and count from 0, not from 1

  • @kamisama1712
    @kamisama17128 ай бұрын

    Been looking for a good reason to use Java again

  • @simpgaming2993
    @simpgaming29938 ай бұрын

    ur the best ytber i ever know

  • @AdityaKrPal
    @AdityaKrPalАй бұрын

    Thanks

  • @0xPixeI
    @0xPixeI4 ай бұрын

    Your are the best

  • @Gamer-oh2lr
    @Gamer-oh2lr8 ай бұрын

    Beautiful Video. Keep Coding. Also please complete Rayndia. I wish we could see the final result one day.

  • @RyiSnow

    @RyiSnow

    8 ай бұрын

    I will most certainly complete Rayndia! I've been working on it behind the scenes and hopefully release a demo next year :D

  • @LeoL3o05
    @LeoL3o058 ай бұрын

    the GOAT

  • @moscamorta2716
    @moscamorta27168 ай бұрын

    thanks... Amazing video!

  • @thasave14
    @thasave148 ай бұрын

    Actually, you should put the "repaint" method outside that if. You should update in every possible moment, it's good to limitate the update but the render should be outside.

  • @user-jz9oh2qm9d
    @user-jz9oh2qm9dАй бұрын

    Hello, could you tell me what application are you using to code in java? (I'm new to programing) Also, how much time did it take to you to make it?

  • @julianhemmer1003
    @julianhemmer10038 ай бұрын

    Hi, why are you using eclipse and not intelij ?

  • @current_goliath
    @current_goliath7 ай бұрын

    I finally finished this tutorial, the end result looks really cool! When testing the Sound class at about 1:26:12 I kept getting a null pointer exception for the Clip object, which seemed to indicate the file paths for the wav files weren't being read correctly. After checking the Sound class for typos and not finding any, I eventually figured out that the res folder wasn't included as a resource in the project's build configuration by default. If anyone runs into this situation while using Eclipse, the steps I took to fix it are: 1. Right-click on your project in the Project Explorer and select "Properties" 2. Select "Java Build Path" from the menu on the left 3. Click "Add Folder", check the "res" folder in the window that pops up, hit OK, and then "Apply and Close". This allowed the res folder to be recognized, stopped the null pointer exception and now music & sound effects play perfectly. :) It's kind of weird because I've never had this issue before. I could always just create a folder, add the sound files and it would work without any extra steps just like it did in the tutorial. So maybe it had to do with me recently moving my projects around on my hard drive? I'm not sure. Anyway, thanks for another awesome tutorial, Ryi. I'd love to see more tutorials for classic games like this. I appreciate your hard work.

  • @RyiSnow

    @RyiSnow

    7 ай бұрын

    Or you can directly create a resource folder as I did in the video! 1:21:06

  • @current_goliath

    @current_goliath

    7 ай бұрын

    @RyiSnow OH woops, I thought I followed what you did at that timestamp exactly, but turns out that I selected "Folder" instead of "Source Folder". That explains it. 😄

  • @chil1isauce
    @chil1isauce2 ай бұрын

    This is timeline for my own studying 44:55

  • @markcristal9484
    @markcristal9484Ай бұрын

    hey @ryiSnow. i've been following your code very carefully but at doing the auto drop part when i tried calling the gp.launchgame, i dont see any blocks falling but before i call the gp.launchgame its just floating and not moving just like yours.

  • @edgaro93
    @edgaro938 ай бұрын

    Hey! I've ran into an issue, I tried adding a 1x1 mino, but it didnt work. I tried putting all 4 cubes in 1, but then the line breaker didn't work, then I tried just removing other 3 parts, but then it had some bugs. Could you please help me?

  • @Chuasanity
    @Chuasanity2 күн бұрын

    hey bro nice tutorial! keep it up, and can i ask you a favor? can i get the source code of this project?

  • @iqrasejal9660
    @iqrasejal96609 сағат бұрын

    can you please tell that how did you change the color theme of netbeans. which one is yours?

  • @robtai6225
    @robtai62258 ай бұрын

    can you build snake game next?

  • @samg5183
    @samg51838 ай бұрын

    thank you!! pls how to make 2d platformer ... You are the best person to explain game programming using Java

  • @RyiSnow

    @RyiSnow

    8 ай бұрын

    Check the @KaarinGaming channel! He did a nice 2D platformer tutorial series ;)

  • @samg5183

    @samg5183

    8 ай бұрын

    Thank you.. but your explanations are good and easier for beginners@@RyiSnow

  • @user-Red_Haired1984

    @user-Red_Haired1984

    7 ай бұрын

    @@RyiSnow His tutrials are good, but his pace of explanation, wiriting, scrolling are too fast so its hard to chatch up for beginners.. I hope your version of platformer tutrial too!

  • @smayanpaul8240
    @smayanpaul82403 ай бұрын

    at 13:01 I have written the code as it is but instead of a white border my whole window is turning white...how can I solve this?

  • @UnderArea51
    @UnderArea518 ай бұрын

    How would you go about approaching a cutscene intro animation - before a game starts? Mega-Man

  • @ianlulu
    @ianlulu7 ай бұрын

    how would you implement holding a tetromino function?

  • @eswarD1306
    @eswarD13068 ай бұрын

    hi how to ocreate a menu for this game?cam you put a tutorial for that?

  • @bfg35dk10
    @bfg35dk108 ай бұрын

    can you do a multiplayer game next one 🤔

  • @atramadres3265
    @atramadres326513 күн бұрын

    ia have a question, in this tetris there is just one thread right?

  • @gandalflesuisse2
    @gandalflesuisse27 ай бұрын

    Hey nice video !! I'm using your video for training my java haha. But i'm stock because I use intelij. Is someone here using intelij ? because at 5:29 you telling us to add unimplemented methods but can we do that on intelij ?

  • @RyiSnow

    @RyiSnow

    7 ай бұрын

    If it doesn't show up in your environment, you can manually type the run method. I just used the auto-fill function of Eclipse. I'm pretty sure IntelliJ also has a similar function though.

  • @gandalflesuisse2

    @gandalflesuisse2

    7 ай бұрын

    @@RyiSnow thank you :) but I have an other bug. I check all of my code but I dont found the bug... the left, top and right colision of the static mino's are OK But the left side have no colision. I review the chapiter colision but I didnt found any diffence btwn my code and your code. can you help me pls ?

  • @reimumario4733
    @reimumario473316 күн бұрын

    why does mine say cannot read field "x" because this.b[0] is null am i missing something

  • @think-tankusa1797
    @think-tankusa17975 ай бұрын

    2:12 I am getting NullPointerException for // window.setLocationRelativeTo(null); // please tell how to fix Exception in thread "main" java.lang.NullPointerException: Cannot read field "x" because "p" is null at java.desktop/java.awt.Component.setLocation(Component.java:2191) at java.desktop/java.awt.Window.setLocation(Window.java:956) at main.Main.main(Main.java:17)

  • @zabinarhainticmon4750
    @zabinarhainticmon47502 ай бұрын

    Theres no error when i run it but the collision didnt work for me i checked it many times i cant see why it wont work

  • @iqrasejal9660
    @iqrasejal96604 сағат бұрын

    how come yours mino is moving and rotating fast and mine is so slow?

  • @eswarD1306
    @eswarD13068 ай бұрын

    hi snow i cannot get the sound part in my project

  • @josefortyfive214
    @josefortyfive2148 ай бұрын

    Can you do a 3D game from scratch?

  • @juliennepper6150
    @juliennepper61506 ай бұрын

    Hi Ryi, thank you very much for this video. I am having some trouble though when creating the first mino. When running the project, it returns the error: Exception in thread "main" java.lang.NullPointerException: Cannot assign field "x" because "this.b[0]" is null. Could anyone help me please?

  • @RyiSnow

    @RyiSnow

    6 ай бұрын

    Sounds like the mino or the b[0] block hasn't been instantiated. I'd recommend you check the line of code that was suggested in the error message.

  • @juliennepper6150

    @juliennepper6150

    6 ай бұрын

    Thank you, I found a solution, checking the rest of the video now :-)@@RyiSnow

  • @enriquepasa
    @enriquepasa4 ай бұрын

    The collision part doesn't work. I've rechecked it, nothing seems to be wrong

  • @shadowfury1006
    @shadowfury10066 ай бұрын

    good video please keep going

  • @melouka3
    @melouka34 ай бұрын

    Thank you so much for the video ❤❤ but the static boolean variables upPressed,downPressed... doesn't work in the class Mino(KeyHandler.upPressed...) please inform me to solve this problem

  • @RyiSnow

    @RyiSnow

    4 ай бұрын

    Could you be more specific? Just saying "it doesn't work" doesn't give me any clue to guess your issue/situation. More context would be appreciated!

  • @melouka3

    @melouka3

    4 ай бұрын

    @RyiSnow the code now is correct until the sound but in execution stoped the score and level and next are displaying but the mino doesn't move

  • @virachi275
    @virachi2758 ай бұрын

    Can you make a Pokemon game in Java ?

  • @crestfall5860
    @crestfall58602 ай бұрын

    Help mine still go out the box but my codes are right

  • @cyanuranus6456
    @cyanuranus64568 ай бұрын

    What Text-Editor is This?

  • @user-sh3zt5nl7f

    @user-sh3zt5nl7f

    8 ай бұрын

    Eclipse

  • @dirtyfrk

    @dirtyfrk

    8 ай бұрын

    @@user-sh3zt5nl7f which font he code?

  • @uchihaitachi7964
    @uchihaitachi79648 ай бұрын

    hmmm, do you like Game Engine like unity or Unreal engine?

  • @RyiSnow

    @RyiSnow

    8 ай бұрын

    Yes (well maybe not Unity anymore though...), but I also like coding from scratch.

  • @uchihaitachi7964

    @uchihaitachi7964

    8 ай бұрын

    ​@@RyiSnow That's awesome

  • @allanbranson4693
    @allanbranson46934 күн бұрын

    can you share the code files? i am lost somewhere

  • @yuukis4776
    @yuukis47768 ай бұрын

    Do you have a github that i can follow you?

  • @josebacci
    @josebacci8 ай бұрын

    Hey Ryi! I wanted to know if you could do a candy crush on java, im studying computer science in Argentina and that is my class first proyect for this semester. Im actually really stressed and nervous about it so it would be the best of helps and reliefs if you could do it. Thank you and I love your videos

  • @dorieta_gaming
    @dorieta_gaming8 ай бұрын

    Bro how you not a google employee yet

  • @afrog5622
    @afrog56223 ай бұрын

    can i try to do this whit intellij idea?

  • @RyiSnow

    @RyiSnow

    3 ай бұрын

    You can!

  • @afrog5622

    @afrog5622

    3 ай бұрын

    @@RyiSnow ty, ill try it then

  • @SubatomicAlektron
    @SubatomicAlektron7 ай бұрын

    At 22:02, when I type in Block.SIZE, it shows an error that it cannot find symbol variable for Block. In the mino class I did make it a public array, so not sure why its not finding the symbol. Otherwise, great video so far!

  • @mp3skater940

    @mp3skater940

    7 ай бұрын

    maybe it's not static.. do you have it like: "public static final int SIZE = 30;" this?

  • @user-gj8gz2vu9k
    @user-gj8gz2vu9kАй бұрын

    am tilted, its not working,idk

  • @user-xs4qc3dz3d
    @user-xs4qc3dz3d5 ай бұрын

    17:39

  • @zel9219
    @zel92196 ай бұрын

    日本人ですか?

  • @RyiSnow

    @RyiSnow

    6 ай бұрын

    はい

  • @zel9219

    @zel9219

    6 ай бұрын

    @@RyiSnow 色々教えてくれてありがとうございます!これからもよろしくお願いします!

  • @leddy69-fn8km
    @leddy69-fn8km5 ай бұрын

    ok i did something wrong, mine turned white xD ahahhahahahha

  • @moscamorta2716
    @moscamorta27168 ай бұрын

    thanks... Amazing video!