Skip to content

Commit

Permalink
Added ability to load map from file
Browse files Browse the repository at this point in the history
  • Loading branch information
fazelukario committed Nov 13, 2023
1 parent df8d29e commit 5d8e416
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
36 changes: 17 additions & 19 deletions Pseudo3DCLIGame/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <utility>
#include <algorithm>
#include <chrono>
#include <fstream>
#include <string>
#include <stdio.h>
#include <Windows.h>

Expand All @@ -12,8 +14,8 @@ void UpdateConsoleSize();

int ScreenWidth = 120; // Console Screen Size X (columns)
int ScreenHeight = 40; // Console Screen Size Y (rows)
int MapWidth = 16; // World Dimensions
int MapHeight = 16;
int MapWidth = 0; // World Dimensions
int MapHeight = 0;

float PlayerX = 14.7f; // Player Start Position
float PlayerY = 5.09f;
Expand All @@ -24,6 +26,11 @@ float Speed = 5.0f; // Walking Speed

int main()
{
string mapFileName;
cout << "Enter the name of the map file: ";
cin >> mapFileName;
system("cls");

UpdateConsoleSize();

// Create Screen Buffer
Expand All @@ -33,23 +40,14 @@ int main()
DWORD bytesWritten = 0;

// Create Map of world space # = wall block, . = space
wstring map;
map += L"################";
map += L"#..............#";
map += L"###.....########";
map += L"#..............#";
map += L"#......##......#";
map += L"#......##......#";
map += L"#..............#";
map += L"###...........##";
map += L"##.............#";
map += L"#......####..###";
map += L"#......#.......#";
map += L"#......#.......#";
map += L"#..............#";
map += L"#......#########";
map += L"#..............#";
map += L"################";
wifstream file(mapFileName);
wstring map, line;
while (getline(file, line))
{
map += line;
MapHeight++;
}
MapWidth = (int)(line.length());

auto tp1 = chrono::system_clock::now();
auto tp2 = chrono::system_clock::now();
Expand Down
Empty file added maps/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions maps/Example_map.p3dmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
################
#..............#
###.....########
#..............#
#......##......#
#......##......#
#..............#
###...........##
##.............#
#......####..###
#......#.......#
#......#.......#
#..............#
#......#########
#..............#
################

0 comments on commit 5d8e416

Please sign in to comment.