diff --git a/.cache/clangd/index/globals.hpp.CBE5601C6A3AB110.idx b/.cache/clangd/index/globals.hpp.CBE5601C6A3AB110.idx new file mode 100644 index 0000000..42be9d2 Binary files /dev/null and b/.cache/clangd/index/globals.hpp.CBE5601C6A3AB110.idx differ diff --git a/.cache/clangd/index/input.cpp.528D820FC1026E99.idx b/.cache/clangd/index/input.cpp.528D820FC1026E99.idx new file mode 100644 index 0000000..6259be4 Binary files /dev/null and b/.cache/clangd/index/input.cpp.528D820FC1026E99.idx differ diff --git a/.cache/clangd/index/input.hpp.D5F1B614184DF267.idx b/.cache/clangd/index/input.hpp.D5F1B614184DF267.idx new file mode 100644 index 0000000..4ae1dcd Binary files /dev/null and b/.cache/clangd/index/input.hpp.D5F1B614184DF267.idx differ diff --git a/.cache/clangd/index/main.cpp.023CAAB69E7B9D8B.idx b/.cache/clangd/index/main.cpp.023CAAB69E7B9D8B.idx index 0f3baa9..5a4c361 100644 Binary files a/.cache/clangd/index/main.cpp.023CAAB69E7B9D8B.idx and b/.cache/clangd/index/main.cpp.023CAAB69E7B9D8B.idx differ diff --git a/.cache/clangd/index/window.cpp.3211998378C3868C.idx b/.cache/clangd/index/window.cpp.3211998378C3868C.idx new file mode 100644 index 0000000..b39f072 Binary files /dev/null and b/.cache/clangd/index/window.cpp.3211998378C3868C.idx differ diff --git a/.cache/clangd/index/window.hpp.F4C2E5CFEA29DA46.idx b/.cache/clangd/index/window.hpp.F4C2E5CFEA29DA46.idx new file mode 100644 index 0000000..450679a Binary files /dev/null and b/.cache/clangd/index/window.hpp.F4C2E5CFEA29DA46.idx differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 794ca4e..9620c6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,19 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(pong) -include_directories(include) -set(SOURCES src/main.cpp) -add_executable(pong ${SOURCES}) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) +include_directories(include) -# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg -# target_link_libraries(Game PRIVATE SDL3::SDL3) +set(SOURCES + src/main.cpp + src/input.cpp + src/window.cpp +) + +add_executable(pong ${SOURCES}) + +find_package(Curses REQUIRED) +include_directories(${CURSES_INCLUDE_DIR}) +target_link_libraries(pong ${CURSES_LIBRARIES}) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/include/globals.hpp b/include/globals.hpp new file mode 100644 index 0000000..f606eb7 --- /dev/null +++ b/include/globals.hpp @@ -0,0 +1,7 @@ +#ifndef GLOBALS_HPP +#define GLOBALS_HPP + +constexpr unsigned int ROW = 10; +constexpr unsigned int COL = 20; + +#endif diff --git a/include/input.hpp b/include/input.hpp new file mode 100644 index 0000000..6184d02 --- /dev/null +++ b/include/input.hpp @@ -0,0 +1,10 @@ +#ifndef INPUT_HPP +#define INPUT_HPP + +struct Input { + int m_current_key = 0; + char m_getch = ' '; + void get_input(bool &r); +}; + +#endif // INPUT_HPP diff --git a/include/window.hpp b/include/window.hpp new file mode 100644 index 0000000..4124807 --- /dev/null +++ b/include/window.hpp @@ -0,0 +1,12 @@ +#ifndef WINDOW_HPP +#define WINDOW_HPP + +#include +#include "globals.hpp" + +struct Window { + Window(); + std::array, ROW> m_board; + void update_display(); +}; +#endif diff --git a/src/input.cpp b/src/input.cpp new file mode 100644 index 0000000..b36d190 --- /dev/null +++ b/src/input.cpp @@ -0,0 +1,25 @@ +#include "input.hpp" +#include + +void Input::get_input(bool &running) { + while(running) { + initscr(); + cbreak(); + noecho(); + + m_getch = getch(); + endwin(); + // if(m_current_key != 1 && (m_getch == 'a' || m_getch == 'D')) { + // direction = m_current_key = -1; + // } else if(m_current_key != - 1 && (m_getch == 'd' || m_getch == 'C')) { + // direction = m_current_key = 1; + // } else if(m_current_key != -2 && (m_getch == 's' || m_getch == 'B')) { + // direction = m_current_key = 2; + // } else if(m_current_key != 2 && (m_getch == 'w' || m_getch == 'A')) { + // direction = m_current_key = -2; + if(m_getch == 'q') { + running = false; + } + } + +} diff --git a/src/main.cpp b/src/main.cpp index 1055224..a3bfd33 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,18 @@ #include +#include +#include "input.hpp" +#include "window.hpp" + +bool running = true; +Input input; +Window window; +std::thread input_thread(&Input::get_input, &input, std::ref(running)); int main() { - std::cout << "Hello World" << std::endl; + while (running) { + window.update_display(); + } + + input_thread.join(); return 0; } diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..0c1ea2e --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,33 @@ +#include "window.hpp" +#include +#include +#include + +Window::Window() { + for(std::array &row : m_board) { row.fill('.'); } +} + +void Window::update_display() { +// // Update symbols of positions +// m_board[head.m_head.m_row][head.m_head.m_col] = '*'; +// m_board[fruit.m_point.m_row][fruit.m_point.m_col] = 'X'; +// for(int i = 0; i < body.m_body.size(); i++) { +// m_board[body.m_body.at(i).m_tail_pos.m_row][body.m_body.at(i).m_tail_pos.m_col] = '0'; +// } +// + std::cout << "\033[H" << std::flush; // Clear screen + // Draw Screen + for(std::array &row : m_board) { + for(char &col : row) { + std::cout << col << " "; + } + std::cout << "\r\n"; + } + std::this_thread::sleep_for(std::chrono::milliseconds((int) (200))); // 1000 / fps; 200ms = 5fps +// // Clear old spaces +// for(int i = 0; i < body.m_body.size(); i++) { +// body.m_body.at(i).m_tail_pos.clear(m_board); +// } +// head.m_head.clear(m_board); +// fruit.m_point.clear(m_board); +}