Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 3.35 KB

README.md

File metadata and controls

97 lines (71 loc) · 3.35 KB

CloneCraft

An implementation of a simple voxel game inspired by Minecraft. It is written in C++ 17 and uses OpenGL 3.3 and SFML 2.5. The game is written with efficiency and simplicity in mind.

Screenshot

Controls

  • WASD, space and left shift to move
  • Left-click to destroy a block
  • Right-click to place a block
  • Middle-click to pick a block
  • Mouse wheel to zoom
  • T to teleport
  • E to create an explosion
  • Alt + E to create a huge explosion
  • G to change gamemode

Implementation details

World

The world consists of chunks of 32x32 blocks that are loaded and unloaded as the player moves. These chunks are divided in sections with an height of 32 blocks and are unlimited in height. The loading of the chunks is made in an other thread. A new thread is also created when a set of sections is updated.

Terrain generation

The terrain consists of multiple octaves of perlin noise. Biomes are generated using noises representing temperature and altitude. A smooth interpolation allows to make smooth transitions between biomes. The structures are generated by dividing the world horizontally in small areas and randomly selecting a potential position in an area.

Mesh creation

Meshes are generated in each section to represent blocks and water. A mesh consists of potentially visible faces of a block. Aligned blocks with the same texture are merged in a same face.

Rendering

Blocks and water are rendered using shaders. The textures of the blocks are stored in an OpenGL texture array. The fog and water effects are implemented in the shaders. The water reflection is simulated by rendering the world symetrically on the other side of the water and drawing it on the water position. Movements in the water are created with a DuDv map. Frustum culling allows to render only visible chunks .

Collisions

Collisions are detected using the Swept AABB algorithm. This algorithm makes it impossible for the player to pass through an obstacle. Between two frames, all of the blocks that the player potentially collides with are checked in a specific order. After a collision, the velocity on the axis of collision is set to 0. The process is repeated 3 times, so that the remaining velocity on each axis is used.

Target block

The block the player is pointing at is found by computing exactly each block in the line of sight of the player, never skipping over a block.

Installation

Some binaries are available for Windows on GitHub. The project can be compiled with CMake. It has been developed on Windows and Ubuntu.

Ubuntu:

git clone https://github.com/Vekteur/clonecraft
sudo apt install cmake libsfml-dev libglm-dev
cmake . -B build -DCMAKE_BUILD_TYPE=release
cmake --build build --config Release --target all -j 12
./build/clonecraft

You can also use, for example, VS Code with CMake Tools to edit and compile the code.

Windows:

Install SFML and GLM using, for example, vcpkg:

vcpkg install sfml glm
vcpkg integrate install

An easy way to compile the code is to open the project with Visual Studio 2019/2022 and select the target clonecraft.exe.

Future additions

  • Dynamic lighting
  • Water physics
  • Simple electricity system
  • Ambient occlusion
  • Workaround to stop rendering the refraction texture twice