Convert Figma logo to code with AI

Hopson97 logoMineCraft-One-Week-Challenge

I challenged myself to see if I could create a voxel game (Minecraft-like) in just one week using C++ and OpenGL, and here is the result

2,633
377
2,633
14

Top Related Projects

10,380

A simple Minecraft clone written in C using modern OpenGL (shaders).

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com

Quick Overview

MineCraft-One-Week-Challenge is a project by Matthew Hopson that aims to recreate Minecraft in C++ within one week. It's a simplified version of the popular game, focusing on basic gameplay elements and rendering techniques. The project serves as an educational resource for game development enthusiasts.

Pros

  • Demonstrates rapid game development techniques
  • Provides a clear example of 3D voxel-based rendering in C++
  • Open-source, allowing for community contributions and learning
  • Achieves a playable Minecraft-like experience in a short timeframe

Cons

  • Limited features compared to the full Minecraft game
  • May contain bugs or performance issues due to the short development time
  • Lacks extensive documentation or detailed explanations of the code
  • Not actively maintained or updated

Code Examples

// Creating a simple cube
void createCube(float x, float y, float z)
{
    glm::vec3 cubePositions[] = {
        glm::vec3(x, y, z),
        glm::vec3(x + 1, y, z),
        glm::vec3(x + 1, y + 1, z),
        glm::vec3(x, y + 1, z)
    };

    for (int i = 0; i < 4; i++)
    {
        m_cubeVertices.push_back(cubePositions[i]);
    }
}

This code snippet demonstrates how to create a simple cube in the game world.

// Handling player movement
void Player::handleInput(const sf::RenderWindow& window, float dt)
{
    static auto lastMousePosition = sf::Mouse::getPosition(window);
    auto change = sf::Mouse::getPosition() - lastMousePosition;

    rotation.y += change.x * 0.05f;
    rotation.x += change.y * 0.05f;

    lastMousePosition = sf::Mouse::getPosition(window);

    // ... (additional movement logic)
}

This code example shows how player input is handled for camera rotation.

// Generating terrain
void Chunk::makeMesh()
{
    for (int y = 0; y < CHUNK_SIZE; y++)
    {
        for (int x = 0; x < CHUNK_SIZE; x++)
        {
            for (int z = 0; z < CHUNK_SIZE; z++)
            {
                Block block = getBlock(x, y, z);
                if (block == Block::Air)
                    continue;

                // ... (mesh generation logic)
            }
        }
    }
}

This code snippet illustrates how terrain is generated using a chunk-based system.

Getting Started

To get started with the MineCraft-One-Week-Challenge project:

  1. Clone the repository:

    git clone https://github.com/Hopson97/MineCraft-One-Week-Challenge.git
    
  2. Install dependencies (SFML, GLM, etc.) as specified in the project's README.

  3. Build the project using CMake:

    mkdir build && cd build
    cmake ..
    make
    
  4. Run the executable:

    ./MineCraft
    

Note: Detailed setup instructions and requirements can be found in the project's README file.

Competitor Comparisons

10,380

A simple Minecraft clone written in C using modern OpenGL (shaders).

Pros of Craft

  • More mature and feature-rich project with a longer development history
  • Better performance and optimization for rendering large voxel worlds
  • Includes multiplayer support out of the box

Cons of Craft

  • Less focused on educational aspects or rapid development
  • More complex codebase, potentially harder for beginners to understand
  • Lacks some of the modern C++ features used in MineCraft-One-Week-Challenge

Code Comparison

MineCraft-One-Week-Challenge uses modern C++ features:

auto& chunkManager = m_world.getChunkManager();
auto* chunk = chunkManager.getChunk(blockPosition.x, blockPosition.z);

Craft uses a more traditional C approach:

int x = roundf(p->x);
int y = roundf(p->y);
int z = roundf(p->z);
int w = get_block(x, y, z);

Both projects use OpenGL for rendering, but Craft's implementation is more optimized for large-scale voxel worlds. MineCraft-One-Week-Challenge focuses on rapid development and modern C++ practices, while Craft prioritizes performance and established game development techniques.

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com

Pros of LearnOpenGL

  • Comprehensive tutorial series covering various OpenGL concepts
  • Well-structured content with clear explanations and code examples
  • Regularly updated with new topics and improvements

Cons of LearnOpenGL

  • Focuses solely on OpenGL, lacking game development specifics
  • May be overwhelming for beginners due to its extensive content
  • Less hands-on project experience compared to MineCraft-One-Week-Challenge

Code Comparison

LearnOpenGL:

glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);

MineCraft-One-Week-Challenge:

