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