Live data from Hacker News

Flappy Bird in 1000 lines of C

github.com

31–40 of 59 posts

Re: Flappy Bird in 1000 lines of C

#32
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…

Even if you can write directly to a framebuffer you are still using other people's VHDL code.

Re: Flappy Bird in 1000 lines of C

#33
post #9
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…

> It's impossible to do graphics in pure C, so what are the alternatives? Back in the days of DOS I used to do this all the time :)

Didn't you still rely on the DOS HAL (by using system libraries)? The C IDEs came with a lot of graphics util libraries too (e.g. Turbo C).

Re: Flappy Bird in 1000 lines of C

#34
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…

Yes indeed, if the project were targetting a simpler machine without an operating system and windowing system in the way, then doing the whole thing - graphics presentation and all - in a thousand lines of C would be perfectly feasible > I'm acutely aware how it's not turtles all the way down (as the logophiles believe) De Chelonian Mobile

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.

Re: Flappy Bird in 1000 lines of C

#36

Earlier quoted context omitted.

Yes indeed, if the project were targetting a simpler machine without an operating system and windowing system in the way, then doing the whole thing - graphics presentation and all - in a thousand lines of C would be perfectly feasible > I'm acutely aware how it's not turtles all the way down (as the logophiles believe) De Chelonian Mobile

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.

Re: Flappy Bird in 1000 lines of C

#37
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…

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.

Re: Flappy Bird in 1000 lines of C

#39
post #9

Earlier quoted context omitted.

> It's impossible to do graphics in pure C, so what are the alternatives? Back in the days of DOS I used to do this all the time :)

Didn't you still rely on the DOS HAL (by using system libraries)? The C IDEs came with a lot of graphics util libraries too (e.g. Turbo C).

You do call a routine stored in VGA ROM (interrupt 0x10) to set up the mode, then do some port I/O to configure VGA registers and then access VGA memory directly. No "system libraries" from DOS involved as such (they are needed for things like filesystem access, allocating memory and dealing with command-line arguments and returning to the system, though).

Borland's dev tools came with "BGI" (Borlands Graphics Interface), but that's not necessary and wasn't really used for many games -- it provides abstract high-level drawing routines, like lines, circles, etc... that can be made to work on different graphics devices (CGA, VGA, ...). This was not necessary for direct graphics card access that most games used.

Re: Flappy Bird in 1000 lines of C

#40
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…

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

Post reply on HN