making minecraft with python code example
Example: how to make basic minecraft in python
'''
For this project, you need ursina installed. If you dont have ursina installed,
use this command
pip install ursina
and then wait for the process to finish
'''
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
'''
each block in minecraft is a voxel, so we make a voxel class (the blocks)
and we give these voxels some attributes
'''
class Voxel(Button):
def __init__(self, position = (0,0,0)):
super().__init__(
parent = scene,
position = position,
model = 'cube',
origin_y = 0.5,
texture = 'white_cube',
color = color.color(0,0,random.uniform(0.9,1)),
highlight_color = color.lime)
def input(self,key):
if self.hovered:
if key == 'left mouse down':
voxel = Voxel(position = self.position + mouse.normal)
if key == "right mouse down":
destroy(self)
for z in range(20):
for x in range(20):
voxel = Voxel(position = (x,0,z))
player = FirstPersonController()
app.run()