Added "color" retaining transparancy. Pixels are now drawn solid

This commit is contained in:
Sheldon Lee
2020-06-18 22:26:14 +01:00
parent 5a8285eb31
commit 59f7bfa061
2 changed files with 22 additions and 8 deletions
+14 -6
View File
@@ -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();