feat: added bird, removed line in readme as it no longer applies
This commit is contained in:
@@ -8,6 +8,7 @@ set(SOURCES
|
||||
src/main.cpp
|
||||
src/window.cpp
|
||||
src/input.cpp
|
||||
src/elements.cpp
|
||||
)
|
||||
|
||||
add_executable(flappy_bird ${SOURCES})
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -3,11 +3,11 @@
|
||||
|
||||
#include <array>
|
||||
#include "globals.hpp"
|
||||
// #include "elements.hpp"
|
||||
#include "elements.hpp"
|
||||
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> m_board = {};
|
||||
void update_display();
|
||||
void update_display(Bird &bird);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "elements.hpp"
|
||||
|
||||
Point::Point() {
|
||||
m_row = 0;
|
||||
m_col = 0;
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,7 +1,7 @@
|
||||
#include <ncurses.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
+4
-2
@@ -2,16 +2,18 @@
|
||||
#include <thread>
|
||||
#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();
|
||||
|
||||
+3
-1
@@ -3,9 +3,11 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
void Window::update_display() {
|
||||
void Window::update_display(Bird &bird) {
|
||||
for(std::array<char, COL> &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<char, COL> &row : m_board) {
|
||||
for(char &col : row) {
|
||||
|
||||
Reference in New Issue
Block a user