mirror of
https://github.com/Motschen/Adventura.git
synced 2025-12-15 11:25:10 +01:00
Add victory & death screens
This commit is contained in:
5
screens/death.txt
Normal file
5
screens/death.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
┌────────────────────────────┐
|
||||||
|
│ Du bist ▞▀▀▀▚ │
|
||||||
|
│ G E S T O R B E N ▙▝ ▘▟ │
|
||||||
|
│ R.I.P. ▚▞▞ │
|
||||||
|
└────────────────────────────┘
|
||||||
5
screens/victory.txt
Normal file
5
screens/victory.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
┌────────────────────────────┐
|
||||||
|
│ Du hast ▚▒░▞ │
|
||||||
|
│ G E W O N N E N ! ▙▟ │
|
||||||
|
│ Yay :) ▟▙ │
|
||||||
|
└────────────────────────────┘
|
||||||
@@ -32,7 +32,8 @@ public:
|
|||||||
for (Block block : registeredBlocks) {
|
for (Block block : registeredBlocks) {
|
||||||
if (block.getEncoding() == encoding) return block;
|
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:
|
private:
|
||||||
|
|||||||
24
src/main.cpp
24
src/main.cpp
@@ -14,14 +14,22 @@ namespace fs = std::filesystem;
|
|||||||
void render(World &world, Player &player);
|
void render(World &world, Player &player);
|
||||||
void redraw(World &world, Player &player);
|
void redraw(World &world, Player &player);
|
||||||
void jumpBackOneLine();
|
void jumpBackOneLine();
|
||||||
|
void printFile(string fileLocation, Color color);
|
||||||
bool startWorld(string worldFile);
|
bool startWorld(string worldFile);
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char *argv[]) {
|
||||||
for (const auto & entry : fs::directory_iterator("./worlds"))
|
if (argc > 1) {
|
||||||
if (!startWorld(entry.path())) return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startWorld(string worldFile) {
|
bool startWorld(string worldFile) {
|
||||||
BlockRegistry blockRegistry = BlockRegistry();
|
BlockRegistry blockRegistry = BlockRegistry();
|
||||||
World world = World(blockRegistry);
|
World world = World(blockRegistry);
|
||||||
@@ -35,6 +43,7 @@ bool startWorld(string worldFile) {
|
|||||||
if (onInput(lastChar, world, player)) redraw(world, player);
|
if (onInput(lastChar, world, player)) redraw(world, player);
|
||||||
else jumpBackOneLine();
|
else jumpBackOneLine();
|
||||||
}
|
}
|
||||||
|
if (!player.isAlive()) printFile("./screens/death.txt", Color::BRIGHT_RED);
|
||||||
return player.hasReachedGoal();
|
return player.hasReachedGoal();
|
||||||
}
|
}
|
||||||
void jumpBackOneLine() {
|
void jumpBackOneLine() {
|
||||||
@@ -65,4 +74,11 @@ void render(World &world, Player &player) {
|
|||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void printFile(string fileLocation, Color color) {
|
||||||
|
cout << color;
|
||||||
|
vector<string> file = readFileAsVector(fileLocation);
|
||||||
|
for (unsigned int y = 0; y < file.size(); y++) {
|
||||||
|
cout << file.at(y) << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +29,14 @@ bool onInput(char lastChar, World& world, Player& player) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool tryWalk(World& world, Player& player, bool left) {
|
bool tryWalk(World& world, Player& player, bool left) {
|
||||||
if (!world.getBlockAt(player.getPos()+(left ? BlockPos(-1, 1) : BlockPos(1, 1))).getSettings().hasCollision()) {
|
BlockPos neighbourPosTorso = player.getPos()+(left ? BlockPos(-1, 0) : BlockPos(1, 0));
|
||||||
player.move(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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -47,13 +53,5 @@ bool tryGoUp(World& world, Player& player) {
|
|||||||
player.move(0, -1);
|
player.move(0, -1);
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -32,13 +32,17 @@ public:
|
|||||||
|
|
||||||
if (world.getBlockAt(pos) == world.getBlockRegistry().GOAL) reachedGoal = true;
|
if (world.getBlockAt(pos) == world.getBlockRegistry().GOAL) reachedGoal = true;
|
||||||
|
|
||||||
|
|
||||||
isFreeFalling = !world.getBlockAt(pos+BlockPos(0, 2)).getSettings().isSolid();
|
isFreeFalling = !world.getBlockAt(pos+BlockPos(0, 2)).getSettings().isSolid();
|
||||||
if (isFreeFalling) {
|
if (isFreeFalling) {
|
||||||
move(BlockPos(0, 1));
|
|
||||||
fallLength += 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;
|
if (world.getBlockAt(pos+BlockPos(0, 2)).getSettings().isLethal()) alive = false;
|
||||||
}
|
}
|
||||||
|
|||||||
30
worlds/3.txt
30
worlds/3.txt
@@ -1,15 +1,15 @@
|
|||||||
|
|
||||||
----------------------
|
----------------------
|
||||||
00
|
00 <>
|
||||||
00
|
00 <++>
|
||||||
00
|
00 [+ +]
|
||||||
---------
|
--------- [ ]
|
||||||
0 o 00----- O
|
0 o 00------ O [ 7 ]
|
||||||
0 S /|\ 00 0
|
0 S /|\ 00 0 [ ]
|
||||||
0 / \ 00 0 ---------------
|
0 / \ 00 0 ---------------
|
||||||
---------------- 0 H 0
|
---------------- 0 H 0
|
||||||
0 H 0
|
0 H 0
|
||||||
0 H 0
|
0 H 0
|
||||||
0 H 0
|
0 H 0
|
||||||
0~~~~~~0---------
|
0~~~~~~0---------0
|
||||||
--------
|
00000000
|
||||||
|
|||||||
Reference in New Issue
Block a user