Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hayden-donnelly/the-navigator

The Navigator is a first person maze navigation game with a pseudo-3D rendering algorithm.
https://github.com/hayden-donnelly/the-navigator

game raycasting rendering

Last synced: about 9 hours ago
JSON representation

The Navigator is a first person maze navigation game with a pseudo-3D rendering algorithm.

Awesome Lists containing this project

README

        

## About
The Navigator is my ICS4U culminating project; a first person maze navigation game built with Java and Processing. You must navigate a procedurally generated maze and
reach the exit as quickly as you can. I used a raycast rendering algorithm similar to the one found in Wolfenstein 3D to achieve pseudo-3D visuals.

Gameplay: https://www.youtube.com/watch?v=srRdGsZwh-Q

## Rendering Algorithm

As mentioned, the rendering algorithm is similar to the one found in Wolfenstein 3D. It uses raycasts to detect walls on a 2D map and then
draws thin vertical rectangles on the screen proportional to each ray's length. A constant number of rays are cast for each degree of
the player's field of view. I chose two rays per degree (or one ray per 0.5 degrees) for aesthetic reasons.

The 2D map is broken up into a grid with walls occupying entire grid cells. Consequently, points of intersection between rays and walls can
be found by checking if a grid cell contains a wall whenever a ray crosses into it. This process is optimized by finding the vertical grid
line which is adjacent to the player in a ray's direction, calculating the y-component (*yv*) of the ray at that line's x-coordinate (*xv*),
checking if a wall occupies the cell that \[*xv yv*] is pointing to (relative to the player's position), terminating if it does, and recurring for the next vertical line if it
does not.

![IMG_0791](https://user-images.githubusercontent.com/30982485/173288733-1f70c778-52c9-4796-b1e8-30d3a133cbf9.jpg)

Between each recurrence of this process, a similar process for horizontal grid lines in the ray's direction is run. The main difference
being that it calculates the x-component (*xh*) of the ray at a horizontal line's y-coordinate (*yh*), and then checks
the cell that \[*xh yh*] is pointing to (again, relative to the player's position). These two processes will each return
a different vector. Whichever one is shorter will be used to calculate the distance to the wall from the player at the given angle.

![IMG_0792](https://user-images.githubusercontent.com/30982485/173289092-48fec7dc-f434-4585-a8a0-daf2a4045e8d.jpg)

After an intersection vector has been determined, it is projected onto the direction the player is looking. Then the height of the corresponding
rectangle is calculated as a function of the resulting vector's magnitude. This prevents the final render from developing
a fisheye effect.

## Screenshots
![s2](https://user-images.githubusercontent.com/30982485/107132108-3ce06500-68aa-11eb-9d7c-8b0ca6e87ba5.png)
![s3](https://user-images.githubusercontent.com/30982485/107132109-3ce06500-68aa-11eb-80f8-1aa034ecaee0.png)
![s1](https://user-images.githubusercontent.com/30982485/107132107-3baf3800-68aa-11eb-92a3-658276520121.png)
![s4](https://user-images.githubusercontent.com/30982485/107132110-3d78fb80-68aa-11eb-93da-f5ab3cd49b8a.gif)