Initial commit: basic cursor movements
authormarkus schnalke <meillo@marmaro.de>
Sun, 19 Dec 2021 16:04:45 +0000 (17:04 +0100)
committermarkus schnalke <meillo@marmaro.de>
Sun, 19 Dec 2021 16:04:45 +0000 (17:04 +0100)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
main.c [new file with mode: 0644]
main.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..68dcf2a
--- /dev/null
@@ -0,0 +1,2 @@
+dungeon1
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..e9c5604
--- /dev/null
+++ b/main.c
@@ -0,0 +1,80 @@
+/*
+** dungeon1
+**
+** 2021-12, markus schnalke <meillo@marmaro.de>
+*/
+
+#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 (file)
index 0000000..603e59b
--- /dev/null
+++ b/main.h
@@ -0,0 +1,4 @@
+#include <stdio.h>
+#include <ncurses.h>
+#include <unistd.h>
+