Let's code Tetris Game in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ค. 2022
  • Pygame Tutorial for Beginners on how to create a Tetris game in Python.
    More Python Projects: • Python Projects
    TetrisCode:
    github.com/StanislavPetrovV/P...
    #coderspace #python #pygame #tetris #pythonpygame
    #programming #coding #programmer #developer #technology #code

ความคิดเห็น • 69

  • @rodakdev
    @rodakdev 2 ปีที่แล้ว +32

    You can also use a simpler way to rotating 90 degrees (x, y) = (y, -x) or (-y, x) depending on the direction

    • @universenerdd
      @universenerdd 2 ปีที่แล้ว +4

      Yeah. I learned that in middle school

  • @footballCartoon91
    @footballCartoon91 ปีที่แล้ว +9

    i dont know what math do you learn but this is so good.. i tried to code tetris with as minimal code as i can but still cannot make a complete game until i found your channel ..this is good and thank you

    • @CoderSpaceChannel
      @CoderSpaceChannel  ปีที่แล้ว +3

      thanks, this is my old project, I keep thinking about rewriting Tetris in a different way, but I'm always busy with other projects

  • @CodingWithAlbert-O
    @CodingWithAlbert-O ปีที่แล้ว +1

    I LLLOOOVVVEEE this tutorial! Great work! It's AWESOME!!!

    • @CodingWithAlbert-O
      @CodingWithAlbert-O ปีที่แล้ว

      It told me everything I needed to know about tetris

  • @htfkid2000
    @htfkid2000 2 ปีที่แล้ว +6

    Your videos are very good, I've watched quite a few from your channel and I feel better about programming stuff, thank you!

  • @playerut19
    @playerut19 ปีที่แล้ว +9

    I always thought that when the line is removed,it's because of the objects removed,not by pushing the line down.But great tutorial!

  • @7177YT
    @7177YT ปีที่แล้ว +3

    Superb!
    I like the pace as well as the content, for once a video I won't get bored watching at 1.0x speed. (:

  • @sergeys7603
    @sergeys7603 2 หลายเดือนก่อน

    Very Helpful Tutorial. Thank You.

  • @baonguyengia6174
    @baonguyengia6174 2 ปีที่แล้ว +2

    Your videos are very good !!! 😀😀

  • @sfk4158
    @sfk4158 ปีที่แล้ว

    Thank u for ur code !

  • @noahashley5634
    @noahashley5634 ปีที่แล้ว

    After making the grid, would anyone know why I can only see the grid when moving my cursor? It causes a flickering effect by dragging my mouse around the games display.

  • @b213videoz
    @b213videoz ปีที่แล้ว +11

    When I was 13 I coded my own version of Tetris in Turbo Basic, it had game Saving/Loading, the "bypasser" character hitting whom would cause Game Over - and yet it was the worst version ever 🤪 (sooo buggy)

    • @Abdul-it1gt
      @Abdul-it1gt 4 หลายเดือนก่อน

      cool man

  • @lorenzkroetzsch
    @lorenzkroetzsch 2 ปีที่แล้ว

    Nice Video

  • @anghoang8583
    @anghoang8583 ปีที่แล้ว

    Nice!

  • @wirbadiims6889
    @wirbadiims6889 2 ปีที่แล้ว

    Nice try for me to trying learn this video 😅

  • @FukatVines
    @FukatVines ปีที่แล้ว

    Shortcut for standard template ??

  • @_____JUNPark_____
    @_____JUNPark_____ 11 หลายเดือนก่อน

    what video editor did you use for 0:47?

  • @-SHEESH-YIKES-
    @-SHEESH-YIKES- 3 หลายเดือนก่อน

    How do we make the substitute box that is in classic Tetris to sub out the next piece please make a quick video in this to improve playability please and thx this video is Awesome i smashed a like early

  • @syedarsal9742
    @syedarsal9742 ปีที่แล้ว

    Are we doing the Best first Search Algorithm in it??

  • @nlegacysolo
    @nlegacysolo ปีที่แล้ว +1

    Great video. I was almost done and everything was working fine, then came.... Lambda and killed it for me. Im using Pycharm like you but it will not let me use the Lambda for making colors for the shapes 😕

  • @Apep88
    @Apep88 ปีที่แล้ว

    HELP ! cant fix it AttributeError: module 'pygame' has no attribute 'load'

  • @nlegacysolo
    @nlegacysolo ปีที่แล้ว

    I just downloaded and tried the code that's in the description and I can't get that one to work either. It must be an update to lambda that is causing the error. Real bummer cause I literally spent hours to build this. But I cant get the colors to change. It works just like the game should but the code for randomized colors doesn't work anymore so I have a working Tetris game with all white tiles. Hmmm... I think I just might have thought of a work around.

    • @insightful_code
      @insightful_code ปีที่แล้ว

      I tried downloaded the code and does`t works in VS Code and in Pycharm too. To much errors and error "no module named - pygame". I did install modul pygame, but still not works and still error = "no module named - pygame"..

  • @footballCartoon91
    @footballCartoon91 ปีที่แล้ว

    i hope you dont mind if i posted a comment here..
    when you write...
    figures=[[pg.Rect(x+W//2,y+1,1,1)for x,y in fig_pos] for fig_pos in figures_pos]
    i feel really confusing with the x,y
    but now i understand that it is the reference to the element inside the outside reference of elements..
    so in this case x,y refers to each tuple elements in the list of tuples
    but then you write the grid like this:
    grid=[pg.Rect(x*TILE,y*TILE,TILE,TILE)for x in range(W) for y in range(H)]
    so this time the reference x and y refers to W and H respectively i.e for x the value will be :
    0,1,2,3,4,5...until 10
    for y:
    0,1,2,3,...until 15
    i notice that this time we dont need the inner bracket to indicate that this is only a list..
    whereby before, when we have nested square bracket means we have something like list of "something"
    where "something" may be a list, or tuple or dictionary i guess or any other data structure?
    haha

  • @aperson6237
    @aperson6237 2 ปีที่แล้ว

    At 5:30, there is the statement field[line][i] = field[row][i].
    When I try to run this, I get an index error saying that the list index is out of range. Can someone help me with this?

    • @CoderSpaceChannel
      @CoderSpaceChannel  2 ปีที่แล้ว

      There is a link to the source code in the description.

    • @THUONGPHAN-kq7cf
      @THUONGPHAN-kq7cf ปีที่แล้ว

      I think you are confusing field[line][i] = field[row][i] and field[line][i] = figure[row][i]

  • @user-mw7st3gj1d
    @user-mw7st3gj1d 6 หลายเดือนก่อน

    my game over state insit working it keep reconising the figure at the start and keeps restating creating new windows over and over again

  • @g3triplegaming35
    @g3triplegaming35 6 หลายเดือนก่อน +1

    Great video! But at 2: 58 when I run my code it drops very fast. Can you please help me? Thank you a lot

  • @DjoleBuduciIlustrator
    @DjoleBuduciIlustrator 2 ปีที่แล้ว

    That 'Lambda : ' one still getting me a syntax error, could you please tell me how to fix it?

    • @CoderSpaceChannel
      @CoderSpaceChannel  2 ปีที่แล้ว

      There is a link to the source code in the video description.

  • @lpslpslpslpslpslps
    @lpslpslpslpslpslps ปีที่แล้ว +1

    You are missing a figure, the T-tetromino: [( -1, 0 ), ( -2, 1 ), ( -1, 1 ), ( 0, 1 ) ]

  • @user-jw4bc3hz1u
    @user-jw4bc3hz1u ปีที่แล้ว

    Hi Can you help me. I don't understand scores. scores is a dictionary with keys = 0,2,3,4. Or you write scores[lines] where lines can be greater than 4 Regards

    • @CoderSpaceChannel
      @CoderSpaceChannel  ปีที่แล้ว

      the value of the lines cannot be more than four, since the maximum height of the figure is 4 blocks

    • @user-jw4bc3hz1u
      @user-jw4bc3hz1u ปีที่แล้ว

      @@CoderSpaceChannel Thank you I haven't see the initializations of lines= 0

    • @Abdul-it1gt
      @Abdul-it1gt 4 หลายเดือนก่อน

      can you make a tutorail were you make a platformer i tried makeing one but sadly it failed so pls i need help@@CoderSpaceChannel

  • @AhmedMohamed-wc6uw
    @AhmedMohamed-wc6uw 11 หลายเดือนก่อน

    Can any one tell me how to install the folder like he did in 6:00

  • @GabrielRodriguez-um8fi
    @GabrielRodriguez-um8fi ปีที่แล้ว

    What editor did you used?

  • @sanyamcreates9322
    @sanyamcreates9322 ปีที่แล้ว

    how do i scale it for my computer

  • @ivankostiv-ml9xg
    @ivankostiv-ml9xg ปีที่แล้ว

    i cannot to put my picture in line bg pygame image can you help me pls i cannot

  • @stcagkggtsvgyzmak3429
    @stcagkggtsvgyzmak3429 ปีที่แล้ว +1

    Great video and great code! I think your explanation is good too but since the coding parts are too fast explanations and coding parts don't follow each other well. For example at around 03:20 while you're defining "field" I can't understand what you're exactly doing by just listening to your explanations because while you're still explaining code part jumps to somewhere else. Other than that as I said before it's a great video. Hope my criticism helps you in your future videos somehow. Edit: Though the problem may be my understanding speed of English since I'm not fluent.

  • @zebijon
    @zebijon ปีที่แล้ว +1

    Yoki are very nest.

  • @footballCartoon91
    @footballCartoon91 ปีที่แล้ว

    @2:04 the figure does not move fast enough in my computer

    • @CoderSpaceChannel
      @CoderSpaceChannel  ปีที่แล้ว

      check that the FPS value is 60

    • @footballCartoon91
      @footballCartoon91 ปีที่แล้ว

      @@CoderSpaceChannel i put dx+=2 and it is ok now

    • @footballCartoon91
      @footballCartoon91 ปีที่แล้ว

      one more thing is that i realise you put dx variable inside the game loop
      i tried to put it outside of the loop
      and suddenly the figure moves so fast..
      and also i tried to move the code to check for key pressing outside the loop
      and suddenly the figure moves so fast too..
      and what is the difference between pygame.display.update() and pygame.display.flip()?

    • @CoderSpaceChannel
      @CoderSpaceChannel  ปีที่แล้ว

      @@footballCartoon91 flip - updates the entire screen, update - you can set a certain area of the screen to update

  • @user-mw7st3gj1d
    @user-mw7st3gj1d 6 หลายเดือนก่อน

    My game oversate is not working

  • @Basic_manQ
    @Basic_manQ ปีที่แล้ว

    1:47

  • @Wallee580
    @Wallee580 2 ปีที่แล้ว

    First comment, nice video :p

  • @mrboyban
    @mrboyban ปีที่แล้ว

    Recently I started to code about 2 months. Is this the level I should be at?

  • @Basic_manQ
    @Basic_manQ ปีที่แล้ว

    6 : 41

  • @Basic_manQ
    @Basic_manQ ปีที่แล้ว

    3:50

  • @ARandomGamerLolBro
    @ARandomGamerLolBro 2 หลายเดือนก่อน

    wrong colors dude, it is like this
    Z is red
    L is orange
    O is yellow
    S is green
    I is cyan
    J is dark blue
    T is purple

  • @flynneugene2675
    @flynneugene2675 ปีที่แล้ว

    Next video idea : Learn python from scratch by making a game

  • @iKostanCom
    @iKostanCom ปีที่แล้ว

    Tooooooooo fast

  • @anonfourtyfive
    @anonfourtyfive ปีที่แล้ว +1

    This guy doesn't explain his code, he's explaining what's code is doing.
    nobody is fallowing his video, expect some who are on repeat button.
    100% sure more than 90% never reach the end because of the lack of explaination or they literallly copy paste without actually understanding what they are doing.
    this ISN'T helpful, it sure is catchy for those who don't know how it actually work. lel.
    sad reality.

    • @wildwest1832
      @wildwest1832 ปีที่แล้ว

      If he did that the video would be 10X longer

    • @mochalatte3547
      @mochalatte3547 ปีที่แล้ว +1

      Agreed. This is a bit advanced for folks who already had a taste of python but for beginners it is not useful; it is as if he is regurgitating his "masterful" code which by itself is great but for beginners it's clearly not. My train of thought is still boarding at the station for the way he explained it...

    • @aurelbartmann5504
      @aurelbartmann5504 4 หลายเดือนก่อน

      I found it very helpul

  • @johnniegilkerson4724
    @johnniegilkerson4724 ปีที่แล้ว

    main_font: Font = pygame.font.Font('font/font.ttf', 65)
    TypeError: not a file object