wip
This commit is contained in:
+8
-8
@@ -5,22 +5,18 @@
|
||||
#include <thread>
|
||||
|
||||
void Window::clear_display() {
|
||||
clear();
|
||||
for(auto &row : view) {
|
||||
row.fill('.');
|
||||
}
|
||||
}
|
||||
|
||||
void Window::draw_display() const {
|
||||
std::cout << "\033[H" << std::flush; // Clear screen
|
||||
std::string output;
|
||||
for(const auto &row : view) {
|
||||
for(const auto val : row) {
|
||||
output += std::isprint(val) ? val : '.';
|
||||
output += ' ';
|
||||
for(int i = 0; i < ROW; i++) {
|
||||
for(int j = 0; j < COL; j++) {
|
||||
mvaddch(i, j * 2, view[i][j]);
|
||||
}
|
||||
output.append("\r\n");
|
||||
}
|
||||
std::cout << output;
|
||||
}
|
||||
|
||||
void Window::update_display(const vec2 &ball, const Paddle &p1, const Paddle &p2) {
|
||||
@@ -57,6 +53,9 @@ Engine::Engine() {
|
||||
nodelay(stdscr, true);
|
||||
keypad(stdscr, true);
|
||||
last_clock_update = std::chrono::steady_clock::now();
|
||||
for(auto &row : win.view) {
|
||||
row.fill('.');
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::run() {
|
||||
@@ -72,6 +71,7 @@ void Engine::run() {
|
||||
win.clear_display();
|
||||
win.update_display(ball, p1, p2);
|
||||
win.draw_display();
|
||||
refresh();
|
||||
auto current_time = std::chrono::steady_clock::now();
|
||||
auto elapsed_time = std::chrono::duration_cast<std::chrono::seconds>(current_time - last_clock_update).count();
|
||||
if(elapsed_time >= 1) {
|
||||
|
||||
Reference in New Issue
Block a user