diff --git a/CMakeLists.txt b/CMakeLists.txt index 176099d..57f7d5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES src/main.cpp src/window.cpp src/input.cpp + src/elements.cpp ) add_executable(flappy_bird ${SOURCES}) diff --git a/README.md b/README.md index 488b845..e69de29 100644 --- a/README.md +++ b/README.md @@ -1 +0,0 @@ -I am experiemnting with using pointers instead of references for parameters to try to understand how they work. Don't yell at me if its not the most optimial or safe. diff --git a/include/elements.hpp b/include/elements.hpp index 7087db1..99aca86 100644 --- a/include/elements.hpp +++ b/include/elements.hpp @@ -2,13 +2,14 @@ #define ELEMENTS_HPP struct Point { + Point(); Point(int row, int col) : m_row(row), m_col(col) {}; int m_row; int m_col; }; struct Bird { - + Point m_body; }; #endif diff --git a/include/input.hpp b/include/input.hpp index 00f083d..6088d1f 100644 --- a/include/input.hpp +++ b/include/input.hpp @@ -1,10 +1,10 @@ #ifndef INPUT_HPP #define INPUT_HPP -// #include "elements.hpp" +#include "elements.hpp" struct Input { int _getch = 0; - void get_input(bool &running); + void get_input(bool &running, Bird &bird); }; #endif diff --git a/include/window.hpp b/include/window.hpp index 0e541f0..780595e 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -3,11 +3,11 @@ #include #include "globals.hpp" -// #include "elements.hpp" +#include "elements.hpp" struct Window { std::array, ROW> m_board = {}; - void update_display(); + void update_display(Bird &bird); }; #endif diff --git a/src/elements.cpp b/src/elements.cpp index e69de29..ca9eb3c 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -0,0 +1,6 @@ +#include "elements.hpp" + +Point::Point() { + m_row = 0; + m_col = 0; +} diff --git a/src/input.cpp b/src/input.cpp index f25d214..d112c5f 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1,7 +1,7 @@ #include #include "input.hpp" -void Input::get_input(bool &running) { +void Input::get_input(bool &running, Bird &bird) { while(running) { initscr(); cbreak(); @@ -10,6 +10,9 @@ void Input::get_input(bool &running) { _getch = getch(); endwin(); + if(_getch == 32) { + + } if(_getch == 113) { running = false; } diff --git a/src/main.cpp b/src/main.cpp index 8c85b48..f4edb72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,18 @@ #include #include "window.hpp" #include "input.hpp" +#include "elements.hpp" int main() { Window window; Input input; + Bird bird; bool running = true; - std::thread input_thread(&Input::get_input, &input, std::ref(running)); + std::thread input_thread(&Input::get_input, &input, std::ref(running), std::ref(bird)); while (running) { - window.update_display(); + window.update_display(bird); } input_thread.join(); diff --git a/src/window.cpp b/src/window.cpp index 737d028..5c47c3d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -3,9 +3,11 @@ #include #include -void Window::update_display() { +void Window::update_display(Bird &bird) { for(std::array &row : m_board) { row.fill('.'); } + m_board[bird.m_body.m_row][bird.m_body.m_col] = '*'; + std::cout << "\033[H" << std::flush; for(std::array &row : m_board) { for(char &col : row) {