forked from pokepetter/ursina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minecraft_clone.py
48 lines (36 loc) · 1.45 KB
/
minecraft_clone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Disclaimer: This solution is not scalable for creating a big world.
Creating a game like Minecraft requires specialized knowledge and is not as easy
to make as it looks.
You'll have to do some sort of chunking of the world and generate a combined mesh
instead of separate blocks if you want it to run fast. You can use the Mesh class for this.
You can then use blocks with colliders like in this example in a small area
around the player so you can interact with the world.
'''
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
# Define a Voxel class.
# By setting the parent to scene and the model to 'cube' it becomes a 3d button.
class Voxel(Button):
def __init__(self, position=(0,0,0)):
super().__init__(parent=scene,
position=position,
model='cube',
origin_y=.5,
texture='white_cube',
color=color.color(0, 0, random.uniform(.9, 1.0)),
highlight_color=color.lime,
)
for z in range(8):
for x in range(8):
voxel = Voxel(position=(x,0,z))
def input(key):
if key == 'left mouse down':
hit_info = raycast(camera.world_position, camera.forward, distance=5)
if hit_info.hit:
Voxel(position=hit_info.entity.position + hit_info.normal)
if key == 'right mouse down' and mouse.hovered_entity:
destroy(mouse.hovered_entity)
player = FirstPersonController()
app.run()