Making Minimalist Snake Game in C on Linux

Поделиться
HTML-код
  • Опубликовано: 4 фев 2025

Комментарии • 95

  • @jcoterhals
    @jcoterhals Год назад +51

    Just wanted to let you know that I really enjoy your videos, the C videos in particular. I learn something from each of them.

  • @TheWinnieston
    @TheWinnieston Год назад +11

    Please keep doing these, they are fantastic jumping off points and they get the point and mechanics across real well

  • @valentinnikolov6882
    @valentinnikolov6882 Год назад +3

    Your C videos are so uplifting and refreshing. They really are a great gift from you to the people like me who now start learning C programming.

  • @_MisterPink
    @_MisterPink Год назад +19

    Oh come on, let the snake grow, thats tricky. Thanks for the amazing videos btw. I really enjoy them.

    • @DavidLatham-productiondave
      @DavidLatham-productiondave Год назад +3

      Yeah, circular buffers... Took me ages and ages to work out how to do that with pointers. On a z80 CPU. 😂

    • @MrValsung
      @MrValsung Год назад

      @@DavidLatham-productiondave what reason would one have to implement circular buffers for growing the snake? makes sense for input handling, but not sure on the logic for growing snakes afaik

    • @DavidLatham-productiondave
      @DavidLatham-productiondave Год назад

      @@MrValsung I had a pointer to the head of the snake and another to the tail position in the framebuffer. When the snake grows, I don't increment the pointer while I add new segments for the grow length. Say 3 segments after each apple eaten.
      I need all the segments saved someplace so I can test for collisions with the body.
      I used a circular buffer because it's fast. I could allocate the memory for the whole buffer and then just manipulate the tail and head pointers.
      When the head reaches the end of the buffer it wraps back around. Same for the tail pointer.
      On a z80 8bit CPU.

  • @wiseskeshom4673
    @wiseskeshom4673 Год назад +1

    What a fantastic channel. I really enjoyed your videos. Please keep doing these, we learn a lot of new things from you. Thank you so much for a great work.

  • @mkay2223
    @mkay2223 Год назад +2

    Effective demonstration! Your videos did demystify C/C++ for me!

  • @jakubwysiecki2080
    @jakubwysiecki2080 Год назад +1

    I'd love watching your videos. I am programming in C for a few years, and you can still show some pieces in this C cake that i don't know.

  • @MadMathMike
    @MadMathMike Год назад +3

    This video felt like it was only 3 minutes long. Great stuff!

  • @BaxxyNut
    @BaxxyNut 10 месяцев назад

    finally, a tutorial that is easy to follow and doesn't leave us with a heap of errors and other things. very nice! i learned a good deal

  • @shirstein2253
    @shirstein2253 11 месяцев назад +1

    im in love with this guy

  • @napukapu
    @napukapu Год назад

    good format, no bullshit intro foreword or anything, just straight on with it

  • @ahmedsaed26
    @ahmedsaed26 Год назад

    I really enjoy watching your videos. Keep up the good work

  • @leonss2356
    @leonss2356 Год назад +1

    these C videos are godsend, I'd love one about making a POC of an ncurses-like library, I'm not a fan of the ncurses API for some reason.

  • @SlideRSB
    @SlideRSB Год назад +11

    The snake isn't a snake.

  • @informagico6331
    @informagico6331 Год назад

    I highly recommend to use switch based control flow for multiple options, it is far more efficient and readable than if - else nesting for this case. The compiler creates a direct access table for option managing.
    After all, nice video, I still learn a lot about computer science concepts that I'm not really into.

  • @anon_y_mousse
    @anon_y_mousse Год назад

    Neat. I would use the characters that Nibbles used if I could find their Unicode equivalents. Those little boxes were perfect for this game.

  • @robertoalbino8156
    @robertoalbino8156 Год назад

    I want to make that game with the C language and you have given me an idea :D Thank you

  • @bartholomewgander540
    @bartholomewgander540 Год назад

    Very nice snipped-like videos! Keep up the good work :)

  • @moody_weirdo
    @moody_weirdo Год назад +2

    Really cool but would be more interesting to see a more low level tutorial without ncurses and manually disabling canonical input etc.

    • @nirlichtman
      @nirlichtman  Год назад +5

      And also another cool direction is to make this as a bootloader game :)

  • @AS-oz6ep
    @AS-oz6ep Год назад

    I did a snake game in Motorola 68k assembler in university. Fun times :)

  • @nykt0r
    @nykt0r Год назад

    I love your C videos! Keep it up 💪

  • @MrAbrazildo
    @MrAbrazildo Год назад

    4:13, by making a hash table, you could nicely fit this in 3-5 lines. Create 3 arrays: for keys, Xs, Ys. Find where the key is located on its array, and get x,y on the same index, on other arrays.
    7:25, if you gonna repeat that number, make it a const. Btw, you are not using const at all. Both things are recommended by C++ Core Guidelines.

    • @guruware8612
      @guruware8612 Год назад

      whut ? by making a hastable you can do it in 3 lines, that funny hashtable is how much lines of code ?
      who needs all this guidelines, what we need is working code?
      why not complaining about missing comments, and a header to babble about license, but not a word about the file itself.
      why over-engineering 20 lines of code, which, btw, are not even c++ ? so no std::map hash-table. i general i use hash for smoking.
      you could also make a few days some scrum-meetings so the shareholders think you are a professional, then add a 3 product-owners and a product-manager or two.
      then comes QA (3 people looking bored at the same monitor), and not to forget the most useless department: marketing.
      this is the so-called "modern" development-environment we should nuke.
      what are the $§%&-guidelines saying about where i'm allowed nowadays to put my curly-braces ?

  • @ПавелТужеляк
    @ПавелТужеляк Год назад

    excellent teacher, informative lesson

  • @GuildOfCalamity
    @GuildOfCalamity Год назад

    I would change the update delay when the snake is moving down/up since the console glyph sizes are taller than they are wide.

  • @MotorBorg
    @MotorBorg Год назад +2

    I thought there was no way anyone can code a snake game in 8 minutes, even a minimalistic one. I wanted to see how you'd implement it's growing, because I did it just yesterday and wanted to compare my solution to someone else's. ☺️

    • @nirlichtman
      @nirlichtman  Год назад +1

      I am also planning to make this as a bootloader game in a future video, and over there I will implement growing as well :)

    • @MotorBorg
      @MotorBorg Год назад

      @@nirlichtman I can't wait!

  • @FaranAiki
    @FaranAiki Год назад +1

    I think we can use switch-case in the if statement for pressed, correct?

  • @geavenxdd4773
    @geavenxdd4773 Год назад

    C IS AMAZING NCURSES IS AMAZING

  • @WhoLeb7
    @WhoLeb7 Год назад

    A switch statement fits much better than ifs

  • @GenZdev
    @GenZdev Год назад +1

    Great tutorial Nir. Just curious do you use wsl for coding.

    • @nirlichtman
      @nirlichtman  Год назад

      Thanks! Yes, I use WSL Debian when coding for Linux

    • @GenZdev
      @GenZdev Год назад +1

      @@nirlichtman a setup tour should be great it looks unique

    • @nirlichtman
      @nirlichtman  Год назад +1

      @@GenZdev thats a good idea, i talk a little about my setup on two of my videos, but i will consider a more in depth vid

  • @agun214
    @agun214 Год назад

    "Now the serpent was more crafty than any of the wild animals the LORD God had made" Genesis 3:1
    you're pitching these videos right at my skill level
    RESPECT

  • @zimmer550i
    @zimmer550i Год назад +1

    How did you use boolean value without stdbool.h?

    • @nirlichtman
      @nirlichtman  Год назад +1

      When including curses.h it brings over stdbool.h as well

  • @nicepingrace
    @nicepingrace Год назад

    more low level tutorial, LET'S GO!)

  • @damasus9677
    @damasus9677 Год назад +1

    I wonder if you use Linux or Windows with WSL. I can see DWM (dmenu and slstatus) at the top of your screen, but there's also Windows Terminal open.

    • @dreamtexx
      @dreamtexx Год назад

      i wonder that to, what is his setup?

    • @nirlichtman
      @nirlichtman  Год назад

      I use dwm-win32 :)

  • @tatse7
    @tatse7 Год назад

    Replace the if statements with switch - case block.

  • @sethikablip8607
    @sethikablip8607 Год назад

    Hello just asking if you can give your vim setup and what font are you using. Otherwise this was a great video.

    • @nirlichtman
      @nirlichtman  Год назад

      Check out my channel description for a link to my vimrc :)

  • @MLGJuggernautgaming
    @MLGJuggernautgaming 8 месяцев назад

    Is openssl easy to install? I had problems finding a 32bit version of it.

  • @shaigoldsmith605
    @shaigoldsmith605 Год назад +1

    Can you make an online tetris first person shooter? (I know how stupid that sounds)

  • @lpsinko9705
    @lpsinko9705 Год назад

    can someone help me i'm using wsl in windows with ubuntu distro and i'm using nvchad distro for neovim but when i want to make some game or app with c or c++ it doesn't work like the window dont apear not like in code::block or vscode and it looks like i should add xserver and cmake which is waaay complicated (at least for me ) to wsl

    • @nirlichtman
      @nirlichtman  Год назад

      Are you specifically talking about the snake game from the video not opening?

    • @lpsinko9705
      @lpsinko9705 Год назад

      not just snake i mean there is the terminal version that works but like i'm talking about when you ./a.out a window apear just like when you click the run button in vscode @@nirlichtman

    • @nirlichtman
      @nirlichtman  Год назад +1

      @@lpsinko9705 the game runs on the terminal so it sounds wierd that it opens a new window when you run a.out, try running the game from within an open terminal

    • @lpsinko9705
      @lpsinko9705 Год назад

      no what i'm trying to say is if i want to make a game or like a calculator that have gui it doesnt apear even after including the sdl2 and more compicated things for me this only in neovim but when i try the same thing in vscode it works the calculator (just an example) works and apears in a window with like that blank white file icon apearing in the task bar@@nirlichtman

  • @nobuharushimazu7320
    @nobuharushimazu7320 6 месяцев назад

    Why is "man 3 rand" not working for me?

  • @AnonymousNoble
    @AnonymousNoble Год назад

    c'mon how can something be this good ?

  • @littlecurrybread
    @littlecurrybread Год назад

    is that your actual typing speed or are you speeding up the typing segments in your videos? its really fast xd

    • @nirlichtman
      @nirlichtman  Год назад

      I sometimes speed up typing segments on my videos, you can notice the speed up when the typing pitch increases :)

  • @VaibhavSharma-zj4gk
    @VaibhavSharma-zj4gk Год назад

    Can this be done without using any library?

  • @Lawsuited
    @Lawsuited Год назад

    Love these videos!

  • @GTA_FIRST_PERSON
    @GTA_FIRST_PERSON Год назад

    wanted to give the like, but you have 420 of them now and I got no hart to change it to 421... I would change 421 to 422 tho :D. Have a sub and comment. I like how you showed the man pages for c libs, I had no idea u can do that... any 1 know how to uninstall google? no need after this tut!

  • @matendafigueiredo
    @matendafigueiredo Год назад

    teus vídeos são muito inspiradores.

  • @entropi314
    @entropi314 Год назад

    Do this window decoration and tabs belong to window manager or to vim?

    • @nirlichtman
      @nirlichtman  Год назад

      The top most bar belongs to the window manager I am using which is called dwm-win32 (it is a port of Suckless dwm for Windows)

  • @VoyivodaFTW1
    @VoyivodaFTW1 Год назад

    dumb question, when you are making these types of games, are you following some type of diagram or game design document? I'm trying to get back into game development and programming, but i get stuck at the actually engineering part. I know how to use most programming languages, but i get stuck when i try to make my own projects like this.

    • @nirlichtman
      @nirlichtman  Год назад +1

      This game is very simple so I didn't make a design document or diagram, but rather I just thought of the basic idea of making a little terminal game with ncurses and started by first reading about it generally on the manual page "ncurses" and from there on to the relevant man pages as I do in the video. For more complex games it is indeed a good idea to make a design document beforehand and decide on the technologies you want to use for the game.

  • @darshanrajpattanaik2154
    @darshanrajpattanaik2154 Год назад

    How are you getting man page in windows? Are you using cygwin?

  • @wispysparks
    @wispysparks Год назад

    High tier content

  • @HaxGuru
    @HaxGuru Год назад

    Hi, I just wanted to ask if there's a specific reason you use WSL in Windows instead of just using a Linux distribution?

    • @nirlichtman
      @nirlichtman  Год назад +1

      I like both Windows and Linux and I use Windows as my main OS since it has wide support for software/games, I find it user friendly and I like Windows programming as well. I like using Linux on WSL and my servers.

    • @HaxGuru
      @HaxGuru Год назад

      @@nirlichtman Oh, thanks for replying. Your videos are amazing!

  • @weetabixharry
    @weetabixharry Год назад

    What is the difference between man and man 3?

    • @nirlichtman
      @nirlichtman  Год назад

      when opening a man page you can specify the category number before the name of the man page so if the same name exists in multiple categories (for example printf) it opens the entry in the specific category, more information in my video about man pages tips.

    • @weetabixharry
      @weetabixharry Год назад

      @@nirlichtman I will hunt down that video... because now I need to know what a "category" is in this context 😆

  • @malakggh
    @malakggh Год назад

    Since when C has had booleans?

    • @nirlichtman
      @nirlichtman  Год назад +1

      You can use the true and false constants by including stdbool header file, and in C23 it is part of the language :) more information over here: devdocs.io/c/language/bool_constant

    • @malakggh
      @malakggh Год назад

      @@nirlichtman Thanks ;)

  • @elyarsadig6955
    @elyarsadig6955 Год назад +1

    The only developers I respect are C developers :)

  • @GameBacardi
    @GameBacardi Год назад

    Thank you

  • @guilherme5094
    @guilherme5094 Год назад

    👍

  • @jinxscript
    @jinxscript Год назад

    this so good for us noobs

  • @mini_motard_kings6883
    @mini_motard_kings6883 Год назад

    Great content!

  • @littlecurrybread
    @littlecurrybread Год назад

    C 🎉

  • @philtoa334
    @philtoa334 Год назад

    Very G**& .

  • @flash_dancer
    @flash_dancer Год назад

    >minimalist
    >2 libraries already
    I'm sick of this clickbait previews

    • @nirlichtman
      @nirlichtman  Год назад

      Actually, it is minimalist, it only uses 1 library (ncurses), an extremely ubiquitous library, there is a good chance it is already installed by default (for example Ubuntu Desktop comes with it pre-installed).
      The dependencies I mention in the video are development dependencies - 2 since one is for the development files and the other is for the man pages, that doesn't mean the users of the program need to install these.