Mini Minecraft : C++

As a final project in a computer graphics class, two of my friends and I worked together to create a custom, underwater version of Minecraft. To achieve this, we each worked on a portion of the game using C++ and the OpenGL pipeline / GLSL. I worked on game engine updates, player physics, multithreaded terrain generation, basic GUI and inventory, post-process shading effects, and sound.

GAME ENGINE UPDATE   ————

The player views the environment through a spherical camera model, where the camera / player is located at the center of a "sphere" representing all the different directions the player can move; traditional WASD controls move the player forward, left, backwards, and right, and the position of the mouse determines the direction the player is facing, much like traditional Minecraft. While the game is open, a tick() function repeatedly calculates elapsed time and updates player position or the environment as needed. When a movement is required, a velocity is applied in the correct direction, and the player's new position is calculated as a function of velocity and time elapsed.

PLAYER PHYSICS   ————

As mentioned above, the player's position is calculated as a function of an applied velocity and elapsed time. In this version of Minecraft, there are two primary modes of transportation: walking / swimming and flying. Whenever in the first mode, whenever the player moves, the game must check for collisions; the player should never walk through a block or fall through the ground. I implemented gravity (collision-checking in the y-direction) by simply checking if there was a non-empty block below the player's feet (the player was set to be 2 blocks high), and I used the same method to check if there is a block above the player's head. In the x-z direction, I used ray-marching to find if there are any blocks in the player's path, and if so, to stop at a certain distance away. I wanted the player to jump repeatedly when the spacebar was pressed, and so to accomplish that, I used several booleans to track the player's current state (falling, jumping, grounded, etc). When the player is moving through water or lava, the player moves slower and keeps falling until hitting the ground unless the spacebar is pressed.

MULTITHREADED TERRAIN GENERATION   ————

The large terrain, whose heightfield is generated by an FBM noise function, is broken into several smaller pieces called "chunks." To allow for smoother gameplay and less lag, each chunk is generated only when the player is a certain distance away from it, and expensive FBM functions are multithreaded so several chunks can generate efficiently at the same time. As more textures were added, the cost of generating VBOs also started to become a problem, and each chunk stored its VBO data as a set of vectors that were also generated concurrently. Once each chunk's FBM function and VBO data was correctly calculated by its worker threads, the data was sent from the main thread to the GPU to render the scene.

BASIC GUI & INVENTORY   ————

When the "I" key is pressed, a simple crosshair display and item bar appear on screen. The player can choose a blocktype to place by using the right and left arrow keys, and by right-clicking on the screen, the selected block type will be added to the terrain.

POST-PROCESS SHADING   ————

I set up a post-process shading pipeline and frame buffer to add underwater effects to the entire screen. Throughout the entire game, there is a slight Worley-noise distortion that creates a stronger illusion of being underwater. Our game also contains underwater rivers and streams as well as volcanic areas filled with lava. When the user goes under these bodies of water or into lava, an even stronger distortion and color overlay is applied.

SOUND   ————

I added a gentle splashing sound effect that looped with the game engine tick function to create an underwater ambience for the player, and I added various other sound effects throughout the game. There are sound effects for splashing down into the underwater river, placing blocks, removing blocks, and walking through lava.