Making Minimalist Snake Game in C on Linux

Поділитися
Вставка
  • Опубліковано 24 січ 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.

  • @mkay2223
    @mkay2223 Рік тому +2

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

  • @MadMathMike
    @MadMathMike Рік тому +3

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

  • @BaxxyNut
    @BaxxyNut 9 місяців тому

    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

  • @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.

  • @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.

  • @shirstein2253
    @shirstein2253 10 місяців тому +1

    im in love with this guy

  • @napukapu
    @napukapu Рік тому

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

  • @SlideRSB
    @SlideRSB Рік тому +11

    The snake isn't a snake.

  • @ahmedsaed26
    @ahmedsaed26 Рік тому

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

  • @nykt0r
    @nykt0r Рік тому

    I love your C videos! Keep it up 💪

  • @bartholomewgander540
    @bartholomewgander540 Рік тому

    Very nice snipped-like 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.

  • @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.

  • @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 :)

  • @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 ?

  • @robertoalbino8156
    @robertoalbino8156 Рік тому

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

  • @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!

  • @geavenxdd4773
    @geavenxdd4773 11 місяців тому

    C IS AMAZING NCURSES IS AMAZING

  • @AS-oz6ep
    @AS-oz6ep Рік тому

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

  • @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.

  • @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

  • @ПавелТужеляк
    @ПавелТужеляк Рік тому

    excellent teacher, informative lesson

  • @FaranAiki
    @FaranAiki Рік тому +1

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

  • @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

  • @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.

  • @WhoLeb7
    @WhoLeb7 Рік тому

    A switch statement fits much better than ifs

  • @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

  • @tatse7
    @tatse7 Рік тому

    Replace the if statements with switch - case block.

  • @MLGJuggernautgaming
    @MLGJuggernautgaming 8 місяців тому

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

  • @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 :)

  • @nicepingrace
    @nicepingrace Рік тому

    more low level tutorial, LET'S GO!)

  • @VaibhavSharma-zj4gk
    @VaibhavSharma-zj4gk Рік тому

    Can this be done without using any library?

  • @Lawsuited
    @Lawsuited Рік тому

    Love these videos!

  • @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 :)

  • @nobuharushimazu7320
    @nobuharushimazu7320 5 місяців тому

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

  • @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.

  • @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)

  • @darshanrajpattanaik2154
    @darshanrajpattanaik2154 Рік тому

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

  • @AnonymousNoble
    @AnonymousNoble Рік тому

    c'mon how can something be this good ?

  • @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

  • @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!

  • @shaigoldsmith605
    @shaigoldsmith605 Рік тому +1

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

  • @wispysparks
    @wispysparks Рік тому

    High tier content

  • @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 😆

  • @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!

  • @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 ;)

  • @matendafigueiredo
    @matendafigueiredo Рік тому

    teus vídeos são muito inspiradores.

  • @mini_motard_kings6883
    @mini_motard_kings6883 Рік тому

    Great content!

  • @elyarsadig6955
    @elyarsadig6955 Рік тому +1

    The only developers I respect are C developers :)

  • @jinxscript
    @jinxscript Рік тому

    this so good for us noobs

  • @GameBacardi
    @GameBacardi Рік тому

    Thank you

  • @guilherme5094
    @guilherme5094 Рік тому

    👍

  • @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.

  • @littlecurrybread
    @littlecurrybread Рік тому

    C 🎉

  • @philtoa334
    @philtoa334 Рік тому

    Very G**& .