diff --git a/README.md b/README.md index a30f8bd..899666f 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,6 @@ g++ levelmaker.cpp -o levelmaker -std=c++17 ...you will see a window like the one above, now you can create your own level by moving the cursor with `W`, `A`, `S`, `D` and placing or removing a block with `P` and `R`. ℹ️ - The blocks are placed under the `$` character if possible -⚠️ - Due to problems with raw input, you will have to press `ENTER` after each key press +⚠️ - Due to problems with raw input, you will have to press `ENTER` after each key press, since `v0.5` this is no longer the case for Linux users. Then you can save your level by pressing `Q` and the level will be saved in the `levels` folder. diff --git a/fullkning b/fullkning new file mode 100755 index 0000000..19afe8f Binary files /dev/null and b/fullkning differ diff --git a/fullkning.cpp b/fullkning.cpp index 364d5bf..7bee791 100644 --- a/fullkning.cpp +++ b/fullkning.cpp @@ -23,6 +23,31 @@ tcsetattr(0, TCSANOW, &noecho); } +#elif __linux__ + #include + #include + + char getch(void) { + char buf = 0; + struct termios old = {0}; + fflush(stdout); + if(tcgetattr(0, &old) < 0) + perror("tcsetattr()"); + old.c_lflag &= ~ICANON; + old.c_lflag &= ~ECHO; + old.c_cc[VMIN] = 1; + old.c_cc[VTIME] = 0; + if(tcsetattr(0, TCSANOW, &old) < 0) + perror("tcsetattr ICANON"); + if(read(0, &buf, 1) < 0) + perror("read()"); + old.c_lflag |= ICANON; + old.c_lflag |= ECHO; + if(tcsetattr(0, TCSADRAIN, &old) < 0) + perror("tcsetattr ~ICANON"); + // printf("%c\n", buf); + return buf; + } #endif #define WIDTH 10 @@ -326,8 +351,8 @@ int main(int argc, char* argv[]) { return getch(); #elif __APPLE__ return getchar(); - #else - return getchar(); + #elif __linux__ + return (int)getch(); #endif }); while (future.wait_for(std::chrono::milliseconds(300)) != std::future_status::ready) { @@ -346,6 +371,9 @@ int main(int argc, char* argv[]) { std::cout << "Cooldown: " << std::max(game::frame_countdown, (short)0) << " "; cursor.set(14, 15); std::cout << "Selected: " << (game::hooked_block == BlockType::Sand ? "Sand" : "Stone") << " "; + #if __linux__ // Ubuntu 22.04 has a low refresh rate... + std::cout << std::flush; + #endif } if (victory()) break; @@ -382,9 +410,9 @@ int main(int argc, char* argv[]) { } else { std::cout << "You won with " << game::score << " points!" << std::endl; } - #ifdef _WIN32 + #if defined(_WIN32) or defined(__linux__) getch(); - #else + #elif __APPLE__ getchar(); #endif return 0; diff --git a/levelmaker b/levelmaker new file mode 100755 index 0000000..0d38b62 Binary files /dev/null and b/levelmaker differ diff --git a/levelmaker.cpp b/levelmaker.cpp index b3cbdda..c0a2aff 100644 --- a/levelmaker.cpp +++ b/levelmaker.cpp @@ -3,6 +3,31 @@ #include #ifdef _WIN32 #include +#elif __linux__ + #include + #include + + char getch(void) { + char buf = 0; + struct termios old = {0}; + fflush(stdout); + if(tcgetattr(0, &old) < 0) + perror("tcsetattr()"); + old.c_lflag &= ~ICANON; + old.c_lflag &= ~ECHO; + old.c_cc[VMIN] = 1; + old.c_cc[VTIME] = 0; + if(tcsetattr(0, TCSANOW, &old) < 0) + perror("tcsetattr ICANON"); + if(read(0, &buf, 1) < 0) + perror("read()"); + old.c_lflag |= ICANON; + old.c_lflag |= ECHO; + if(tcsetattr(0, TCSADRAIN, &old) < 0) + perror("tcsetattr ~ICANON"); + // printf("%c\n", buf); + return buf; + } #endif #define WIDTH 10 @@ -46,7 +71,7 @@ int main(int argc, char* argv[]) { std::cout << "Use {Q}+ENTER to quit" << std::endl; while (true) { - #ifdef _WIN32 + #if _WIN32 or __linux__ char input = getch(); #elif __APPLE__ cursor_handler.set({20, 30});