Live data from Hacker News

Flappy Bird in 1000 lines of C

github.com

41–50 of 59 posts

Re: Flappy Bird in 1000 lines of C

#41

Earlier quoted context omitted.

The idiot there is Babbage -- the politician, more well trained in general thinking, clearly observed that thinking-things can correct mistakes against a background of common understanding. eg., "Q. Who is the king of france?", "A. France has no king, did you mean who was the last king of france?"

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 Babbage was fit to be so smug, he is fit to be called an idiot when having been so foolishly.

"Peak HN" is presumably when you can cite an oblivious smarter-than-thou Engineer at his most inastute, but not call one an idiot.

Re: Flappy Bird in 1000 lines of C

#43
flappy bird is a simple game, 1000 lines sounds like a normal amount(assuming there is a graphics scaffold, which in this case appears to be SDL), and it would indicate that it's not compressed code-golf style

Re: Flappy Bird in 1000 lines of C

#45
post #5

Earlier 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…

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

#46

Earlier quoted context omitted.

It uses a sprite sheet png file. I am curious how you would target a simpler machine without a bunch of code to display those. I am having trouble picturing this.

There's no special reason it has to PNG, though - if you're aiming for minimum line-count without dependencies then just use a raw bitmap.

You can just inline sprites in code too. Even though that would add at least one big line of code :)

This is how I do fonts in one of my projects.

Re: Flappy Bird in 1000 lines of C

#47
post #19
post #15

Earlier quoted context omitted.

> It's impossible to do graphics in pure C, so what are the alternatives Plenty of other comments have already disputed this. It's a reasonable mistake to make, especially if your experience is with more recent technologies and languages. All the same if reminds me of this perennial quote from a man who really couldn't just use C for everything; > On two occasions I have been asked, — "Pray, Mr. Babbage, if you put i…

>> It's impossible to do graphics in pure C, so what are the alternatives > I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. [...] , but you can do it all in C If you trace the actual context of the conversation from ggp (doubtfuluser - "SDL is not 1000 lines anymore" ) to gp (shric - "pure C" ) ... it is clear that "pure C" was just an imprecise and shorthand alte…

You can do graphics in pure C though. Really, file i/o is all you need for anything. Anything.

Re: Flappy Bird in 1000 lines of C

#48
post #43

flappy bird is a simple game, 1000 lines sounds like a normal amount(assuming there is a graphics scaffold, which in this case appears to be SDL), and it would indicate that it's not compressed code-golf style

Indeed. The linked project is quite verbose in fact. Just checked my old ncurses clone in Python and it had 280 lines. JS clone based on Pixi had less than 200. It wouldn't be much more if translated directly to C.

Re: Flappy Bird in 1000 lines of C

#49
post #5

I 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…

How do you think libwayland-client is implemented? Or even SDL?

Re: Flappy Bird in 1000 lines of C

#50

Please post screenshots or a video/gif of it in the main Github README.md. Would make this post so much more popular.

It always baffles me how people making anything on GitHub don't show how it looks, especially with something as visually prominent as a video game or similarly visual products. I'm always extremely eager to show how my projects function and look, even if they are command-line programs!
Post reply on HN