Raycaster_diagram.png

Raycaster Engine (hackathon):

I wrote this game engine for a hackathon in November 2018. It is all written in C++, using SDL for the graphics, fonts and image loading. The point of the game was to demonstrate pseudo 3D rendering technique present in popular retro games such as Wolfenstein 3D. I also tried to implement multiplayer functionality whereby multiple players could join a game and shoot each other. Unfortunately I ran out of time in the hackathon before this could be properly implemented, but other randomly moving characters are rendered.

In order to render the graphics, a technique called raycasting is used in order to extrapolate the 2D game map (shown in the top left corner) into a pseudo 3D frame.

In order to render the player’s view in 3D, a ray is cast out of the camera for each column of the output image. This ray is extended until it intersects a wall on the 2d map. The length of the ray dictates the height of the column in the image and its brightness. In this way, walls that are farther away appear smaller and darker. Additional calculations are done with the point of intersection to determine which wall type was encountered and which segment of the wall to render on screen.

Entities (such as the barrels or the other players) are rendered differently. Their images are scaled and moved based on their distance to the player and drawn in order of their proximity, from farthest to closest. The image used for the other players changes based on their orientation, which allows them to look different if viewed from the side, back, front, etc. This is extremely important for gameplay because it tells the player if others are aiming at them.

The last things to be drawn onscreen are the player’s gun, map and crosshairs, since they lie on top of all of the other graphics. The gun is animated using a sequence of 12 frames shown consecutively after the mouse is clicked. All of the images used in the game were taken from the internet.

A GitHub repository of this project’s source code is located here: https://github.com/Plasmabot1/Raycaster

Demo Video:

This video illustrates the core functionality of the engine and what I was able to accomplish in the limited hackathon time. The map in the corner shows much of what is going on behind the scenes. The player is represented by the light green square, which is also used to calculate collisions so that the player cannot move through solid walls and barrels. Each ray cast out from the camera is represented by a blue line, all of which together make up the player’s field of view. Each red square is an enemy, and their opacities indicate the order in which they are rendered, darkest red being the last to be drawn.