Learn to Code via Tutorials on Repl.it!

← Back to all posts
Minecraft tutorial!
NVVC007

Minecraft tutorial!

Hi everyone! So, in this tutorial, you'll learn how to make minecraft in python! So, go to the original, and download all the files except for the code file. If you do, all my hard work is a waste and you don't learn anything! So please, don't download the code file! Go to command prompt or windows powershell and type pip install ursina. This won't work in Replit so open Visual Studio Code. If you don't have it, download it here. So, open the folder in Visual Studio Code (I hope you downloaded the files into a folder called assets) and create a new python file called Minecraft.py. Let's start with the imports.

Leave a line and type:

The block_pick variable shows which block the player is using. 1 is ground, 2 is stone, etc. Everything else loads the sprite sheet textures into the game. The punch_sound is the punching audio. So, leave a blank line and in the next two lines, type this:

You can also set window.fps_counter.enabled = True to window.fps_counter.enabled = False , but keeping it as window.fps_counter.enabled = True makes it easier to understand how FPS works. Leave a line and in the next line, add this definition:

This sets the block the player is using based on the numbers 1, 2, 3, and 4. Now, a class with definitions:

This spawns and deletes the blocks based on which key is pressed, and which block type it is. Now leave a line for the sky class:

So basically, this is the sphere in which the player is concealed in. Later, when we add the ground and you fall off, you'll see what I mean. So, now, leave a line and add the class for the player's hand:

This cuts the arm's sprite sheet(well, sort of) and pastes it onto the arm 3D object and checks whether it's active or not. Almost done! Now, let's add the ground.

This spawns a terrain with the length of 20 and breadth of 20 blocks. You can make it bigger, but it then it becomes a lot slower. And, to finish it off:

BANG! There you go, a fully functioning Minecraft game!

How FPS works

So, remember when I told you about FPS earlier? Now, let me explain that. Here, Visual Studio Code is actually creating and deleting many windows at once! If you set that line to window.fps_counter.enabled = True, look at the counter in the top right corner. You'll see that the numbers keep changing. That's how many frames Visual Studio Code creates and deletes per second. So, depending on that, the game is slower or faster.

Notes and credits

Thanks for reading this tutorial everyone! I hope you go away with better understanding of python and not just faster typing skills 😁. Thanks to @amasad for the tutorial on how to use Markdown. Thanks and bye!

Voters
LuqmanKhan1
NVVC007
Comments
hotnewtop
NVVC008

Cool! This is amazing!