feat: screen is made and basic things are in to make the game
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+15
-7
@@ -1,11 +1,19 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(pong)
|
project(pong)
|
||||||
include_directories(include)
|
|
||||||
set(SOURCES src/main.cpp)
|
|
||||||
add_executable(pong ${SOURCES})
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
set(CMAKE_C_STANDARD 23)
|
set(CMAKE_C_STANDARD 23)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
include_directories(include)
|
||||||
|
|
||||||
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
|
set(SOURCES
|
||||||
# target_link_libraries(Game PRIVATE SDL3::SDL3)
|
src/main.cpp
|
||||||
|
src/input.cpp
|
||||||
|
src/window.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(pong ${SOURCES})
|
||||||
|
|
||||||
|
find_package(Curses REQUIRED)
|
||||||
|
include_directories(${CURSES_INCLUDE_DIR})
|
||||||
|
target_link_libraries(pong ${CURSES_LIBRARIES})
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef GLOBALS_HPP
|
||||||
|
#define GLOBALS_HPP
|
||||||
|
|
||||||
|
constexpr unsigned int ROW = 10;
|
||||||
|
constexpr unsigned int COL = 20;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef INPUT_HPP
|
||||||
|
#define INPUT_HPP
|
||||||
|
|
||||||
|
struct Input {
|
||||||
|
int m_current_key = 0;
|
||||||
|
char m_getch = ' ';
|
||||||
|
void get_input(bool &r);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INPUT_HPP
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef WINDOW_HPP
|
||||||
|
#define WINDOW_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include "globals.hpp"
|
||||||
|
|
||||||
|
struct Window {
|
||||||
|
Window();
|
||||||
|
std::array<std::array<char, COL>, ROW> m_board;
|
||||||
|
void update_display();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
@@ -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 <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() {
|
int main() {
|
||||||
std::cout << "Hello World" << std::endl;
|
while (running) {
|
||||||
|
window.update_display();
|
||||||
|
}
|
||||||
|
|
||||||
|
input_thread.join();
|
||||||
return 0;
|
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