Projecting a 2D map
The renderer traces horizontal and vertical grid intersections and selects the nearer wall hit. Wall distance determines the height of a projected vertical strip; a cosine correction accounts for the angle between each ray and the player’s viewing direction.
Input and rendering
SDL2 handles keyboard events, texture loading and drawing. The prototype includes player movement, rotation, textured map geometry and a separate viewport for the projected scene.
A foundation in graphics programming
This is a learning prototype rather than a complete game engine. The project makes the core geometry of raycasting explicit and provides a foundation for later rendering and engine work.
Explore the implementation
git clone https://github.com/SAED2906/C-Game-Engine.gitCode example
float ca = pa-ra;
if (ca < 0) { ca += 2*PI; }
if (ca > 2*PI) { ca -= 2*PI; }
float line_heigth = (36*SCREEN_HEIGHT)/(dist1*cosf(ca));
if (line_heigth > SCREEN_HEIGHT) { line_heigth = SCREEN_HEIGHT; }
SDL_RenderSetScale(renderer, 15.0f, 1.0f);
float line = SCREEN_HEIGHT/2 - line_heigth/2;
SDL_RenderDrawLine(renderer, r, line, r, line_heigth+line);