diff --git a/screens/death.txt b/screens/death.txt new file mode 100644 index 0000000..97d00ca --- /dev/null +++ b/screens/death.txt @@ -0,0 +1,5 @@ +┌────────────────────────────┐ +│ Du bist ▞▀▀▀▚ │ +│ G E S T O R B E N ▙▝ ▘▟ │ +│ R.I.P. ▚▞▞ │ +└────────────────────────────┘ diff --git a/screens/victory.txt b/screens/victory.txt new file mode 100644 index 0000000..0c3d9e7 --- /dev/null +++ b/screens/victory.txt @@ -0,0 +1,5 @@ +┌────────────────────────────┐ +│ Du hast ▚▒░▞ │ +│ G E W O N N E N ! ▙▟ │ +│ Yay :) ▟▙ │ +└────────────────────────────┘ diff --git a/src/blockRegistry.hpp b/src/blockRegistry.hpp index 51d82bc..4428aec 100644 --- a/src/blockRegistry.hpp +++ b/src/blockRegistry.hpp @@ -32,7 +32,8 @@ public: for (Block block : registeredBlocks) { if (block.getEncoding() == encoding) return block; } - return AIR; + if (encoding == '/' || encoding == '\\' || encoding == '|' || encoding == 'o') return AIR; // The static player defined in the level should not be part of the world + return Block(Identifier("decoration", string(1, encoding)), encoding, BlockSettingsBuilder().nonSolid().build()); // Keep other characters as decoration } private: diff --git a/src/main.cpp b/src/main.cpp index d54a318..a2265f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,14 +14,22 @@ namespace fs = std::filesystem; void render(World &world, Player &player); void redraw(World &world, Player &player); void jumpBackOneLine(); +void printFile(string fileLocation, Color color); bool startWorld(string worldFile); -int main() { - for (const auto & entry : fs::directory_iterator("./worlds")) - if (!startWorld(entry.path())) return 0; - +int main(int argc, char *argv[]) { + if (argc > 1) { + if (!startWorld("./worlds/" + string(argv[1]))) return 0; + } + else { + for (const auto & entry : fs::directory_iterator("./worlds")) + if (!startWorld(entry.path())) return 0; + } + printFile("./screens/victory.txt", Color::BRIGHT_GREEN); + return 0; } + bool startWorld(string worldFile) { BlockRegistry blockRegistry = BlockRegistry(); World world = World(blockRegistry); @@ -35,6 +43,7 @@ bool startWorld(string worldFile) { if (onInput(lastChar, world, player)) redraw(world, player); else jumpBackOneLine(); } + if (!player.isAlive()) printFile("./screens/death.txt", Color::BRIGHT_RED); return player.hasReachedGoal(); } void jumpBackOneLine() { @@ -65,4 +74,11 @@ void render(World &world, Player &player) { } cout << endl; } +} +void printFile(string fileLocation, Color color) { + cout << color; + vector file = readFileAsVector(fileLocation); + for (unsigned int y = 0; y < file.size(); y++) { + cout << file.at(y) << endl; + } } \ No newline at end of file diff --git a/src/movementHandler.hpp b/src/movementHandler.hpp index c9a3a11..d3239e7 100644 --- a/src/movementHandler.hpp +++ b/src/movementHandler.hpp @@ -29,8 +29,14 @@ bool onInput(char lastChar, World& world, Player& player) { } } bool tryWalk(World& world, Player& player, bool left) { - if (!world.getBlockAt(player.getPos()+(left ? BlockPos(-1, 1) : BlockPos(1, 1))).getSettings().hasCollision()) { - player.move(left ? BlockPos(-1, 0) : BlockPos(1,0)); + BlockPos neighbourPosTorso = player.getPos()+(left ? BlockPos(-1, 0) : BlockPos(1, 0)); + BlockPos neighbourPosFeet = player.getPos()+(left ? BlockPos(-1, 1) : BlockPos(1, 1)); + if (!world.getBlockAt(neighbourPosFeet).getSettings().hasCollision()) { + player.setPos(neighbourPosTorso); + return true; + } + else if (!left && world.getBlockAt(neighbourPosFeet).getSettings().hasCollision() && !world.getBlockAt(neighbourPosTorso).getSettings().isSolid()) { + left ? player.move(-1, -1) : player.move(1, -1); return true; } return false; @@ -47,13 +53,5 @@ bool tryGoUp(World& world, Player& player) { player.move(0, -1); return true; } - else if (world.getBlockAt(player.getPos()+BlockPos(1, 1)).getSettings().hasCollision() && !world.getBlockAt(player.getPos()+BlockPos(1, 0)).getSettings().isSolid()) { - player.move(1, -1); - return true; - } - else if (world.getBlockAt(player.getPos()+BlockPos(-1, 1)).getSettings().hasCollision() && !world.getBlockAt(player.getPos()+BlockPos(-1, 0)).getSettings().isSolid()) { - player.move(-1, -1); - return true; - } return false; } \ No newline at end of file diff --git a/src/player.hpp b/src/player.hpp index 7412b85..804d166 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -32,13 +32,17 @@ public: if (world.getBlockAt(pos) == world.getBlockRegistry().GOAL) reachedGoal = true; + isFreeFalling = !world.getBlockAt(pos+BlockPos(0, 2)).getSettings().isSolid(); if (isFreeFalling) { - move(BlockPos(0, 1)); fallLength += 1; - if (fallLength > 5) alive = false; + if (world.getBlockAt(pos+BlockPos(0, 2)) == world.getBlockRegistry().WATER) fallLength = 0; + move(BlockPos(0, 1)); + } + else { + if (fallLength > 5) alive = false; + fallLength = 0; } - else fallLength = 0; if (world.getBlockAt(pos+BlockPos(0, 2)).getSettings().isLethal()) alive = false; } diff --git a/worlds/3.txt b/worlds/3.txt index 1e4791c..ff349d4 100644 --- a/worlds/3.txt +++ b/worlds/3.txt @@ -1,15 +1,15 @@ - - ---------------------- - 00 - 00 - 00 ---------- -0 o 00----- O -0 S /|\ 00 0 -0 / \ 00 0 --------------- ----------------- 0 H 0 - 0 H 0 - 0 H 0 - 0 H 0 - 0~~~~~~0--------- - -------- + + ---------------------- + 00 <> + 00 <++> + 00 [+ +] +--------- [ ] +0 o 00------ O [ 7 ] +0 S /|\ 00 0 [ ] +0 / \ 00 0 --------------- +---------------- 0 H 0 + 0 H 0 + 0 H 0 + 0 H 0 + 0~~~~~~0---------0 + 00000000