@@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
@@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.
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.
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.
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.
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 ?
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. ☺️
"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
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.
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.
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
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
@@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
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
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.
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.
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!
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
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.
Just wanted to let you know that I really enjoy your videos, the C videos in particular. I learn something from each of them.
Same
Same with me
Please keep doing these, they are fantastic jumping off points and they get the point and mechanics across real well
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.
Oh come on, let the snake grow, thats tricky. Thanks for the amazing videos btw. I really enjoy them.
Yeah, circular buffers... Took me ages and ages to work out how to do that with pointers. On a z80 CPU. 😂
@@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
@@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.
Effective demonstration! Your videos did demystify C/C++ for me!
This video felt like it was only 3 minutes long. Great stuff!
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
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.
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.
im in love with this guy
me too bro
Schizophrenic ahhh
good format, no bullshit intro foreword or anything, just straight on with it
The snake isn't a snake.
I really enjoy watching your videos. Keep up the good work
I love your C videos! Keep it up 💪
Very nice snipped-like videos! Keep up the good work :)
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.
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.
Neat. I would use the characters that Nibbles used if I could find their Unicode equivalents. Those little boxes were perfect for this game.
Really cool but would be more interesting to see a more low level tutorial without ncurses and manually disabling canonical input etc.
And also another cool direction is to make this as a bootloader game :)
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.
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 ?
I want to make that game with the C language and you have given me an idea :D Thank you
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. ☺️
I am also planning to make this as a bootloader game in a future video, and over there I will implement growing as well :)
@@nirlichtman I can't wait!
C IS AMAZING NCURSES IS AMAZING
I did a snake game in Motorola 68k assembler in university. Fun times :)
I would change the update delay when the snake is moving down/up since the console glyph sizes are taller than they are wide.
Great tutorial Nir. Just curious do you use wsl for coding.
Thanks! Yes, I use WSL Debian when coding for Linux
@@nirlichtman a setup tour should be great it looks unique
@@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
I think we can use switch-case in the if statement for pressed, correct?
Right, also possible :)
How did you use boolean value without stdbool.h?
When including curses.h it brings over stdbool.h as well
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.
i wonder that to, what is his setup?
I use dwm-win32 :)
A switch statement fits much better than ifs
"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
Replace the if statements with switch - case block.
Is openssl easy to install? I had problems finding a 32bit version of it.
Hello just asking if you can give your vim setup and what font are you using. Otherwise this was a great video.
Check out my channel description for a link to my vimrc :)
more low level tutorial, LET'S GO!)
Can this be done without using any library?
Love these videos!
is that your actual typing speed or are you speeding up the typing segments in your videos? its really fast xd
I sometimes speed up typing segments on my videos, you can notice the speed up when the typing pitch increases :)
Why is "man 3 rand" not working for me?
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.
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.
Do this window decoration and tabs belong to window manager or to vim?
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)
How are you getting man page in windows? Are you using cygwin?
I am using Debian on WSL
c'mon how can something be this good ?
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
Are you specifically talking about the snake game from the video not opening?
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
@@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
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
Hi, I just wanted to ask if there's a specific reason you use WSL in Windows instead of just using a Linux distribution?
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.
@@nirlichtman Oh, thanks for replying. Your videos are amazing!
Can you make an online tetris first person shooter? (I know how stupid that sounds)
High tier content
What is the difference between man and man 3?
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.
@@nirlichtman I will hunt down that video... because now I need to know what a "category" is in this context 😆
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!
Since when C has had booleans?
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
@@nirlichtman Thanks ;)
teus vídeos são muito inspiradores.
Great content!
The only developers I respect are C developers :)
this so good for us noobs
Thank you
👍
>minimalist
>2 libraries already
I'm sick of this clickbait previews
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.
C 🎉
Very G**& .