batman
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
build/
|
||||
.cache/
|
||||
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(flappy_bird)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
include_directories(include)
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
src/window.cpp
|
||||
src/input.cpp
|
||||
)
|
||||
|
||||
add_executable(flappy_bird ${SOURCES})
|
||||
|
||||
find_package(Curses REQUIRED)
|
||||
include_directories(${CURSES_INCLUDE_DIR})
|
||||
target_link_libraries(flappy_bird ${CURSES_LIBRARIES})
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
compile_commands.json
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef ELEMENTS_HPP
|
||||
#define ELEMENTS_HPP
|
||||
|
||||
struct Point {
|
||||
Point(int row, int col) : m_row(row), m_col(col) {};
|
||||
int m_row;
|
||||
int m_col;
|
||||
};
|
||||
|
||||
struct Bird {
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef GLOBALS_HPP
|
||||
#define GLOBALS_HPP
|
||||
|
||||
constexpr int ROW = 10;
|
||||
constexpr int COL = 10;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef INPUT_HPP
|
||||
#define INPUT_HPP
|
||||
// #include "elements.hpp"
|
||||
|
||||
struct Input {
|
||||
int _getch = 0;
|
||||
void get_input(bool &running);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef WINDOW_HPP
|
||||
#define WINDOW_HPP
|
||||
|
||||
#include <array>
|
||||
#include "globals.hpp"
|
||||
// #include "elements.hpp"
|
||||
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> m_board = {};
|
||||
void update_display();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <ncurses.h>
|
||||
#include "input.hpp"
|
||||
|
||||
void Input::get_input(bool &running) {
|
||||
while(running) {
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
_getch = getch();
|
||||
|
||||
endwin();
|
||||
if(_getch == 113) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "window.hpp"
|
||||
#include "input.hpp"
|
||||
|
||||
int main() {
|
||||
Window window;
|
||||
Input input;
|
||||
bool running = true;
|
||||
|
||||
std::thread input_thread(&Input::get_input, &input, std::ref(running));
|
||||
|
||||
while (running) {
|
||||
window.update_display();
|
||||
}
|
||||
|
||||
input_thread.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "window.hpp"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
void Window::update_display() {
|
||||
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
||||
|
||||
std::cout << "\033[H" << std::flush;
|
||||
for(std::array<char, COL> &row : m_board) {
|
||||
for(char &col : row) {
|
||||
std::cout << col << " ";
|
||||
}
|
||||
std::cout << "\r\n";
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // 1000 / fps; 200ms = 5fps
|
||||
}
|
||||
Reference in New Issue
Block a user