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;
|
unsigned int width, height;
|
||||||
width = grid->width;
|
width = grid->width;
|
||||||
height = grid->size/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 y = 0; y < height; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
if (grid->state[toIndex(grid, x, y)]) mvprintw(y, x, "X");
|
if (grid->state[toIndex(grid, x, y)]){
|
||||||
else mvprintw(y, x, " ");
|
attron(COLOR_PAIR(1));
|
||||||
|
mvaddch(y, x, ' ');
|
||||||
|
attroff(COLOR_PAIR(1));
|
||||||
|
}
|
||||||
|
else mvaddch(y, x, ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
main.c
18
main.c
@ -15,6 +15,10 @@ int main()
|
|||||||
bool running = true;
|
bool running = true;
|
||||||
initscr();
|
initscr();
|
||||||
raw();
|
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.
|
// doesn't wait for user to input.
|
||||||
// timeout(100) waits for 100ms for input.
|
// timeout(100) waits for 100ms for input.
|
||||||
timeout(0);
|
timeout(0);
|
||||||
@ -26,8 +30,9 @@ int main()
|
|||||||
// stdscr is screen created by initscr()
|
// stdscr is screen created by initscr()
|
||||||
getmaxyx(stdscr, height, width);
|
getmaxyx(stdscr, height, width);
|
||||||
|
|
||||||
// hz
|
// framerate of the game
|
||||||
const int FRAME_RATE = 100;
|
const int FRAME_RATE = 30;
|
||||||
|
const float FRAME_TIME = 1.f/(double)FRAME_RATE;
|
||||||
|
|
||||||
const int DELAY = (float)pow(10,6)/(float)FRAME_RATE;
|
const int DELAY = (float)pow(10,6)/(float)FRAME_RATE;
|
||||||
|
|
||||||
@ -41,14 +46,17 @@ int main()
|
|||||||
char ch = getch();
|
char ch = getch();
|
||||||
if (ch == 'q') running = false;
|
if (ch == 'q') running = false;
|
||||||
|
|
||||||
|
float actual_frame_time = (float) t / (float) CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
if (actual_frame_time >= FRAME_TIME) {
|
||||||
drawGrid(&grid);
|
drawGrid(&grid);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
updateGrid(&grid);
|
updateGrid(&grid);
|
||||||
|
t = 0;
|
||||||
|
}
|
||||||
|
|
||||||
t += clock()-start_t;
|
t += clock()-start_t;
|
||||||
|
|
||||||
usleep(DELAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endwin();
|
endwin();
|
||||||
|
Loading…
Reference in New Issue
Block a user