diff --git a/include/engine.hpp b/include/engine.hpp index 12482e8..39994be 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -1,5 +1,4 @@ -#ifndef ENGINE_HPP -#define ENGINE_HPP +#pragma once #include #include @@ -53,5 +52,3 @@ private: bool move_ball(); void on_collision_with_ball(); }; - -#endif diff --git a/src/engine.cpp b/src/engine.cpp index 30395a2..dc406d7 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -5,22 +5,18 @@ #include 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(current_time - last_clock_update).count(); if(elapsed_time >= 1) {