I made Tetris in C, this is what I learned

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ม.ค. 2025

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

  • @Austin-ft8pn
    @Austin-ft8pn  10 หลายเดือนก่อน +7

    There are some issues with the code in this video. I fixed them recently. I wonder if anyone can spot them or find issues I didn't find 🤔. I'll give you a hint about one of the issues and say that is related to how the game evaluates the score

  • @anon_y_mousse
    @anon_y_mousse 10 หลายเดือนก่อน +56

    Ah yes, the game where your moral character is insulted when you lose, love it. Also, you might want to increase your volume.

    • @itsnotfantom
      @itsnotfantom 14 วันที่ผ่านมา +3

      lmaoooo 😂

    • @hughjass3434
      @hughjass3434 8 วันที่ผ่านมา +2

      Loose

  • @RockTo11
    @RockTo11 8 วันที่ผ่านมา +9

    The kind of iterative program you describe in the first two minutes is probably the best method. Results are almost always superior to speculative design, which is where functions, data, etc. is all put into a place which makes sense from a big picture point of view. But the reality is that the big picture is never understood until the nuance of all the details are first tested and iterated on, and understood.

  • @AbAb-th5qe
    @AbAb-th5qe 10 วันที่ผ่านมา +9

    It doesn't matter if consts are global. By avoid global variables we are attempting to avoid shared mutable state. Consts are immutable.

  • @SB-rf2ye
    @SB-rf2ye วันที่ผ่านมา

    I 100% support the method to do bounds checking and add the result to an array.
    This is an extremely important method to write safe/correct code in C.
    This can also be used to retrieve data from complex data structures. If you have a complex data structure just use a local stack variable to store data.
    Then once you have completed the work, save it to your data structure with a function call that does all of the safety checks.

  • @kernelpanics
    @kernelpanics 8 วันที่ผ่านมา +3

    Tetris is one of the greatest video games, its originaly created using Pascal for the RT-11

  • @sourcecode6467
    @sourcecode6467 14 วันที่ผ่านมา +5

    Did this in pygame just recently, simpler than I initially thought, though still challenging.

  • @Austin-ft8pn
    @Austin-ft8pn  11 หลายเดือนก่อน +11

    source code: github.com/A-Larsen/tetris

  • @eddi-y4e
    @eddi-y4e หลายเดือนก่อน +7

    I had a weird implementation of tetris I made it in SDL2 raylib then ncurses (the code sucks for all of them) instead of doing a rotation algorithm I just had a huge array of each piece and its rotation so I just changed the index any time I wanted to rotate also instead of using global variables I had a nasty habit of just passing a pointer of a game state struct around to every function

    • @JohnDoe-m8i
      @JohnDoe-m8i 26 วันที่ผ่านมา +4

      What's wrong with passing a game struct pointer around?

    • @eddi-y4e
      @eddi-y4e 26 วันที่ผ่านมา +2

      @@JohnDoe-m8i I'm not an experienced enough programmer to say for sure but it felt wrong having to call each function with a pointer to the argument
      A better a approach maybe to pass the pointer to an UpdateGame function and have functions that only take in the relevant data as arguments the code is more readable and more importantly easier to refactor that way passing the whole struct made it easier for me to make functions do more than what they're supposed to do
      I haven't programmed in while so this may just be naval gazing

    • @TheCommunistRabbit
      @TheCommunistRabbit 13 วันที่ผ่านมา

      its completely fine to have a pointer of the game state passed around as long as you arent making multithreaded apps

    • @gastonrc94
      @gastonrc94 10 วันที่ผ่านมา

      Why can't you use it in multithreaded applications? Wouldn't it be enough to simply add a mutex?

  • @omnimathic
    @omnimathic 15 วันที่ผ่านมา +4

    Amazing brother

  • @Ri2ek
    @Ri2ek 15 วันที่ผ่านมา +7

    did anyone mention the sniffles?

  • @Wggwjzjjxmsk
    @Wggwjzjjxmsk 11 วันที่ผ่านมา +1

    Having globals is not necessarily bad one allocation vs allocating every time a method is called

  • @tranquythuong
    @tranquythuong 12 วันที่ผ่านมา +1

    Great content, I love it!

  • @unknownaxis2852
    @unknownaxis2852 11 หลายเดือนก่อน +46

    it should be lose not loose lol

    • @DustinKazi
      @DustinKazi 11 หลายเดือนก่อน +45

      classic dev moment: code works, English doesn't

    • @Austin-ft8pn
      @Austin-ft8pn  11 หลายเดือนก่อน +17

      Lol thanks

    • @Hasansaid51
      @Hasansaid51 10 วันที่ผ่านมา +1

      That’s not a bug, that’s a feature lmao

    • @rickdutta942
      @rickdutta942 10 วันที่ผ่านมา

      ​@@Hasansaid51fr😂

  • @friedrichwilhelmhufnagel3577
    @friedrichwilhelmhufnagel3577 13 วันที่ผ่านมา +3

    Hello. Can you maybe say something about your setup for producrivity reasons for us mere mortal terminal users? *feels.like.an.npc"
    thanks!

    • @genericuser1546
      @genericuser1546 2 วันที่ผ่านมา

      looks like they are using nvim (editor) + alacritty (term) + sway/i3wm (window manager)

    • @friedrichwilhelmhufnagel3577
      @friedrichwilhelmhufnagel3577 2 วันที่ผ่านมา

      @genericuser1546 thanks!

  • @Calypso694
    @Calypso694 11 วันที่ผ่านมา +1

    wasnt the original Tetris in C? also how long did this take you and did you know C pretty well or did you kinda roll with it?

    • @gcolombelli
      @gcolombelli 11 วันที่ผ่านมา +3

      The Elektronika 60 version? It was written in Pascal, as was the first IBM PC port IIRC.

  • @raeplaysval
    @raeplaysval 16 วันที่ผ่านมา +1

    is this nes Tetris or modern spin hell tetris

  • @adityagautam4689
    @adityagautam4689 13 วันที่ผ่านมา +1

    You should use ST terminal to get the maximum performance in Tetris :wink:

  • @luke-gamedevlearning
    @luke-gamedevlearning 3 วันที่ผ่านมา

    Great working code. | Your volume has bigger issues.
    I have to set my PC volume to 100 to hear you normally.

    • @luke-gamedevlearning
      @luke-gamedevlearning 3 วันที่ผ่านมา

      Then the TH-cam ad blasts at full volume. 👎

  • @Leverquin
    @Leverquin 4 วันที่ผ่านมา

    what editor is that? :)

    • @ldtig8099
      @ldtig8099 4 วันที่ผ่านมา

      vim

  • @lumberjackdreamer6267
    @lumberjackdreamer6267 11 วันที่ผ่านมา +1

    Volume too low, can’t hear.

  • @Digitalgems9000
    @Digitalgems9000 10 วันที่ผ่านมา

    cool overview man

  • @earthlingsunited
    @earthlingsunited 10 วันที่ผ่านมา

    Bro please for the love of God, what neovim theme are you using in this video?

    • @slowtyper95
      @slowtyper95 10 วันที่ผ่านมา +2

      Looks like gruvbox

  • @turanamo
    @turanamo หลายเดือนก่อน +3

    Don't you think, C++ handles the global variable conundrum neatly as they can be accessed from the Class itself? I think that's one reason C++ is better than C. What do you think?

    • @Austin-ft8pn
      @Austin-ft8pn  หลายเดือนก่อน +4

      I personal just don't like classes for a lot of things. It takes me just as long to organize variables to be in the right spots as it does to organize a class correctly. If I make a class with a member that I'm using for other parts of my code it's harder for me to change that member when it is associated with other elements in the class, and possibly classes associated with that class. It's becomes almost like a tangled web. It really just depends on what your doing and your personal preferences. But this is all just my opinion

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

      @@Austin-ft8pn i agree. i found the access to local variables from the class functions a useful feature that effectively removes the use of global variables. But overall I think C++ is a PITA

    • @Austin-ft8pn
      @Austin-ft8pn  หลายเดือนก่อน +1

      @turanamo also structs really aren't that bad IMO

    • @taufiqurrahmansagafkelrey2833
      @taufiqurrahmansagafkelrey2833 29 วันที่ผ่านมา

      @@Austin-ft8pn that's very understandable. i'm doing python and learning C recently. in my experience with python, most of the time, it sucks to work with classes--OOP style--and mix them with functional style with the same portion, like equally keeping the style of those 2 in the main program, i tend to use like 80%-20% or 20%-80% of oop and functional when integrating bunch of different things in the main program, so yeah, it is very depended on the situation and personal preferences.

    • @AhnafAbdullah
      @AhnafAbdullah 11 วันที่ผ่านมา +1

      I mean, you could also just modify the function arguments to take a pointer to the variable you want it to use instead of using a global variable.

  • @user-dz6il2bx5p70
    @user-dz6il2bx5p70 หลายเดือนก่อน +12

    bro talking from the kitchen

  • @10vid5
    @10vid5 10 วันที่ผ่านมา +7

    Removing ALL global variables and instead passing them as dependencies among functions is a pretty bad idea. A function should preferably have only arguments that are relevant to the function's name, such as:
    LineTo (x, y);
    instead of
    LineTo (x, y, &framebuffer, &other_internal_stuff);
    There is no performance penalty in using a handful of global variables, they are most likely cached.

    • @Austin-ft8pn
      @Austin-ft8pn  9 วันที่ผ่านมา +2

      I just looked this up. Very helpful, Thanks!

    • @genericuser1546
      @genericuser1546 2 วันที่ผ่านมา

      @@Austin-ft8pn to take the opposite approach: Having ANY global variables instead of passing functions their dependencies is a pretty bad idea. A function should preferably be pure only acting upon it's given inputs, such as:
      LineTo(&frame, x, y);
      instead of
      LineTo(x, y);
      There is a compounding cost to relying on global variables, it inhibits testing and leads to less readable code.

    • @JacobAulin
      @JacobAulin วันที่ผ่านมา

      ​@@genericuser1546 Two schools of thought. I myself also prefer pure functions - makes it easier to debug.

  • @bearfm
    @bearfm 11 หลายเดือนก่อน +9

    why you so quiet man

  • @Rockyzach88
    @Rockyzach88 6 วันที่ผ่านมา

    "YOU LOOSE"?? Are you trolling?

  • @Bodzin-w3r
    @Bodzin-w3r 22 วันที่ผ่านมา +3

    Nice one!

  • @terry-
    @terry- 9 วันที่ผ่านมา

    Great!

  • @timstevens3361
    @timstevens3361 22 วันที่ผ่านมา +1

    i made a graphics thing
    in C in idk mabe 500+ hrs
    its not a game
    its not cad/cam software
    im rewriting it in C++ and opengl 4.6
    i call it ncptr

    • @Austin-ft8pn
      @Austin-ft8pn  13 วันที่ผ่านมา +1

      Nice! That's awesome

    • @Austin-ft8pn
      @Austin-ft8pn  13 วันที่ผ่านมา +1

      Wait. I've talked to you in a linux programming discord community. That's crazy!

  • @Phenom0100
    @Phenom0100 11 วันที่ผ่านมา +1

    If it was a game I would have gone object oriented and worked in C++.

  • @bissogood
    @bissogood 2 วันที่ผ่านมา

    I built it in 5 seconds and in every language. Thanks to chat gpt…😅

  • @handfoamsanitiser
    @handfoamsanitiser 5 วันที่ผ่านมา

    Nice

  • @emad-xp8gy
    @emad-xp8gy 11 หลายเดือนก่อน +1

    Amazing, keep it up 👏👏👏👏

  • @MrDukeeeey
    @MrDukeeeey 14 วันที่ผ่านมา +3

    You loose

  • @Sub0x-x40
    @Sub0x-x40 10 วันที่ผ่านมา

    lose*

  • @seanshields9209
    @seanshields9209 9 วันที่ผ่านมา

    You loose