├── materials ├── solid.txt └── walkable.txt ├── animations └── logo.txt ├── documentation ├── screenShots │ ├── bug.png │ └── example.png ├── offline │ ├── 3.4._Functions_and_3.4.1._input.h.md │ ├── 3.4.6._animation.h.md │ ├── 1._Introduction.md │ ├── 3._Description_of_EVERYTHING_and_3.1._Defines.md │ ├── 3.4.4._render.h.md │ ├── 3.2._Structures.md │ ├── 4._Table_of_contents.md │ ├── 3.4.3._output.h.md │ ├── 2.2._How_to_use_the_editors,_and_other_further_details.md │ └── 3.3._Variables_in_the_main_.cpp_file.md └── online │ ├── 3.4. Functions and 3.4.1. input.h.md │ ├── 3.4.6. animation.h.md │ ├── 3. Description of EVERYTHING and 3.1. Defines.md │ ├── 3.4.4. render.h.md │ ├── 3.2. Structures.md │ ├── 3.4.3. output.h.md │ └── 2.2. How to use the editors, and other further details.md ├── headers ├── rendering │ ├── animation.h │ ├── render.h │ ├── shadowFunctions.h │ ├── animation.cpp │ └── render.cpp ├── input │ ├── input.h │ └── input.cpp ├── output │ ├── movement.h │ ├── output.h │ ├── output.cpp │ └── movement.cpp └── system │ └── system.h ├── .gitignore ├── FOVs ├── left.txt ├── leftDown.txt ├── leftUp.txt ├── right.txt ├── rightUp.txt ├── down.txt ├── rightDown.txt └── up.txt ├── ShadowFunctionsEngine.layout ├── CMakeLists.txt ├── Makefile.win ├── ShadowFunctionsEngine.dev ├── README.md └── ShadowFunctionsEngine.cpp /materials/solid.txt: -------------------------------------------------------------------------------- 1 | x -------------------------------------------------------------------------------- /materials/walkable.txt: -------------------------------------------------------------------------------- 1 | i -------------------------------------------------------------------------------- /animations/logo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmmuscus/Shadow-Functions-Engine/HEAD/animations/logo.txt -------------------------------------------------------------------------------- /documentation/screenShots/bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmmuscus/Shadow-Functions-Engine/HEAD/documentation/screenShots/bug.png -------------------------------------------------------------------------------- /documentation/screenShots/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmmuscus/Shadow-Functions-Engine/HEAD/documentation/screenShots/example.png -------------------------------------------------------------------------------- /headers/rendering/animation.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "../system/system.h" 5 | 6 | animation initNewAnimation(animation anim, string fileName); 7 | 8 | void playAnimation(char console[CONSOLEROWS][CONSOLECOLS], animation anim, int yRow, int xCol); 9 | -------------------------------------------------------------------------------- /headers/input/input.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "../system/system.h" 5 | 6 | bool wPressed (); 7 | 8 | bool sPressed (); 9 | 10 | bool aPressed (); 11 | 12 | bool dPressed (); 13 | 14 | bool ePressed (); 15 | 16 | bool escPressed (); 17 | 18 | void cancelOut (bool plus, bool minus); 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | build/ -------------------------------------------------------------------------------- /headers/output/movement.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "../system/system.h" 5 | 6 | mob playerMovement(mob playr, bool w, bool s, bool a, bool d); 7 | 8 | mob keepInBounds(mob playr, mob lastPlayr, map world[WORLDROWS][WORLDCOLS]); 9 | 10 | mob setDirections(mob playr, bool w, bool s, bool a, bool d); 11 | 12 | mob camMovement(mob cam, mob playr); 13 | 14 | mob cameraPan(mob cam, mob camDest); 15 | 16 | mob keepCamInBounds(mob cam); 17 | -------------------------------------------------------------------------------- /headers/rendering/render.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "../system/system.h" 5 | 6 | void goTo (int row, int column); 7 | 8 | void clearScreen(); 9 | 10 | void renderConsole(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]); 11 | 12 | void clearConsole(char newC[CONSOLEROWS][CONSOLECOLS], char oldC[CONSOLEROWS][CONSOLECOLS]); 13 | 14 | void calculateScreen(map world[WORLDROWS][WORLDCOLS], char screen[CONSOLEROWS][CONSOLECOLS], int cameraRow, int cameraCol); 15 | -------------------------------------------------------------------------------- /headers/output/output.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "../system/system.h" 5 | 6 | void saveLastConsoleArray(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]); 7 | 8 | void initSolid(char solide[SOLIDCOUNT], string fileName); 9 | 10 | void initWalkable(char walkablee[WALKABLECOUNT], string fileName); 11 | 12 | void initWorld(map world[WORLDROWS][WORLDCOLS], char solide[SOLIDCOUNT], char walkablee[WALKABLECOUNT], string fileName); 13 | 14 | void initFOV(fov [FOVROWS][FOVCOLS], string fileName); 15 | -------------------------------------------------------------------------------- /FOVs/left.txt: -------------------------------------------------------------------------------- 1 | 000000000000000000000000______00000 2 | 0000000000000000000_____________000 3 | 000000000000000__________________00 4 | 00000000000______________________00 5 | 000000000________________________00 6 | 0000000___________________________0 7 | 00000_____________________________0 8 | 000_______________________________0 9 | 00________________________________0 10 | 0_________________________________0 11 | 0________________________________@0 12 | 0_________________________________0 13 | 00________________________________0 14 | 000_______________________________0 15 | 00000_____________________________0 16 | 0000000___________________________0 17 | 000000000________________________00 18 | 00000000000______________________00 19 | 000000000000000__________________00 20 | 0000000000000000000______________00 21 | 000000000000000000000000______00000 -------------------------------------------------------------------------------- /FOVs/leftDown.txt: -------------------------------------------------------------------------------- 1 | 0000000000000_______000000000000000 2 | 00000000000___________0000000000000 3 | 000000000_______________00000000000 4 | 00000000_________________0000000000 5 | 0000000___________________000000000 6 | 000000_____________________00000000 7 | 00000______________________@0000000 8 | 0000_________________________000000 9 | 000___________________________00000 10 | 00_____________________________0000 11 | 0_______________________________000 12 | 0________________________________00 13 | __________________________________0 14 | ___________________________________ 15 | ___________________________________ 16 | ___________________________________ 17 | __________________________________0 18 | 0______________________________0000 19 | 00___________________________000000 20 | 000_____________________00000000000 21 | 0000000____________0000000000000000 -------------------------------------------------------------------------------- /FOVs/leftUp.txt: -------------------------------------------------------------------------------- 1 | 0000000____________0000000000000000 2 | 000_____________________00000000000 3 | 00___________________________000000 4 | 0______________________________0000 5 | __________________________________0 6 | ___________________________________ 7 | ___________________________________ 8 | ___________________________________ 9 | __________________________________0 10 | 0________________________________00 11 | 0_______________________________000 12 | 00_____________________________0000 13 | 000___________________________00000 14 | 0000_________________________000000 15 | 00000______________________@0000000 16 | 000000_____________________00000000 17 | 0000000___________________000000000 18 | 00000000_________________0000000000 19 | 000000000_______________00000000000 20 | 00000000000___________0000000000000 21 | 0000000000000_______000000000000000 -------------------------------------------------------------------------------- /FOVs/right.txt: -------------------------------------------------------------------------------- 1 | 00000______000000000000000000000000 2 | 000_____________0000000000000000000 3 | 00__________________000000000000000 4 | 00______________________00000000000 5 | 00________________________000000000 6 | 0___________________________0000000 7 | 0_____________________________00000 8 | 0_______________________________000 9 | 0________________________________00 10 | 0_________________________________0 11 | 0@________________________________0 12 | 0_________________________________0 13 | 0________________________________00 14 | 0_______________________________000 15 | 0_____________________________00000 16 | 0___________________________0000000 17 | 00________________________000000000 18 | 00______________________00000000000 19 | 00__________________000000000000000 20 | 000_____________0000000000000000000 21 | 00000______000000000000000000000000 -------------------------------------------------------------------------------- /FOVs/rightUp.txt: -------------------------------------------------------------------------------- 1 | 0000000000000000____________0000000 2 | 00000000000_____________________000 3 | 000000___________________________00 4 | 0000______________________________0 5 | 0__________________________________ 6 | ___________________________________ 7 | ___________________________________ 8 | ___________________________________ 9 | 0__________________________________ 10 | 00________________________________0 11 | 000_______________________________0 12 | 0000_____________________________00 13 | 00000___________________________000 14 | 000000_________________________0000 15 | 0000000@______________________00000 16 | 00000000_____________________000000 17 | 000000000___________________0000000 18 | 0000000000_________________00000000 19 | 00000000000_______________000000000 20 | 0000000000000___________00000000000 21 | 000000000000000_______0000000000000 -------------------------------------------------------------------------------- /FOVs/down.txt: -------------------------------------------------------------------------------- 1 | 00000000_________@_________00000000 2 | 000_____________________________000 3 | 0_________________________________0 4 | 0_________________________________0 5 | 0_________________________________0 6 | 0_________________________________0 7 | 00_______________________________00 8 | 00_______________________________00 9 | 00_______________________________00 10 | 000_____________________________000 11 | 000_____________________________000 12 | 0000___________________________0000 13 | 00000_________________________00000 14 | 00000_________________________00000 15 | 000000_______________________000000 16 | 0000000_____________________0000000 17 | 000000000_________________000000000 18 | 0000000000_______________0000000000 19 | 000000000000___________000000000000 20 | 00000000000000_______00000000000000 21 | 00000000000000000000000000000000000 22 | -------------------------------------------------------------------------------- /FOVs/rightDown.txt: -------------------------------------------------------------------------------- 1 | 000000000000000_______0000000000000 2 | 0000000000000___________00000000000 3 | 00000000000_______________000000000 4 | 0000000000_________________00000000 5 | 000000000___________________0000000 6 | 00000000_____________________000000 7 | 0000000@______________________00000 8 | 000000_________________________0000 9 | 00000___________________________000 10 | 0000_____________________________00 11 | 000_______________________________0 12 | 00________________________________0 13 | 0__________________________________ 14 | ___________________________________ 15 | ___________________________________ 16 | ___________________________________ 17 | 0__________________________________ 18 | 0000______________________________0 19 | 000000___________________________00 20 | 00000000000_____________________000 21 | 0000000000000000____________0000000 -------------------------------------------------------------------------------- /FOVs/up.txt: -------------------------------------------------------------------------------- 1 | 00000000000000000000000000000000000 2 | 00000000000000_______00000000000000 3 | 000000000000___________000000000000 4 | 0000000000_______________0000000000 5 | 000000000_________________000000000 6 | 0000000_____________________0000000 7 | 000000_______________________000000 8 | 00000_________________________00000 9 | 00000_________________________00000 10 | 0000___________________________0000 11 | 000_____________________________000 12 | 000_____________________________000 13 | 00_______________________________00 14 | 00_______________________________00 15 | 00_______________________________00 16 | 0_________________________________0 17 | 0_________________________________0 18 | 0_________________________________0 19 | 0_________________________________0 20 | 000_____________________________000 21 | 00000000_________@_________00000000 22 | -------------------------------------------------------------------------------- /headers/input/input.cpp: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "input.h" 5 | 6 | // These functions return true if the correct button was pressed. 7 | bool wPressed() 8 | { 9 | return (GetKeyState('W') & 0x8000 || GetKeyState(VK_UP) & 0x8000); 10 | } 11 | 12 | bool aPressed() 13 | { 14 | return (GetKeyState('A') & 0x8000 || GetKeyState(VK_LEFT) & 0x8000); 15 | } 16 | 17 | bool sPressed() 18 | { 19 | return (GetKeyState('S') & 0x8000 || GetKeyState(VK_DOWN) & 0x8000); 20 | } 21 | 22 | bool dPressed() 23 | { 24 | return (GetKeyState('D') & 0x8000 || GetKeyState(VK_RIGHT) & 0x8000); 25 | } 26 | 27 | bool ePressed() 28 | { 29 | return (GetKeyState('E') & 0x8000); 30 | } 31 | 32 | bool escPressed() 33 | { 34 | return (GetKeyState(VK_ESCAPE) & 0x8000); 35 | } 36 | 37 | // This function sets two bools to false if they were both true. 38 | void cancelOut (bool plus, bool minus) 39 | { 40 | // The function checks if both of the bools are true, if they are it sets them to 41 | // fasle. 42 | if (plus && minus) 43 | { 44 | plus = false; 45 | minus = false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ShadowFunctionsEngine.layout: -------------------------------------------------------------------------------- 1 | [Editor_11] 2 | CursorCol=1 3 | CursorRow=3 4 | TopLine=1 5 | LeftChar=1 6 | [Editor_10] 7 | CursorCol=82 8 | CursorRow=1 9 | TopLine=1 10 | LeftChar=1 11 | [Editor_0] 12 | CursorCol=1 13 | CursorRow=1 14 | TopLine=1 15 | LeftChar=1 16 | [Editors] 17 | Order=0,9 18 | Focused=0 19 | [Editor_1] 20 | CursorCol=1 21 | CursorRow=3 22 | TopLine=1 23 | LeftChar=1 24 | [Editor_2] 25 | CursorCol=1 26 | CursorRow=3 27 | TopLine=1 28 | LeftChar=1 29 | [Editor_3] 30 | CursorCol=2 31 | CursorRow=269 32 | TopLine=240 33 | LeftChar=1 34 | [Editor_5] 35 | CursorCol=4 36 | CursorRow=140 37 | TopLine=129 38 | LeftChar=1 39 | [Editor_4] 40 | CursorCol=1 41 | CursorRow=3 42 | TopLine=1 43 | LeftChar=1 44 | [Editor_6] 45 | CursorCol=82 46 | CursorRow=1 47 | TopLine=1 48 | LeftChar=1 49 | [Editor_8] 50 | CursorCol=82 51 | CursorRow=1 52 | TopLine=1 53 | LeftChar=1 54 | [Editor_7] 55 | CursorCol=14 56 | CursorRow=103 57 | TopLine=64 58 | LeftChar=1 59 | [Editor_9] 60 | CursorCol=69 61 | CursorRow=1358 62 | TopLine=1 63 | LeftChar=1 64 | [Editor_12] 65 | CursorCol=14 66 | CursorRow=53 67 | TopLine=1 68 | LeftChar=1 69 | [Editor_13] 70 | CursorCol=82 71 | CursorRow=1 72 | TopLine=1 73 | LeftChar=1 74 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project(Shadow_Functions_Engine CXX) 4 | 5 | set(INCLUDE_FILES 6 | ${PROJECT_SOURCE_DIR}/headers/input/input.h 7 | 8 | ${PROJECT_SOURCE_DIR}/headers/output/movement.h 9 | ${PROJECT_SOURCE_DIR}/headers/output/output.h 10 | 11 | ${PROJECT_SOURCE_DIR}/headers/rendering/animation.h 12 | ${PROJECT_SOURCE_DIR}/headers/rendering/render.h 13 | ${PROJECT_SOURCE_DIR}/headers/rendering/shadowFunctions.h 14 | 15 | ${PROJECT_SOURCE_DIR}/headers/system/system.h 16 | ) 17 | 18 | set(SOURCE_FILES 19 | ${PROJECT_SOURCE_DIR}/headers/input/input.cpp 20 | 21 | ${PROJECT_SOURCE_DIR}/headers/output/movement.cpp 22 | ${PROJECT_SOURCE_DIR}/headers/output/output.cpp 23 | 24 | ${PROJECT_SOURCE_DIR}/headers/rendering/animation.cpp 25 | ${PROJECT_SOURCE_DIR}/headers/rendering/render.cpp 26 | ${PROJECT_SOURCE_DIR}/headers/rendering/shadowFunctions.cpp 27 | 28 | ${PROJECT_SOURCE_DIR}/ShadowFunctionsEngine.cpp 29 | ) 30 | 31 | add_executable(${PROJECT_NAME} ${INCLUDE_FILES} ${SOURCE_FILES}) 32 | 33 | if (UNIX) 34 | target_link_libraries(${PROJECT_NAME} X11) 35 | endif() 36 | 37 | set_target_properties( 38 | ${PROJECT_NAME} 39 | PROPERTIES 40 | CXX_STANDARD 14 41 | CXX_STANDARD_REQUIRED ON 42 | CXX_EXTENSIONS OFF 43 | ) -------------------------------------------------------------------------------- /headers/rendering/shadowFunctions.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "../system/system.h" 5 | 6 | void makeCurrentFov(fov presetDir[FOVROWS][FOVCOLS], fov toBeDir[FOVROWS][FOVCOLS]); 7 | 8 | void setCurrentFov(mob playr, fov toBecomeCurrentFov[FOVROWS][FOVCOLS], fov r[FOVROWS][FOVCOLS], fov l[FOVROWS][FOVCOLS], fov u[FOVROWS][FOVCOLS], fov d[FOVROWS][FOVCOLS], fov ru[FOVROWS][FOVCOLS], fov rd[FOVROWS][FOVCOLS], fov lu[FOVROWS][FOVCOLS], fov ld[FOVROWS][FOVCOLS]); 9 | 10 | mob getPlayerPosInFov(mob playr, mob fovPlayr); 11 | 12 | void addFovInfoToMap(map world[WORLDROWS][WORLDCOLS], mob playr, mob fovPlayr, fov fov[FOVROWS][FOVCOLS]); 13 | 14 | koordinate getPov(koordinate pov, mob playr); 15 | 16 | line getLineEquation(double aXCol, double aYRow, int bXCol, int bYRow); 17 | 18 | bool isUnderLine(line e, int solidYRow, int solidXCol); 19 | 20 | bool isOverLine(line e, int solidYRow, int solidXCol); 21 | 22 | bool isBetweenLines(line a, line b, int yRow, int xCol); 23 | 24 | bool isMoreThanHalfInShade(line e, int yRow, int xCol); 25 | 26 | bool isBehindWall(koordinate pov, int yRow, int xCol, int top, int bottom, int right, int left); 27 | 28 | bool tShapeDetector(koordinate pov, int yRow, int xCol, int top, int bottom, int right, int left); 29 | 30 | edgeLines getEdgeLines(koordinate pov, int top, int bot, int right, int left); 31 | 32 | void shadowFunction(map world[WORLDROWS][WORLDCOLS], int cameraCol, int cameraRow, koordinate pov, edgeLines edg); 33 | 34 | void holePlugger(map world[WORLDROWS][WORLDCOLS], int cameraCol, int cameraRow); 35 | 36 | bool isBesideNotSolidInView(map world[WORLDROWS][WORLDCOLS], int xCol, int yRow); 37 | 38 | void mapIsEdgeCalculation(map world[WORLDROWS][WORLDCOLS], int cameraRow, int cameraCol); 39 | -------------------------------------------------------------------------------- /headers/rendering/animation.cpp: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "animation.h" 5 | 6 | // This function initalizes an anmiation. 7 | animation initNewAnimation(animation anim, string fileName) 8 | { 9 | // First we get a temporary variable we can read characters into and check for 10 | // different things. 11 | char cahr; 12 | 13 | // Next we open the file. 14 | fstream fbe (fileName.c_str()); 15 | 16 | // After that we read the amount of frames the animation has, the height of each 17 | // frame and the widht of every frame. 18 | fbe>>anim.frames>>anim.height>>anim.width; 19 | 20 | // Then we set the currentFrame sub variable of the structure to 0. 21 | anim.currentFrame = 0; 22 | 23 | // After all that we loop over evey cell of every frame of the animation. 24 | for (int g = 0; g < anim.frames; g++) 25 | { 26 | for (int i = 0; i < anim.height; i++) 27 | { 28 | for (int j = 0; j < anim.width; j++) 29 | { 30 | // We read the next character into cahr. 31 | fbe>>cahr; 32 | 33 | // We check if the character we just read was an 'i'. 34 | if (cahr == 'i') 35 | { 36 | // If the character we just read was an 'i' we make the texture of 37 | // the variable a ' ' character. 38 | anim.frameArray[g][i][j] = ' '; 39 | } 40 | else 41 | { 42 | // If the character we just read wasn't an 'i' we make the texture 43 | // of the variable the character we just read. 44 | anim.frameArray[g][i][j] = cahr; 45 | } 46 | } 47 | } 48 | } 49 | 50 | // Lastly the function closes the .txt file. 51 | fbe.close(); 52 | 53 | return anim; 54 | } 55 | 56 | // This function plays the animation frame by frame. 57 | void playAnimation(char console[CONSOLEROWS][CONSOLECOLS], animation anim, int yRow, int xCol) 58 | { 59 | // The function checks if the current frame of the animation is still an existing 60 | // frame of the animation. 61 | if (anim.currentFrame < anim.frames) 62 | { 63 | // If the current frame does exist we loop through all the variables of the 64 | // current frame of the animation. 65 | for (int i = 0; i < anim.height; i++) 66 | { 67 | for (int j = 0; j < anim.width; j++) 68 | { 69 | // The function writes every variable into the correct cell (all 70 | // positions being offset with yRow and xCol). 71 | console[yRow + i][xCol + j] = anim.frameArray[anim.currentFrame][i][j]; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Makefile.win: -------------------------------------------------------------------------------- 1 | # Project: ShadowFunctionsEngine 2 | # Makefile created by Dev-C++ 5.11 3 | 4 | CPP = g++.exe 5 | CC = gcc.exe 6 | WINDRES = windres.exe 7 | OBJ = ShadowFunctionsEngine.o headers/input/input.o headers/output/movement.o headers/output/output.o headers/rendering/render.o headers/rendering/shadowFunctions.o headers/rendering/animation.o 8 | LINKOBJ = ShadowFunctionsEngine.o headers/input/input.o headers/output/movement.o headers/output/output.o headers/rendering/render.o headers/rendering/shadowFunctions.o headers/rendering/animation.o 9 | LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc 10 | INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" 11 | CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" 12 | BIN = ShadowFunctionsEngine.exe 13 | CXXFLAGS = $(CXXINCS) -std=c99 14 | CFLAGS = $(INCS) -std=c99 15 | RM = rm.exe -f 16 | 17 | .PHONY: all all-before all-after clean clean-custom 18 | 19 | all: all-before $(BIN) all-after 20 | 21 | clean: clean-custom 22 | ${RM} $(OBJ) $(BIN) 23 | 24 | $(BIN): $(OBJ) 25 | $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS) 26 | 27 | ShadowFunctionsEngine.o: ShadowFunctionsEngine.cpp 28 | $(CPP) -c ShadowFunctionsEngine.cpp -o ShadowFunctionsEngine.o $(CXXFLAGS) 29 | 30 | headers/input/input.o: headers/input/input.cpp 31 | $(CPP) -c headers/input/input.cpp -o headers/input/input.o $(CXXFLAGS) 32 | 33 | headers/output/movement.o: headers/output/movement.cpp 34 | $(CPP) -c headers/output/movement.cpp -o headers/output/movement.o $(CXXFLAGS) 35 | 36 | headers/output/output.o: headers/output/output.cpp 37 | $(CPP) -c headers/output/output.cpp -o headers/output/output.o $(CXXFLAGS) 38 | 39 | headers/rendering/render.o: headers/rendering/render.cpp 40 | $(CPP) -c headers/rendering/render.cpp -o headers/rendering/render.o $(CXXFLAGS) 41 | 42 | headers/rendering/shadowFunctions.o: headers/rendering/shadowFunctions.cpp 43 | $(CPP) -c headers/rendering/shadowFunctions.cpp -o headers/rendering/shadowFunctions.o $(CXXFLAGS) 44 | 45 | headers/rendering/animation.o: headers/rendering/animation.cpp 46 | $(CPP) -c headers/rendering/animation.cpp -o headers/rendering/animation.o $(CXXFLAGS) 47 | -------------------------------------------------------------------------------- /documentation/offline/3.4._Functions_and_3.4.1._input.h.md: -------------------------------------------------------------------------------- 1 | ## 3.4. Functions 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This section of [the third chapter of the documentation](3._Description_of_EVERYTHING_and_3.1._Defines.md/#3-detailed-description-of-everything) will not go over the functions in order of appearance (as opposed to the previous sections) but in the order that they are in their header files. Thus this section will have the following parts: 4 | * [input.h](#341-inputh) 5 | * [movement.h](3.4.2._movement.h.md/#342-movementh) 6 | * [output.h](3.4.3._output.h.md/#343-outputh) 7 | * [render.h](3.4.4._render.h.md/#344-renderh) 8 | * [shadowFunctions.h](3.4.5._shadowFunctions.h.md/#345-shadowfunctionsh) 9 | * [animation.h](3.4.6._animation.h.md/#346-animationh) 10 | ### 3.4.1. [input.h](../../headers/input/input.h) 11 | ###### This section was last checked in the 2.0.3. version of the engine 12 | This header file contains functions that deal with the input coming form the keyboard. 13 | #### 3.4.1.1. ___Pressed 14 | ###### This section was last checked in the 2.0.3. version of the engine 15 | ```cpp 16 | // These functions return true if the correct button was pressed. 17 | bool wPressed() 18 | { 19 | return (GetKeyState('W') & 0x8000); 20 | } 21 | 22 | bool aPressed() 23 | { 24 | return (GetKeyState('A') & 0x8000); 25 | } 26 | 27 | bool sPressed() 28 | { 29 | return (GetKeyState('S') & 0x8000); 30 | } 31 | 32 | bool dPressed() 33 | { 34 | return (GetKeyState('D') & 0x8000); 35 | } 36 | 37 | bool ePressed() 38 | { 39 | return (GetKeyState('E') & 0x8000); 40 | } 41 | 42 | bool escPressed() 43 | { 44 | return (GetKeyState(VK_ESCAPE) & 0x8000); 45 | } 46 | ``` 47 | 48 | **Usage:** These functions return true when the correct key is pressed down. 49 | 50 | **Variables:** - 51 | 52 | **How it's done & notes:** The functions use another function called [GetKeyState](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getkeystate). This function can be found in [the windows.h header](https://en.wikipedia.org/wiki/Windows.h) which contains lots of useful functions from the windows API. The ___Pressed functions are one of the three places where I used external resources to solve a problem (this was before version 2.0.2.). The other link I used to write these can be found [here](https://stackoverflow.com/questions/6331868/using-getkeystate). To reduce the amount of clutter for the 3.0.0. version I plan to write a universal keyPressed function, so one function will be able to deal with all the key presses. 53 | 54 | #### 3.4.1.2. cancelOut 55 | ###### This section was last checked in the 2.0.3. version of the engine 56 | ```cpp 57 | // This function sets two bools to false if they were both true. 58 | void cancelOut (bool plus, bool minus) 59 | { 60 | // The function checks if both of the bools are true, if they are it sets them to 61 | // fasle. 62 | if (plus && minus) 63 | { 64 | plus = false; 65 | minus = false; 66 | } 67 | } 68 | ``` 69 | **Usage:** This function cancels out two bools if they are both true. 70 | 71 | **Variables:** 72 | * **plus:** Holds the first bool we want to check. 73 | * **minus:** Holds the second bool we want to check. 74 | 75 | **How it's done & notes:** We check if both of the variables are true. If they are we set them both to false. This is used to cancel out contradictory input (for example when both the 'A' and 'D' keys are pressed), but it could be used for any form of cancellation of contradictory bools. -------------------------------------------------------------------------------- /ShadowFunctionsEngine.dev: -------------------------------------------------------------------------------- 1 | [Project] 2 | FileName=ShadowFunctionsEngine.dev 3 | Name=ShadowFunctionsEngine 4 | Type=1 5 | Ver=2 6 | ObjFiles= 7 | Includes= 8 | Libs= 9 | PrivateResource= 10 | ResourceIncludes= 11 | MakeIncludes= 12 | Compiler= 13 | CppCompiler= 14 | Linker= 15 | IsCpp=1 16 | Icon= 17 | ExeOutput= 18 | ObjectOutput= 19 | LogOutput= 20 | LogOutputEnabled=0 21 | OverrideOutput=0 22 | OverrideOutputName= 23 | HostApplication= 24 | UseCustomMakefile=0 25 | CustomMakefile= 26 | CommandLine= 27 | Folders= 28 | IncludeVersionInfo=0 29 | SupportXPThemes=0 30 | CompilerSet=0 31 | CompilerSettings=0000000000000000000000000 32 | UnitCount=14 33 | 34 | [VersionInfo] 35 | Major=1 36 | Minor=0 37 | Release=0 38 | Build=0 39 | LanguageID=1033 40 | CharsetID=1252 41 | CompanyName= 42 | FileVersion= 43 | FileDescription=Developed using the Dev-C++ IDE 44 | InternalName= 45 | LegalCopyright= 46 | LegalTrademarks= 47 | OriginalFilename= 48 | ProductName= 49 | ProductVersion= 50 | AutoIncBuildNr=0 51 | SyncProduct=1 52 | 53 | [Unit1] 54 | FileName=ShadowFunctionsEngine.cpp 55 | CompileCpp=1 56 | Folder= 57 | Compile=1 58 | Link=1 59 | Priority=1000 60 | OverrideBuildCmd=0 61 | BuildCmd= 62 | 63 | [Unit2] 64 | FileName=headers\input\input.cpp 65 | CompileCpp=1 66 | Folder= 67 | Compile=1 68 | Link=1 69 | Priority=1000 70 | OverrideBuildCmd=0 71 | BuildCmd= 72 | 73 | [Unit3] 74 | FileName=headers\input\input.h 75 | CompileCpp=1 76 | Folder= 77 | Compile=1 78 | Link=1 79 | Priority=1000 80 | OverrideBuildCmd=0 81 | BuildCmd= 82 | 83 | [Unit4] 84 | FileName=headers\output\movement.cpp 85 | CompileCpp=1 86 | Folder= 87 | Compile=1 88 | Link=1 89 | Priority=1000 90 | OverrideBuildCmd=0 91 | BuildCmd= 92 | 93 | [Unit5] 94 | FileName=headers\output\movement.h 95 | CompileCpp=1 96 | Folder= 97 | Compile=1 98 | Link=1 99 | Priority=1000 100 | OverrideBuildCmd=0 101 | BuildCmd= 102 | 103 | [Unit6] 104 | FileName=headers\output\output.cpp 105 | CompileCpp=1 106 | Folder= 107 | Compile=1 108 | Link=1 109 | Priority=1000 110 | OverrideBuildCmd=0 111 | BuildCmd= 112 | 113 | [Unit7] 114 | FileName=headers\output\output.h 115 | CompileCpp=1 116 | Folder= 117 | Compile=1 118 | Link=1 119 | Priority=1000 120 | OverrideBuildCmd=0 121 | BuildCmd= 122 | 123 | [Unit8] 124 | FileName=headers\rendering\render.cpp 125 | CompileCpp=1 126 | Folder= 127 | Compile=1 128 | Link=1 129 | Priority=1000 130 | OverrideBuildCmd=0 131 | BuildCmd= 132 | 133 | [Unit9] 134 | FileName=headers\rendering\render.h 135 | CompileCpp=1 136 | Folder= 137 | Compile=1 138 | Link=1 139 | Priority=1000 140 | OverrideBuildCmd=0 141 | BuildCmd= 142 | 143 | [Unit10] 144 | FileName=headers\rendering\shadowFunctions.cpp 145 | CompileCpp=1 146 | Folder= 147 | Compile=1 148 | Link=1 149 | Priority=1000 150 | OverrideBuildCmd=0 151 | BuildCmd= 152 | 153 | [Unit11] 154 | FileName=headers\rendering\shadowFunctions.h 155 | CompileCpp=1 156 | Folder= 157 | Compile=1 158 | Link=1 159 | Priority=1000 160 | OverrideBuildCmd=0 161 | BuildCmd= 162 | 163 | [Unit12] 164 | FileName=headers\system\system.h 165 | CompileCpp=1 166 | Folder= 167 | Compile=1 168 | Link=1 169 | Priority=1000 170 | OverrideBuildCmd=0 171 | BuildCmd= 172 | 173 | [Unit13] 174 | FileName=headers\rendering\animation.cpp 175 | CompileCpp=1 176 | Folder= 177 | Compile=1 178 | Link=1 179 | Priority=1000 180 | OverrideBuildCmd=0 181 | BuildCmd= 182 | 183 | [Unit14] 184 | FileName=headers\rendering\animation.h 185 | CompileCpp=1 186 | Folder= 187 | Compile=1 188 | Link=1 189 | Priority=1000 190 | OverrideBuildCmd=0 191 | BuildCmd= 192 | 193 | -------------------------------------------------------------------------------- /documentation/online/3.4. Functions and 3.4.1. input.h.md: -------------------------------------------------------------------------------- 1 | ## 3.4. Functions 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This section of [the third chapter of the documentation](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#3-detailed-description-of-everything) will not go over the functions in order of appearance (as opposed to the previous sections) but in the order that they are in their header files. Thus this section will have the following parts: 4 | * [input.h](#341-inputh) 5 | * [movement.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.2.%20movement.h.md/#342-movementh) 6 | * [output.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.3.%20output.h.md/#343-outputh) 7 | * [render.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.4.%20render.h.md/#344-renderh) 8 | * [shadowFunctions.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.5.%20shadowFunctions.h.md/#345-shadowfunctionsh) 9 | * [animation.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.6.%20animation.h.md/#346-animationh) 10 | ### 3.4.1. [input.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/input/input.h) 11 | ###### This section was last checked in the 2.0.3. version of the engine 12 | This header file contains functions that deal with the input coming form the keyboard. 13 | #### 3.4.1.1. ___Pressed 14 | ###### This section was last checked in the 2.0.3. version of the engine 15 | ```cpp 16 | // These functions return true if the correct button was pressed. 17 | bool wPressed() 18 | { 19 | return (GetKeyState('W') & 0x8000); 20 | } 21 | 22 | bool aPressed() 23 | { 24 | return (GetKeyState('A') & 0x8000); 25 | } 26 | 27 | bool sPressed() 28 | { 29 | return (GetKeyState('S') & 0x8000); 30 | } 31 | 32 | bool dPressed() 33 | { 34 | return (GetKeyState('D') & 0x8000); 35 | } 36 | 37 | bool ePressed() 38 | { 39 | return (GetKeyState('E') & 0x8000); 40 | } 41 | 42 | bool escPressed() 43 | { 44 | return (GetKeyState(VK_ESCAPE) & 0x8000); 45 | } 46 | ``` 47 | 48 | **Usage:** These functions return true when the correct key is pressed down. 49 | 50 | **Variables:** - 51 | 52 | **How it's done & notes:** The functions use another function called [GetKeyState](https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getkeystate). This function can be found in [the windows.h header](https://en.wikipedia.org/wiki/Windows.h) which contains lots of useful functions from the windows API. The ___Pressed functions are one of the three places where I used external resources to solve a problem (this was before version 2.0.2.). The other link I used to write these can be found [here](https://stackoverflow.com/questions/6331868/using-getkeystate). To reduce the amount of clutter for the 3.0.0. version I plan to write a universal keyPressed function, so one function will be able to deal with all the key presses. 53 | 54 | #### 3.4.1.2. cancelOut 55 | ###### This section was last checked in the 2.0.3. version of the engine 56 | ```cpp 57 | // This function sets two bools to false if they were both true. 58 | void cancelOut (bool plus, bool minus) 59 | { 60 | // The function checks if both of the bools are true, if they are it sets them to 61 | // fasle. 62 | if (plus && minus) 63 | { 64 | plus = false; 65 | minus = false; 66 | } 67 | } 68 | ``` 69 | **Usage:** This function cancels out two bools if they are both true. 70 | 71 | **Variables:** 72 | * **plus:** Holds the first bool we want to check. 73 | * **minus:** Holds the second bool we want to check. 74 | 75 | **How it's done & notes:** We check if both of the variables are true. If they are we set them both to false. This is used to cancel out contradictory input (for example when both the 'A' and 'D' keys are pressed), but it could be used for any form of cancellation of contradictory bools. 76 | -------------------------------------------------------------------------------- /headers/rendering/render.cpp: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "render.h" 5 | 6 | using namespace std; 7 | 8 | // This function puts the cursor in a set position on the console window. 9 | // The working of this function can be found in the link below as the fourth answer: 10 | // https://stackoverflow.com/questions/10401724/move-text-cursor-to-particular-screen-coordinate 11 | void goTo (int row, int column) 12 | { 13 | HANDLE hStdout; 14 | hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 15 | 16 | COORD destCoord; 17 | 18 | destCoord.X = column; 19 | destCoord.Y = row; 20 | 21 | SetConsoleCursorPosition(hStdout, destCoord); 22 | } 23 | 24 | // This function clears the console window. 25 | // The workings of this function can be found at this link: 26 | // https://docs.microsoft.com/en-us/windows/console/clearing-the-screen 27 | void clearScreen() 28 | { 29 | HANDLE hConsole; 30 | hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 31 | 32 | COORD coordScreen = { 0, 0 }; 33 | DWORD cCharsWritten; 34 | CONSOLE_SCREEN_BUFFER_INFO csbi; 35 | DWORD dwConSize; 36 | 37 | // Get the number of character cells in the current buffer. 38 | 39 | if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) 40 | return; 41 | dwConSize = csbi.dwSize.X * csbi.dwSize.Y; 42 | 43 | // Fill the entire screen with blanks. 44 | 45 | if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', 46 | dwConSize, coordScreen, &cCharsWritten )) 47 | return; 48 | 49 | // Get the current text attribute. 50 | 51 | if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) 52 | return; 53 | 54 | // Set the buffer's attributes accordingly. 55 | 56 | if( !FillConsoleOutputAttribute( hConsole, csbi.wAttributes, 57 | dwConSize, coordScreen, &cCharsWritten )) 58 | return; 59 | 60 | // Put the cursor at its home coordinates. 61 | 62 | SetConsoleCursorPosition( hConsole, coordScreen ); 63 | } 64 | 65 | // This function renders the console array onto the console window. 66 | void renderConsole(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]) 67 | { 68 | // First the function loops through all of the variables in the array. 69 | for (int i = 0; i < CONSOLEROWS; i++) 70 | { 71 | for (int j = 0; j < CONSOLECOLS; j++) 72 | { 73 | // We check if the variable we are on is different in the pervious frame, 74 | // if it is we go to the correct cell on the console window and write the 75 | // variable from the current frame onto the window. 76 | if (newC[i][j] != oldC[i][j]) 77 | { 78 | goTo(i, j); 79 | cout<>anim.frames>>anim.height>>anim.width; 21 | 22 | // Then we set the currentFrame sub variable of the structure to 0. 23 | anim.currentFrame = 0; 24 | 25 | // After all that we loop over evey cell of every frame of the animation. 26 | for (int g = 0; g < anim.frames; g++) 27 | { 28 | for (int i = 0; i < anim.height; i++) 29 | { 30 | for (int j = 0; j < anim.width; j++) 31 | { 32 | // We read the next character into cahr. 33 | fbe>>cahr; 34 | 35 | // We check if the character we just read was an 'i'. 36 | if (cahr == 'i') 37 | { 38 | // If the character we just read was an 'i' we make the texture of 39 | // the variable a ' ' character. 40 | anim.frameArray[g][i][j] = ' '; 41 | } 42 | else 43 | { 44 | // If the character we just read wasn't an 'i' we make the texture 45 | // of the variable the character we just read. 46 | anim.frameArray[g][i][j] = cahr; 47 | } 48 | } 49 | } 50 | } 51 | 52 | // Lastly the function closes the .txt file. 53 | fbe.close(); 54 | 55 | return anim; 56 | } 57 | ``` 58 | 59 | **Usage:** This function initializes a new animation from an appropriate .txt file 60 | 61 | **Variables:** 62 | 63 | * **anim:** This variable will hold all the relevant information about the animation. 64 | * **fileName:** This string holds the path from the main .cpp file to the .txt that contains the information about the animation. 65 | 66 | **How it's done & notes:** First the function opens the correct file, and then reads the frames, height and the width of the animation (these numbers are at the start of the .txt file). Then for each frame it loops through a height by width chunk of characters, replaces all 'i' characters with ' ' characters and reads them into the animation variable. At the end it returns this variable. To learn more about the animation pipeline click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#224-the-animation-pipeline). To learn more about the animation structure click [here](3.2._Structures.md/#327-animation). 67 | 68 | #### 3.4.6.2. playAnimation 69 | ###### This section was last checked in the 2.0.3. version of the engine 70 | 71 | ```cpp 72 | // This function plays the animation frame by frame. 73 | void playAnimation(char console[CONSOLEROWS][CONSOLECOLS], animation anim, int yRow, int xCol) 74 | { 75 | // The function checks if the current frame of the animation is still an existing 76 | // frame of the animation. 77 | if (anim.currentFrame < anim.frames) 78 | { 79 | // If the current frame does exist we loop through all the variables of the 80 | // current frame of the animation. 81 | for (int i = 0; i < anim.height; i++) 82 | { 83 | for (int j = 0; j < anim.width; j++) 84 | { 85 | // The function writes every variable into the correct cell (all 86 | // positions being offset with yRow and xCol). 87 | console[yRow + i][xCol + j] = anim.frameArray[anim.currentFrame][i][j]; 88 | } 89 | } 90 | } 91 | } 92 | ``` 93 | 94 | **Usage:** This function copies the animations current frame to the correct place in the newConsole array (which holds the information about the current to-be-rendered frame). 95 | 96 | **Variables:** 97 | 98 | - **console:** This array holds the current to-be-rendered frame of the console window. 99 | - **anim:** This variable holds the information about the animation we want to play 100 | - **yRow:** This variable determines which row will contain the first row of the animation frame. 101 | - **xCol:** This variable determines which column will contain the first column of the animation frame 102 | 103 | **How it's done & notes:** First the function checks if the current frame is smaller then the amount of frames in the animation. If it is then it copies the animation's current frame into the correct position into the console array. The cell in the console window with the coordinate of (yRow; xCol) will contain the upper left character of the animation frame. To learn more about the animation pipeline click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#224-the-animation-pipeline). This function can only be called inside a game loop since it only "renders" one frame per call (you'll need to call [the renderConsole function](3.2._Structures.md/#327-animation) too if you want to see the results of this function on screen), as of 2.0.3. you need to externally increment the currentFrame sub variable of the correct animation, this bug will hopefully be fixed by the 3.0.0. version. To learn more about the animation structure click [here](3.2._Structures.md/#327-animation). 104 | 105 | -------------------------------------------------------------------------------- /documentation/offline/1._Introduction.md: -------------------------------------------------------------------------------- 1 | # 1. Introduction 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | **Note:** The 2.0.2. version of the engine now runs on Linux too! This port is thanks to the work of [SuperFola](https://github.com/SuperFola) who also did a few quality of life changes as well, go and check him out! 4 | 5 | ## 1.1. The structure of this documentation 6 | ###### This section was last checked in the 2.0.3. version of the engine 7 | This documentation will have three main parts and a [table of contents](4._Table_of_contents.md/#4-table-of-contents): 8 | * [The first](#1-introduction) is the introduction (the part you are reading right now) 9 | * [The second](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2-how-to-use-the-engine) is an overview of [how the engine works](2._How_to_use_the_engine_and_2.1._how_the_engine_works.md/#21-how-the-engine-works-a-breakdown-of-the-main-cpp-file) and [how you can operate it and it's different editors](2.2._How_to_use_the_editors_and_other_further_details.md/#22-how-to-use-the-editors-and-other-further-details) 10 | * [The third](3._Description_of_EVERYTHING_and_3.1._Defines.md/#3-detailed-description-of-everything) will go over every last detail about the [defines](3._Description_of_EVERYTHING_and_3.1._Defines.md/#31-defines), [structures](3.2._Structures.md/#32-structures), [variables](3.3._Variables_in_the_main_.cpp_file.md/#33-variables-in-the-main-cpp-file) and [functions](3.4._Functions_and_3.4.1._input.h.md/#34-functions) the engine uses 11 | 12 | In the [introduction](#1-introduction) I will cover [my motivation](#12-who-the-hell-am-i-and-what-the-hecky-heck-is-this) for this engine, [the idea, the end product and plans about the future of the project](#13-so-what-is-the-project). 13 | 14 | [The second part](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2-how-to-use-the-engine) will have two segments. [The first](2._How_to_use_the_engine_and_2.1._how_the_engine_works.md/#21-how-the-engine-works-a-breakdown-of-the-main-cpp-file) detailing the architecture of the system, what it does. [The second](2.2._How_to_use_the_editors_and_other_further_details.md/#22-how-to-use-the-editors-and-other-further-details) will be the guide to operate it. Hopefully these two segments will provide you with sufficient information to make a game with this engine. 15 | 16 | [The last part](3._Description_of_EVERYTHING_and_3.1._Defines.md/#3-detailed-description-of-everything) will (as mentioned above) go over the hows of the systems in place. It will be broken down into different subsections, each dealing with a header or cpp file and it's [defines](3._Description_of_EVERYTHING_and_3.1._Defines.md/#31-defines), [structures](3.2._Structures.md/#32-structures), [variables](3.3._Variables_in_the_main_.cpp_file.md/#33-variables-in-the-main-cpp-file), or [functions](3.4._Functions_and_3.4.1._input.h.md/#34-functions). [This part](3._Description_of_EVERYTHING_and_3.1._Defines.md/#3-detailed-description-of-everything) will act more like a cheat sheet than anything, if you wish to conserve your sanity do not read it from start to finish in one sitting. 17 | 18 | ## 1.2. Who the hell am I and what the hecky heck is this? 19 | ###### This section was last checked in the 2.0.3. version of the engine 20 | I originally started this project in high school. The initial goals of the project was to find out what I can do with my basic understanding of programming, whilst not looking up the answers to my problems. The last update I did while (on paper) I still was in high school was version 2.0.2. 21 | 22 | Now I am enrolled in a computer science degree. With this the project's goals have changed a bit. In the classes that I am taking and will be taking I will learn a lot of new things about programming. I plan to incorporate all this knowledge into my project. Another thing that has changed is the fact that after the 2.0.2. update I plan to look up different parts and functionalities of (for example) the windows.h header file, like how to set the dimensions or the font of the console window. The one goal that still remains the same is that if I have a problem I want to figure out the solution to it by myself. 23 | 24 | ## 1.3. So what is the project? 25 | ###### This section was last checked in the 2.0.3. version of the engine 26 | The bare minimum I wanted to accomplish was a real time 2D top down game, with a "realistic" binary shading system (this was all planned to be running in the windows console). The concept of the shading system is the following: There is a player (represented by the '@' character); who has a field of view in which he can see things; anything that would block his view (e.g.: an 'x' character) casts a shadow, meaning that he can't see the things behind the "wall", even if those things would be in his field of view. 27 | 28 | Here is an example for the shading system in action: 29 | 30 | ![example](../screenShots/example.png) 31 | 32 | Besides the minimum goal I created basic text file based level and field of view editors. I also created the option to make new characters that could block light, or player movement. In the latest version (2.0.0.) I added an animation pipeline, with this you can create .txt files that will be parsed into animation arrays and can be played in the console window. 33 | 34 | Features as of now: 35 | * Real time 8 directional player movement 36 | * Binary shading 37 | * Map and field of view editors 38 | * Character attribute editors (can this character block light? can it block player movement?) 39 | * Animation pipeline 40 | 41 | The next big update of the project (3.0.0.) will be the entity update. In this version i plan to add different entities with different attributes, for example: torches that emit light, NPCs that can be interacted with, posts that have text on them etc. 42 | -------------------------------------------------------------------------------- /headers/output/output.cpp: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "output.h" 5 | 6 | using namespace std; 7 | 8 | // This function copies a console array into another console array. 9 | void saveLastConsoleArray(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]) 10 | { 11 | // The function loops through all the values in the array and copies all of them 12 | // from one array to another. 13 | for (int i = 0; i < CONSOLEROWS; i++) 14 | { 15 | for (int j = 0; j < CONSOLECOLS; j++) 16 | { 17 | oldC[i][j] = newC[i][j]; 18 | } 19 | } 20 | } 21 | 22 | // This function initializes all the characters that block light. 23 | void initSolid(char solide[SOLIDCOUNT], string fileName) 24 | { 25 | // First the function opens the file. 26 | fstream fbe (fileName.c_str()); 27 | 28 | // Next the function loops through all the characters in the .txt file and reads 29 | // them in. 30 | for (int i = 0; i < SOLIDCOUNT; i++) 31 | { 32 | fbe>>solide[i]; 33 | } 34 | 35 | // Lastly the function closes the .txt file. 36 | fbe.close(); 37 | } 38 | 39 | // This function initializes all the characters that don't block player movement. 40 | void initWalkable(char walkablee[WALKABLECOUNT], string fileName) 41 | { 42 | // First the function opens the file. 43 | fstream fbe (fileName.c_str()); 44 | 45 | // Next the function loops through all the characters in the .txt file and reads 46 | // them in. 47 | for (int i = 0; i < WALKABLECOUNT; i++) 48 | { 49 | fbe>>walkablee[i]; 50 | } 51 | 52 | // Lastly the function closes the .txt file. 53 | fbe.close(); 54 | } 55 | 56 | // This function initializes the world map. 57 | void initWorld(map world[WORLDROWS][WORLDCOLS], char solide[SOLIDCOUNT], char walkablee[WALKABLECOUNT], string fileName) 58 | { 59 | // First we get a temporary variable we can read characters into and check for 60 | // different things. 61 | char cahr; 62 | 63 | // Next we open the file. 64 | freopen(fileName.c_str(),"r",stdin); 65 | 66 | // After that we start looping through the characters in the .txt file. 67 | for (int i = 0; i < WORLDROWS; i++) 68 | { 69 | for (int j = 0; j < WORLDCOLS; j++) 70 | { 71 | // We read the next character into cahr. 72 | cin>>cahr; 73 | 74 | // We check if the character we read was an 'i'. 75 | if (cahr == 'i') 76 | { 77 | // If the character we read was an 'i' we set the texture of the cell 78 | // to a ' ' character. 79 | world[i][j].texture = ' '; 80 | } 81 | else 82 | { 83 | // If the character we read wasn't an 'i' we set the texture of the 84 | // cell to what we read in. 85 | world[i][j].texture = cahr; 86 | } 87 | 88 | // Next we check if the cell we just read blocks light or player movement. 89 | 90 | // We set the .solid sub variable of the cell to false. 91 | world[i][j].solid = false; 92 | 93 | // After that we start looping through all the characters that block light. 94 | for (int k = 0; k < SOLIDCOUNT; k++) 95 | { 96 | // If the character we read is one of the characters that block light 97 | // we set the .solid sub variable of the cell to true. 98 | if (cahr == solide[k]) 99 | { 100 | world[i][j].solid = true; 101 | } 102 | } 103 | 104 | // We set the .walkable sub variable of the cell to false. 105 | world[i][j].walkable = false; 106 | 107 | // After that we start looping through all the characters that don't block 108 | // movement. 109 | for (int k = 0; k < WALKABLECOUNT; k++) 110 | { 111 | // If the character we read is one of the characters that don't block 112 | // movement we set the .solid sub variable of the cell to true. 113 | if (cahr == walkablee[k]) 114 | { 115 | world[i][j].walkable = true; 116 | } 117 | } 118 | } 119 | } 120 | 121 | // Lastly the function closes the .txt file. 122 | fclose(stdin); 123 | } 124 | 125 | // This function initializes a FOV array. 126 | void initFOV(fov dir[FOVROWS][FOVCOLS], string fileName) 127 | { 128 | // First we get a temporary variable we can read characters into and check for 129 | // different things. 130 | char cahr; 131 | 132 | // Next we open the file. 133 | freopen(fileName.c_str(),"r",stdin); 134 | 135 | // After that we start looping through the characters in the .txt file. 136 | for (int i = 0; i < FOVROWS; i++) 137 | { 138 | for (int j = 0; j < FOVCOLS; j++) 139 | { 140 | // We read the next character into cahr. 141 | cin>>cahr; 142 | 143 | // We check if the character we read was an '_'. 144 | if (cahr == '_') 145 | { 146 | // If the character we read was an '_' we set the .inView sub variable 147 | // of the cell to true. 148 | dir[i][j].inView = true; 149 | } 150 | else 151 | { 152 | // If the character we read wasn't an '_' we set the .inView sub 153 | // variable of the cell to false. 154 | dir[i][j].inView = false; 155 | } 156 | 157 | // We check if the character we read was an '@'. 158 | if (cahr == '@') 159 | { 160 | // If the character we read was an '@' we set both the .isPlayer and 161 | // the .inView sub variable of the cell to true. 162 | dir[i][j].isPlayer = true; 163 | dir[i][j].inView = true; 164 | } 165 | else 166 | { 167 | // If the character we read wasn't an '@' we set the .isPlayer sub 168 | // variable of the cell to false. 169 | dir[i][j].isPlayer = false; 170 | } 171 | } 172 | } 173 | 174 | // Lastly the function closes the .txt file. 175 | fclose(stdin); 176 | } 177 | -------------------------------------------------------------------------------- /documentation/offline/3._Description_of_EVERYTHING_and_3.1._Defines.md: -------------------------------------------------------------------------------- 1 | # 3. Detailed description of EVERYTHING 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This segment of the documentation will have four main subsections: 4 | * [Defines](#31-defines) 5 | * [Structures](3.2._Structures.md/#32-structures) 6 | * [Variables](3.3._Variables_in_the_main_.cpp_file.md/#33-variables-in-the-main-cpp-file) 7 | * [Functions](3.4._Functions_and_3.4.1._input.h.md/#34-functions) 8 | 9 | ## 3.1. Defines 10 | ### 3.1.1. SCREENCOLS, MENUCOLS, CONSOLEROWS and CONSOLECOLS 11 | ###### This section was last checked in the 2.0.3. version of the engine 12 | ```cpp 13 | // The width of the "screen" part of the console window. 14 | #define SCREENCOLS 39 15 | 16 | // The width of the "screen" part of the console window. 17 | #define MENUCOLS 41 18 | 19 | // The dimensions of the console window. 20 | #define CONSOLEROWS 24 21 | #define CONSOLECOLS 80 22 | ``` 23 | **Usage:** These define the dimensions of the console window, and furthermore the "length" of the "screen" and "menu" part of the console window. 24 | 25 | **Notes:** The "screen" part of the console window is where the player in the world is displayed. The "menu" part of the console window is empty as of 2.0.3. but in further updates I plan to add a basic inventory/menu system in this part of the console. If you change the dimensions of the FOVs it may be necessary to alter the SCREENROWS and MENUCOLS defines, the CONSOLEROWS and CONSOLECOLS defines however should not be altered since the console window is 24 by 80. For more information about why the console window is divided into two smaller parts click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2212-the-whys-of-the-fov-editors-and-the-explanation-of-the-newscreen-and-newmenu-arrays). 26 | 27 | ### 3.1.2. FOVROWS and FOVCOLS 28 | ###### This section was last checked in the 2.0.3. version of the engine 29 | ```cpp 30 | // The dimensions of the FOVs and FOV arrays. 31 | #define FOVROWS 21 32 | #define FOVCOLS 35 33 | ``` 34 | **Usage:** These define the dimensions of the [FOV editors](../../FOVs), and also [the arrays that hold the information parsed from those editors](3.3._Variables_in_the_main_.cpp_file.md/#3316-fov-arrays). 35 | 36 | **Notes:** These defines can be altered if someone wishes, but I don't think that is necessary. However if you do alter these please be wary, you can accidentally set their values to numbers that could mess with the rendering of the "screen" part of the console window, or these values [could indirectly negatively affect the map of the world](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor). 37 | 38 | ### 3.1.3. WORLDROWS and WORLDCOLS 39 | ###### This section was last checked in the 2.0.3. version of the engine 40 | ```cpp 41 | // The dimensions of the world map. 42 | #define WORLDROWS 63 43 | #define WORLDCOLS 231 44 | ``` 45 | **Usage:** These define the dimensions of the [map editor](../../maps/world.txt), and also the [newWorld array](3.3._Variables_in_the_main_.cpp_file.md/#3320-newworld) which holds the information parsed from said editor. 46 | 47 | **Notes:** These values can be altered freely, just make sure they are equal to the dimensions of [the map editor file](../../maps/world.txt), if you want to parse the whole of that file. Also leave 19 cells on the top and bottom and 35 cells on each side of the map unalterable, the reason for this was explained in a note [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor). For the 3.0.0. update I plan to make this process more streamlined, so you don't need to hard code the dimensions of the world into the program itself. 48 | 49 | ### 3.1.4. SOLIDCOUNT and WALKABLECOUNT 50 | ###### This section was last checked in the 2.0.3. version of the engine 51 | ```cpp 52 | // The amount of characters in the solidcount.txt file. 53 | #define SOLIDCOUNT 1 54 | // The amount of characters in the walkablecount.txt file. 55 | #define WALKABLECOUNT 1 56 | ``` 57 | **Usage:** These defines are equal to the number of characters that will be parsed in their respective material editor. 58 | 59 | **Notes:** These values should be changed if you want to add more "materials" (or characters) that have one or both of the possible attributes. These values should NEVER be any more than the number of characters their respective .txt files hold! For more information about these editors click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#222-how-to-use-the-material-editors). 60 | 61 | ### 3.1.5 INFINITECIMAL 62 | 63 | ###### This section was last checked in the 2.0.3. version of the engine 64 | 65 | ```cpp 66 | // A small amount that helps correcting cases like x = 1/3 = 0.333333 then 67 | // x * 3 = 0.999999 =/= 1. 68 | #define INFINITECIMAL 0.000001 69 | ``` 70 | 71 | **Usage:** This define holds a small amount that is in some cases added or subtracted to or from equations that are used to calculate line intersections. 72 | 73 | **Notes:** The usage of this define will be explored in further detail in [the description of the isMoreThanHalfInShade function](3.4.5._shadowFunctions.h.md/#34510-ismorethanhalfinshade), but this define should never be altered because it will wreck the shading system completely. 74 | 75 | ### 3.1.6. MAXAMOUNTOFANIMATIONFRAMES 76 | 77 | ###### This section was last checked in the 2.0.3. version of the engine 78 | 79 | ```cpp 80 | // The maximum amount of frames that can be in an animation. 81 | #define MAXAMOUNTOFANIMATIONFRAMES 500 82 | ``` 83 | 84 | **Usage:** This define contains the maximum amount of frames an animation can have. 85 | 86 | **Notes:** You should change this define if you want to have an animation that exceeds the length of `(sleepTime * MAXAMOUNTOFANIMATIONFRAMES) / 1000` seconds. Where sleepTime is the milliseconds that pass between drawing two frame, and 1000 is the amount of milliseconds a second has. To learn more about the animation pipeline click [here](3.2._Structures.md/#327-animation). -------------------------------------------------------------------------------- /documentation/online/3.4.6. animation.h.md: -------------------------------------------------------------------------------- 1 | ### 3.4.6. [animation.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/rendering/animation.h) 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This header file contains all the functions that are a part of the animation pipeline. 4 | #### 3.4.6.1. initNewAnimation 5 | ###### This section was last checked in the 2.0.3. version of the engine 6 | 7 | ```cpp 8 | // This function initalizes an anmiation. 9 | animation initNewAnimation(animation anim, string fileName) 10 | { 11 | // First we get a temporary variable we can read characters into and check for 12 | // different things. 13 | char cahr; 14 | 15 | // Next we open the file. 16 | fstream fbe (fileName.c_str()); 17 | 18 | // After that we read the amount of frames the animation has, the height of each 19 | // frame and the widht of every frame. 20 | fbe>>anim.frames>>anim.height>>anim.width; 21 | 22 | // Then we set the currentFrame sub variable of the structure to 0. 23 | anim.currentFrame = 0; 24 | 25 | // After all that we loop over evey cell of every frame of the animation. 26 | for (int g = 0; g < anim.frames; g++) 27 | { 28 | for (int i = 0; i < anim.height; i++) 29 | { 30 | for (int j = 0; j < anim.width; j++) 31 | { 32 | // We read the next character into cahr. 33 | fbe>>cahr; 34 | 35 | // We check if the character we just read was an 'i'. 36 | if (cahr == 'i') 37 | { 38 | // If the character we just read was an 'i' we make the texture of 39 | // the variable a ' ' character. 40 | anim.frameArray[g][i][j] = ' '; 41 | } 42 | else 43 | { 44 | // If the character we just read wasn't an 'i' we make the texture 45 | // of the variable the character we just read. 46 | anim.frameArray[g][i][j] = cahr; 47 | } 48 | } 49 | } 50 | } 51 | 52 | // Lastly the function closes the .txt file. 53 | fbe.close(); 54 | 55 | return anim; 56 | } 57 | ``` 58 | 59 | **Usage:** This function initializes a new animation from an appropriate .txt file 60 | 61 | **Variables:** 62 | 63 | * **anim:** This variable will hold all the relevant information about the animation. 64 | * **fileName:** This string holds the path from the main .cpp file to the .txt that contains the information about the animation. 65 | 66 | **How it's done & notes:** First the function opens the correct file, and then reads the frames, height and the width of the animation (these numbers are at the start of the .txt file). Then for each frame it loops through a height by width chunk of characters, replaces all 'i' characters with ' ' characters and reads them into the animation variable. At the end it returns this variable. To learn more about the animation pipeline click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#224-the-animation-pipeline). To learn more about the animation structure click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#327-animation). 67 | 68 | #### 3.4.6.2. playAnimation 69 | ###### This section was last checked in the 2.0.3. version of the engine 70 | 71 | ```cpp 72 | // This function plays the animation frame by frame. 73 | void playAnimation(char console[CONSOLEROWS][CONSOLECOLS], animation anim, int yRow, int xCol) 74 | { 75 | // The function checks if the current frame of the animation is still an existing 76 | // frame of the animation. 77 | if (anim.currentFrame < anim.frames) 78 | { 79 | // If the current frame does exist we loop through all the variables of the 80 | // current frame of the animation. 81 | for (int i = 0; i < anim.height; i++) 82 | { 83 | for (int j = 0; j < anim.width; j++) 84 | { 85 | // The function writes every variable into the correct cell (all 86 | // positions being offset with yRow and xCol). 87 | console[yRow + i][xCol + j] = anim.frameArray[anim.currentFrame][i][j]; 88 | } 89 | } 90 | } 91 | } 92 | ``` 93 | 94 | **Usage:** This function copies the animations current frame to the correct place in the newConsole array (which holds the information about the current to-be-rendered frame). 95 | 96 | **Variables:** 97 | 98 | - **console:** This array holds the current to-be-rendered frame of the console window. 99 | - **anim:** This variable holds the information about the animation we want to play 100 | - **yRow:** This variable determines which row will contain the first row of the animation frame. 101 | - **xCol:** This variable determines which column will contain the first column of the animation frame 102 | 103 | **How it's done & notes:** First the function checks if the current frame is smaller then the amount of frames in the animation. If it is then it copies the animation's current frame into the correct position into the console array. The cell in the console window with the coordinate of (yRow; xCol) will contain the upper left character of the animation frame. To learn more about the animation pipeline click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#224-the-animation-pipeline). This function can only be called inside a game loop since it only "renders" one frame per call (you'll need to call [the renderConsole function](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.4.%20render.h.md/#3443-renderconsole) too if you want to see the results of this function on screen), as of 2.0.3. you need to externally increment the currentFrame sub variable of the correct animation, this bug will hopefully be fixed by the 3.0.0. version. To learn more about the animation structure click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#327-animation). 104 | 105 | -------------------------------------------------------------------------------- /headers/system/system.h: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #ifndef shadow_functions_engine_system_h 5 | #define shadow_functions_engine_system_h 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | // 12 | 13 | #if defined(WIN32) or defined(_WINDOWS) 14 | #include 15 | #include 16 | #include 17 | #elif defined(unix) || defined(__unix) || defined(__unix__) 18 | #include // for sleep 19 | #define Sleep sleep 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include // For ioctl, TIOCGWINSZ 26 | #include // For STDOUT_FILENO 27 | 28 | #define VK_ESCAPE XK_Escape 29 | 30 | inline short GetKeyState(int key) 31 | { 32 | static KeySym keymap[] = { 33 | XK_A, XK_B, XK_C, XK_D, XK_E, XK_F, XK_G, XK_H, XK_I, XK_J, 34 | XK_K, XK_L, XK_M, XK_N, XK_O, XK_P, XK_Q, XK_R, XK_S, XK_T, 35 | XK_U, XK_V, XK_W, XK_X, XK_Y, XK_Z 36 | }; 37 | 38 | Display* dpy = XOpenDisplay(NULL); 39 | char keys_return[32]; 40 | XQueryKeymap(dpy, keys_return); 41 | KeyCode kc2 = XKeysymToKeycode(dpy, (key == VK_ESCAPE) ? key : keymap[key - 'A']); 42 | bool bPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7))); 43 | XCloseDisplay(dpy); 44 | 45 | return bPressed ? 0x8000 : 0; 46 | } 47 | 48 | #define HANDLE void* 49 | #define STD_OUTPUT_HANDLE 0 50 | #define GetStdHandle(_) nullptr 51 | 52 | struct COORD { 53 | int X, Y; 54 | }; 55 | 56 | #define SetConsoleCursorPosition(_, dest) printf("\033[%d;%dH", dest.Y + 1, dest.X + 1) 57 | 58 | #define DWORD unsigned 59 | #define TCHAR char 60 | 61 | struct CONSOLE_SCREEN_BUFFER_INFO 62 | { 63 | struct dwSize 64 | { 65 | int X, Y; 66 | } dwSize; 67 | 68 | int wAttributes; 69 | }; 70 | 71 | inline bool GetConsoleScreenBufferInfo(HANDLE h, CONSOLE_SCREEN_BUFFER_INFO* csbi) 72 | { 73 | (void) h; 74 | 75 | struct winsize size; 76 | ioctl(STDOUT_FILENO,TIOCGWINSZ, &size); 77 | 78 | csbi->dwSize.X = size.ws_col; 79 | csbi->dwSize.Y = size.ws_row; 80 | return true; 81 | } 82 | 83 | inline bool FillConsoleOutputCharacter(HANDLE h, TCHAR c, DWORD dwConSize, COORD coordScreen, DWORD* cCharsWritten ) 84 | { 85 | (void) h; (void) c; (void) dwConSize; (void) coordScreen; (void) cCharsWritten; 86 | std::cout << "\f"; 87 | 88 | return true; 89 | } 90 | 91 | inline bool FillConsoleOutputAttribute(HANDLE h, int wAttr, DWORD dwConSize, COORD coordScreen, DWORD* cCharsWritten) 92 | { 93 | (void) h; (void) wAttr; (void) dwConSize; (void) coordScreen; (void) cCharsWritten; 94 | std::cout << "\x1B[2J\x1B[H"; 95 | 96 | return true; 97 | } 98 | #endif // WINDOWS OR LINUX 99 | 100 | #endif // shadow_functions_engine_system_h 101 | 102 | // 103 | 104 | using namespace std; 105 | 106 | #ifndef DEFINE_INIT 107 | #define DEFINE_INIT 108 | 109 | // The width of the "screen" part of the console window. 110 | #define SCREENCOLS 39 111 | 112 | // The width of the "screen" part of the console window. 113 | #define MENUCOLS 41 114 | 115 | // The dimensions of the console window. 116 | #define CONSOLEROWS 24 117 | #define CONSOLECOLS 80 118 | 119 | // The dimensions of the FOVs and FOV arrays. 120 | #define FOVROWS 21 121 | #define FOVCOLS 35 122 | 123 | // The dimensions of the world map. 124 | #define WORLDROWS 63 125 | #define WORLDCOLS 231 126 | 127 | // The amount of characters in the solidcount.txt file. 128 | #define SOLIDCOUNT 1 129 | // The amount of characters in the walkablecount.txt file. 130 | #define WALKABLECOUNT 1 131 | 132 | // A small amount that helps correcting cases like x = 1/3 = 0.333333 then 133 | // x * 3 = 0.999999 =/= 1. 134 | #define INFINITECIMAL 0.000001 135 | 136 | // The maximum amount of frames that can be in an animation. 137 | #define MAXAMOUNTOFANIMATIONFRAMES 500 138 | 139 | #endif //DEFINE_INIT 140 | 141 | #ifndef STRUCT_INIT 142 | #define STRUCT_INIT 143 | 144 | // This strcture holds entities in the world (right now these entities are just the 145 | // player and the camera). 146 | struct mob 147 | { 148 | // These variables hold the coordinate/the position of the mob/entity in the world. 149 | int row; 150 | int col; 151 | // These variables hold the orientation of the mob. There are 8 different 152 | // orientatins. Currentaly only the player entity uses these sub variables. 153 | bool up; 154 | bool down; 155 | bool right; 156 | bool left; 157 | }; 158 | 159 | // This structure holds information about the map in the engine. 160 | struct map 161 | { 162 | // This sub variable holds the texture of the cell. 163 | char texture; 164 | // These sub variables hold the properties of the different cells. Solid si true 165 | // when the given cell blocks light, and walkable is true when the given cell does 166 | // not block movement. 167 | bool solid; 168 | bool walkable; 169 | // These sub variables hold information about the visibility of the different 170 | // cells. When mapInView is true the cell is in view, when mapIsEdge is true a 171 | // less intense shadow gets displayed in the game on that cell. 172 | bool mapInView; 173 | bool mapIsEdge; 174 | }; 175 | 176 | // This structure holds information about the FOV arrays. 177 | struct fov 178 | { 179 | // This is true if the cell is in view in the FOV array. 180 | bool inView; 181 | // This is true on the cell where the player is in the FOV array. 182 | bool isPlayer; 183 | }; 184 | 185 | // This structure holds the variables that define a line in the engine. 186 | struct line 187 | { 188 | // This is the slope of the line. 189 | double mSlope; 190 | // This is the point where the line intercepts the y axis. 191 | double bIntercept; 192 | // This is true if the line is below any given object we want to "compare" it to. 193 | bool isItLowerLine; 194 | }; 195 | 196 | // This structure holds two lines at once. 197 | struct edgeLines 198 | { 199 | line first; 200 | line second; 201 | }; 202 | 203 | // This structure holds coordinates. 204 | struct koordinate 205 | { 206 | double x; 207 | double y; 208 | }; 209 | 210 | // This structure holds animations. 211 | struct animation 212 | { 213 | // The number of frames in the animation. 214 | int frames; 215 | // The current frame of the animation the engine is playing/displaying. 216 | int currentFrame; 217 | // The "height" of every frame of the animation. 218 | int height; 219 | // The "width" of every frame of the animation. 220 | int width; 221 | // This array holds every frame of the animation. 222 | char frameArray[MAXAMOUNTOFANIMATIONFRAMES][CONSOLEROWS][SCREENCOLS + MENUCOLS]; 223 | }; 224 | 225 | #endif //STRUCT INIT 226 | -------------------------------------------------------------------------------- /documentation/online/3. Description of EVERYTHING and 3.1. Defines.md: -------------------------------------------------------------------------------- 1 | # 3. Detailed description of EVERYTHING 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This segment of the documentation will have four main subsections: 4 | * [Defines](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#31-defines) 5 | * [Structures](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#32-structures) 6 | * [Variables](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#33-variables-in-the-main-cpp-file) 7 | * [Functions](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.%20Functions%20and%203.4.1.%20input.h.md/#34-functions) 8 | 9 | ## 3.1. Defines 10 | ### 3.1.1. SCREENCOLS, MENUCOLS, CONSOLEROWS and CONSOLECOLS 11 | ###### This section was last checked in the 2.0.3. version of the engine 12 | ```cpp 13 | // The width of the "screen" part of the console window. 14 | #define SCREENCOLS 39 15 | 16 | // The width of the "screen" part of the console window. 17 | #define MENUCOLS 41 18 | 19 | // The dimensions of the console window. 20 | #define CONSOLEROWS 24 21 | #define CONSOLECOLS 80 22 | ``` 23 | **Usage:** These define the dimensions of the console window, and furthermore the "length" of the "screen" and "menu" part of the console window. 24 | 25 | **Notes:** The "screen" part of the console window is where the player in the world is displayed. The "menu" part of the console window is empty as of 2.0.3. but in further updates I plan to add a basic inventory/menu system in this part of the console. If you change the dimensions of the FOVs it may be necessary to alter the SCREENROWS and MENUCOLS defines, the CONSOLEROWS and CONSOLECOLS defines however should not be altered since the console window is 24 by 80. For more information about why the console window is divided into two smaller parts click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2212-the-whys-of-the-fov-editors-and-the-explanation-of-the-separation-of-the-newconsole-array). 26 | 27 | ### 3.1.2. FOVROWS and FOVCOLS 28 | ###### This section was last checked in the 2.0.3. version of the engine 29 | ```cpp 30 | // The dimensions of the FOVs and FOV arrays. 31 | #define FOVROWS 21 32 | #define FOVCOLS 35 33 | ``` 34 | **Usage:** These define the dimensions of the [FOV editors](https://github.com/mmmuscus/Shadow-Functions-Engine/tree/master/FOVs), and also [the arrays that hold the information parsed from those editors](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#3316-fov-arrays). 35 | 36 | **Notes:** These defines can be altered if someone wishes, but I don't think that is necessary. However if you do alter these please be wary, you can accidentally set their values to numbers that could mess with the rendering of the "screen" part of the console window, or these values [could indirectly negatively affect the map of the world](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2231-how-to-use-the-map-editor). 37 | 38 | ### 3.1.3. WORLDROWS and WORLDCOLS 39 | ###### This section was last checked in the 2.0.3. version of the engine 40 | ```cpp 41 | // The dimensions of the world map. 42 | #define WORLDROWS 63 43 | #define WORLDCOLS 231 44 | ``` 45 | **Usage:** These define the dimensions of the [map editor](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt), and also the [newWorld array](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#3320-newworld) which holds the information parsed from said editor. 46 | 47 | **Notes:** These values can be altered freely, just make sure they are equal to the dimensions of [the map editor file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt), if you want to parse the whole of that file. Also leave 19 cells on the top and bottom and 35 cells on each side of the map unalterable, the reason for this was explained in a note [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2231-how-to-use-the-map-editor). For the 3.0.0. update I plan to make this process more streamlined, so you don't need to hard code the dimensions of the world into the program itself. 48 | 49 | ### 3.1.4. SOLIDCOUNT and WALKABLECOUNT 50 | ###### This section was last checked in the 2.0.3. version of the engine 51 | ```cpp 52 | // The amount of characters in the solidcount.txt file. 53 | #define SOLIDCOUNT 1 54 | // The amount of characters in the walkablecount.txt file. 55 | #define WALKABLECOUNT 1 56 | ``` 57 | **Usage:** These defines are equal to the number of characters that will be parsed in their respective material editor. 58 | 59 | **Notes:** These values should be changed if you want to add more "materials" (or characters) that have one or both of the possible attributes. These values should NEVER be any more than the number of characters their respective .txt files hold! For more information about these editors click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#222-how-to-use-the-material-editors). 60 | 61 | ### 3.1.5 INFINITECIMAL 62 | 63 | ###### This section was last checked in the 2.0.3. version of the engine 64 | 65 | ```cpp 66 | // A small amount that helps correcting cases like x = 1/3 = 0.333333 then 67 | // x * 3 = 0.999999 =/= 1. 68 | #define INFINITECIMAL 0.000001 69 | ``` 70 | 71 | **Usage:** This define holds a small amount that is in some cases added or subtracted to or from equations that are used to calculate line intersections. 72 | 73 | **Notes:** The usage of this define will be explored in further detail in [the description of the isMoreThanHalfInShade function](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.5.%20shadowFunctions.h.md/#34510-ismorethanhalfinshade), but this define should never be altered because it will wreck the shading system completely. 74 | 75 | ### 3.1.6. MAXAMOUNTOFANIMATIONFRAMES 76 | 77 | ###### This section was last checked in the 2.0.3. version of the engine 78 | 79 | ```cpp 80 | // The maximum amount of frames that can be in an animation. 81 | #define MAXAMOUNTOFANIMATIONFRAMES 500 82 | ``` 83 | 84 | **Usage:** This define contains the maximum amount of frames an animation can have. 85 | 86 | **Notes:** You should change this define if you want to have an animation that exceeds the length of `(sleepTime * MAXAMOUNTOFANIMATIONFRAMES) / 1000` seconds. Where sleepTime is the milliseconds that pass between drawing two frame, and 1000 is the amount of milliseconds a second has. To learn more about the animation pipeline click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#224-the-animation-pipeline). 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 1. Introduction 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | **Note:** The 2.0.2. version of the engine now runs on Linux too! This port is thanks to the work of [SuperFola](https://github.com/SuperFola) who also did a few quality of life changes as well, go and check him out! 4 | 5 | ## 1.1. The structure of this documentation 6 | ###### This section was last checked in the 2.0.3. version of the engine 7 | This documentation will have three main parts and a [table of contents](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/4.%20Table%20of%20contents.md/#4-table-of-contents): 8 | * [The first](#1-introduction) is the introduction (the part you are reading right now) 9 | * [The second](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.%20How%20to%20use%20the%20engine%20and%202.1.%20How%20the%20engine%20works.md/#2-how-to-use-the-engine) is an overview of [how the engine works](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.%20How%20to%20use%20the%20engine%20and%202.1.%20How%20the%20engine%20works.md/#21-how-the-engine-works-a-breakdown-of-the-main-cpp-file) and [how you can operate it and it's different editors](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#22-how-to-use-the-editors-and-other-further-details) 10 | * [The third](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#3-detailed-description-of-everything) will go over every last detail about the [defines](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#31-defines), [structures](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#32-structures), [variables](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#33-variables-in-the-main-cpp-file) and [functions](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.%20Functions%20and%203.4.1.%20input.h.md/#34-functions) the engine uses 11 | 12 | In the [introduction](#1-introduction) I will cover [my motivation](#12-who-the-hell-am-i-and-what-the-hecky-heck-is-this) for this engine, [the idea, the end product and plans about the future of the project](#13-so-what-is-the-project). 13 | 14 | [The second part](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.%20How%20to%20use%20the%20engine%20and%202.1.%20How%20the%20engine%20works.md/#2-how-to-use-the-engine) will have two segments. [The first](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.%20How%20to%20use%20the%20engine%20and%202.1.%20How%20the%20engine%20works.md/#21-how-the-engine-works-a-breakdown-of-the-main-cpp-file) detailing the architecture of the system, what it does. [The second](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#22-how-to-use-the-editors-and-other-further-details) will be the guide to operate it. Hopefully these two segments will provide you with sufficient information to make a game with this engine. 15 | 16 | [The last part](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#3-detailed-description-of-everything) will (as mentioned above) go over the hows of the systems in place. It will be broken down into different subsections, each dealing with a header or cpp file and it's [defines](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#31-defines), [structures](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#32-structures), [variables](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#33-variables-in-the-main-cpp-file), or [functions](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.%20Functions%20and%203.4.1.%20input.h.md/#34-functions). [This part](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#3-detailed-description-of-everything) will act more like a cheat sheet than anything, if you wish to conserve your sanity do not read it from start to finish in one sitting. 17 | 18 | ## 1.2. Who the hell am I and what the hecky heck is this? 19 | ###### This section was last checked in the 2.0.3. version of the engine 20 | I originally started this project in high school. The initial goals of the project was to find out what I can do with my basic understanding of programming, whilst not looking up the answers to my problems. The last update I did while (on paper) I still was in high school was version 2.0.2. 21 | 22 | Now I am enrolled in a computer science degree. With this the project's goals have changed a bit. In the classes that I am taking and will be taking I will learn a lot of new things about programming. I plan to incorporate all this knowledge into my project. Another thing that has changed is the fact that after the 2.0.2. update I plan to look up different parts and functionalities of (for example) the windows.h header file, like how to set the dimensions or the font of the console window. The one goal that still remains the same is that if I have a problem I want to figure out the solution to it by myself. 23 | 24 | ## 1.3. So what is the project? 25 | ###### This section was last checked in the 2.0.3. version of the engine 26 | The bare minimum I wanted to accomplish was a real time 2D top down game, with a "realistic" binary shading system (this was all planned to be running in the windows console). The concept of the shading system is the following: There is a player (represented by the '@' character); who has a field of view in which he can see things; anything that would block his view (e.g.: an 'x' character) casts a shadow, meaning that he can't see the things behind the "wall", even if those things would be in his field of view. 27 | 28 | Here is an example for the shading system in action: 29 | 30 | ![example](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/screenShots/example.png) 31 | 32 | Besides the minimum goal I created basic text file based level and field of view editors. I also created the option to make new characters that could block light, or player movement. In the latest version (2.0.0.) I added an animation pipeline, with this you can create .txt files that will be parsed into animation arrays and can be played in the console window. 33 | 34 | Features as of now: 35 | * Real time 8 directional player movement 36 | * Binary shading 37 | * Map and field of view editors 38 | * Character attribute editors (can this character block light? can it block player movement?) 39 | * Animation pipeline 40 | 41 | The next big update of the project (3.0.0.) will be the entity update. In this version I plan to add different entities with different attributes, for example: torches that emit light, NPCs that can be interacted with, posts that have text on them etc. 42 | -------------------------------------------------------------------------------- /headers/output/movement.cpp: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "movement.h" 5 | 6 | // This function increments the correct coordinate of the player according to input. 7 | mob playerMovement(mob playr, bool w, bool s, bool a, bool d) 8 | { 9 | // The function checks for all 4 different directions and then increments the 10 | // coordinates accordingly. 11 | 12 | if (s) 13 | { 14 | playr.row++; 15 | } 16 | 17 | if (w) 18 | { 19 | playr.row--; 20 | } 21 | 22 | if (d) 23 | { 24 | playr.col++; 25 | } 26 | 27 | if (a) 28 | { 29 | playr.col--; 30 | } 31 | 32 | return playr; 33 | } 34 | 35 | // This function keeps the player in bounds. 36 | mob keepInBounds(mob playr, mob lastPlayr, map world[WORLDROWS][WORLDCOLS]) 37 | { 38 | // First the function checks if both of the coordinates of the player have changed. 39 | if (playr.row != lastPlayr.row && playr.col != lastPlayr.col) 40 | { 41 | // If the coordinates of the player have changed then the function checks if 42 | // the cell the player wants to pass into blocks player movement. 43 | if (world[playr.row][playr.col].walkable == false) 44 | { 45 | // If the cell that the player wants to pass into blocks player movement 46 | // the function checks if the cells that are next to the position of the 47 | // player from the last frame and the cell the player wants to pass both are 48 | // "walkable". 49 | if (world[playr.row][lastPlayr.col].walkable == true && world[lastPlayr.row][playr.col].walkable == true) 50 | { 51 | // If both of the cells next to the position of the player from the 52 | // last frame and the cell teh player wants to pass into are true we set 53 | // the player's position back to it's position from the last frame. 54 | playr.row = lastPlayr.row; 55 | playr.col = lastPlayr.col; 56 | } 57 | else 58 | { 59 | // If at least one of the cells that are next to both the position of 60 | // the player from the last frame and the cell the player wants to pass 61 | // into blocks player movement we check if both of them do. 62 | if (world[playr.row][lastPlayr.col].walkable == false && world[lastPlayr.row][playr.col].walkable == false) 63 | { 64 | // If both of the cells that are next to the position of the player 65 | // from the last frame and the cell the player wants to pass into 66 | // block player movement we set the player's position back to it's 67 | // postion from the last frame. 68 | playr.row = lastPlayr.row; 69 | playr.col = lastPlayr.col; 70 | } 71 | 72 | // After we concluded that only one of the cells that are next to both 73 | // the position of the player from the last frame and the cell the player 74 | // wants to pass into blocks player movement the function checks if the 75 | // cell that is above the cell the player wants to pass into blocks 76 | // player movement. 77 | if (world[lastPlayr.row][playr.col].walkable == false) 78 | { 79 | // If the cell that is above the cell the player wants to pass into 80 | // blocks movement we set the column part of the position of the 81 | // player back to the column part of the position of the player from 82 | // the last frame. 83 | playr.col = lastPlayr.col; 84 | } 85 | else 86 | { 87 | // If the cell that is above the cell the player wants to pass into 88 | // dosen't block movement (this means that the cell that is below the 89 | // position of the player from the last frame blocks movement) we set 90 | // the row part of the position of the player back to the row part of 91 | // the position of the player from the last frame. 92 | playr.row = lastPlayr.row; 93 | } 94 | } 95 | } 96 | else 97 | { 98 | // If the cell the player wants to pass into doesn't block movement the 99 | // function checks if the 2 cells that are next to both the position of the 100 | // player on the last frame and the position the player wants to pass into 101 | // are both blocking player movement. 102 | if (world[playr.row][lastPlayr.col].walkable == false && world[lastPlayr.row][playr.col].walkable == false) 103 | { 104 | // If both cells that are next to the position of the player on the 105 | // last frame and the cell the player wants to pass into block player 106 | // movement the function sets the player's position back to it's position 107 | // from the last frame. 108 | playr.row = lastPlayr.row; 109 | playr.col = lastPlayr.col; 110 | } 111 | } 112 | } 113 | else 114 | { 115 | // If at least one coordinate of the player stayed the same, we check if the 116 | // cell the player wants to pass into does block player movement. 117 | if (world[playr.row][playr.col].walkable == false) 118 | { 119 | // If the cell the player wants to pass into blocks player movement, we set 120 | // the player's position back to it's position from the last frame. 121 | playr.row = lastPlayr.row; 122 | playr.col = lastPlayr.col; 123 | } 124 | } 125 | 126 | return playr; 127 | } 128 | 129 | // This function sets the orientation of the player. 130 | mob setDirections(mob playr, bool w, bool s, bool a, bool d) 131 | { 132 | // First the function clears the orientation of the player from the last frame. 133 | playr.up = false; 134 | playr.down = false; 135 | playr.right = false; 136 | playr.left = false; 137 | 138 | // Next the function sets the correct orientation according to the input using the 139 | // orientational bools. 140 | 141 | if (w) 142 | { 143 | playr.up = true; 144 | } 145 | 146 | if (s) 147 | { 148 | playr.down = true; 149 | } 150 | 151 | if (a) 152 | { 153 | playr.left = true; 154 | } 155 | 156 | if (d) 157 | { 158 | playr.right = true; 159 | } 160 | 161 | return playr; 162 | } 163 | 164 | // This function sets where the camera should be according to the position and the 165 | // orientation of the player. 166 | mob camMovement(mob cam, mob playr) 167 | { 168 | // The function hardcodes the correct one of the 8 possible cases according to the 169 | // orientation of the player. 170 | 171 | if (playr.right && !playr.up && !playr.down) 172 | { 173 | cam.row = playr.row - 12; 174 | cam.col = playr.col - 3; 175 | } 176 | 177 | if (playr.right && playr.up) 178 | { 179 | cam.row = playr.row - 16; 180 | cam.col = playr.col - 9; 181 | } 182 | 183 | if (playr.right && playr.down) 184 | { 185 | cam.row = playr.row - 8; 186 | cam.col = playr.col - 9; 187 | } 188 | 189 | if (playr.left && !playr.up && !playr.down) 190 | { 191 | cam.row = playr.row - 12; 192 | cam.col = playr.col - 35; 193 | } 194 | 195 | if (playr.left && playr.up) 196 | { 197 | cam.row = playr.row - 16; 198 | cam.col = playr.col - 29; 199 | } 200 | 201 | if (playr.left && playr.down) 202 | { 203 | cam.row = playr.row - 8; 204 | cam.col = playr.col - 29; 205 | } 206 | 207 | if (playr.up && !playr.right && !playr.left) 208 | { 209 | cam.row = playr.row - 22; 210 | cam.col = playr.col - 19; 211 | } 212 | 213 | if (playr.down && !playr.right && !playr.left) 214 | { 215 | cam.row = playr.row - 2; 216 | cam.col = playr.col - 19; 217 | } 218 | 219 | return cam; 220 | } 221 | 222 | // This function pans the camera to the position it should be. 223 | mob cameraPan(mob cam, mob camDest) 224 | { 225 | // The function increments/decrements the correct coordinate of the camera 226 | // according to the destination it should arrive to. 227 | 228 | if (cam.row < camDest.row) 229 | { 230 | cam.row++; 231 | } 232 | 233 | if (cam.row > camDest.row) 234 | { 235 | cam.row--; 236 | } 237 | 238 | if (cam.col < camDest.col) 239 | { 240 | cam.col++; 241 | } 242 | 243 | if (cam.col > camDest.col) 244 | { 245 | cam.col--; 246 | } 247 | 248 | return cam; 249 | } 250 | 251 | // This function keeps the camera in bounds. 252 | mob keepCamInBounds(mob cam) 253 | { 254 | // If the upper edge of the camera would fall onto cells that do not exist on the 255 | // map the function sets the coordinates of the camera so that they are at the upper 256 | // edge of the map. 257 | if (cam.row < 0) 258 | { 259 | cam.row = 0; 260 | } 261 | 262 | // If the leftmost edge of the camera would fall onto cells that do not exist on 263 | // the map the function sets the coordinates of the camera so that they are at the 264 | // leftmost edge of the map. 265 | if (cam.col < 0) 266 | { 267 | cam.col = 0; 268 | } 269 | 270 | // If the lower edge of the camera would fall onto cells that do not exist on the 271 | // map the function sets the coordinates of the camera so that they are at the lower 272 | // edge of the map. 273 | if (cam.row > WORLDROWS - CONSOLEROWS) 274 | { 275 | cam.row = WORLDROWS - CONSOLEROWS; 276 | } 277 | 278 | // If the rightmost edge of the camera would fall onto cells that do not exist on 279 | // the map the function sets the coordinates of the camera so that they are at the 280 | // rightmost edge of the map. 281 | if (cam.col > WORLDCOLS - SCREENCOLS) 282 | { 283 | cam.col = WORLDCOLS - SCREENCOLS; 284 | } 285 | 286 | return cam; 287 | } 288 | -------------------------------------------------------------------------------- /documentation/offline/3.4.4._render.h.md: -------------------------------------------------------------------------------- 1 | ### 3.4.4. [render.h](../../headers/rendering/render.h) 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This header contains functions that either help rendering, or actually render stuff. 4 | #### 3.4.4.1. goTo 5 | ###### This section was last checked in the 2.0.3. version of the engine 6 | ```cpp 7 | // This function puts the cursor in a set position on the console window. 8 | // The working of this function can be found in the link below as the fourth answer: 9 | // https://stackoverflow.com/questions/10401724/move-text-cursor-to-particular-screen-coordinate 10 | void goTo (int row, int column) 11 | { 12 | HANDLE hStdout; 13 | hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 14 | 15 | COORD destCoord; 16 | 17 | destCoord.X = column; 18 | destCoord.Y = row; 19 | 20 | SetConsoleCursorPosition(hStdout, destCoord); 21 | } 22 | ``` 23 | **Usage:** This function puts the cursor into a set position in the console window. 24 | 25 | **Variables:** 26 | * **row:** The row of the cell to which the cursor will be put on the console window. 27 | * **col:** The column of the cell to which the cursor will be put on the console window. 28 | 29 | **How it's done & notes:** This was one of the three times where I resorted to outside sources to solve a problem. I found my answer [here](https://stackoverflow.com/questions/10401724/move-text-cursor-to-particular-screen-coordinate) in the fourth answer. For information about the coordinate system in place please click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2232-further-ramblings-about-the-coordinate-system). 30 | 31 | #### 3.4.4.2. clearScreen 32 | ###### This section was last checked in the 2.0.3. version of the engine 33 | ```cpp 34 | // This function clears the console window. 35 | // The workings of this function can be found at this link: 36 | // https://docs.microsoft.com/en-us/windows/console/clearing-the-screen 37 | void clearScreen() 38 | { 39 | HANDLE hConsole; 40 | hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 41 | 42 | COORD coordScreen = { 0, 0 }; 43 | DWORD cCharsWritten; 44 | CONSOLE_SCREEN_BUFFER_INFO csbi; 45 | DWORD dwConSize; 46 | 47 | // Get the number of character cells in the current buffer. 48 | 49 | if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) 50 | return; 51 | dwConSize = csbi.dwSize.X * csbi.dwSize.Y; 52 | 53 | // Fill the entire screen with blanks. 54 | 55 | if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', 56 | dwConSize, coordScreen, &cCharsWritten )) 57 | return; 58 | 59 | // Get the current text attribute. 60 | 61 | if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) 62 | return; 63 | 64 | // Set the buffer's attributes accordingly. 65 | 66 | if( !FillConsoleOutputAttribute( hConsole, csbi.wAttributes, 67 | dwConSize, coordScreen, &cCharsWritten )) 68 | return; 69 | 70 | // Put the cursor at its home coordinates. 71 | 72 | SetConsoleCursorPosition( hConsole, coordScreen ); 73 | } 74 | ``` 75 | **Usage:** Clears the console window. 76 | 77 | **Variables:** - 78 | 79 | **How it's done & notes:** This was one of the three times where I resorted to outside sources to solve my problem. Sadly I lost the original link, but I found this implementation of a clear screen function right [here](https://docs.microsoft.com/en-us/windows/console/clearing-the-screen)! 80 | 81 | #### 3.4.4.3. renderConsole 82 | ###### This section was last checked in the 2.0.3. version of the engine 83 | ```cpp 84 | // This function renders the console array onto the console window. 85 | void renderConsole(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]) 86 | { 87 | // First the function loops through all of the variables in the array. 88 | for (int i = 0; i < CONSOLEROWS; i++) 89 | { 90 | for (int j = 0; j < CONSOLECOLS; j++) 91 | { 92 | // We check if the variable we are on is different in the pervious frame, 93 | // if it is we go to the correct cell on the console window adn write the 94 | // variable from the current frame onto the window. 95 | if (newC[i][j] != oldC[i][j]) 96 | { 97 | goTo(i, j); 98 | cout< (mSlope * a) + bIntercept`, if the point is on the line this equation is true: `b = (mSlope * a) + bIntercept`. For more information about this formula of the line click [here](https://en.wikipedia.org/wiki/Linear_equation#Slope%E2%80%93intercept_form). 122 | 123 | ### 3.2.5. edgeLines 124 | 125 | ###### This section was last checked in the 2.0.3. version of the engine 126 | 127 | ```cpp 128 | // This structure holds two lines at once. 129 | struct edgeLines 130 | { 131 | line first; 132 | line second; 133 | }; 134 | ``` 135 | 136 | **Usage:** This structure holds two [lines](#324-line) at once. 137 | 138 | **Sub variables:** 139 | 140 | - **first:** The first line. 141 | - **second:** The second line. 142 | 143 | **Notes:** This structure makes accessing the two lines that are cast to a rectangle (binary shading is produced by casting lines to only rectangles) from a player easier. 144 | 145 | ### 3.2.6. koordinate 146 | 147 | ###### This section was last checked in the 2.0.3. version of the engine 148 | 149 | ```cpp 150 | // This structure holds coordinates. 151 | struct koordinate 152 | { 153 | double x; 154 | double y; 155 | }; 156 | ``` 157 | 158 | **Usage:** This structure holds the values of a coordinate. 159 | 160 | **Sub variables:** 161 | 162 | - **x:** The x value. 163 | - **y:** The y value. 164 | 165 | **Notes:** This should not be confused with the coordinates of cells. This is the coordinate of points, this structure is used when casting lines from the player to objects. Details about the difference between cell and point coordinates can be found [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2232-further-ramblings-about-the-coordinate-system). 166 | 167 | ### 3.2.7. animation 168 | 169 | ###### This section was last checked in the 2.0.3. version of the engine 170 | 171 | ```cpp 172 | // This structure holds animations. 173 | struct animation 174 | { 175 | // The number of frames in the animation. 176 | int frames; 177 | // The current frame of the animation the engine is playing/displaying. 178 | int currentFrame; 179 | // The "height" of every frame of the animation. 180 | int height; 181 | // The "width" of every frame of the animation. 182 | int width; 183 | // This array holds every frame of the animation. 184 | char frameArray[MAXAMOUNTOFANIMATIONFRAMES][CONSOLEROWS][SCREENCOLS + MENUCOLS]; 185 | }; 186 | ``` 187 | 188 | **Usage:** This structure holds the properties of an animation, parsed from a .txt file 189 | 190 | **Sub variables:** 191 | 192 | - **frames:** The number of frames in the animation. 193 | - **currentFrame:** The current frame the animation is on, this is in use when playing the animation with the proper function. 194 | - **height:** The "height" of the animation, or the number of rows it contains. 195 | - **width:** The "width" of the animation, or the number of columns it contains. 196 | - **frameArray:** This 3 dimensional array holds the characters in every row and column of every frame. 197 | 198 | **Notes:** You should only change the number of frames in the frameArray sub array, since the other two dimensions (CONSOLEROWS and SCREENCOLS + MENUCOLS) are exactly 24 by 80 which is equal to the dimensions of the console window. Evidently the maximum value of height should not exceed the second dimension of the frameArray array (which is CONSOLEROWS = 24) and the maximum value of width should not exceed the third dimension of the frameArray array (which is SCEENCOLS + MENUCOLS = 80). To learn more about the animation pipeline click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#224-the-animation-pipeline). -------------------------------------------------------------------------------- /documentation/offline/4._Table_of_contents.md: -------------------------------------------------------------------------------- 1 | # 4. Table of contents 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | [1. Introduction](1._Introduction.md/#1-introduction) 4 | 5 | * [1.1. The structure of this documentation](1._Introduction.md/#11-the-structure-of-this-documentation) 6 | * [1.2. Who the hell am I and what the hecky heck is this?](1._Introduction.md/#12-who-the-hell-am-i-and-what-the-hecky-heck-is-this) 7 | * [1.3. So what is the project?](1._Introduction.md/#13-so-what-is-the-project) 8 | 9 | [2. How to use the engine](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2-how-to-use-the-engine) 10 | 11 | * [2.1. How the engine works: a breakdown of the main .cpp file](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#21-how-the-engine-works-a-breakdown-of-the-main-cpp-file) 12 | * [2.1.1. Initialization](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#211-initialization) 13 | * [2.1.1.1. System variables](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2111-system-variables) 14 | * [2.1.1.2. Alterable variables](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2112-alterable-variables) 15 | * [2.1.1.3. Variables that hold information parsed from the editors](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2113-variables-that-hold-information-parsed-from-the-editors) 16 | * [2.1.2. The game loop](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#212-the-game-loop) 17 | * [2.1.2.1. The intro](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2121-the-intro) 18 | * [2.1.2.2. Keeping the loop going, storing input and information from the last frame](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2122-keeping-the-loop-going-storing-input-and-information-from-the-last-frame) 19 | * [2.1.2.3. Player and camera movement](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2123-player-and-camera-movement) 20 | * [2.1.2.4. Producing the binary shading](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2124-producing-the-binary-shading) 21 | * [2.1.2.5. Rendering](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2125-rendering) 22 | * [2.2. How to use the editors, and other further details](2.2._How_to_use_the_editors,_and_other_further_details.md/22-how-to-use-the-editors-and-other-further-details) 23 | * [2.2.1. The FOV editors](2.2._How_to_use_the_editors,_and_other_further_details.md/#221-the-fov-editors) 24 | * [2.2.1.1. How to use the FOV editors](2.2._How_to_use_the_editors,_and_other_further_details.md/#2211-how-to-use-the-fov-editors) 25 | * [2.2.1.2. The whys of the FOV editors and the explanation of the separation of the newConsole array](2.2._How_to_use_the_editors,_and_other_further_details.md/#2212-the-whys-of-the-fov-editors-and-the-explanation-of-the-newscreen-and-newmenu-arrays) 26 | * [2.2.2. How to use the material editors](2.2._How_to_use_the_editors,_and_other_further_details.md/#222-how-to-use-the-material-editors) 27 | * [2.2.3. The map editor](2.2._How_to_use_the_editors,_and_other_further_details.md/#223-the-map-editor) 28 | * [2.2.3.1. How to use the map editor](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor) 29 | * [2.2.3.2. Further ramblings about the coordinate system](2.2._How_to_use_the_editors,_and_other_further_details.md/#2232-further-ramblings-about-the-coordinate-system) 30 | * [2.2.4. The animation pipeline](2.2._How_to_use_the_editors,_and_other_further_details.md/#224-the-animation-pipeline) 31 | 32 | [3. Detailed description of EVERYTHING](3._Description_of_EVERYTHING_and_3.1._Defines.md/#3-detailed-description-of-everything) 33 | 34 | * [3.1. Defines](3._Description_of_EVERYTHING_and_3.1._Defines.md/#31-defines) 35 | * [3.1.1. SCREENCOLS, MENUCOLS, CONSOLEROWS and CONSOLECOLS](3._Description_of_EVERYTHING_and_3.1._Defines.md/#311-screencols-menucols-consolerows-and-consolecols) 36 | * [3.1.2. FOVROWS and FOVCOLS](3._Description_of_EVERYTHING_and_3.1._Defines.md/#312-fovrows-and-fovcols) 37 | * [3.1.3. WORLDROWS and WORLDCOLS](3._Description_of_EVERYTHING_and_3.1._Defines.md/#313-worldrows-and-worldcols) 38 | * [3.1.4. SOLIDCOUNT and WALKABLECOUNT](3._Description_of_EVERYTHING_and_3.1._Defines.md/#314-solidcount-and-walkablecount) 39 | * [3.1.5. INFINITECIMAL](3._Description_of_EVERYTHING_and_3.1._Defines.md/#315-infinitecimal) 40 | * [3.1.6. MAXAMOUNTOFANIMATIONFRAMES](3._Description_of_EVERYTHING_and_3.1._Defines.md/#316-maxamountofanimationframes) 41 | * [3.2. Structures](3.2._Structures.md/#32-structures) 42 | * [3.2.1. mob](3.2._Structures.md/#321-mob) 43 | * [3.2.2. map](3.2._Structures.md/#322-map) 44 | * [3.2.3. fov](3.2._Structures.md/#323-fov) 45 | * [3.2.4. line](3.2._Structures.md/#324-line) 46 | * [3.2.5. edgeLines](3.2._Structures.md/#325-edgelines) 47 | * [3.2.6. koordinate](3.2._Structures.md/#326-koordinate) 48 | * [3.2.7. animation](3.2._Structures.md/#327-animation) 49 | * [3.3. Variables in the main .cpp file](3.3._Variables_in_the_main_.cpp_file.md/#33-variables-in-the-main-cpp-file) 50 | * [3.3.1. playerTexture](3.3._Variables_in_the_main_.cpp_file.md/#331-playertexture) 51 | * [3.3.2. screenDivisionTexture](3.3._Variables_in_the_main_.cpp_file.md/#332-screendivisiontexture) 52 | * [3.3.3. is___Pressed](3.3._Variables_in_the_main_.cpp_file.md/#333-is___pressed) 53 | * [3.3.4. player](3.3._Variables_in_the_main_.cpp_file.md/#334-player) 54 | * [3.3.5. lastPlayer](3.3._Variables_in_the_main_.cpp_file.md/#335-lastplayer) 55 | * [3.3.6. camera](3.3._Variables_in_the_main_.cpp_file.md/#336-camera) 56 | * [3.3.7. whereToCamera](3.3._Variables_in_the_main_.cpp_file.md/#337-wheretocamera) 57 | * [3.3.8. playerInFov](3.3._Variables_in_the_main_.cpp_file.md/#338-playerinfov) 58 | * [3.3.9. playerPov](3.3._Variables_in_the_main_.cpp_file.md/#339-playerpov) 59 | * [3.3.10. edges](3.3._Variables_in_the_main_.cpp_file.md/#3310-edges) 60 | * [3.3.11. sleepTime](3.3._Variables_in_the_main_.cpp_file.md/#3311-sleeptime) 61 | * [3.3.12. isNotExit](3.3._Variables_in_the_main_.cpp_file.md/#3312-isnotexit) 62 | * [3.3.13. isIntro](3.3._Variables_in_the_main_.cpp_file.md/#3313-isintro) 63 | * [3.3.14. oldConsole](3.3._Variables_in_the_main_.cpp_file.md/#3314-oldconsole) 64 | * [3.3.15. newConsole](3.3._Variables_in_the_main_.cpp_file.md/#3315-newconsole) 65 | * [3.3.16. FOV arrays](3.3._Variables_in_the_main_.cpp_file.md/#3316-fov-arrays) 66 | * [3.3.17. currentFov](3.3._Variables_in_the_main_.cpp_file.md/#3317-currentfov) 67 | * [3.3.18. solid](3.3._Variables_in_the_main_.cpp_file.md/#3318-solid) 68 | * [3.3.19. walkable](3.3._Variables_in_the_main_.cpp_file.md/#3319-walkable) 69 | * [3.3.20. newWorld](3.3._Variables_in_the_main_.cpp_file.md/#3320-newworld) 70 | * [3.3.21. logo](3.3._Variables_in_the_main_.cpp_file.md/#3321-logo) 71 | * [3.4. Functions](3.4._Functions_and_3.4.1._input.h.md/#34-functions) 72 | * [3.4.1. input.h](3.4._Functions_and_3.4.1._input.h.md/#341-inputh) 73 | * [3.4.1.1. ___Pressed](3.4._Functions_and_3.4.1._input.h.md/#3411-___pressed) 74 | * [3.4.1.2. cancelOut](3.4._Functions_and_3.4.1._input.h.md/#3412-cancelout) 75 | * [3.4.2. movement.h](3.4.2._movement.h.md/#342-movementh) 76 | * [3.4.2.1. playerMovement](3.4.2._movement.h.md/#3421-playermovement) 77 | * [3.4.2.2. keepInBounds](3.4.2._movement.h.md/#3422-keepinbounds) 78 | * [3.4.2.3. setDirections](3.4.2._movement.h.md/#3423-setdirections) 79 | * [3.4.2.4. camMovement](3.4.2._movement.h.md/#3424-cammovement) 80 | * [3.4.2.5. cameraPan](3.4.2._movement.h.md/#3425-camerapan) 81 | * [3.4.2.6. keepCamInBounds](3.4.2._movement.h.md/#3426-keepcaminbounds) 82 | * [3.4.3. output.h](3.4.3._output.h.md/#343-outputh) 83 | * [3.4.3.1. saveLastConsoleArray](3.4.3._output.h.md/#3431-savelastconsolearray) 84 | * [3.4.3.2. initSolid](3.4.3._output.h.md/#3432-initsolid) 85 | * [3.4.3.3. initWalkable](3.4.3._output.h.md/#3433-initwalkable) 86 | * [3.4.3.4. initWorld](3.4.3._output.h.md/#3434-initworld) 87 | * [3.4.3.5. initFOV](3.4.3._output.h.md/#3435-initfov) 88 | * [3.4.4. render.h](3.4.4._render.h.md/#344-renderh) 89 | * [3.4.4.1. goTo](3.4.4._render.h.md/#3441-goto) 90 | * [3.4.4.2. clearScreen](3.4.4._render.h.md/#3442-clearscreen) 91 | * [3.4.4.3. renderConsole](3.4.4._render.h.md/#3443-renderconsole) 92 | * [3.4.4.4. clearConsole](3.4.4._render.h.md/#3444-clearconsole) 93 | * [3.4.4.5. calculateScreen](3.4.4._render.h.md/#3445-calculatescreen) 94 | * [3.4.5. shadowFunctions.h](3.4.5._shadowFunctions.h.md/#345-shadowfunctionsh) 95 | * [3.4.5.1. makeCurrentFov](3.4.5._shadowFunctions.h.md/#3451-makecurrentfov) 96 | * [3.4.5.2. setCurrentFov](3.4.5._shadowFunctions.h.md/#3452-setcurrentfov) 97 | * [3.4.5.3. getPlayerPosInFov](3.4.5._shadowFunctions.h.md/#3453-getplayerposinfov) 98 | * [3.4.5.4. addFovInfoToMap](3.4.5._shadowFunctions.h.md/#3454-addfovinfotomap) 99 | * [3.4.5.5. getPov](3.4.5._shadowFunctions.h.md/#3455-getpov) 100 | * [3.4.5.6. getLineEquation](3.4.5._shadowFunctions.h.md/#3456-getlineequation) 101 | * [3.4.5.7. isUnderLine](3.4.5._shadowFunctions.h.md/#3457-isunderline) 102 | * [3.4.5.8. isOverLine](3.4.5._shadowFunctions.h.md/#3458-isoverline) 103 | * [3.4.5.9. isBetweenLines](3.4.5._shadowFunctions.h.md/#3459-isbetweenlines) 104 | * [3.4.5.10. isMoreThanHalfInShade](3.4.5._shadowFunctions.h.md/#34510-ismorethanhalfinshade) 105 | * [3.4.5.11. isBehindWall](3.4.5._shadowFunctions.h.md/#34511-isbehindwall) 106 | * [3.4.5.12. tShapeDetector](3.4.5._shadowFunctions.h.md/#34512-tshapedetector) 107 | * [3.4.5.13. getEdgeLines](3.4.5._shadowFunctions.h.md/#34513-getedgelines) 108 | * [3.4.5.14. shadowFunction](3.4.5._shadowFunctions.h.md/#34514-shadowfunction) 109 | * [3.4.5.15. holePlugger](3.4.5._shadowFunctions.h.md/#34515-holeplugger) 110 | * [3.4.5.16. isBesideNotSolidInView](3.4.5._shadowFunctions.h.md/#34516-isbesidenotsolidinview) 111 | * [3.4.5.17. mapIsEdgeCalculation](3.4.5._shadowFunctions.h.md/#34517-mapisedgecalculation) 112 | * [3.4.6. animation.h](3.4.6._animation.h.md/#346-animationh) 113 | * [3.4.6.1. initNewAimation](3.4.6._animation.h.md/#3461-initnewanimation) 114 | * [3.4.6.2. playAnimation](3.4.6._animation.h.md/#3462-playanimation) 115 | 116 | [4. Table of contents](#4-table-of-contents) 117 | 118 | -------------------------------------------------------------------------------- /documentation/online/3.4.4. render.h.md: -------------------------------------------------------------------------------- 1 | ### 3.4.4. [render.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/rendering/render.h) 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This header contains functions that either help rendering, or actually render stuff. 4 | #### 3.4.4.1. goTo 5 | ###### This section was last checked in the 2.0.3. version of the engine 6 | ```cpp 7 | // This function puts the cursor in a set position on the console window. 8 | // The working of this function can be found in the link below as the fourth answer: 9 | // https://stackoverflow.com/questions/10401724/move-text-cursor-to-particular-screen-coordinate 10 | void goTo (int row, int column) 11 | { 12 | HANDLE hStdout; 13 | hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 14 | 15 | COORD destCoord; 16 | 17 | destCoord.X = column; 18 | destCoord.Y = row; 19 | 20 | SetConsoleCursorPosition(hStdout, destCoord); 21 | } 22 | ``` 23 | **Usage:** This function puts the cursor into a set position in the console window. 24 | 25 | **Variables:** 26 | * **row:** The row of the cell to which the cursor will be put on the console window. 27 | * **col:** The column of the cell to which the cursor will be put on the console window. 28 | 29 | **How it's done & notes:** This was one of the three times where I resorted to outside sources to solve a problem. I found my answer [here](https://stackoverflow.com/questions/10401724/move-text-cursor-to-particular-screen-coordinate) in the fourth answer. For information about the coordinate system in place please click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2232-further-ramblings-about-the-coordinate-system). 30 | 31 | #### 3.4.4.2. clearScreen 32 | ###### This section was last checked in the 2.0.3. version of the engine 33 | ```cpp 34 | // This function clears the console window. 35 | // The workings of this function can be found at this link: 36 | // https://docs.microsoft.com/en-us/windows/console/clearing-the-screen 37 | void clearScreen() 38 | { 39 | HANDLE hConsole; 40 | hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 41 | 42 | COORD coordScreen = { 0, 0 }; 43 | DWORD cCharsWritten; 44 | CONSOLE_SCREEN_BUFFER_INFO csbi; 45 | DWORD dwConSize; 46 | 47 | // Get the number of character cells in the current buffer. 48 | 49 | if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) 50 | return; 51 | dwConSize = csbi.dwSize.X * csbi.dwSize.Y; 52 | 53 | // Fill the entire screen with blanks. 54 | 55 | if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', 56 | dwConSize, coordScreen, &cCharsWritten )) 57 | return; 58 | 59 | // Get the current text attribute. 60 | 61 | if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) 62 | return; 63 | 64 | // Set the buffer's attributes accordingly. 65 | 66 | if( !FillConsoleOutputAttribute( hConsole, csbi.wAttributes, 67 | dwConSize, coordScreen, &cCharsWritten )) 68 | return; 69 | 70 | // Put the cursor at its home coordinates. 71 | 72 | SetConsoleCursorPosition( hConsole, coordScreen ); 73 | } 74 | ``` 75 | **Usage:** Clears the console window. 76 | 77 | **Variables:** - 78 | 79 | **How it's done & notes:** This was one of the three times where I resorted to outside sources to solve my problem. Sadly I lost the original link, but I found this implementation of a clear screen function right [here](https://docs.microsoft.com/en-us/windows/console/clearing-the-screen)! 80 | 81 | #### 3.4.4.3. renderConsole 82 | ###### This section was last checked in the 2.0.3. version of the engine 83 | ```cpp 84 | // This function renders the console array onto the console window. 85 | void renderConsole(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]) 86 | { 87 | // First the function loops through all of the variables in the array. 88 | for (int i = 0; i < CONSOLEROWS; i++) 89 | { 90 | for (int j = 0; j < CONSOLECOLS; j++) 91 | { 92 | // We check if the variable we are on is different in the pervious frame, 93 | // if it is we go to the correct cell on the console window adn write the 94 | // variable from the current frame onto the window. 95 | if (newC[i][j] != oldC[i][j]) 96 | { 97 | goTo(i, j); 98 | cout< (mSlope * a) + bIntercept`, if the point is on the line this equation is true: `b = (mSlope * a) + bIntercept`. For more information about this formula of the line click [here](https://en.wikipedia.org/wiki/Linear_equation#Slope%E2%80%93intercept_form). 122 | 123 | ### 3.2.5. edgeLines 124 | 125 | ###### This section was last checked in the 2.0.3. version of the engine 126 | 127 | ```cpp 128 | // This structure holds two lines at once. 129 | struct edgeLines 130 | { 131 | line first; 132 | line second; 133 | }; 134 | ``` 135 | 136 | **Usage:** This structure holds two [lines](#324-line) at once. 137 | 138 | **Sub variables:** 139 | 140 | - **first:** The first line. 141 | - **second:** The second line. 142 | 143 | **Notes:** This structure makes accessing the two lines that are cast to a rectangle (binary shading is produced by casting lines to only rectangles) from a player easier. 144 | 145 | ### 3.2.6. koordinate 146 | 147 | ###### This section was last checked in the 2.0.3. version of the engine 148 | 149 | ```cpp 150 | // This structure holds coordinates. 151 | struct koordinate 152 | { 153 | double x; 154 | double y; 155 | }; 156 | ``` 157 | 158 | **Usage:** This structure holds the values of a coordinate. 159 | 160 | **Sub variables:** 161 | 162 | - **x:** The x value. 163 | - **y:** The y value. 164 | 165 | **Notes:** This should not be confused with the coordinates of cells. This is the coordinate of points, this structure is used when casting lines from the player to objects. Details about the difference between cell and point coordinates can be found [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2232-further-ramblings-about-the-coordinate-system). 166 | 167 | ### 3.2.7. animation 168 | 169 | ###### This section was last checked in the 2.0.3. version of the engine 170 | 171 | ```cpp 172 | // This structure holds animations. 173 | struct animation 174 | { 175 | // The number of frames in the animation. 176 | int frames; 177 | // The current frame of the animation the engine is playing/displaying. 178 | int currentFrame; 179 | // The "height" of every frame of the animation. 180 | int height; 181 | // The "width" of every frame of the animation. 182 | int width; 183 | // This array holds every frame of the animation. 184 | char frameArray[MAXAMOUNTOFANIMATIONFRAMES][CONSOLEROWS][SCREENCOLS + MENUCOLS]; 185 | }; 186 | ``` 187 | 188 | **Usage:** This structure holds the properties of an animation, parsed from a .txt file 189 | 190 | **Sub variables:** 191 | 192 | - **frames:** The number of frames in the animation. 193 | - **currentFrame:** The current frame the animation is on, this is in use when playing the animation with the proper function. 194 | - **height:** The "height" of the animation, or the number of rows it contains. 195 | - **width:** The "width" of the animation, or the number of columns it contains. 196 | - **frameArray:** This 3 dimensional array holds the characters in every row and column of every frame. 197 | 198 | **Notes:** You should only change the number of frames in the frameArray sub array, since the other two dimensions (CONSOLEROWS and SCREENCOLS + MENUCOLS) are exactly 24 by 80 which is equal to the dimensions of the console window. Evidently the maximum value of height should not exceed the second dimension of the frameArray array (which is CONSOLEROWS = 24) and the maximum value of width should not exceed the third dimension of the frameArray array (which is SCEENCOLS + MENUCOLS = 80). To learn more about the animation pipeline click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#224-the-animation-pipeline). -------------------------------------------------------------------------------- /documentation/offline/3.4.3._output.h.md: -------------------------------------------------------------------------------- 1 | ### 3.4.3. [output.h](../../headers/output/output.h) 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This header file contains [the function that makes rendering smoother and the game run faster](#3431-savelastconsolearray) and other functions that initialize the information from the different editors. I don't know why I named it output, but its too late now! 4 | 5 | #### 3.4.3.1. saveLastConsoleArray 6 | 7 | ###### This section was last checked in the 2.0.3. version of the engine 8 | 9 | ```cpp 10 | // This function copies a console array into another console array. 11 | void saveLastConsoleArray(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]) 12 | { 13 | // The function loops through all the values in the array and copies all of them 14 | // from one array to another. 15 | for (int i = 0; i < CONSOLEROWS; i++) 16 | { 17 | for (int j = 0; j < CONSOLECOLS; j++) 18 | { 19 | oldC[i][j] = newC[i][j]; 20 | } 21 | } 22 | } 23 | ``` 24 | 25 | **Usage:** This function saves the textures from the last frame of the console window. 26 | 27 | **Variables:** 28 | 29 | * **oldC:** This array will hold the textures from the last frame of the console window. 30 | 31 | * **newC:** This array currently holds the textures from the last frame of the console window. 32 | 33 | **How it's done & notes:** The function loops over every variable of the arrays and saves the information from the newC array into the oldC array. With this information the engine will run much smoother and faster since we only need to update cells that actually changed since the last frame. 34 | 35 | #### 3.4.3.2. initSolid 36 | ###### This section was last checked in the 2.0.3. version of the engine 37 | ```cpp 38 | // This function initializes all the characters that block light. 39 | void initSolid(char solide[SOLIDCOUNT], string fileName) 40 | { 41 | // First the function opens the file. 42 | fstream fbe (fileName.c_str()); 43 | 44 | // Next the function loops through all the characters in the .txt file and reads 45 | // them in. 46 | for (int i = 0; i < SOLIDCOUNT; i++) 47 | { 48 | fbe>>solide[i]; 49 | } 50 | 51 | // Lastly the function closes the .txt file. 52 | fbe.close(); 53 | } 54 | ``` 55 | **Usage:** This function gets all of the characters loaded from [the solid.txt](../../materials/solid.txt), these characters block light and thus create shadow. 56 | 57 | **Variables:** 58 | * **solide:** This array will hold all of the characters that block light. 59 | * **fileName:** This string holds the path from [the main .cpp file](../../ShadowFunctionsEngine.cpp) to [the solid.txt file](../../materials/solid.txt). 60 | 61 | **How it's done & notes:** The function opens and reads [the solid.txt file](../../materials/solid.txt). [SOLIDCOUNT](3._Description_of_EVERYTHING_and_3.1._Defines.md/#314-solidcount-and-walkablecount) determines how many of the characters from the file the function loops through. For more information about the solid material editor click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#222-how-to-use-the-material-editors). 62 | 63 | #### 3.4.3.3. initWalkable 64 | ###### This section was last checked in the 2.0.3. version of the engine 65 | ```cpp 66 | // This function initializes all the characters that don't block player movement. 67 | void initWalkable(char walkablee[WALKABLECOUNT], string fileName) 68 | { 69 | // First the function opens the file. 70 | fstream fbe (fileName.c_str()); 71 | 72 | // Next the function loops through all the characters in the .txt file and reads 73 | // them in. 74 | for (int i = 0; i < WALKABLECOUNT; i++) 75 | { 76 | fbe>>walkablee[i]; 77 | } 78 | 79 | // Lastly the function closes the .txt file. 80 | fbe.close(); 81 | } 82 | ``` 83 | **Usage:** This function gets all of the characters loaded from [the walkable.txt](../../materials/walkable.txt), these characters don't block player movement. 84 | 85 | **Variables:** 86 | * **solide:** This array will hold all of the characters that don't block player movement. 87 | * **fileName:** This string holds the path from [the main .cpp file](../../ShadowFunctionsEngine.cpp) to [the walkable.txt file](../../materials/walkable.txt). 88 | 89 | **How it's done & notes:** The function opens and reads [the walkable.txt file](../../materials/walkable.txt). [WALKABLECOUNT](3._Description_of_EVERYTHING_and_3.1._Defines.md/#314-solidcount-and-walkablecount) determines how many of the characters from the file the function loops through. For more information about the walkable material editor click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#222-how-to-use-the-material-editors). 90 | 91 | #### 3.4.3.4. initWorld 92 | ###### This section was last checked in the 2.0.3. version of the engine 93 | ```cpp 94 | // This function initializes the world map. 95 | void initWorld(map world[WORLDROWS][WORLDCOLS], char solide[SOLIDCOUNT], char walkablee[WALKABLECOUNT], string fileName) 96 | { 97 | // First we get a temporary variable we can read characters into and check for 98 | // different things. 99 | char cahr; 100 | 101 | // Next we open the file. 102 | freopen(fileName.c_str(),"r",stdin); 103 | 104 | // After that we start looping through the characters in the .txt file. 105 | for (int i = 0; i < WORLDROWS; i++) 106 | { 107 | for (int j = 0; j < WORLDCOLS; j++) 108 | { 109 | // We read the next character into cahr. 110 | cin>>cahr; 111 | 112 | // We check if the character we read was an 'i'. 113 | if (cahr == 'i') 114 | { 115 | // If the character we read was an 'i' we set the texture of the cell 116 | // to a ' ' character. 117 | world[i][j].texture = ' '; 118 | } 119 | else 120 | { 121 | // If the character we read wasn't an 'i' we set the texture of the 122 | // cell to what we read in. 123 | world[i][j].texture = cahr; 124 | } 125 | 126 | // Next we check if the cell we just read blocks light or player movement. 127 | 128 | // We set the .solid sub variable of the cell to false. 129 | world[i][j].solid = false; 130 | 131 | // After that we start looping through all the characters that block light. 132 | for (int k = 0; k < SOLIDCOUNT; k++) 133 | { 134 | // If the character we read is one of the characters that block light 135 | // we set the .solid sub variable of the cell to true. 136 | if (cahr == solide[k]) 137 | { 138 | world[i][j].solid = true; 139 | } 140 | } 141 | 142 | // We set the .walkable sub variable of the cell to false. 143 | world[i][j].walkable = false; 144 | 145 | // After that we start looping through all the characters that don't block 146 | // movement. 147 | for (int k = 0; k < WALKABLECOUNT; k++) 148 | { 149 | // If the character we read is one of the characters that don't block 150 | // movement we set the .solid sub variable of the cell to true. 151 | if (cahr == walkablee[k]) 152 | { 153 | world[i][j].walkable = true; 154 | } 155 | } 156 | } 157 | } 158 | 159 | // Lastly the function closes the .txt file. 160 | fclose(stdin); 161 | } 162 | ``` 163 | **Usage:** This function initializes the map of the world, with all of the important information such as textures, cells blocking light, or player movement etc. attached to each cell. 164 | 165 | **Variables:** 166 | * **world:** This array will hold all of the important information about each cell of the map of the game. 167 | * **soldie:** This array holds all of the characters that block light, and thus create shadows. 168 | * **walkablee:** This array holds all of the characters that don't block player movement. 169 | * **fileName:** This string holds the path from [the main .cpp file](../../ShadowFunctionsEngine.cpp) to [the world.txt file](../../maps/world.txt). 170 | 171 | **How it's done & notes:** Firstly the function opens [the world.txt file](../../maps/world.txt). Then it starts looping through each character. If the character is an 'i' the function replaces it with a ' ' character for the texture (click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor) if you want to find out why this is). Then the function loops through both the solid and walkable characters, and sets the correct attributes of [the structure](3.2._Structures.md/#322-map) to the correct values. For more information about the map editor click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#223-the-map-editor). 172 | 173 | #### 3.4.3.5. initFOV 174 | ###### This section was last checked in the 2.0.3. version of the engine 175 | ```cpp 176 | // This function initializes a FOV array. 177 | void initFOV(fov dir[FOVROWS][FOVCOLS], string fileName) 178 | { 179 | // First we get a temporary variable we can read characters into and check for 180 | // different things. 181 | char cahr; 182 | 183 | // Next we open the file. 184 | freopen(fileName.c_str(),"r",stdin); 185 | 186 | // After that we start looping through the characters in the .txt file. 187 | for (int i = 0; i < FOVROWS; i++) 188 | { 189 | for (int j = 0; j < FOVCOLS; j++) 190 | { 191 | // We read the next character into cahr. 192 | cin>>cahr; 193 | 194 | // We check if the character we read was an '_'. 195 | if (cahr == '_') 196 | { 197 | // If the character we read was an '_' we set the .inView sub variable 198 | // of the cell to true. 199 | dir[i][j].inView = true; 200 | } 201 | else 202 | { 203 | // If the character we read wasn't an '_' we set the .inView sub 204 | // variable of the cell to false. 205 | dir[i][j].inView = false; 206 | } 207 | 208 | // We check if the character we read was an '@'. 209 | if (cahr == '@') 210 | { 211 | // If the character we read was an '@' we set both the .isPlayer and 212 | // the .inView sub variable of the cell to true. 213 | dir[i][j].isPlayer = true; 214 | dir[i][j].inView = true; 215 | } 216 | else 217 | { 218 | // If the character we read wasn't an '@' we set the .isPlayer sub 219 | // variable of the cell to false. 220 | dir[i][j].isPlayer = false; 221 | } 222 | } 223 | } 224 | 225 | // Lastly the function closes the .txt file. 226 | fclose(stdin); 227 | } 228 | ``` 229 | **Usage:** This function is used to initialize all of the [FOV arrays](3.3._Variables_in_the_main_.cpp_file.md/#3316-fov-arrays). 230 | 231 | **Variables:** 232 | * **dir:** This array will hold all of the information about the FOV we are initializing right now. 233 | * **fileName:** This string holds the path from [the main .cpp file](../../ShadowFunctionsEngine.cpp) to the desired FOV file. 234 | 235 | **How it's done & notes:** First we open the desired FOV file. Then we start looping through all of the characters. According to the '\_', '0' and '@' characters we set the correct sub variable of the structure to true or false. For the meaning of the different characters in the FOV files click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2211-how-to-use-the-fov-editors). For more information about the FOV editors click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#221-the-fov-editors). -------------------------------------------------------------------------------- /documentation/offline/2.2._How_to_use_the_editors,_and_other_further_details.md: -------------------------------------------------------------------------------- 1 | ## 2.2. How to use the editors, and other further details 2 | ### 2.2.1. The FOV editors 3 | #### 2.2.1.1. How to use the FOV editors 4 | ###### This section was last checked in the 2.0.3. version of the engine 5 | The FOV "editors" are the text files located in [the FOVs folder](../../FOVs). There is a file for each of the eight directions the player can look. For example, this is the [rightUp.txt](../../FOVs/rightUp.txt): 6 | ``` 7 | 0000000000000000____________0000000 8 | 00000000000_____________________000 9 | 000000___________________________00 10 | 0000______________________________0 11 | 0__________________________________ 12 | ___________________________________ 13 | ___________________________________ 14 | ___________________________________ 15 | 0__________________________________ 16 | 00________________________________0 17 | 000_______________________________0 18 | 0000_____________________________00 19 | 00000___________________________000 20 | 000000_________________________0000 21 | 0000000@______________________00000 22 | 00000000_____________________000000 23 | 000000000___________________0000000 24 | 0000000000_________________00000000 25 | 00000000000_______________000000000 26 | 0000000000000___________00000000000 27 | 000000000000000_______0000000000000 28 | ``` 29 | The description of each character: 30 | * The '@' character represents the player, there should be exactly 1 of these characters per FOV file because it acts as the anchor point between the .txt and the map on which the information about the field of view is pasted onto (the function that does this can be found [here](3.4.5._shadowFunctions.h.md/#3454-addfovinfotomap)). (As of version 2.0.3. the position of this character does not get automatically parsed by the engine, so if you want to change it in this file you'll need to hard code that change into [the correct function](3.4.5._shadowFunctions.h.md/#3453-getplayerposinfov) as well. Fixing this issue is a planned goal for version 3.0.0.) 31 | * The '_' characters represent cells that are in the player's field of view. 32 | * The '0' characters represent cells that are not in the player's field of view. 33 | 34 | You can freely redraw any part of these .txt files, with the '@', '_' and '0' characters. The engine will parse the information and produce the new fields of view in the game. (When dealing with the '@' character please refer back to the description of it to make sure everything will work properly) 35 | 36 | #### 2.2.1.2. The whys of the FOV editors and the explanation of the separation of the newConsole array 37 | ###### This section was last checked in the 2.0.3. version of the engine 38 | All of these .txt files have a set height (21) and width (35). I wanted to make FOVs that are symmetrical, because it doesn't make sense if for example the player has a bigger field of view when he is looking right than when he is looking up. Since the console window is 24 cells by 80 cells the maximum width of the field of view can only be roughly equal to the height of 24 cells. That comes to about 39 cells in width (mileage may vary depending on the command prompt settings you have hopefully by 3.0.0. this won't be a factor). I also wanted to make a margin around all of the field of views. The reasoning behind this decision was that I think it looks weird if there is a cell that is in the field of view and also on the edge of the screen. Any such cell could mistakenly communicate that the field of view stretches beyond the screen which is (in my opinion) not something we want. As a result of all of this the field of view files shrunk to 21 by 35 (however upon further thinking for an easier time interpreting the editors I plan to expand their dimensions to 24 by 39 for the 3.0.0. version of the engine). 39 | 40 | Since the dimensions of the field of view are this small there is plenty of space on the console window for other stuff to be displayed. For the unused half of the console window I plan to add basic functions and/or editors that could produce a menu or an inventory system. If you want to expand the dimensions of the FOV files you'll need to change the value of [FOVROWS and FOVCOLS](3._Description_of_EVERYTHING_and_3.1._Defines.md/#312-fovrows-and-fovcols) which are defined in the [system.h header file](../../headers/system/system.h), but be prepared, if you change it to anything that is bigger than the dimensions of the newConsole array (which is 24 by 80) you will run into complications. But before you do anything with any of these values or the files please read [the part about using the map editors](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor), there is a note referring to possible problems that might surface. 41 | 42 | ### 2.2.2. How to use the material editors 43 | ###### This section was last checked in the 2.0.3. version of the engine 44 | The material "editors" are the .txt files located in [the materials folder](../../materials). One of them ([walkable.txt](../../materials/walkable.txt)) contains characters that don't block player movement, and the other ([solid.txt](../../materials/solid.txt)) contains characters that block light, thus creating shadows. Both of them function exactly the same, so I am only going to discuss the workings of the one concerned with the characters that are blocking light. Characters in the editor should be separated by an enter. When you are updating this file, make sure that the value of [SOLIDCOUNT](3._Description_of_EVERYTHING_and_3.1._Defines.md/#314-solidcount-and-walkablecount) (which variable is located in [the system.h file](../../headers/system/system.h)) equals that of the characters in this file, otherwise the function that loads these characters would go over too few or too many of them. Till 3.0.0. I plan to make this process more streamlined so you don't need to hard code changes into the program's files, just rewrite a number in the correct .txt file. 45 | 46 | ### 2.2.3. The map editor 47 | #### 2.2.3.1. How to use the map editor 48 | ###### This section was last checked in the 2.0.3. version of the engine 49 | The map "editor" is [the text file](../../maps/world.txt) located in [the maps folder](../../maps). It is a huge 231 by 63 .txt file, as with the other editors if you want to alter its size you should alter the value of [WORLDROWS and WORLDROWS](3._Description_of_EVERYTHING_and_3.1._Defines.md/#313-worldrows-and-worldcols) in [the system.h file](../../headers/system/system.h) as well. You might wonder why it's filled with 'i' characters, thats because I didn't figure out a way to read spaces, so any 'i' you see in any of the editors will be parsed by the engine as a ' ' character. You can write anything into [this .txt](../../maps/world.txt) (except for spaces I guess) and it will be visible in the map of the game. Any character that you write here and also into at least one of [the material editors](../../materials) will have the properties associated with said editor. 50 | 51 | **Note:** As of now it is recommended that you leave out 19 cells on the top and bottom and 35 cells at the sides of any map you create. Make sure the player can't pass into any of these left out cells (there is an example of how you can do this in [the default world.txt file](../../maps/world.txt)). The reason for this is that if the player would be in any of these cells, looking in the wrong direction, the engine would make calculations with variables in the [newWorld array](3.3._Variables_in_the_main_.cpp_file.md/#3320-newworld) that simply do not exist, leading to all sorts of problems. If you [alter the dimensions of the FOV files](2.2._How_to_use_the_editors,_and_other_further_details.md/#2212-the-whys-of-the-fov-editors-and-the-explanation-of-the-newscreen-and-newmenu-arrays) this recommended 19 and 35 cells might be too little to avoid any such catastrophe (or they might be too much, which can be a problem if you want to make bigger walkable maps). Hopefully the 3.0.0. update will solve this issue and we can finally use the map editor in its intended way. 52 | 53 | #### 2.2.3.2. Further ramblings about the coordinate system 54 | ###### This section was last checked in the 2.0.3. version of the engine 55 | I have explained the coordinate system once before, but just to be sure I will reiterate here. The coordinate system only deals with positive coordinates, and it is flipped, meaning that the (0; 0) cell is on the top left, and the (231; 63) cell is at the bottom right of (in this case) [the editor](../../maps/world.txt) (this is because the windows header uses a coordinate system like this, and I use this header for certain tasks that involve the manipulation of the console window). Columns run along the x axis and rows run along the y axis, the conversion between these names is often needed to understand the code of this engine. 56 | 57 | **Cells and points should NOT be confused!** Cell coordinates refer to the coordinate of a character in for example [the map editor](../../maps/world.txt), or in the [newWorld array](3.3._Variables_in_the_main_.cpp_file.md/#3320-newworld), and they are often used with col and row variables instead of the x and the y of a normal coordinate system. Points on the other hand refer to actual coordinates. These point coordinates are used in casting the lines from the player to the different obstacles in the environment, to produce shadows. 58 | 59 | ``` 60 | Coordinate of the Coordinate of the 61 | upper left point upper right point 62 | (a; b) _____________________________ (a + 1; b) 63 | | | 64 | | | 65 | | | 66 | | | 67 | | Coordinate of the cell: | 68 | | (a; b) | 69 | | | 70 | | | 71 | | | 72 | (a; b + 1) |___________________________| (a + 1; b + 1) 73 | Coordinate of the Coordinate of the 74 | bottom left point bottom right point: 75 | ``` 76 | Each cell has four point coordinates associated with it. If the cell's coordinates are (a; b) then the point on the upper left is (a; b) the point on the upper right is (a + 1; b) the point on the bottom left is (a; b + 1) and the point on the bottom right is (a + 1; b + 1), as the figure above shows. 77 | 78 | ### 2.2.4. The animation pipeline 79 | 80 | ###### This section was last checked in the 2.0.3. version of the engine 81 | 82 | The animation pipeline as of 2.0.3. consists of two functions, [the initNewAnimation function](3.4.6._animation.h.md/#3461-initnewanimation) and [the playAnimation function](3.4.6._animation.h.md/#3462-playanimation), and [the animation structure](3.2._Structures.md/#327-animation). A detailed description of all these elements will be found in [the next big chapter of this documentation](3._Description_of_EVERYTHING_and_3.1._Defines.md/#3-detailed-description-of-everything). To create a .txt file that contains an animation and can be initialized by the engine you'll need to do the following: 83 | 84 | * In the first row of the file you'll need to write the number of frames the animation contains 85 | 86 | * In the second row you'll need to write the number of rows each frame of the animation has 87 | 88 | * In the third row you'll need to write the number of columns each frame of the animation has 89 | 90 | * After these three numbers you must "write" all the frames of the animation with no division characters between the frames (except for enters and spaces) 91 | 92 | If you have done all these you now can initialize the animation from this .txt file with [the initNewAnimation function](3.4.6._animation.h.md/#3461-initnewanimation). For an example of a parse able animation file check out [the animation .txt of the intro animation](../../animations/logo.txt), this animation for example has 24 rows and 80 columns in each of its 220 frames, and this information can be clearly seen from the file's first three lines. 93 | -------------------------------------------------------------------------------- /documentation/online/3.4.3. output.h.md: -------------------------------------------------------------------------------- 1 | ### 3.4.3. [output.h](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/output/output.h) 2 | ###### This section was last checked in the 2.0.3. version of the engine 3 | This header file contains [the function that makes rendering smoother and the game run faster](#3431-savelastconsolearray) and other functions that initialize the information from the different editors. I don't know why I named it output, but its too late now! 4 | 5 | #### 3.4.3.1. saveLastConsoleArray 6 | ###### This section was last checked in the 2.0.3. version of the engine 7 | ```cpp 8 | // This function copies a console array into another console array. 9 | void saveLastConsoleArray(char oldC[CONSOLEROWS][CONSOLECOLS], char newC[CONSOLEROWS][CONSOLECOLS]) 10 | { 11 | // The function loops through all the values in the array and copies all of them 12 | // from one array to another. 13 | for (int i = 0; i < CONSOLEROWS; i++) 14 | { 15 | for (int j = 0; j < CONSOLECOLS; j++) 16 | { 17 | oldC[i][j] = newC[i][j]; 18 | } 19 | } 20 | } 21 | ``` 22 | 23 | **Usage:** This function saves the textures from the last frame of the console window. 24 | 25 | **Variables:** 26 | 27 | * **oldC:** This array will hold the textures from the last frame of the console window. 28 | 29 | * **newC:** This array currently holds the textures from the last frame of the console window. 30 | 31 | **How it's done & notes:** The function loops over every variable of the arrays and saves the information from the newC array into the oldC array. With this information the engine will run much smoother and faster since we only need to update cells that actually changed since the last frame. 32 | 33 | #### 3.4.3.2. initSolid 34 | ###### This section was last checked in the 2.0.3. version of the engine 35 | ```cpp 36 | // This function initializes all the characters that block light. 37 | void initSolid(char solide[SOLIDCOUNT], string fileName) 38 | { 39 | // First the function opens the file. 40 | fstream fbe (fileName.c_str()); 41 | 42 | // Next the function loops through all the characters in the .txt file and reads 43 | // them in. 44 | for (int i = 0; i < SOLIDCOUNT; i++) 45 | { 46 | fbe>>solide[i]; 47 | } 48 | 49 | // Lastly the function closes the .txt file. 50 | fbe.close(); 51 | } 52 | ``` 53 | **Usage:** This function gets all of the characters loaded from [the solid.txt](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/solid.txt), these characters block light and thus create shadow. 54 | 55 | **Variables:** 56 | * **solide:** This array will hold all of the characters that block light. 57 | * **fileName:** This string holds the path from [the main .cpp file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/ShadowFunctionsEngine.cpp) to [the solid.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/solid.txt). 58 | 59 | **How it's done & notes:** The function opens and reads [the solid.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/solid.txt). [SOLIDCOUNT](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#314-solidcount-and-walkablecount) determines how many of the characters from the file the function loops through. For more information about the solid material editor click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#222-how-to-use-the-material-editors). 60 | #### 3.4.3.3. initWalkable 61 | ###### This section was last checked in the 2.0.3. version of the engine 62 | ```cpp 63 | // This function initializes all the characters that don't block player movement. 64 | void initWalkable(char walkablee[WALKABLECOUNT], string fileName) 65 | { 66 | // First the function opens the file. 67 | fstream fbe (fileName.c_str()); 68 | 69 | // Next the function loops through all the characters in the .txt file and reads 70 | // them in. 71 | for (int i = 0; i < WALKABLECOUNT; i++) 72 | { 73 | fbe>>walkablee[i]; 74 | } 75 | 76 | // Lastly the function closes the .txt file. 77 | fbe.close(); 78 | } 79 | ``` 80 | **Usage:** This function gets all of the characters loaded from [the walkable.txt](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/walkable.txt), these characters don't block player movement. 81 | 82 | **Variables:** 83 | * **solide:** This array will hold all of the characters that don't block player movement. 84 | * **fileName:** This string holds the path from [the main .cpp file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/ShadowFunctionsEngine.cpp) to [the walkable.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/walkable.txt). 85 | 86 | **How it's done & notes:** The function opens and reads [the walkable.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/walkable.txt). [WALKABLECOUNT](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#314-solidcount-and-walkablecount) determines how many of the characters from the file the function loops through. For more information about the walkable material editor click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#222-how-to-use-the-material-editors). 87 | #### 3.4.3.4. initWorld 88 | ###### This section was last checked in the 2.0.3. version of the engine 89 | ```cpp 90 | // This function initializes the world map. 91 | void initWorld(map world[WORLDROWS][WORLDCOLS], char solide[SOLIDCOUNT], char walkablee[WALKABLECOUNT], string fileName) 92 | { 93 | // First we get a temporary variable we can read characters into and check for 94 | // different things. 95 | char cahr; 96 | 97 | // Next we open the file. 98 | freopen(fileName.c_str(),"r",stdin); 99 | 100 | // After that we start looping through the characters in the .txt file. 101 | for (int i = 0; i < WORLDROWS; i++) 102 | { 103 | for (int j = 0; j < WORLDCOLS; j++) 104 | { 105 | // We read the next character into cahr. 106 | cin>>cahr; 107 | 108 | // We check if the character we read was an 'i'. 109 | if (cahr == 'i') 110 | { 111 | // If the character we read was an 'i' we set the texture of the cell 112 | // to a ' ' character. 113 | world[i][j].texture = ' '; 114 | } 115 | else 116 | { 117 | // If the character we read wasn't an 'i' we set the texture of the 118 | // cell to what we read in. 119 | world[i][j].texture = cahr; 120 | } 121 | 122 | // Next we check if the cell we just read blocks light or player movement. 123 | 124 | // We set the .solid sub variable of the cell to false. 125 | world[i][j].solid = false; 126 | 127 | // After that we start looping through all the characters that block light. 128 | for (int k = 0; k < SOLIDCOUNT; k++) 129 | { 130 | // If the character we read is one of the characters that block light 131 | // we set the .solid sub variable of the cell to true. 132 | if (cahr == solide[k]) 133 | { 134 | world[i][j].solid = true; 135 | } 136 | } 137 | 138 | // We set the .walkable sub variable of the cell to false. 139 | world[i][j].walkable = false; 140 | 141 | // After that we start looping through all the characters that don't block 142 | // movement. 143 | for (int k = 0; k < WALKABLECOUNT; k++) 144 | { 145 | // If the character we read is one of the characters that don't block 146 | // movement we set the .solid sub variable of the cell to true. 147 | if (cahr == walkablee[k]) 148 | { 149 | world[i][j].walkable = true; 150 | } 151 | } 152 | } 153 | } 154 | 155 | // Lastly the function closes the .txt file. 156 | fclose(stdin); 157 | } 158 | ``` 159 | **Usage:** This function initializes the map of the world, with all of the important information such as textures, cells blocking light, or player movement etc. attached to each cell. 160 | 161 | **Variables:** 162 | * **world:** This array will hold all of the important information about each cell of the map of the game. 163 | * **soldie:** This array holds all of the characters that block light, and thus create shadows. 164 | * **walkablee:** This array holds all of the characters that don't block player movement. 165 | * **fileName:** This string holds the path from [the main .cpp file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/ShadowFunctionsEngine.cpp) to [the world.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt). 166 | 167 | **How it's done & notes:** Firstly the function opens [the world.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt). Then it starts looping through each character. If the character is an 'i' the function replaces it with a ' ' character for the texture (click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2231-how-to-use-the-map-editor) if you want to find out why this is). Then the function loops through both the solid and walkable characters, and sets the correct attributes of [the structure](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#322-map) to the correct values. For more information about the map editor click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#223-the-map-editor). 168 | 169 | #### 3.4.3.5. initFOV 170 | ###### This section was last checked in the 2.0.3. version of the engine 171 | ```cpp 172 | // This function initializes a FOV array. 173 | void initFOV(fov dir[FOVROWS][FOVCOLS], string fileName) 174 | { 175 | // First we get a temporary variable we can read characters into and check for 176 | // different things. 177 | char cahr; 178 | 179 | // Next we open the file. 180 | freopen(fileName.c_str(),"r",stdin); 181 | 182 | // After that we start looping through the characters in the .txt file. 183 | for (int i = 0; i < FOVROWS; i++) 184 | { 185 | for (int j = 0; j < FOVCOLS; j++) 186 | { 187 | // We read the next character into cahr. 188 | cin>>cahr; 189 | 190 | // We check if the character we read was an '_'. 191 | if (cahr == '_') 192 | { 193 | // If the character we read was an '_' we set the .inView sub variable 194 | // of the cell to true. 195 | dir[i][j].inView = true; 196 | } 197 | else 198 | { 199 | // If the character we read wasn't an '_' we set the .inView sub 200 | // variable of the cell to false. 201 | dir[i][j].inView = false; 202 | } 203 | 204 | // We check if the character we read was an '@'. 205 | if (cahr == '@') 206 | { 207 | // If the character we read was an '@' we set both the .isPlayer and 208 | // the .inView sub variable of the cell to true. 209 | dir[i][j].isPlayer = true; 210 | dir[i][j].inView = true; 211 | } 212 | else 213 | { 214 | // If the character we read wasn't an '@' we set the .isPlayer sub 215 | // variable of the cell to false. 216 | dir[i][j].isPlayer = false; 217 | } 218 | } 219 | } 220 | 221 | // Lastly the function closes the .txt file. 222 | fclose(stdin); 223 | } 224 | ``` 225 | **Usage:** This function is used to initialize all of the [FOV arrays](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#3316-fov-arrays). 226 | 227 | **Variables:** 228 | * **dir:** This array will hold all of the information about the FOV we are initializing right now. 229 | * **fileName:** This string holds the path from [the main .cpp file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/ShadowFunctionsEngine.cpp) to the desired FOV file. 230 | 231 | **How it's done & notes:** First we open the desired FOV file. Then we start looping through all of the characters. According to the '_', '0' and '@' characters we set the correct sub variable of the structure to true or false. For the meaning of the different characters in the FOV files click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2211-how-to-use-the-fov-editors). For more information about the FOV editors click [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#221-the-fov-editors). -------------------------------------------------------------------------------- /ShadowFunctionsEngine.cpp: -------------------------------------------------------------------------------- 1 | // For further infromation about the code please refer back to the documentation! 2 | 3 | 4 | #include "headers/system/system.h" 5 | 6 | 7 | #include "headers/input/input.h" 8 | 9 | 10 | #include "headers/output/output.h" 11 | #include "headers/output/movement.h" 12 | 13 | 14 | #include "headers/rendering/render.h" 15 | #include "headers/rendering/shadowFunctions.h" 16 | #include "headers/rendering/animation.h" 17 | 18 | // The texture of the player. 19 | const char playerTexture = '@'; 20 | // The texture that divides the "screen" and "menu" parts of the console window. 21 | const char screenDivisionTexture = '#'; 22 | 23 | int main() 24 | { 25 | // First the engine initializes all the variables that are needed fot it to run 26 | 27 | 28 | // The first kind of variables that the engine initializes are called "system variables". 29 | // These are variables that the engine manipulates, they should not be altered. 30 | // 31 | // The second kind of variables are ones that could be altered, if one wants to change 32 | // them, tho some have some restrictions about how you can alter them e.g.: player.row, 33 | // player.pow etc. 34 | // 35 | // The thrid type of variables are the ones that hold the information that is getting 36 | // parsed from the different kinds of editors. 37 | 38 | 39 | // In the following comments I will provide some detail about the variables that should 40 | // help the cursory glancer to understand some basics about the code. However theese comments 41 | // wont go into detail about the engine, for that please refer back to the documentation. 42 | 43 | 44 | // These varaibles hold the input coming from the kayboard. 45 | bool isWPressed; 46 | bool isSPressed; 47 | bool isAPressed; 48 | bool isDPressed; 49 | bool isEPressed; 50 | bool isEscPressed; 51 | 52 | // This variable holds the information about the player (position/orientation). 53 | mob player; 54 | player.row = 31; 55 | player.col = 45; 56 | player.up = false; 57 | player.down = false; 58 | player.right = true; 59 | player.left = false; 60 | 61 | // This variable holds the position of the player in the last frame. 62 | mob lastPlayer; 63 | lastPlayer.row = player.row; 64 | lastPlayer.col = player.col; 65 | 66 | // This variable holds the position of the camera. 67 | mob camera; 68 | camera = camMovement(camera, player); 69 | 70 | // This variable holds the position of where the camera should get to. 71 | mob whereToCamera; 72 | whereToCamera.row = camera.row; 73 | whereToCamera.col = camera.col; 74 | 75 | // This variable holds the position of the player in the current FOV array. 76 | mob playerInFov; 77 | 78 | // This variable holds the coordinate from which the player "sees" the world. 79 | koordinate playerPov; 80 | 81 | // This variable holds the lines that get cast from the player to the edges of 82 | // rectangles. 83 | edgeLines edges; 84 | 85 | 86 | // This variable holds the amount of time the engine waits inbetween every frame in 87 | // miliseconds. 88 | int sleepTime = 60; 89 | 90 | // If this variable gets set to false the game loop terminates. 91 | bool isNotExit = true; 92 | // If this variable gets set to false the intro part of the game loop stops and the 93 | // game part of the game loop begins. 94 | bool isIntro = true; 95 | 96 | // This array holds information about the last frame of the console window. With the 97 | // help of this array the rendering can run much smoother and faster. 98 | char oldConsole[CONSOLEROWS][CONSOLECOLS]; 99 | // This array holds information about the current frame of the console window. 100 | char newConsole[CONSOLEROWS][CONSOLECOLS]; 101 | 102 | // These arrays hold all the 8 possible FOVs. 103 | fov right[FOVROWS][FOVCOLS]; 104 | fov left[FOVROWS][FOVCOLS]; 105 | fov up[FOVROWS][FOVCOLS]; 106 | fov down[FOVROWS][FOVCOLS]; 107 | fov rightUp[FOVROWS][FOVCOLS]; 108 | fov rightDown[FOVROWS][FOVCOLS]; 109 | fov leftUp[FOVROWS][FOVCOLS]; 110 | fov leftDown[FOVROWS][FOVCOLS]; 111 | 112 | // This array holds the current FOV of the player. 113 | fov currentFov[FOVROWS][FOVCOLS]; 114 | 115 | initFOV(right, "FOVs/right.txt"); 116 | initFOV(left, "FOVs/left.txt"); 117 | initFOV(down, "FOVs/down.txt"); 118 | initFOV(up, "FOVs/up.txt"); 119 | initFOV(rightDown, "FOVs/rightDown.txt"); 120 | initFOV(rightUp, "FOVs/rightUp.txt"); 121 | initFOV(leftDown, "FOVs/leftDown.txt"); 122 | initFOV(leftUp, "FOVs/leftUp.txt"); 123 | 124 | makeCurrentFov(right, currentFov); 125 | 126 | playerInFov = getPlayerPosInFov(player, playerInFov); 127 | 128 | playerPov = getPov(playerPov, player); 129 | 130 | // This vector holds all the characters that block the player from seeing things 131 | // behind them. 132 | char solid[SOLIDCOUNT]; 133 | // This vector holds all the characters that don't block player movement. 134 | char walkable[WALKABLECOUNT]; 135 | 136 | initSolid(solid, "materials/solid.txt"); 137 | initWalkable(walkable, "materials/walkable.txt"); 138 | 139 | // This array holds all the relevant inforation about the world map. 140 | map newWorld[WORLDROWS][WORLDCOLS]; 141 | 142 | initWorld(newWorld, solid, walkable, "maps/world.txt"); 143 | 144 | // This variable holds the logo animation. 145 | animation logo = initNewAnimation(logo, "animations/logo.txt"); 146 | 147 | 148 | // After initialization we start the game loop. 149 | 150 | 151 | while (isNotExit) 152 | { 153 | // The game loop starts off with the intro. 154 | 155 | 156 | if (isIntro) 157 | { 158 | // The loop first waits for the set amount of time before computing anything. 159 | Sleep(sleepTime); 160 | 161 | // First we check if the 'E' button was pressed. 162 | isEPressed = ePressed(); 163 | 164 | if (isEPressed) 165 | { 166 | // If the 'E' button was pressed then we prime the game loop to exit the intro 167 | // part and enter the game part. 168 | 169 | // For this we first set the correct bool to false (so the game loop starts). 170 | isIntro = false; 171 | 172 | // Next we set the variable controlling the framerate to the correct value for 173 | // the gameplay. 174 | sleepTime = 30; 175 | 176 | // After that we prime the console window for cleariing the screen. 177 | clearConsole(newConsole, oldConsole); 178 | } 179 | else 180 | { 181 | // If the 'E' button wasn't pressed we continue playing the animation. 182 | 183 | // For any type of rendering in the engine we need to save the last frame of the 184 | // console window. 185 | saveLastConsoleArray(oldConsole, newConsole); 186 | 187 | // Next we update the current frame of the console window by "playing" the next 188 | // frame of the animation. 189 | playAnimation(newConsole, logo, 0, 0); 190 | if (logo.currentFrame < logo.frames) 191 | { 192 | logo.currentFrame++; 193 | } 194 | } 195 | 196 | // Lastly we render the console window. 197 | renderConsole(oldConsole, newConsole); 198 | } 199 | else 200 | { 201 | // If the intro part of the loop has ended, we start the game part of the loop. 202 | 203 | 204 | // The loop first waits for the set amount of time before computing anything. 205 | Sleep(sleepTime); 206 | 207 | 208 | // Next we deal with the incoming input. 209 | 210 | 211 | // First we set back all the bools that deal with the input to false. 212 | isWPressed = false; 213 | isAPressed = false; 214 | isSPressed = false; 215 | isDPressed = false; 216 | isEPressed = false; 217 | isEscPressed = false; 218 | 219 | // Next we get the input by using the correct functions of the engine. 220 | isWPressed = wPressed(); 221 | isAPressed = aPressed(); 222 | isSPressed = sPressed(); 223 | isDPressed = dPressed(); 224 | isEPressed = ePressed(); 225 | isEscPressed = escPressed(); 226 | 227 | // After that we check if the escape key was pressed. If it was we set the bool that 228 | // is responsible for getting into the game loop false, thus terminating the loop in 229 | // the next pass. 230 | if (isEscPressed) 231 | { 232 | isNotExit = false; 233 | } 234 | 235 | // Lastly we cancel out any contradictory input (such as left AND right). 236 | cancelOut(isWPressed, isSPressed); 237 | cancelOut(isAPressed, isDPressed); 238 | 239 | 240 | // After the input we ensure the smoother running of the engine by saving information 241 | // from the last frame. 242 | 243 | 244 | // Firstly we save the last frame of the console window. 245 | saveLastConsoleArray(oldConsole, newConsole); 246 | 247 | // Next we save the position of the player in the last frame. 248 | lastPlayer.row = player.row; 249 | lastPlayer.col = player.col; 250 | 251 | 252 | // After all this prep we start moving the player. 253 | 254 | 255 | // First we calculate where the player should be moved according to the input. 256 | player = playerMovement(player, isWPressed, isSPressed, isAPressed, isDPressed); 257 | // Next we calculate if the player can be moved into said position. 258 | player = keepInBounds(player, lastPlayer, newWorld); 259 | // Lastly we set the direction of the player according to input. 260 | player = setDirections(player, isWPressed, isSPressed, isAPressed, isDPressed); 261 | 262 | 263 | // After the player is moved next, we move the camera. 264 | 265 | 266 | // First we calculate where the camera should be according to the player's position. 267 | whereToCamera = camMovement(whereToCamera, player); 268 | // Next we "pan" the camera from the position it is to the position it should be 269 | // (the camera gets closer to its target by 1 cell both vertically and horizontally in 270 | // every frame). 271 | camera = cameraPan(camera, whereToCamera); 272 | // Lastly we make sure the camera is still in bounds. 273 | camera = keepCamInBounds(camera); 274 | 275 | 276 | // Next we start the prep work for the binadry shading 277 | 278 | 279 | // First we set the correct Field Of View according to the orientation of the player. 280 | setCurrentFov(player, currentFov, right, left, up, down, rightUp, rightDown, leftUp, leftDown); 281 | // Next we get the position of the player in the set FOV array. 282 | playerInFov = getPlayerPosInFov(player, playerInFov); 283 | // With the help of the position of the player in the FOV array we paste the FOV 284 | // information onto the map of the world. 285 | addFovInfoToMap(newWorld, player, playerInFov, currentFov); 286 | 287 | // Lastly we get the point of view of the player from which he sees the world (and 288 | // from which the lines that do the shading are cast). 289 | playerPov = getPov(playerPov, player); 290 | 291 | 292 | // After the prep work we start actually doing the shading. 293 | 294 | 295 | // With all the previous information we do the shading calculations. 296 | shadowFunction(newWorld, camera.col, camera.row, playerPov, edges); 297 | // Next we correct a bug thats due to the small resolution of the console window. 298 | holePlugger(newWorld, camera.col, camera.row); 299 | 300 | // We add an edge around the visible cells of the screen to make it look prettier. 301 | mapIsEdgeCalculation(newWorld, camera.row, camera.col); 302 | 303 | // Lastly we convert all this information into acual displayable textures. 304 | calculateScreen(newWorld, newConsole, camera.row, camera.col); 305 | 306 | 307 | // Lastly we do the actual rendering of the engine using all the information 308 | // calculated previously. 309 | 310 | // First we move the player's texture to the correct position in the currentFrame 311 | // array. We do this by first placing the correct texture onto the last position of the 312 | // player, and then placing the player's texture into the correct position in the array. 313 | if (newConsole[lastPlayer.row - camera.row][lastPlayer.col - camera.col] == playerTexture) 314 | { 315 | newConsole[lastPlayer.row - camera.row][lastPlayer.col - camera.col] = ' '; 316 | } 317 | newConsole[player.row - camera.row][player.col - camera.col] = playerTexture; 318 | 319 | // Next we place the line that divides the "screen" and "menu" part of the console 320 | // window into the correct coloumn of the window. 321 | for (int i = 0; i < CONSOLEROWS; i++) 322 | { 323 | newConsole[i][39] = screenDivisionTexture; 324 | } 325 | 326 | // Lastly we render the console window. 327 | renderConsole(oldConsole, newConsole); 328 | } 329 | } 330 | 331 | clearScreen(); 332 | 333 | return 0; 334 | } 335 | -------------------------------------------------------------------------------- /documentation/offline/3.3._Variables_in_the_main_.cpp_file.md: -------------------------------------------------------------------------------- 1 | ## 3.3. Variables in [the main .cpp file](../../ShadowFunctionsEngine.cpp) 2 | ### 3.3.1. playerTexture 3 | ###### This section was last checked in the 2.0.3. version of the engine 4 | ```cpp 5 | // The texture of the player. 6 | const char playerTexture = '@'; 7 | ``` 8 | **Usage:** This is the texture of the player character. 9 | 10 | **Notes:** This is a constant variable because I don't think there is a reason the texture of the player should change. 11 | 12 | ### 3.3.2. screenDivisionTexture 13 | ###### This section was last checked in the 2.0.3. version of the engine 14 | ```cpp 15 | // The texture that divides the "screen" and "menu" parts of the console window. 16 | const char screenDivisionTexture = '#'; 17 | ``` 18 | **Usage:** This is the texture of the line that divides the console window into the "screen" and "menu" sections. 19 | 20 | **Notes:** This is a constant character because I don't think the texture of the line should change. To learn more about this separation click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2212-the-whys-of-the-fov-editors-and-the-explanation-of-the-newscreen-and-newmenu-arrays). 21 | 22 | ### 3.3.3. is___Pressed 23 | ###### This section was last checked in the 2.0.3. version of the engine 24 | ```cpp 25 | // These varaibles hold the input coming from the kayboard. 26 | bool isWPressed; 27 | bool isSPressed; 28 | bool isAPressed; 29 | bool isDPressed; 30 | bool isEPressed; 31 | bool isEscPressed; 32 | ``` 33 | **Usage:** These variables are true on every frame the correct button (which's name is in the ___ space) is pressed. 34 | 35 | **Notes:** You can easily get the information from more keys as well, you just need to add a new variable in [the main .cpp file](../../ShadowFunctionsEngine.cpp) and a new function in the [input.h](../../headers/input/input.h) and [input.cpp](../../headers/input/input.cpp) file. I plan to omit the latter from the process until the 3.0.0. update 36 | 37 | ### 3.3.4. player 38 | ###### This section was last checked in the 2.0.3. version of the engine 39 | ```cpp 40 | // This variable holds the information about the player (position/orientation). 41 | mob player; 42 | player.row = 31; 43 | player.col = 45; 44 | player.up = false; 45 | player.down = false; 46 | player.right = true; 47 | player.left = false; 48 | ``` 49 | **Usage:** This variable holds all the important information about the player's location and orientation. 50 | 51 | **Notes:** You can freely alter any of these values, but when you do please refer back to [the section explaining the mob structure](3.2._Structures.md/#321-mob), and [the one detailing possible complications if the player goes to certain parts of the map](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor). 52 | 53 | ### 3.3.5. lastPlayer 54 | ###### This section was last checked in the 2.0.3. version of the engine 55 | ```cpp 56 | // This variable holds the position of the player in the last frame. 57 | mob lastPlayer; 58 | lastPlayer.row = player.row; 59 | lastPlayer.col = player.col; 60 | ``` 61 | **Usage:** This variable holds information about the position of the player in the last frame. 62 | 63 | **Notes:** For information about the mob structure click [here](3.2._Structures.md/#321-mob). 64 | 65 | ### 3.3.6. camera 66 | ###### This section was last checked in the 2.0.3. version of the engine 67 | ```cpp 68 | // This variable holds the position of the camera. 69 | mob camera; 70 | camera = camMovement(camera, player); 71 | ``` 72 | **Usage:** This variable holds information about the position of the camera. 73 | 74 | **Notes:** The camera's position is defined by the upper left corner of the view it shows. Meaning that if `camera.row = a` and `camera.col = b` the cell that is described by the row a and column b will be the top left cell shown by the engine. Altering these variables right here will result in the camera being in a different position relative to the player only until the player is first moved. If you want to alter the camera's position to the player at all times you should change [the responsible function](3.4.2._movement.h.md/#3424-cammovement) alongside these variables (for the 3.0.0. update I plan this to be automatic, so you dont have to hard code the camera's position). If you do decide to alter the camera's relative position watch out for the complications explained right [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#2231-how-to-use-the-map-editor). For information about the mob structure click [here](3.2._Structures.md/#321-mob). 75 | 76 | ### 3.3.7. whereToCamera 77 | ###### This section was last checked in the 2.0.3. version of the engine 78 | ```cpp 79 | // This variable holds the position of where the camera should get to. 80 | mob whereToCamera; 81 | whereToCamera.row = camera.row; 82 | whereToCamera.col = camera.col; 83 | ``` 84 | **Usage:** This variable holds information about the position the camera should be. 85 | 86 | **Notes:** Since I didn't want to teleport the camera franticly every time the player changes directions, I needed a variable that holds the position of where the camera should be (this position is changing very frantically but its not visible to the player). [The function dealing with camera pan](3.4.2._movement.h.md/#3425-camerapan) brings the camera one cell closer both vertically and horizontally to its desired location on every frame. For information about the mob structure click [here](3.2._Structures.md/#321-mob). 87 | 88 | ### 3.3.8. playerInFov 89 | ###### This section was last checked in the 2.0.3. version of the engine 90 | 91 | ```cpp 92 | // This variable holds the position of the player in the current FOV array. 93 | mob playerInFov; 94 | ``` 95 | **Usage:** This variable holds information about the player's location in the current [FOV array](#3316-fov-arrays). This position acts as an anchor between the current FOV and the map of the world. 96 | 97 | **Notes:** Further details about the need for this variable and the workings of it can be found in [the part discussing the usage of the FOV editors](2.2._How_to_use_the_editors,_and_other_further_details.md/#2211-how-to-use-the-fov-editors) and [the function that pastes the current FOV array into the world map](3.4.5._shadowFunctions.h.md/#3454-addfovinfotomap). For information about the mob structure click [here](3.2._Structures.md/#321-mob). 98 | 99 | ### 3.3.9. playerPov 100 | ###### This section was last checked in the 2.0.3. version of the engine 101 | ```cpp 102 | // This variable holds the coordinate from which the player "sees" the world. 103 | koordinate playerPov; 104 | ``` 105 | **Usage:** This variable holds information about the point of view of the player. Its the point from which lines are cast to objects to produce the binary shading effect. 106 | 107 | **Notes:** For information about the koordinate structure click [here](3.2._Structures.md/#326-koordinate). 108 | 109 | ### 3.3.10. edges 110 | ###### This section was last checked in the 2.0.3. version of the engine 111 | ```cpp 112 | // This variable holds the lines that get cast from the player to the edges of 113 | // rectangles. 114 | edgeLines edges; 115 | ``` 116 | **Usage:** This variable holds the two lines that are currently being cast from the player to objects that don't let light through. 117 | 118 | **Notes:** For information about the edgeLines structure click [here](3.2._Structures.md/#325-edgelines). 119 | 120 | ### 3.3.11. sleepTime 121 | ###### This section was last checked in the 2.0.3. version of the engine 122 | ```cpp 123 | // This variable holds the amount of time the engine waits inbetween every frame in 124 | // miliseconds. 125 | int sleepTime = 60; 126 | ``` 127 | **Usage:** This variable is equal to the time in milliseconds between two frames. 128 | 129 | **Notes:** Altering this variable can be done right here, no need for any extra steps. If you want to achieve 60 FPS set the value to 16. I found that animations are best played at 60 milliseconds of sleepTime, the game however is better played at 30. 130 | 131 | ### 3.3.12. isNotExit 132 | ###### This section was last checked in the 2.0.3. version of the engine 133 | ```cpp 134 | // If this variable gets set to false the game loop terminates. 135 | bool isNotExit = true 136 | ``` 137 | **Usage:** While this is true the game loop gets called. 138 | 139 | **Notes:** When the escape key is pressed this is set to false, that final loop still gets processed even after pressing the escape key. 140 | 141 | ### 3.3.13. isIntro 142 | 143 | ###### This section was last checked in the 2.0.3. version of the engine 144 | 145 | ```cpp 146 | // If this variable gets set to false the intro part of the game loop stops and the 147 | // game part of the game loop begins. 148 | bool isIntro = true; 149 | ``` 150 | 151 | **Usage:** While this is true [the "intro" part of the game loop](2._How_to_use_the_engine_and_2.1._How_the_engine_works.md/#2121-the-intro) gets called (this part only plays the intro animation). 152 | 153 | **Notes:** When the 'E' key is pressed the game loop moves on from the intro onto the actual game. 154 | 155 | ### 3.3.14. oldConsole 156 | 157 | ###### This section was last checked in the 2.0.3. version of the engine 158 | 159 | ```cpp 160 | // This array holds information about the last frame of the console window. With the 161 | // help of this array the rendering can run much smoother and faster. 162 | char oldConsole[CONSOLEROWS][CONSOLECOLS]; 163 | ``` 164 | 165 | **Usage: ** This array holds the textures from the last frame of the console window. 166 | 167 | **Notes:** This array is needed for the faster and smoother running of the game. 168 | 169 | ### 3.3.15. newConsole 170 | 171 | ###### This section was last checked in the 2.0.3. version of the engine 172 | 173 | ```cpp 174 | // This array holds information about the current frame of the console window. 175 | char newConsole[CONSOLEROWS][CONSOLECOLS]; 176 | ``` 177 | 178 | **Usage: ** This array holds the textures for the current frame of the console window. 179 | 180 | **Notes:** In every loop this is the array that gets updated with the current frame's properties. 181 | 182 | ### 3.3.16. FOV arrays 183 | ###### This section was last checked in the 2.0.3. version of the engine 184 | ```cpp 185 | // These arrays hold all the 8 possible FOVs. 186 | fov right[FOVROWS][FOVCOLS]; 187 | fov left[FOVROWS][FOVCOLS]; 188 | fov up[FOVROWS][FOVCOLS]; 189 | fov down[FOVROWS][FOVCOLS]; 190 | fov rightUp[FOVROWS][FOVCOLS]; 191 | fov rightDown[FOVROWS][FOVCOLS]; 192 | fov leftUp[FOVROWS][FOVCOLS]; 193 | fov leftDown[FOVROWS][FOVCOLS]; 194 | ``` 195 | **Usage:** These arrays hold the information about the 8 possible fields of view in the engine. 196 | 197 | **Notes:** These arrays get initialized from the [FOV editors](../../FOVs), for details about these editors click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#221-the-fov-editors). For information about the fov structure click [here](3.2._Structures.md/#323-fov). 198 | 199 | ### 3.3.17. currentFov 200 | ###### This section was last checked in the 2.0.3. version of the engine 201 | ```cpp 202 | // This array holds the current FOV of the player. 203 | fov currentFov[FOVROWS][FOVCOLS]; 204 | ``` 205 | **Usage:** This is where the according to the current orientation of the player the correct FOV array is stored. 206 | 207 | **Notes:** For information about the fov structure click [here](3.2._Structures.md/#323-fov). 208 | 209 | ### 3.3.18. solid 210 | ###### This section was last checked in the 2.0.3. version of the engine 211 | ```cpp 212 | // This vector holds all the characters that block the player from seeing things 213 | // behind them. 214 | char solid[SOLIDCOUNT]; 215 | ``` 216 | **Usage:** This array holds all the characters that block light. 217 | 218 | **Notes:** This array gets initialized from the [solid.txt](../../materials/solid.txt), for details about this editor click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#222-how-to-use-the-material-editors). 219 | 220 | ### 3.3.19. walkable 221 | ###### This section was last checked in the 2.0.3. version of the engine 222 | ```cpp 223 | // This vector holds all the characters that don't block player movement. 224 | char walkable[WALKABLECOUNT]; 225 | ``` 226 | **Usage:** This array holds all the characters that do not block player movement. 227 | 228 | **Notes:** This array gets initialized from the [walkable.txt](../../materials/walkable.txt), for details about this editor click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#222-how-to-use-the-material-editors). 229 | 230 | ### 3.3.20. newWorld 231 | ###### This section was last checked in the 2.0.3. version of the engine 232 | ```cpp 233 | // This array holds all the relevant inforation about the world map. 234 | map newWorld[WORLDROWS][WORLDCOLS]; 235 | ``` 236 | **Usage:** This array holds all of the needed information about the world. 237 | 238 | **Notes:** This array gets initialized from the [map editor](../../maps/world.txt), for details about this editor click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#223-the-map-editor). For details about the map structure click [here](3.2._Structures.md/#322-map). 239 | 240 | ### 3.3.21. logo 241 | 242 | ###### This section was last checked in the 2.0.3. version of the engine 243 | 244 | ```cpp 245 | // This variable holds the logo animation. 246 | animation logo = initNewAnimation(logo, "animations/logo.txt"); 247 | ``` 248 | 249 | **Usage:** This variable holds all the information about the intro/logo animation. 250 | 251 | **Notes:** For more information about the animation pipeline click [here](2.2._How_to_use_the_editors,_and_other_further_details.md/#224-the-animation-pipeline). -------------------------------------------------------------------------------- /documentation/online/2.2. How to use the editors, and other further details.md: -------------------------------------------------------------------------------- 1 | ## 2.2. How to use the editors, and other further details 2 | ### 2.2.1. The FOV editors 3 | #### 2.2.1.1. How to use the FOV editors 4 | ###### This section was last checked in the 2.0.3. version of the engine 5 | The FOV "editors" are the text files located in [the FOVs folder](https://github.com/mmmuscus/Shadow-Functions-Engine/tree/master/FOVs). There is a file for each of the eight directions the player can look. For example, this is the [rightUp.txt](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/FOVs/rightUp.txt): 6 | ``` 7 | 0000000000000000____________0000000 8 | 00000000000_____________________000 9 | 000000___________________________00 10 | 0000______________________________0 11 | 0__________________________________ 12 | ___________________________________ 13 | ___________________________________ 14 | ___________________________________ 15 | 0__________________________________ 16 | 00________________________________0 17 | 000_______________________________0 18 | 0000_____________________________00 19 | 00000___________________________000 20 | 000000_________________________0000 21 | 0000000@______________________00000 22 | 00000000_____________________000000 23 | 000000000___________________0000000 24 | 0000000000_________________00000000 25 | 00000000000_______________000000000 26 | 0000000000000___________00000000000 27 | 000000000000000_______0000000000000 28 | ``` 29 | The description of each character: 30 | * The '@' character represents the player, there should be exactly 1 of these characters per FOV file because it acts as the anchor point between the .txt and the map on which the information about the field of view is pasted onto (the function that does this can be found [here](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.5.%20shadowFunctions.h.md/#3454-addfovinfotomap)). (As of version 2.0.3. the position of this character does not get automatically parsed by the engine, so if you want to change it in this file you'll need to hard code that change into [the correct function](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.5.%20shadowFunctions.h.md/#3453-getplayerposinfov) as well. Fixing this issue is a planned goal for version 3.0.0.) 31 | * The '_' characters represent cells that are in the player's field of view. 32 | * The '0' characters represent cells that are not in the player's field of view. 33 | 34 | You can freely redraw any part of these .txt files, with the '@', '_' and '0' characters. The engine will parse the information and produce the new fields of view in the game. (When dealing with the '@' character please refer back to the description of it to make sure everything will work properly) 35 | 36 | #### 2.2.1.2. The whys of the FOV editors and the explanation of the separation of the newConsole array 37 | ###### This section was last checked in the 2.0.3. version of the engine 38 | All of these .txt files have a set height (21) and width (35). I wanted to make FOVs that are symmetrical, because it doesn't make sense if for example the player has a bigger field of view when he is looking right than when he is looking up. Since the console window is 24 cells by 80 cells the maximum width of the field of view can only be roughly equal to the height of 24 cells. That comes to about 39 cells in width (mileage may vary depending on the command prompt settings you have hopefully by 3.0.0. this won't be a factor). I also wanted to make a margin around all of the field of views. The reasoning behind this decision was that I think it looks weird if there is a cell that is in the field of view and also on the edge of the screen. Any such cell could mistakenly communicate that the field of view stretches beyond the screen which is (in my opinion) not something we want. As a result of all of this the field of view files shrunk to 21 by 35 (however upon further thinking for an easier time interpreting the editors I plan to expand their dimensions to 24 by 39 for the 3.0.0. version of the engine). 39 | 40 | Since the dimensions of the field of view are this small there is plenty of space on the console window for other stuff to be displayed. For the unused half of the console window I plan to add basic functions and/or editors that could produce a menu or an inventory system. If you want to expand the dimensions of the FOV files you'll need to change the value of [FOVROWS and FOVCOLS](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#312-fovrows-and-fovcols) which are defined in the [system.h header file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/system/system.h), but be prepared, if you change it to anything that is bigger than the dimensions of the newConsole array (which is 24 by 80) you will run into complications. But before you do anything with any of these values or the files please read [the part about using the map editors](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2231-how-to-use-the-map-editor), there is a note referring to possible problems that might surface. 41 | 42 | ### 2.2.2. How to use the material editors 43 | ###### This section was last checked in the 2.0.3. version of the engine 44 | The material "editors" are the .txt files located in [the materials folder](https://github.com/mmmuscus/Shadow-Functions-Engine/tree/master/materials). One of them ([walkable.txt](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/walkable.txt)) contains characters that don't block player movement, and the other ([solid.txt](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/materials/solid.txt)) contains characters that block light, thus creating shadows. Both of them function exactly the same, so I am only going to discuss the workings of the one concerned with the characters that are blocking light. Characters in the editor should be separated by an enter. When you are updating this file, make sure that the value of [SOLIDCOUNT](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#314-solidcount-and-walkablecount) (which variable is located in [the system.h file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/system/system.h)) equals that of the characters in this file, otherwise the function that loads these characters would go over too few or too many of them. Till 3.0.0. I plan to make this process more streamlined so you don't need to hard code changes into the program's files, just rewrite a number in the correct .txt file. 45 | 46 | ### 2.2.3. The map editor 47 | #### 2.2.3.1. How to use the map editor 48 | ###### This section was last checked in the 2.0.3. version of the engine 49 | The map "editor" is [the text file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt) located in [the maps folder](https://github.com/mmmuscus/Shadow-Functions-Engine/tree/master/maps). It is a huge 231 by 63 .txt file, as with the other editors if you want to alter its size you should alter the value of [WORLDROWS and WORLDROWS](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#313-worldrows-and-worldcols) in [the system.h file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/headers/system/system.h) as well. You might wonder why it's filled with 'i' characters, thats because I didn't figure out a way to read spaces, so any 'i' you see in any of the editors will be parsed by the engine as a ' ' character. You can write anything into [this .txt](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt) (except for spaces I guess) and it will be visible in the map of the game. Any character that you write here and also into at least one of [the material editors](https://github.com/mmmuscus/Shadow-Functions-Engine/tree/master/materials) will have the properties associated with said editor. 50 | 51 | **Note:** As of now it is recommended that you leave out 19 cells on the top and bottom and 35 cells at the sides of any map you create. Make sure the player can't pass into any of these left out cells (there is an example of how you can do this in [the default world.txt file](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt)). The reason for this is that if the player would be in any of these cells, looking in the wrong direction, the engine would make calculations with variables in the [newWorld array](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#3320-newworld) that simply do not exist, leading to all sorts of problems. If you [alter the dimensions of the FOV files](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/2.2.%20How%20to%20use%20the%20editors%2C%20and%20other%20further%20details.md/#2212-the-whys-of-the-fov-editors-and-the-explanation-of-the-separation-of-the-newconsole-array) this recommended 19 and 35 cells might be too little to avoid any such catastrophe (or they might be too much, which can be a problem if you want to make bigger walkable maps). Hopefully the 3.0.0. update will solve this issue and we can finally use the map editor in its intended way. 52 | 53 | #### 2.2.3.2. Further ramblings about the coordinate system 54 | ###### This section was last checked in the 2.0.3. version of the engine 55 | I have explained the coordinate system once before, but just to be sure I will reiterate here. The coordinate system only deals with positive coordinates, and it is flipped, meaning that the (0; 0) cell is on the top left, and the (231; 63) cell is at the bottom right of (in this case) [the editor](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt) (this is because the windows header uses a coordinate system like this, and I use this header for certain tasks that involve the manipulation of the console window). Columns run along the x axis and rows run along the y axis, the conversion between these names is often needed to understand the code of this engine. 56 | 57 | **Cells and points should NOT be confused!** Cell coordinates refer to the coordinate of a character in for example [the map editor](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/maps/world.txt), or in the [newWorld array](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.3.%20Variables%20in%20the%20main%20.cpp%20file.md/#3320-newworld), and they are often used with col and row variables instead of the x and the y of a normal coordinate system. Points on the other hand refer to actual coordinates. These point coordinates are used in casting the lines from the player to the different obstacles in the environment, to produce shadows. 58 | 59 | ``` 60 | Coordinate of the upper left point: Coordinate of the upper right point: 61 | (a; b) _____________________________ (a + 1; b) 62 | | | 63 | | | 64 | | | 65 | | | 66 | | Coordinate of the cell: | 67 | | (a; b) | 68 | | | 69 | | | 70 | | | 71 | Coordinate of the bottom left point: |___________________________| Coordinate of the bottom right point: 72 | (a; b + 1) (a + 1; b + 1) 73 | ``` 74 | Each cell has four point coordinates associated with it. If the cell's coordinates are (a; b) then the point on the upper left is (a; b) the point on the upper right is (a + 1; b) the point on the bottom left is (a; b + 1) and the point on the bottom right is (a + 1; b + 1), as the figure above shows. 75 | 76 | ### 2.2.4. The animation pipeline 77 | 78 | ###### This section was last checked in the 2.0.3. version of the engine 79 | 80 | The animation pipeline as of 2.0.3. consists of two functions, [the initNewAnimation function](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.6.%20animation.h.md/#3461-initnewanimation) and [the playAnimation function](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.6.%20animation.h.md/#3462-playanimation), and [the animation structure](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.2.%20Structures.md/#327-animation). A detailed description of all these elements will be found in [the next big chapter of this documentation](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.%20Description%20of%20EVERYTHING%20and%203.1.%20Defines.md/#3-detailed-description-of-everything). To create a .txt file that contains an animation and can be initialized by the engine you'll need to do the following: 81 | 82 | * In the first row of the file you'll need to write the number of frames the animation contains 83 | 84 | * In the second row you'll need to write the number of rows each frame of the animation has 85 | 86 | * In the third row you'll need to write the number of columns each frame of the animation has 87 | 88 | * After these three numbers you must "write" all the frames of the animation with no division characters between the frames (except for enters and spaces) 89 | 90 | If you have done all these you now can initialize the animation from this .txt file with [the initNewAnimation function](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/documentation/online/3.4.6.%20animation.h.md/#3461-initnewanimation). For an example of a parse able animation file check out [the animation .txt of the intro animation](https://github.com/mmmuscus/Shadow-Functions-Engine/blob/master/animations/logo.txt), this animation for example has 24 rows and 80 columns in each of its 220 frames, and this information can be clearly seen from the file's first three lines. 91 | --------------------------------------------------------------------------------