Added "color" retaining transparancy. Pixels are now drawn solid
This commit is contained in:
parent
5a8285eb31
commit
59f7bfa061
10
grid.c
10
grid.c
@ -96,10 +96,16 @@ void drawGrid(Grid* grid)
|
||||
unsigned int width, height;
|
||||
width = grid->width;
|
||||
height = grid->size/width;
|
||||
// Init color pair init_pair(index, fg, bg);
|
||||
init_pair(1, COLOR_BLUE, COLOR_WHITE);
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
if (grid->state[toIndex(grid, x, y)]) mvprintw(y, x, "X");
|
||||
else mvprintw(y, x, " ");
|
||||
if (grid->state[toIndex(grid, x, y)]){
|
||||
attron(COLOR_PAIR(1));
|
||||
mvaddch(y, x, ' ');
|
||||
attroff(COLOR_PAIR(1));
|
||||
}
|
||||
else mvaddch(y, x, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
main.c
20
main.c
@ -15,6 +15,10 @@ int main()
|
||||
bool running = true;
|
||||
initscr();
|
||||
raw();
|
||||
// allows for transparancy when color values in init_pair(); are set to -1 or, no pair specified
|
||||
// e.g init_pair(1, COLOR_WHITE, -1) would be transparent background but white text
|
||||
use_default_colors();
|
||||
start_color();
|
||||
// doesn't wait for user to input.
|
||||
// timeout(100) waits for 100ms for input.
|
||||
timeout(0);
|
||||
@ -26,8 +30,9 @@ int main()
|
||||
// stdscr is screen created by initscr()
|
||||
getmaxyx(stdscr, height, width);
|
||||
|
||||
// hz
|
||||
const int FRAME_RATE = 100;
|
||||
// framerate of the game
|
||||
const int FRAME_RATE = 30;
|
||||
const float FRAME_TIME = 1.f/(double)FRAME_RATE;
|
||||
|
||||
const int DELAY = (float)pow(10,6)/(float)FRAME_RATE;
|
||||
|
||||
@ -41,14 +46,17 @@ int main()
|
||||
char ch = getch();
|
||||
if (ch == 'q') running = false;
|
||||
|
||||
drawGrid(&grid);
|
||||
float actual_frame_time = (float) t / (float) CLOCKS_PER_SEC;
|
||||
|
||||
refresh();
|
||||
if (actual_frame_time >= FRAME_TIME) {
|
||||
drawGrid(&grid);
|
||||
refresh();
|
||||
updateGrid(&grid);
|
||||
t = 0;
|
||||
}
|
||||
|
||||
updateGrid(&grid);
|
||||
t += clock()-start_t;
|
||||
|
||||
usleep(DELAY);
|
||||
}
|
||||
|
||||
endwin();
|
||||
|
Loading…
Reference in New Issue
Block a user