summaryrefslogtreecommitdiff
path: root/userspace/snake2.c
blob: 6fbd09223d247a69627a50fa08a3b06c0d85c86e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include "newcalls.h"

static char lastc='d';

int main()
{

    // turn off buffering for stdin and stdout
    setvbuf(stdin,NULL,_IONBF,0);
    setvbuf(stdout,NULL,_IONBF,0);

    printf("\033c\033HFOOL-SNAKE\033d\n"); // title
    char snake[]="FOOLSNAKES"; // snakes letters

    int thread=_clone(); // we want to threads
    uint64_t x=0; // counter

    if(thread==0) // thread 1
    {
	while(1)
	{
	    for(int i=0;i<10000000;i++); // naive wait

	    x++;
	    if(lastc=='d')printf("\033f"); //rigth
	    if(lastc=='a')printf("\033b"); //left
	    if(lastc=='w')printf("\033u"); //up 
	    if(lastc=='s')printf("\033d"); //down

	    // put letter
	    printf("\033[0;%im\033b%c",31+(uint8_t)(x%6),snake[x%10]); 

	}
	
    }
    else while(1) lastc=fgetc(stdin); // thread 2

}