diff --git a/worlds/1.txt b/1.world.txt similarity index 100% rename from worlds/1.txt rename to 1.world.txt diff --git a/worlds/2.txt b/2.world.txt similarity index 100% rename from worlds/2.txt rename to 2.world.txt diff --git a/worlds/3.txt b/3.world.txt similarity index 100% rename from worlds/3.txt rename to 3.world.txt diff --git a/worlds/4.txt b/4.world.txt similarity index 100% rename from worlds/4.txt rename to 4.world.txt diff --git a/worlds/5.txt b/5.world.txt similarity index 100% rename from worlds/5.txt rename to 5.world.txt diff --git a/COMPILE.txt b/COMPILE.txt index 3754a16..f06506d 100644 --- a/COMPILE.txt +++ b/COMPILE.txt @@ -1 +1,2 @@ -g++ -std=c++23 -Wall ./src/main.cpp -o ./build/testCompiled && ./build/testCompiled \ No newline at end of file +mkdir build +g++ -std=c++23 -Wall ./main.cpp -o ./build/testCompiled && ./build/testCompiled \ No newline at end of file diff --git a/README.md b/README.md index dd89264..75167cf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# Adventura - Simple terminal game made in 24 hours +# Adventura by Martin Prokoph + Simple terminal game created for the GdP module at HTWK Leipzig diff --git a/TEST.txt b/TEST.txt index a2f38e7..a6f203a 100644 --- a/TEST.txt +++ b/TEST.txt @@ -1,4 +1,4 @@ -Führe das Programm mit dem Argument --test aus +Für einen automatisierten Test, führe das Programm mit dem Argument --test aus asdddddddddddddddwwwwwwddddddwwwwdddd aaaaaaassssssddddssssdddddddddddwwwwwddddddwwwwdddddddddddddddddddd diff --git a/src/block.hpp b/block.hpp similarity index 100% rename from src/block.hpp rename to block.hpp diff --git a/src/blockPos.hpp b/blockPos.hpp similarity index 100% rename from src/blockPos.hpp rename to blockPos.hpp diff --git a/src/blockRegistry.hpp b/blockRegistry.hpp similarity index 100% rename from src/blockRegistry.hpp rename to blockRegistry.hpp diff --git a/src/blockSettings.hpp b/blockSettings.hpp similarity index 100% rename from src/blockSettings.hpp rename to blockSettings.hpp diff --git a/src/color.hpp b/color.hpp similarity index 100% rename from src/color.hpp rename to color.hpp diff --git a/screens/completed_single_level.txt b/completed_single_level.screen.txt similarity index 100% rename from screens/completed_single_level.txt rename to completed_single_level.screen.txt diff --git a/screens/death.txt b/death.screen.txt similarity index 100% rename from screens/death.txt rename to death.screen.txt diff --git a/src/fileutils.hpp b/fileutils.hpp similarity index 85% rename from src/fileutils.hpp rename to fileutils.hpp index 136e587..d2bef13 100644 --- a/src/fileutils.hpp +++ b/fileutils.hpp @@ -37,13 +37,15 @@ string readInput(string feedback) { * This is used to progress through the worlds in the correct order. * * @param dir The directory to get the file names from + * @param extension The file extension to filter by * @return A list of all file names in the specified directory, sorted alphabetically. */ -vector getOrderedFileNames(string dir) { +vector getOrderedFileNames(string dir, string extension) { vector worlds; - // Iterate over all files in the worlds directory + // This used to be so elegant and iterate over all files in the worlds directory, + // but because of the weird restriction with no folders being allowed, we just filter the files based on their extension. for (auto & entry : std::filesystem::directory_iterator(dir)) { - worlds.push_back(entry.path()); + if (static_cast(entry.path()).ends_with(extension)) worlds.push_back(entry.path()); } // We use this to sort the worlds alphabetically, so that the game progresses in the correct order. std::sort( worlds.begin(), worlds.end(), [](string a, string b) { diff --git a/screens/help.txt b/help.screen.txt similarity index 100% rename from screens/help.txt rename to help.screen.txt diff --git a/src/identifier.hpp b/identifier.hpp similarity index 100% rename from src/identifier.hpp rename to identifier.hpp diff --git a/src/main.cpp b/main.cpp similarity index 81% rename from src/main.cpp rename to main.cpp index 8d4746a..29bb5f1 100644 --- a/src/main.cpp +++ b/main.cpp @@ -15,7 +15,6 @@ using std::cout; using std::endl; bool startWorld(string worldFile); -vector getOrderedFileNames(string dir); bool testMode = false; unsigned int worldIndex = 2; @@ -40,27 +39,27 @@ int main(int argc, char *argv[]) { if (!startWorld("./worlds/" + string(argv[i+1]))) return 0; // Load only the specified world else - printFile("./screens/completed_single_level.txt", Color::BRIGHT_GREEN); + printFile("./completed_single_level.screen.txt", Color::BRIGHT_GREEN); return 0; } } if (!testMode) { - printFile("./screens/help.txt", Color::BRIGHT_BLUE); // Print help screen + printFile("./help.screen.txt", Color::BRIGHT_BLUE); // Print help screen return 0; } } if (!testMode) { - printFile("./screens/start.txt", Color::BRIGHT_YELLOW); + printFile("./start.screen.txt", Color::BRIGHT_YELLOW); waitForInput(); printGuide(); waitForInput(); } // Load every world in order - for (const auto & world : getOrderedFileNames("./worlds")) + for (const auto & world : getOrderedFileNames("./", ".world.txt")) if (!startWorld(world)) return 0; // Print the victory screen once all levels have been completed - printFile("./screens/victory.txt", Color::BRIGHT_GREEN); + printFile("./victory.screen.txt", Color::BRIGHT_GREEN); return 0; } @@ -82,6 +81,6 @@ bool startWorld(string worldFile) { inputLoop(player, world, testMode, worldIndex); worldIndex++; - if (!player.isAlive()) printFile("./screens/death.txt", Color::BRIGHT_RED); + if (!player.isAlive()) printFile("./death.screen.txt", Color::BRIGHT_RED); return player.hasReachedGoal(); } \ No newline at end of file diff --git a/src/movementHandler.hpp b/movementHandler.hpp similarity index 98% rename from src/movementHandler.hpp rename to movementHandler.hpp index 9dc7215..d64b595 100644 --- a/src/movementHandler.hpp +++ b/movementHandler.hpp @@ -6,9 +6,6 @@ #include "blockRegistry.hpp" #include "output.hpp" -bool tryWalk(World& world, Player& player, bool left); -bool tryGoDown(World& world, Player& player); -bool tryGoUp(World& world, Player& player); void tryPushBlock(BlockPos& blockPos, World& world, bool left); void tryBlockGravity(BlockPos& blockPos, World& world); @@ -38,41 +35,6 @@ void waitForInput() { while (!is_in(lastChar, 'w', 'a', 's', 'd')) cin >> lastChar; } - -/** - * Processes the player's input and attempts to move the player in the game world - * based on the input character. Supports moving up, left, down, or right - * using the keys 'w', 'a', 's', 'd' as well as their upper-case equivalents (useful in case caps lock is pressed by accident). - * - * @param lastChar The character input representing the player's movement command. - * @param world Reference to the World object representing the game's world. - * @param player Reference to the Player object representing the player's state. - * @return true if the player's position was successfully updated, false otherwise. - */ - -bool onInput(char lastChar, World& world, Player& player) { - switch (lastChar) { - case ' ': - case 'w': - case 'W': - return tryGoUp(world, player); - - case 'a': - case 'A': - return tryWalk(world, player, true); - - case 's': - case 'S': - return tryGoDown(world, player); - - case 'd': - case 'D': - return tryWalk(world, player, false); - - default: return false; - } -} - /** * Attempts to move the player one block to the left or right. * @@ -180,6 +142,40 @@ void tryBlockGravity(BlockPos& playerPos, World& world) { } } +/** + * Processes the player's input and attempts to move the player in the game world + * based on the input character. Supports moving up, left, down, or right + * using the keys 'w', 'a', 's', 'd' as well as their upper-case equivalents (useful in case caps lock is pressed by accident). + * + * @param lastChar The character input representing the player's movement command. + * @param world Reference to the World object representing the game's world. + * @param player Reference to the Player object representing the player's state. + * @return true if the player's position was successfully updated, false otherwise. + */ + +bool onInput(char lastChar, World& world, Player& player) { + switch (lastChar) { + case ' ': + case 'w': + case 'W': + return tryGoUp(world, player); + + case 'a': + case 'A': + return tryWalk(world, player, true); + + case 's': + case 'S': + return tryGoDown(world, player); + + case 'd': + case 'D': + return tryWalk(world, player, false); + + default: return false; + } +} + /** * Listens for the player's input and updates the game state accordingly. * If test mode is enabled, reads input from the file TEST.txt instead of the console. diff --git a/src/output.hpp b/output.hpp similarity index 100% rename from src/output.hpp rename to output.hpp diff --git a/src/player.hpp b/player.hpp similarity index 87% rename from src/player.hpp rename to player.hpp index ba3e62b..cca03d3 100644 --- a/src/player.hpp +++ b/player.hpp @@ -43,12 +43,17 @@ public: move(0, 1); } else { - if (fallLength > 5) alive = false; - fallLength = 0; playerTexture = REGULAR_PLAYER_TEXTURE; + if (fallLength > 5) unalive(); + fallLength = 0; } - if (world.getBlockAt(pos.add(0, 2)).getSettings().isLethal()) alive = false; + if (world.getBlockAt(pos.add(0, 2)).getSettings().isLethal()) unalive(); + } + void unalive() { + playerTexture = DEAD_PLAYER_TEXTURE; + redraw(world, this->mapToWorldspace()); + alive = false; } bool isAlive() { return alive; @@ -91,12 +96,16 @@ private: {' ', 'o', ' '}, {'/', '|', '\\'}, {'/', ' ', '\\'} - } // Player pos is at the center '|' char - }; + // Player pos is at the center '|' char + }}; const std::array, 3> FALLING_PLAYER_TEXTURE {{ {'\\', 'o', '/'}, {' ', '|', ' '}, {'/', ' ', '\\'} - } // Player pos is at the center '|' char - }; + }}; + const std::array, 3> DEAD_PLAYER_TEXTURE {{ + {' ', ' ', ' '}, + {'/', '-', 'X'}, + {'/', ' ', '\\'} + }}; }; \ No newline at end of file diff --git a/screens/start.txt b/start.screen.txt similarity index 100% rename from screens/start.txt rename to start.screen.txt diff --git a/screens/victory.txt b/victory.screen.txt similarity index 100% rename from screens/victory.txt rename to victory.screen.txt diff --git a/src/world.hpp b/world.hpp similarity index 100% rename from src/world.hpp rename to world.hpp