feat: screen is made and basic things are in to make the game
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#include "input.hpp"
|
||||
#include <ncurses.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+13
-1
@@ -1,6 +1,18 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "window.hpp"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
Window::Window() {
|
||||
for(std::array<char, COL> &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<char, COL> &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);
|
||||
}
|
||||
Reference in New Issue
Block a user