From: markus schnalke Date: Mon, 20 Dec 2021 15:48:13 +0000 (+0100) Subject: User curses windows X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;ds=sidebyside;h=60d176bbc9199cf2b654c1823b341987f47d213b;p=dungeon1 User curses windows --- diff --git a/main.c b/main.c index bd5c248..f11e1ee 100644 --- a/main.c +++ b/main.c @@ -6,39 +6,53 @@ #include "main.h" +static void draw(void); +static void wboxborder(WINDOW *); + int main(void) { int x, y, x2, y2; - WINDOW *win; int c; char c2; struct map *map, *fow; int gold=0; + char *title = "**** DUNGEON1 ****"; - win = initscr(); + initscr(); noecho(); cbreak(); keypad(stdscr, TRUE); + + w_title = newwin(1, COLS-1, 0, 0); + mvwprintw(w_title, 0, MAPW/2 - strlen(title)/2, "%s", title); + + w_mapborder = newwin(MAPH+2*BORDER, MAPW+2*BORDER, 1, 0); + wboxborder(w_mapborder); + w_map = subwin(w_mapborder, MAPH, MAPW, 2, 1); + + w_info = newwin(4, MAPW+2*BORDER, MAPH+2*BORDER+1, 0); + wboxborder(w_info); + w_gold = subwin(w_info, 1, 10, MAPH+2*BORDER+1+2, 50); + w_pos = subwin(w_info, 1, 20, MAPH+2*BORDER+1+2, 10); /* - nonl(); - intrflush(stdscr, FALSE); */ + fow = getblackmap(); showmap(fow); map = readmap("map1"); findchar(map, '>', &y, &x); - move(y, x); + wmove(w_map, y, x); see(map, y, x); - refresh(); + draw(); while ((c = getch()) != ERR) { if (c == 'q') { break; } - getyx(win, y, x); + getyx(w_map, y, x); x2 = x; y2 = y; switch (c) { @@ -68,31 +82,56 @@ main(void) case '$': gold++; map->map[y2][x2] = ' '; - mvaddch(y2, x2, ' '); + mvwaddch(w_map, y2, x2, ' '); + mvwprintw(w_gold, 0, 0, "gold:%d", gold); /* FALL */ case ' ': - mvprintw(0, 0, "%d:%d", x2, y2); - move(y2, x2); + mvwprintw(w_pos, 0, 0, "pos: %d,%d", x2, y2); + wmove(w_map, y2, x2); see(map, y2, x2); break; case '*': - mvprintw(H/2, 10, "AUSGANG gefunden!"); + mvwprintw(w_map, H-5, 10, "AUSGANG gefunden!"); goto exit; default: continue; } - mvprintw(0, 40, "<%c> gold:%d", c2, gold); - move(y2, x2); + mvwprintw(w_pos, 0, 10, "<%c>", c2); + wmove(w_map, y2, x2); - refresh(); - napms(10); + draw(); } exit: +/* mvprintw(H, 0, "press key to exit..."); getch(); +*/ endwin(); return 0; } +static void +draw(void) +{ +/* +*/ + refresh(); + wrefresh(w_info); + wrefresh(w_gold); + wrefresh(w_pos); + overlay(w_gold, w_info); + overlay(w_pos, w_info); + wrefresh(w_title); + wrefresh(w_mapborder); + overlay(w_map, w_mapborder); + wrefresh(w_map); +} + +static void +wboxborder(WINDOW *win) +{ + wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); +} + diff --git a/main.h b/main.h index 7cce2ec..e513f97 100644 --- a/main.h +++ b/main.h @@ -13,8 +13,15 @@ enum { W = 80, T = 1, SEEDIST = 4, + MAPH = 24, + MAPW = 80, + BORDER = 1, }; +WINDOW *w_map, *w_mapborder; +WINDOW *w_hud, *w_pos, *w_info, *w_gold; +WINDOW *w_title; + struct map { char *name; char map[24][80]; diff --git a/map.c b/map.c index 92a8d92..4c548e6 100644 --- a/map.c +++ b/map.c @@ -20,8 +20,8 @@ readmap(char *fname) return NULL; } - for (y=0; ymap[y][x] = fgetc(fp); } if (fgetc(fp) != '\n') { @@ -39,8 +39,8 @@ beautifymap(struct map *map) int x, y; char c; - for (y=0; ymap[y][x]; if (c != '#') { continue; @@ -48,8 +48,8 @@ beautifymap(struct map *map) map->map[y][x] = getnewchar(map, y, x); } } - for (y=0; ymap[y][x]; if (c == '#') { map->map[y][x] = ' '; @@ -94,7 +94,7 @@ getnewchar(struct map *map, int y, int x) l = strchr(WALLCHARS, l) ? '#' : ' '; r = x+1 > W ? '#' : map->map[y][x+1]; r = strchr(WALLCHARS, r) ? '#' : ' '; - a = y-1 < T ? '#' : map->map[y-1][x]; + a = y-1 < 0 ? '#' : map->map[y-1][x]; a = strchr(WALLCHARS, a) ? '#' : ' '; b = y+1 > H ? '#' : map->map[y+1][x]; b = strchr(WALLCHARS, b) ? '#' : ' '; @@ -141,17 +141,17 @@ see(struct map *map, int ypos, int xpos) int y, x; for (y=ypos-SEEDIST; y <= ypos+SEEDIST; y++) { - if (y=H) { + if (y<0 || y>=MAPH) { continue; } for (x=xpos-SEEDIST; x <= xpos+SEEDIST; x++) { - if (x<0 || x>=W) { + if (x<0 || x>=MAPW) { continue; } - mvaddch(y, x, map->map[y][x]); + mvwaddch(w_map, y, x, map->map[y][x]); } } - move(ypos, xpos); + wmove(w_map, ypos, xpos); } void @@ -169,8 +169,8 @@ findchar(struct map *map, char c, int *yret, int *xret) { int y, x; - for (y=0; ymap[y][x] == c) { *yret = y; *xret = x; @@ -185,10 +185,10 @@ showmap(struct map *map) { int x, y; - mvprintw(0, 60, "map: %s", map->name); - for (y=T; ymap[y][x]); + mvwprintw(w_info, 1, 20, "map: %s", map->name); + for (y=0; ymap[y][x]); } } }