
Solving the maze
The objective of this project was to apply an important part of the programming skills acquired in the C language throughout the program, assuming the challenge of applying Raycasting to generate a virtual tour, using only this language and the SDL2 library
as well as basic elements of trigonometry and vector geometry, without the no game engine help or support tool to generate graphic elements. Mainly it was a personal challenge, to test the skills for solving algorithmic problems, which were enhanced through the foundations stage at Holberton School.
The Maze project is inspired in the world of the famous video game Wolfenstein 3D, which is built from a grid of walls of uniform height that are joined by solid colored floors and ceilings. To draw the world, a single ray is traced for each column of pixels on the screen and a vertical slice of the wall texture is selected and scaled according to where in the world the lightning strikes a wall and what so far he travels before he does. This project does not intend to build an exact replica of the video game or match it in complexity, but to generate the basic infrastructure to obtain an approximate model in the projection of the game environment and the player’s movement. The following diagram shows in a simplified way, the logic behind the game:

Technologies
Programming language: C
The C and C ++ languages are still preferred by professional developers of high-end video games. They are general-purpose languages, with a large number of compilers available that produce very efficient binaries, and are also used for develop all kinds of software, especially systems, such as the Linux kernel, and compilers, libraries and interpreters of other programming languages
Compiler: GCC (Ubuntu 4.8.4–2ubuntu1~14.04) 4.8.4)
Currently GCC is in standard use on most UNIX-like systems such as Linux, the family BSD and Mac OS X, is used to develop all kinds of professional software and is available for a wide variety of processor and platform architectures
GNU Make
It is a tool that controls the generation of executables and other files not source, of a program from the source files of the program. It will be used to execute and run the program, as well as manage the update of the executable file
SDL2 library in C
Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.
SDL framework vs a game engine
A game engine centralizes everything you need to develop video games. In other words, it is a tool that allows you to create video games for various platforms using a visual editor and scripting programming. SDL involves encoding a video game from its very bottom, it implies a much greater challenge and it requires a strong application of low-level programming skills as well as the application of vector geometry and trigonometry. Additionally SDL is free and open source software and provides Portability Facilitates software development for a wide variety of systems.
Ray Casting vs Ray Tracing
In Ray Tracing each ray is traced separately, so each point, usually a pixel, is traced by one single ray. In Ray Casting, 3-D worlds are described by 2-D maps which are overhead views of the worlds, this implies that the rays are cast and traced in groups, for example in a 640x400 display resolution a ray-caster traces only 640 rays, instead a ray-tracer needs to trace 256.000 rays. Ray Casting is much faster than ray tracing and makes it a much more viable option for real time rendering.
Ray tracing can produce a very high degree of visual realism however, it uses many more calculation cycles. Currently the video game industry is working on perfecting the implementation of Ray Tracing technique to provide much more real experiences.
Features and Challenges
This first version of the game includes 3 fundamental features:
- The projection of walls, floors and ceilings, from the perspective of the player.
- The implementation of forward and backward movements and player rotation, allowing for constant camera rotation.
- The use of different textures on stage.
Initialize the window
One of the biggest challenges was getting the SDL window to be displayed, multiple attempts were made with the graphical environment of an Ubuntu 14.04 virtual machine, however, it was not possible to establish communication with the video driver of the machine. so the first tests of the project were carried out on windows from visual studio. Subsequently, a disk partition was made and the X11 user interface system was installed, as well as the respective video drivers.
Create a player
Although C is not an object-oriented programming language, it was possible to simulate a player and define its attributes by means of a structure and thus achieve backward, forward and turning movements. Once the player is created, all kinds of challenges are triggered, the player ends up largely defining the existence of the labyrinth itself, depending on their movements, their position and their distance from the walls, ceiling and floor, it was an exciting challenge.
The Ray Casting
The player’s field of vision makes magic possible, you have to find a way to generate a projection plane and play with the speed, direction and distance variables to project the rays that make up that field of vision and start converting a 2D plant In a 3D illusion completely generated from mathematical analysis, this is something that involves long hours of study and abstraction.
Put textures on the stage
A texture is a digital representation of an image or a bunch of colors and pixels. it is something very similar to an array of pixel colors, which implies dynamic memory generation and finding a way to convert a png image into pixel by pixel information that SDL can interpret and display on the screen, for this purpose an external program was used.
The challenge is not over
It has been a very good challenge to put problem solving skills to the test, but without a doubt, to achieve high-level implementations, it is necessary to resort to game engines, all the logic that The Maze relies on, is under the hood and there is no need to reinvent the wheel.
Regarding the challenge initially posed by Holberton, without a doubt there are many things to improve and implement, such as the creation of enemies and the implementation of powers to the player, as well as functional elements to the stage.
From each challenge there is always the need to continue learning more, to not stop training in the art of solving problems and in the use of the infinity of tools and facilities that are part of this field and that evolve at an accelerated rate; there is no reason to stick to any language, you have to adapt, take advantage of all the tools you have at hand and be open to changes.
Daniela Lopera (Full-Stack Software Engineer)