FWIW I had to install some extra dependencies on macos before the build instructions worked. $ brew install libxmp fluid-synth wavpack
Flappy Bird in 1000 lines of C
51–59 of 59 posts
Re: Flappy Bird in 1000 lines of C
#52Earlier quoted context omitted.
Calling Charles Babbage an idiot has to be peak HN.
Clearly raised to a higher peak by taking one of the words of a statement most easy to misread for the sake of outrage, and highlighting it, whilst ignoring the substance of the comment. Babbage was insulting politicians who had, in the instance of his insult, a better grasp on the nature of intelligence than he had. It is a foolish quote to repeat, and reeks of the same smug obliviousness in which it was said. If Ba…
Please become familiar with the British sense of humor and the context of the writing before taking it at face value. If that is too much work, at least be prepared to give the writer the benefit of the doubt. Babbage was writing for a specific audience and with a specific intent, and I would suggest that you are probably misunderstanding him if you are inferring smugness from an isolated quote.
Re: Flappy Bird in 1000 lines of C
#53Earlier quoted context omitted.
On Linux, you may mmap /dev/fb0 to access the front buffer like you would have on old computers. Not all kernel configs and GPU devices allow that. You can test if fb0 is usable with cat /dev/random > /dev/fb0 to see if the screen is filled with garbage (you may also need root privilege).
You could also implement a Wayland or X11 client by yourself. Those libraries are also implemented in C after all. No need for external libraries to write to some sockets. Whether it's worth doing is another matter.
Re: Flappy Bird in 1000 lines of C
#54Earlier quoted context omitted.
You could also implement a Wayland or X11 client by yourself. Those libraries are also implemented in C after all. No need for external libraries to write to some sockets. Whether it's worth doing is another matter.
This is not actually that difficult if you just want the basics. I have a project that implements just the x11 key & mouse events, and the shared memory extension in 400 lines of Rust. Was worth it for me since it eliminated dependency on libx11 and libc, which removed a dependency on something like 800,000 lines of code across those two libraries. (Determined by a basic cloc on each library source. Actually compiled…
Re: Flappy Bird in 1000 lines of C
#55Re: Flappy Bird in 1000 lines of C
#56I like these challenges, where people rebuild stuff low level and “line efficient” (not saying this is a good idea in general). This makes me curious and I can learn a lot from these examples. I was a bit disappointed though to see that this code used SDL for sprites and more stuff though. That’s not 1000 lines anymore imo. Still the code was an interesting read. Thank you OP
It's impossible to do graphics in pure C, so what are the alternatives? Whatever you do at whatever level of abstraction/portability (SDL, OpenGL, Metal, Vulkan, Unity, ...), you're leveraging zillions of lines of other people's code. The only way arguably you could do it in pure C (with undefined behavior) is in enviroments that let you write straight to graphics framebuffers without any abstraction layer and even w…
My original response was to the person claiming that it was basically cheating to use SDL. You need abstraction, so there is nothing wrong with having SDL in the way.
Someone said that it's C all the way down. It's not. The Linux kernel is not 100% C and it cannot possibly be.
There are no C facilities to:
- Read a keystroke and/or mouse (required for Flappy Bird) directly. C only supports reading from the stdin and stdout streams.
- Generate graphics (more on this below).
As I mentioned in the original post, some operating systems let you write straight to graphics memory.
While you can technically do this in C with a pointer to an address, you're still going to have to issue e.g. a BIOS call to set the mode to something other than the default text mode. But we can let that slide.
There is absolutely no way to do "C all the way down" when reading and writing I/O ports, executing interrupts, etc. which is required for I/O beyond just the buffered stdout and stdin streams that C provides.
Linux of course provides things in /dev, but they're also not C all the way down.
If there was a hypothetical computer which supported all graphics and other I/O via reading and writing to/from streams, then sure, but I don't think that computer exists.
I know very well what C can and cannot do, I've been using it for 40 years.
Re: Flappy Bird in 1000 lines of C
#57Earlier quoted context omitted.
It's impossible to do graphics in pure C, so what are the alternatives? Whatever you do at whatever level of abstraction/portability (SDL, OpenGL, Metal, Vulkan, Unity, ...), you're leveraging zillions of lines of other people's code. The only way arguably you could do it in pure C (with undefined behavior) is in enviroments that let you write straight to graphics framebuffers without any abstraction layer and even w…
This is x86 assembly not C, but could be done just as easily in C. No kernel support either, since there isn’t one. https://github.com/stillwwater/raycaster
Re: Flappy Bird in 1000 lines of C
#58It uses SDL. Not saying that's good or bad, but it's the first thing I wondered about.
Yeah, it still seems like a reasonable choice if you're going to write a simple game in C.
Very low overhead abstraction over platform specific APIs.
IIRC the source engine uses it.
Re: Flappy Bird in 1000 lines of C
#59Please post screenshots or a video/gif of it in the main Github README.md. Would make this post so much more popular.