From 90f60101878cc8418bbe90b323c046660d25029b Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Sun, 19 Dec 2021 17:04:45 +0100 Subject: [PATCH] Initial commit: basic cursor movements --- .gitignore | 2 ++ Makefile | 18 ++++++++++++++ main.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.h | 4 +++ 4 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.c create mode 100644 main.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68dcf2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dungeon1 +*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a4bb22a --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CFLAGS=-Wall -Wextra -pedantic -g +LDFLAGS=-lncurses + +PROG=dungeon1 +OBJS=main.o +HDRS=main.h + +all: dungeon1 + +dungeon1: $(OBJS) $(HDRS) + $(CC) $(LDFLAGS) $(OBJS) -o $@ + +clean: + rm -f $(OBJS) + +realclean: clean + rm -f $(PROG) + diff --git a/main.c b/main.c new file mode 100644 index 0000000..e9c5604 --- /dev/null +++ b/main.c @@ -0,0 +1,80 @@ +/* +** dungeon1 +** +** 2021-12, markus schnalke +*/ + +#include "main.h" + +int +main(void) +{ + int x, y; + WINDOW *win; + int c; + enum { + W = 80, + H = 24, + }; + char c2; + + win = initscr(); + noecho(); + cbreak(); + keypad(stdscr, TRUE); +/* + nonl(); + intrflush(stdscr, FALSE); +*/ + + mvprintw(0, 20, "%d:%d", W, H); + move(H/2, W/2); + refresh(); + + while ((c = getch()) != ERR) { + if (c == 'q') { + break; + } + getyx(win, y, x); + addch('.'); + switch (c) { + case KEY_LEFT: + case 'h': + if (x > 0) { + x--; + } + break; + case KEY_RIGHT: + case 'l': + if (x < W) { + x++; + } + break; + case KEY_UP: + case 'k': + if (y > 1) { + y--; + } + break; + case KEY_DOWN: + case 'j': + if (y < H) { + y++; + } + break; + } + c2 = mvinch(y, x) & 255; + switch (c2) { + } + mvprintw(0, 40, "<%c>", c2); + mvprintw(0, 0, "%d:%d", x, y); + move(y, x); + + refresh(); + napms(10); + } + + endwin(); + return 0; +} + diff --git a/main.h b/main.h new file mode 100644 index 0000000..603e59b --- /dev/null +++ b/main.h @@ -0,0 +1,4 @@ +#include +#include +#include + -- 1.7.10.4