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/main.cpp
|
||||||
src/window.cpp
|
src/window.cpp
|
||||||
src/input.cpp
|
src/input.cpp
|
||||||
|
src/elements.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(flappy_bird ${SOURCES})
|
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
|
#define ELEMENTS_HPP
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
|
Point();
|
||||||
Point(int row, int col) : m_row(row), m_col(col) {};
|
Point(int row, int col) : m_row(row), m_col(col) {};
|
||||||
int m_row;
|
int m_row;
|
||||||
int m_col;
|
int m_col;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Bird {
|
struct Bird {
|
||||||
|
Point m_body;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
#ifndef INPUT_HPP
|
#ifndef INPUT_HPP
|
||||||
#define INPUT_HPP
|
#define INPUT_HPP
|
||||||
// #include "elements.hpp"
|
#include "elements.hpp"
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
int _getch = 0;
|
int _getch = 0;
|
||||||
void get_input(bool &running);
|
void get_input(bool &running, Bird &bird);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-2
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
// #include "elements.hpp"
|
#include "elements.hpp"
|
||||||
|
|
||||||
struct Window {
|
struct Window {
|
||||||
std::array<std::array<char, COL>, ROW> m_board = {};
|
std::array<std::array<char, COL>, ROW> m_board = {};
|
||||||
void update_display();
|
void update_display(Bird &bird);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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 <ncurses.h>
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
|
|
||||||
void Input::get_input(bool &running) {
|
void Input::get_input(bool &running, Bird &bird) {
|
||||||
while(running) {
|
while(running) {
|
||||||
initscr();
|
initscr();
|
||||||
cbreak();
|
cbreak();
|
||||||
@@ -10,6 +10,9 @@ void Input::get_input(bool &running) {
|
|||||||
_getch = getch();
|
_getch = getch();
|
||||||
|
|
||||||
endwin();
|
endwin();
|
||||||
|
if(_getch == 32) {
|
||||||
|
|
||||||
|
}
|
||||||
if(_getch == 113) {
|
if(_getch == 113) {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -2,16 +2,18 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
|
#include "elements.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Window window;
|
Window window;
|
||||||
Input input;
|
Input input;
|
||||||
|
Bird bird;
|
||||||
bool running = true;
|
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) {
|
while (running) {
|
||||||
window.update_display();
|
window.update_display(bird);
|
||||||
}
|
}
|
||||||
|
|
||||||
input_thread.join();
|
input_thread.join();
|
||||||
|
|||||||
+3
-1
@@ -3,9 +3,11 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
void Window::update_display() {
|
void Window::update_display(Bird &bird) {
|
||||||
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
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;
|
std::cout << "\033[H" << std::flush;
|
||||||
for(std::array<char, COL> &row : m_board) {
|
for(std::array<char, COL> &row : m_board) {
|
||||||
for(char &col : row) {
|
for(char &col : row) {
|
||||||
|
|||||||
Reference in New Issue
Block a user