kiddie
.:: @OREL ::.
ascii
When I started learning c.s., I remembered being amazed while watching the demo
"second reality" done by future crew. more recently, I came across another kind 
of demo presented at ioccc, the international obfuscated c code contest. 
The "ascii fluid dynamics" done by yusuke endoh is mind blowing and it brighten
up my desire to create an ascii game in c. 

I describe here how I created my first ascii game, Starscii. 

On unix like operating system, you can easily turn your terminal into an animated
window by modifying terminal's buffering option and playing with console_codes. 

First, we need to get rid of buffering output, by default, output is buffered till 
a newline is encountered, if you want to animate your screen you might not want to 
keep this behaviour. 
By setting stdout to unbuffered, each string sent to stdout will be directly printed 
to display. Stdout can be set to unbufferd with : setvbuf(stdout, null, _ionbf, 0) 

Secondly, every time user type a character, it is echoed in the terminal. as you
might expect this is also not a behaviour we want to keep, we can turn off echo
with following sequence : 

static void enable_raw(struct termios *conf) { if (tcgetattr(stdin_fileno, conf) == -1) goto error; conf->c_lflag &= ~(icanon | echo); if (tcsetattr(stdin_fileno, tcsanow, conf) == -1) goto error; return; error: fprintf(stderr, "[!] - %s:enable_raw: %s\n", __file__, strerror(errno)); exit(exit_failure); }
Last but not least, we need something to clear and move around the screen. We can find those features inside Linux control sequences although we could also do this the dirty way by playing with carriage return and spaces. All control sequences can be looked up with man console_codes, we will only use 2 of them which are listed below :
void __attribute__((always_inline)) clear_screen(void) { printf("\033[H\033[J"); } void __attribute__((always_inline)) mov_cursor(const int x, const int y) { printf("\033[%d;%dH", y, x); }
Thanks to those 3 modifications, I manage to create simple animation and build the game on top of that. I used a stack data structure to manage both weapons and starships but didn't design any decent gameplay. Still, this was an amazing experience, I discovered amazing projects including asciicker and asciipatrol in addition to a cool tool, rexpaint. Starscii's source code is availaible here.

Tout est faux tout est conforme.