how to make basic minecraft in python

Solutions on MaxInterview for how to make basic minecraft in python by the best coders in the world

showing results for - "how to make basic minecraft in python"
Audrey
09 Feb 2020
1#How to make basic MINECRAFT in python? You are in the right place!
2
3'''
4For this project, you need ursina installed. If you dont have ursina installed,
5use this command 
6pip install ursina
7and then wait for the process to finish
8'''
9
10#import ursina and the first person controller
11from ursina import * 
12from ursina.prefabs.first_person_controller import FirstPersonController
13
14#we make this 'app' so that we can let the program run 
15app = Ursina()
16
17'''
18each block in minecraft is a voxel, so we make a voxel class (the blocks)
19and we give these voxels some attributes
20'''
21class Voxel(Button):
22    def __init__(self, position = (0,0,0)):
23        super().__init__(
24            parent = scene,
25            position = position,
26            model = 'cube',
27            origin_y = 0.5,
28            texture = 'white_cube',
29            color = color.color(0,0,random.uniform(0.9,1)),
30            highlight_color = color.lime)
31#this method below allows us to mine and place blocks on key command
32    def input(self,key):
33        if self.hovered:
34            if key == 'left mouse down':
35                voxel = Voxel(position = self.position + mouse.normal)
36
37            if key == "right mouse down":
38                destroy(self)
39#the below tells us how big the field is going to be
40for z in range(20):
41    for x in range(20):
42        voxel = Voxel(position = (x,0,z))
43
44#this calls the first person controller
45player = FirstPersonController()
46
47#this makes ursina get called and runs the program
48app.run()
49
50#Run the program! Hopefully, it should work!!!!Good luck mining and crafting!
51
52#This project is also on ClearCode's channel, so thanks to ClearCode.