117 lines
3.1 KiB
C
117 lines
3.1 KiB
C
#include <curses.h>
|
|
#include "curses.h"
|
|
#include "../player.h"
|
|
#include "../game.h"
|
|
#include "../wall.h"
|
|
#include "../main.h"
|
|
#include "../common.h"
|
|
|
|
/*
|
|
Acceptable colors for foreground and background (from manpage, curs_color):
|
|
COLOR_BLACK
|
|
COLOR_RED
|
|
COLOR_GREEN
|
|
COLOR_YELLOW
|
|
COLOR_BLUE
|
|
COLOR_MAGENTA
|
|
COLOR_CYAN
|
|
COLOR_WHITE
|
|
|
|
Acceptable attributes (from manpage, curs_attr):
|
|
A_NORMAL Normal display (no highlight)
|
|
A_STANDOUT Best highlighting mode of the terminal.
|
|
A_UNDERLINE Underlining
|
|
A_REVERSE Reverse video
|
|
A_BLINK Blinking
|
|
A_DIM Half bright
|
|
A_BOLD Extra bright or bold
|
|
A_PROTECT Protected mode
|
|
A_INVIS Invisible or blank mode
|
|
A_ALTCHARSET Alternate character set
|
|
A_CHARTEXT Bit-mask to extract a character
|
|
*/
|
|
CursesTile ascii_walls[] = {
|
|
{'#', COLOR_WHITE, COLOR_BLACK, 0}, // 0=STONE_WALL
|
|
{'#', COLOR_YELLOW, COLOR_BLACK, 0}, // 1=WOOD_WALL
|
|
{'#', COLOR_WHITE, COLOR_BLACK, A_BOLD} // 2=STEEL_WALL
|
|
};
|
|
|
|
int interfaceInit() {
|
|
// initialize ncurses library
|
|
if ((screen = initscr()) == NULL) {
|
|
perror("initscr() error'd");
|
|
return ERROR;
|
|
}
|
|
original_cursor = curs_set(0); // store original cursor position for restore and hide cursor
|
|
keypad(screen, TRUE); // enable arrow keys/keypad
|
|
noecho(); // turn off key echoing
|
|
nonl(); // do not do NL->CR/NL on output
|
|
cbreak(); // Handle char presses immediately, do not wait for \n
|
|
|
|
if (has_colors()) {
|
|
start_color();
|
|
// set up all possible color pairs using COLORS as our max (8 default)
|
|
int x, y;
|
|
for (x=0;x<COLORS;x++) {
|
|
for(y=0;y<COLORS;y++) {
|
|
init_pair(x*COLORS+y, x, y);
|
|
}
|
|
}
|
|
}
|
|
return SUCCESS;
|
|
}
|
|
|
|
void interfaceLoop() {
|
|
int key = getch();
|
|
switch (key) {
|
|
case 'q':
|
|
case 'Q':
|
|
is_running = 0;
|
|
break;
|
|
case KEY_UP:
|
|
(*player_commands[PLAYER_MOVE])(NORTH, 1);
|
|
break;
|
|
case KEY_DOWN:
|
|
(*player_commands[PLAYER_MOVE])(SOUTH, 1);
|
|
break;
|
|
case KEY_RIGHT:
|
|
(*player_commands[PLAYER_MOVE])(EAST, 1);
|
|
break;
|
|
case KEY_LEFT:
|
|
(*player_commands[PLAYER_MOVE])(WEST, 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void interfaceDraw() {
|
|
//clear();
|
|
int step_x = player.x - 12;
|
|
int step_y = player.y - 6;
|
|
int end_x = player.x + 12;
|
|
int end_y = player.y + 6;
|
|
while (step_x < end_x) {
|
|
step_y = player.y - 6;
|
|
while (step_y < end_y) {
|
|
if (visible_matrix[step_x][step_y] & TILE_VISIBLE) {
|
|
//int color = temp->fg * COLORS + temp->bg;
|
|
//attron(COLOR_PAIR(color) | temp->attr);
|
|
mvwaddch(screen, step_y, step_x, ascii_walls[map_matrix[step_x][step_y].tile[0]->id].ch);
|
|
//attroff(COLOR_PAIR(color) | temp->attr);
|
|
} else {
|
|
mvwaddch(screen, step_y, step_x, ' ');
|
|
}
|
|
step_y++; // move down
|
|
}
|
|
step_x++; // move right
|
|
}
|
|
// draw player last
|
|
mvwaddch(screen, player.y, player.x, '@');
|
|
refresh();
|
|
}
|
|
|
|
void interfaceClose() {
|
|
delwin(screen);
|
|
endwin();
|
|
refresh();
|
|
}
|