ちょっとCLI上で描画したくてcurses使おうとしたら、なんかエラって怒られた。
これって自分で入れなきゃいけないんだっけ...(汗) ってなったので、そのメモ
fatal error: curses.h: No such file or directory
#include <curses.h>
^~~~~~~~~~
aptを使ってインストール。ちなみにncursesはnew cursesの略。
apt-get install libncurses5-dev
とりあえず、テスト用に作ったプログラムを走らせる。というか車を走らせる。
gcc car.c -o car -l curses
./car
一応、コードも載せておく。
car.c
# include <unistd.h>
# include <curses.h>
# include <string.h>
int main(void){
char *car_up= " ___ ";
char *car_mp= "_|[ ]|_";
char *car_dp= "-O---O-";
char *blank = " ";
int car_len = strlen(car_dp);
int dir = +1;
int pos = 1;
int ground = 20;
initscr();
clear();
while(1){
move(ground-2, pos);
addstr(car_up);
move(ground-1, pos);
addstr(car_mp);
move(ground, pos);
addstr(car_dp);
refresh();
if(pos >= (COLS-car_len))
break;
usleep(50000);
move(18, pos);
addstr(blank);
move(19, pos);
addstr(blank);
move(20, pos);
addstr(blank);
pos += dir;
}
endwin();
}