m_texture.loadFromFile("Res/Textures/Atlas.png");
m_shader.loadFromFile("Res/Shaders/Basic_Vertex.glsl", "Res/Shaders/Basic_Fragment.glsl");
m_cubeModel.create();
m_cubeModel.addData({vertexPositions, textureCoords, indices});
m_cubeModel.addVBO(3, vertexPositions);

The LearnOpenGL code focuses on low-level OpenGL operations, while MineCraft-One-Week-Challenge uses higher-level abstractions for game development tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

MineCraft-One-Week-Challenge

I challenged myself to see if I could create Minecraft in just one week... So lets go!

Video: https://www.youtube.com/watch?v=Xq3isov6mZ8

Note: I continued to edit after the 7 days, however the version seen in the video is found here https://github.com/Hopson97/MineCraft-One-Week-Challenge/tree/eb01640580cc5ad403f6a8b9fb58af37e2f03f0c

And the "optimized" version can be found here: https://github.com/Hopson97/MineCraft-One-Week-Challenge/tree/792df07e9780b444be5290fd05a3c8598aacafc8 (~1 week later version)

There also is a version of this game with very good graphics, and things like a day/night cycle. However, it was causing rendering issues for many people. This version can be found here: https://github.com/Hopson97/MineCraft-One-Week-Challenge/tree/aa50ad8077ef0e617a9cfc336bdb7db81c313017

Other People's Projects

This was made in a week, as a challenge for a video. There do exist other, more mature and developed Minecraft clones written in C++.

MineTest here: https://github.com/minetest/minetest

Building

You will need GLM and SFML 2.4.1+ libraries w/headers, and this also requires a compiler that supports C++14 (or newer) with threads.

macOS

Install macports from https://www.macports.org

sudo port install sfml glm

Ubuntu

sudo apt-get install libsfml-dev libglm-dev

Compile Source and Running

Linux

Debug

sh scripts/build.sh
sh scripts/run.sh

Release

sh scripts/build.sh release
sh scripts/run.sh release

The Challenge

Day One

End of day one commit: https://github.com/Hopson97/MineCraft-One-Week-Challenge/tree/44ace72573833796da05a97972be5765b05ce94f

The first day was spent setting up boilerplate code such as the game state/ game screen system, and the basic rendering engines, starting off with a mere quad.

The day was finished off by creating a first person camera.

Quad

End of day stats:

TitleData
Time programming Today3:21:51
Lines of Code Today829
Total Time programming3:21:51
Total Lines of Code829

Day Two

End of day two commit: https://github.com/Hopson97/MineCraft-One-Week-Challenge/tree/98055215f735335de80193221a30c0bb8586fba5

The second day was spent setting up the basic ChunkSection and various block classes.

I also worked out the coordinates for a cube, and thus created a cube renderer.

I finished up the day attempting to create a mesh builder for the chunk; however, this did not go well at all, and two had ended before I got it to work correctly.

Messed up chunk

End of day stats:

TitleData
Time programming Today4:16:07
Lines of Code Today732
Total Time programming7:37:58
Total Lines of Code1561

Day Three

End of day three commit: https://github.com/Hopson97/MineCraft-One-Week-Challenge/commit/78bd637581542576372d75cf7638f76381e933b4

To start the day off, I fixed the chunk drawing. Turns out I was telling OpenGL the indices were GL_UNSIGNED_BYTE, but they were actually GL_UNSIGNED_INT. This took 3 hours to work out...

gl bytesss

Anyways, after this I got the game working with more chunks. I now have an area of 16x16 chunks, made out of chunk sections of 16x16x16 blocks.

To finish the day off, I got some naive block editing to work.

Block editing

End of day stats:

TitleData
Time programming Today3:15:38
Lines of Code Today410
Total Time programming10:53:36
Total Lines of Code1974

Day 4

The first thing I did on day 4 was create a sky box using OpenGL cube maps.

After this, I started work on the world generation, eg adding height map and trees.

Skybox and world gen

End of day stats:

TitleData
Time programming Today3:14:15
Lines of Code Today523
Total Time programming14:07:51
Total Lines of Code2489

Day 5

I started off the day by cleaning up some of the chunk code, and then proceeded to make the world infinite, but I felt it was not needed, so I simply went back to a fixed-sized world.

I then added an item system. My implementation probably was not great for this, but it was my first time at creating that sort of the thing.

Basically, when a player breaks a block, it gets added to their inventory. When they place a block, a block is placed.

TitleData
Time programming Today2:54:14
Lines of Code Today560
Total Time programming17:02:05
Total Lines of Code3049

Day 6

Mostly optimizations, such as view-frustum culling and making the mesh building faster.

Day 7

Focus on improving how it looks, eg adding directional lighting

Also implemented concurrency :)